Skip to content

Commit

Permalink
Build & getconf fixes for macOS (and UnixWare)
Browse files Browse the repository at this point in the history
src/lib/libast/features/standards:
- Add heuristic (u_long availability) for systems that hide rather
  than reveal functionality in the presence of _POSIX_SOURCE, etc.
- Define _DARWIN_C_SOURCE, like _GNU_SOURCE, to enable the full
  range of definitions on macOS systems.
- Due to the above, remove MACH (macOS)-specific hack.
- These changes ported from att#1492 -
  thanks to Lev Kujawski (@lkujaw). His PR indicates that this
  fixes the standards macros on UnixWare, too. Therefore, no longer
  exclude UnixWare from standards macros (re: ff70c27).

src/lib/libast/comp/conf.sh:
- Promote the 'op' member in Conf_t (struct Conf_s) from short to
  int. This allows some Darwin/macOS values, now exposed, to fit
  that would otherwise be truncated, namely:
  _CS_DARWIN_USER_CACHE_DIR               65538
  _CS_DARWIN_USER_DIR                     65536
  _CS_DARWIN_USER_TEMP_DIR                65537
  Thus, the following AST getconf values are now correct on macOS:
  $ /opt/ast/bin/getconf | grep ^DARWIN
  DARWIN_USER_CACHE_DIR=/var/folders/nx/(REDACTED)/C/
  DARWIN_USER_DIR=/var/folders/nx/(REDACTED)/0/
  DARWIN_USER_TEMP_DIR=/var/folders/nx/(REDACTED)/T/

src/lib/libast/features/tty:
- Include <sys/ioctl.h> if available. This silences a compiler
  warning in src/lib/libast/misc/procopen.c about an invalid
  implicit declaration of ioctl(2).
  • Loading branch information
McDutchie committed Dec 6, 2021
1 parent e18cf64 commit d431900
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/lib/libast/comp/conf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1546,7 +1546,7 @@ struct Conf_s
short standard;
short section;
short call;
short op;
int op;
};
typedef struct Prefix_s
Expand Down
77 changes: 53 additions & 24 deletions src/lib/libast/features/standards
Original file line number Diff line number Diff line change
@@ -1,29 +1,39 @@
set stdio

# Flag systems that omit necessary definitions such as u_long
# when _POSIX_SOURCE or _XOPEN_SOURCE are defined.
# Affected: Mac OS X, UnixWare.
typ u_long

# In FreeBSD, definitions like _POSIX_SOURCE and such are used to *limit*
# functionality to known API; they don't enable anything. The general intent in
# BSD is to enable everything by default (effectively, providing the
# _KITCHEN_SINK_SOURCE mentioned below). So we look for that here, but stay
# BSD is to enable everything by default. So we look for that here, but stay
# careful that we don't get fooled by presence of FreeBSD that underpins some
# subsystems in Mac OS X; there are other Apple-specific portability hacks
# elsewhere we should not interfere with.
if tst note{ FreeBSD, DragonFly BSD, or UnixWare }end compile{
if tst note{ FreeBSD or DragonFly BSD }end compile{
#include <sys/param.h>
#if (!defined(__FreeBSD__) && !defined(__DragonFly__) && !defined(__USLC__)) || defined(APPLE)
#error not a FreeBSD or DragonFly BSD system
#if (!defined(__FreeBSD__) && !defined(__DragonFly__)) || defined(__APPLE__) || defined(__MACH__)
#error not one of the listed systems
#endif
}end {
}
elif tst note{ _ALL_SOURCE & _POSIX_SOURCE & _POSIX_C_SOURCE & _XOPEN_SOURCE & __EXTENSIONS__ works }end compile{
elif tst note{ _ALL_SOURCE & _POSIX_SOURCE & _POSIX_C_SOURCE & _XOPEN_SOURCE & _GNU_SOURCE & _DARWIN_C_SOURCE & __EXTENSIONS__ works }end compile{
#define _ALL_SOURCE 1
#define _POSIX_SOURCE 1
#define _POSIX_C_SOURCE 21000101L
#define _XOPEN_SOURCE 9900
#define _GNU_SOURCE 1
#define _DARWIN_C_SOURCE 1
#define __EXTENSIONS__ 1
#include <sys/types.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#if _typ_u_long
u_long _test_dummy_;
#endif
}end {
#ifndef _ALL_SOURCE
#define _ALL_SOURCE 1
Expand All @@ -40,20 +50,28 @@ elif tst note{ _ALL_SOURCE & _POSIX_SOURCE & _POSIX_C_SOURCE & _XOPEN_SOURCE & _
#ifndef _GNU_SOURCE
#define _GNU_SOURCE 1
#endif
#ifndef _DARWIN_C_SOURCE
#define _DARWIN_C_SOURCE 1
#endif
#ifndef __EXTENSIONS__
#define __EXTENSIONS__ 1
#endif
}
elif tst note{ _ALL_SOURCE & _POSIX_SOURCE & _XOPEN_SOURCE & __EXTENSIONS__ works }end compile{
elif tst note{ _ALL_SOURCE & _POSIX_SOURCE & _XOPEN_SOURCE & _GNU_SOURCE & _DARWIN_C_SOURCE & __EXTENSIONS__ works }end compile{
#define _ALL_SOURCE 1
#define _POSIX_SOURCE 1
#define _XOPEN_SOURCE 9900
#define _GNU_SOURCE 1
#define _DARWIN_C_SOURCE 1
#define __EXTENSIONS__ 1
#include <sys/types.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#if _typ_u_long
u_long _test_dummy;
#endif
}end {
#ifndef _ALL_SOURCE
#define _ALL_SOURCE 1
Expand All @@ -67,20 +85,28 @@ elif tst note{ _ALL_SOURCE & _POSIX_SOURCE & _XOPEN_SOURCE & __EXTENSIONS__ work
#ifndef _GNU_SOURCE
#define _GNU_SOURCE 1
#endif
#ifndef _DARWIN_C_SOURCE
#define _DARWIN_C_SOURCE 1
#endif
#ifndef __EXTENSIONS__
#define __EXTENSIONS__ 1
#endif
}
elif tst note{ _POSIX_SOURCE & _POSIX_C_SOURCE & _XOPEN_SOURCE & __EXTENSIONS__ works }end compile{
elif tst note{ _POSIX_SOURCE & _POSIX_C_SOURCE & _XOPEN_SOURCE & _GNU_SOURCE & _DARWIN_C_SOURCE & __EXTENSIONS__ works }end compile{
#define _POSIX_SOURCE 1
#define _POSIX_C_SOURCE 21000101L
#define _XOPEN_SOURCE 9900
#define _GNU_SOURCE 1
#define _DARWIN_C_SOURCE 1
#define __EXTENSIONS__ 1
#include <sys/types.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#if _typ_u_long
u_long _test_dummy;
#endif
}end {
#ifndef _POSIX_SOURCE
#define _POSIX_SOURCE 1
Expand All @@ -94,6 +120,9 @@ elif tst note{ _POSIX_SOURCE & _POSIX_C_SOURCE & _XOPEN_SOURCE & __EXTENSIONS__
#ifndef _GNU_SOURCE
#define _GNU_SOURCE 1
#endif
#ifndef _DARWIN_C_SOURCE
#define _DARWIN_C_SOURCE 1
#endif
#ifndef __EXTENSIONS__
#define __EXTENSIONS__ 1
#endif
Expand All @@ -106,6 +135,10 @@ elif tst note{ _POSIX_SOURCE & _XOPEN_SOURCE & __EXTENSIONS__ works }end compile
#include <sys/stat.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#if _typ_u_long
u_long _test_dummy;
#endif
}end {
#ifndef _POSIX_SOURCE
#define _POSIX_SOURCE 1
Expand All @@ -124,6 +157,10 @@ elif tst note{ _XOPEN_SOURCE & __EXTENSIONS__ works }end compile{
#include <sys/stat.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#if _typ_u_long
u_long _test_dummy;
#endif
}end {
#ifndef _XOPEN_SOURCE
#define _XOPEN_SOURCE 1
Expand All @@ -138,6 +175,10 @@ elif tst note{ _XOPEN_SOURCE works }end compile{
#include <sys/stat.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#if _typ_u_long
u_long _test_dummy;
#endif
}end {
#ifndef _XOPEN_SOURCE
#define _XOPEN_SOURCE 1
Expand All @@ -147,6 +188,10 @@ else tst note{ __EXTENSIONS__ works }end compile{
#define __EXTENSIONS__ 1
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#if _typ_u_long
u_long _test_dummy;
#endif
}end {
#ifndef __EXTENSIONS__
#define __EXTENSIONS__ 1
Expand All @@ -167,19 +212,3 @@ if tst -D_ISOC99_SOURCE -lm note{ _ISOC99_SOURCE plays nice }end link{
#endif
}
endif

cat{

/*
* this is a nasty game we all play to honor standards symbol visibility
* it would help if all implementations had
* _KITCHEN_SINK_SOURCE
* that enabled all symbols from the latest implemented standards
* that's probably the most useful but least portable request
*/

#if __MACH__
#undef _POSIX_SOURCE
#endif

}end
6 changes: 5 additions & 1 deletion src/lib/libast/features/tty
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
hdr termios,termio,sgtty
hdr termios,termio,sgtty,sys/ioctl
sys termios,termio,ioctl,bsdtty,nttyio,ttyio
lib tcgetattr,tcgetpgrp termios.h
mac _POSIX_VDISABLE termios.h
Expand Down Expand Up @@ -107,6 +107,10 @@ cat{
# endif /* TCSANOW */
#endif /* _hdr_termios */

#if _hdr_sys_ioctl
# include <sys/ioctl.h>
#endif

/* set ECHOCTL if driver can echo control characters as ^c */
#ifdef LCTLECH
# ifndef ECHOCTL
Expand Down

1 comment on commit d431900

@McDutchie
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lkujaw, could you confirm that ksh 93u+m builds correctly on UnixWare after this commit? It gives UnixWare the standards macros again after your fix from att#1492.

Please sign in to comment.