From 17f13345dcbe873c8583ca56b39d88c537263aa1 Mon Sep 17 00:00:00 2001 From: Martijn Dekker Date: Mon, 6 Dec 2021 08:35:29 +0100 Subject: [PATCH] Build & getconf fixes for macOS (and UnixWare) 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 https://github.com/att/ast/pull/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: ff70c27f). 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 if available. This silences a compiler warning in src/lib/libast/misc/procopen.c about an invalid implicit declaration of ioctl(2). --- src/lib/libast/comp/conf.sh | 2 +- src/lib/libast/features/standards | 77 +++++++++++++++++++++---------- src/lib/libast/features/tty | 6 ++- 3 files changed, 59 insertions(+), 26 deletions(-) diff --git a/src/lib/libast/comp/conf.sh b/src/lib/libast/comp/conf.sh index adde98f18..7e9c0ae11 100644 --- a/src/lib/libast/comp/conf.sh +++ b/src/lib/libast/comp/conf.sh @@ -1546,7 +1546,7 @@ struct Conf_s short standard; short section; short call; - short op; + int op; }; typedef struct Prefix_s diff --git a/src/lib/libast/features/standards b/src/lib/libast/features/standards index 1d329ea8a..0d871a653 100644 --- a/src/lib/libast/features/standards +++ b/src/lib/libast/features/standards @@ -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 - #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 #include #include #include + #include + #if _typ_u_long + u_long _test_dummy_; + #endif }end { #ifndef _ALL_SOURCE #define _ALL_SOURCE 1 @@ -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 #include #include #include + #include + #if _typ_u_long + u_long _test_dummy; + #endif }end { #ifndef _ALL_SOURCE #define _ALL_SOURCE 1 @@ -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 #include #include #include + #include + #if _typ_u_long + u_long _test_dummy; + #endif }end { #ifndef _POSIX_SOURCE #define _POSIX_SOURCE 1 @@ -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 @@ -106,6 +135,10 @@ elif tst note{ _POSIX_SOURCE & _XOPEN_SOURCE & __EXTENSIONS__ works }end compile #include #include #include + #include + #if _typ_u_long + u_long _test_dummy; + #endif }end { #ifndef _POSIX_SOURCE #define _POSIX_SOURCE 1 @@ -124,6 +157,10 @@ elif tst note{ _XOPEN_SOURCE & __EXTENSIONS__ works }end compile{ #include #include #include + #include + #if _typ_u_long + u_long _test_dummy; + #endif }end { #ifndef _XOPEN_SOURCE #define _XOPEN_SOURCE 1 @@ -138,6 +175,10 @@ elif tst note{ _XOPEN_SOURCE works }end compile{ #include #include #include + #include + #if _typ_u_long + u_long _test_dummy; + #endif }end { #ifndef _XOPEN_SOURCE #define _XOPEN_SOURCE 1 @@ -147,6 +188,10 @@ else tst note{ __EXTENSIONS__ works }end compile{ #define __EXTENSIONS__ 1 #include #include + #include + #if _typ_u_long + u_long _test_dummy; + #endif }end { #ifndef __EXTENSIONS__ #define __EXTENSIONS__ 1 @@ -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 diff --git a/src/lib/libast/features/tty b/src/lib/libast/features/tty index 34ea8ed2e..179e0e85a 100644 --- a/src/lib/libast/features/tty +++ b/src/lib/libast/features/tty @@ -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 @@ -107,6 +107,10 @@ cat{ # endif /* TCSANOW */ #endif /* _hdr_termios */ +#if _hdr_sys_ioctl +# include +#endif + /* set ECHOCTL if driver can echo control characters as ^c */ #ifdef LCTLECH # ifndef ECHOCTL