1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-03-09 15:50:02 +00:00

Sanitise standards/feature macros, remove compiler/linker wrappers

The goal is to get rid of all compiler/linker wrapper scripts as
they are overridden by passing CC/LD and it should be possible to
select your compiler or linker without breaking the build. The
probing and feature testing system should set the appropriate flags
and macros. This makes some progress towards that.

src/lib/libast/features/standards:
- Eliminate the shotgun approach to standards macros on popular
  systems where the macros we we need to set are known and
  documented. The following will enable standards compliance plus
  all the available extensions:
  - Set no macros at all for any BSD system (excluding macOS).
  - Set _DARWIN_C_SOURCE on Darwin/macOS.
  - Set everything and the kitchen sink for Solaris/illumos in
    a way that enables backwards compatibility with older Solaris.
    This is unofficial, but following the standards(5) manual
    disables a lot of basic functionality that we depend on.
  - Set _GNU_SOURCE for GNU (glibc).
  - Remove the covered macros from the shotgun approach fallback.
- Add a new heuristic. _POSIX_PATH_MAX and _SC_PAGESIZE are among
  the basic macros disabled when you pass recommended standards
  macros, killing the build, so it's good to check if they compile.

src/cmd/INIT/ar.freebsd12.amd64,
src/cmd/INIT/ar.linux.i386-64:
- Removed. May cause build failures on some systems as not all 'ar'
  implementations support the U option. Plus, I can think of no
  good reason to disable deterministic mode (which always creates
  identical output) on 'ar' implementations that support it. See:
  https://groups.google.com/g/comp.unix.shell/c/LdOD1Ya0C9E/m/U6DhgHVICwAJ

src/cmd/INIT/cc.linux.*-icc,
  Removed icc wrappers. These manually source /etc/profile.d/icc.sh
  but I don't think that is the build system's job. Profile scripts
  should be run at login time and export variables we inherit
  through the environment.

src/cmd/INIT.cc.{freebsd,linux,openbsd}*:
- Removed. Should be entirely superfluous now that the standards
  feature test sets the appropriate macros.

src/cmd/INIT.cc.sol11.*:
- Removed as the standards feature test now sets the approopriate
  macros. Note the Solaris build system should now simply pass CC
  as normal instead of passing CC_EXPLICIT.
This commit is contained in:
Martijn Dekker 2021-12-20 12:21:37 +00:00
parent d3f553ca76
commit 24fc1bbca9
15 changed files with 138 additions and 236 deletions

View file

@ -1,6 +0,0 @@
: freebsd12.amd64 ar wrapper
case $1 in
*x*) /usr/bin/ar "$@" ;;
*) /usr/bin/ar U"$@" ;;
esac

View file

@ -1,6 +0,0 @@
: linux.i386-64 ar wrapper
case $1 in
*x*) /usr/bin/ar "$@" ;;
*) /usr/bin/ar U"$@" ;;
esac

View file

@ -1,9 +0,0 @@
: FreeBSD cc wrapper
HOSTTYPE=freebsd.generic
case " $* " in
*" -dumpmachine "*) echo $HOSTTYPE; exit ;;
esac
exec /usr/bin/cc -P "$@"

View file

@ -1,9 +0,0 @@
: linux cc wrapper : 2021-04-08 :
HOSTTYPE=linux.generic
case " $* " in
*" -dumpmachine "*) echo $HOSTTYPE; exit ;;
esac
exec /usr/bin/cc -P -D_LARGEFILE64_SOURCE "$@"

View file

@ -1,9 +0,0 @@
: linux.aarch64 cc wrapper : 2006-02-14 :
HOSTTYPE=linux.aarch64
case " $* " in
*" -dumpmachine "*) echo $HOSTTYPE; exit ;;
esac
/usr/bin/cc -P "$@"

View file

@ -1,9 +0,0 @@
: linux.i386-64 cc wrapper : 2006-02-14 :
HOSTTYPE=linux.i386-64
case " $* " in
*" -dumpmachine "*) echo $HOSTTYPE; exit ;;
esac
/usr/bin/cc -P "$@"

View file

@ -1,22 +0,0 @@
: linux.i386-64 icc wrapper : 2011-10-18 :
HOSTTYPE=linux.i386-64-icc
case " $* " in
*" -dumpmachine "*) echo $HOSTTYPE; exit ;;
esac
icc=$(which icc 2>/dev/null)
case $icc in
"") if test -f /etc/profile.d/icc.sh
then . /etc/profile.d/icc.sh
fi
icc=$(which icc 2>/dev/null)
case $icc in
"") echo icc: not found >&2
exit 127
;;
esac
;;
esac
$icc "$@"

View file

@ -1,22 +0,0 @@
: linux.i386 icc wrapper : 2021-01-31 :
HOSTTYPE=linux.ia64-icc
case " $* " in
*" -dumpmachine "*) echo $HOSTTYPE; exit ;;
esac
icc=$(which icc 2>/dev/null)
case $icc in
"") if test -f /etc/profile.d/icc.sh
then . /etc/profile.d/icc.sh
fi
icc=$(which icc 2>/dev/null)
case $icc in
"") echo icc: not found >&2
exit 127
;;
esac
;;
esac
exec "$icc" -D_LARGEFILE64_SOURCE "$@"

View file

@ -1,22 +0,0 @@
: linux.ia64 icc wrapper : 2011-10-18 :
HOSTTYPE=linux.ia64-icc
case " $* " in
*" -dumpmachine "*) echo $HOSTTYPE; exit ;;
esac
icc=$(which icc 2>/dev/null)
case $icc in
"") if test -f /etc/profile.d/icc.sh
then . /etc/profile.d/icc.sh
fi
icc=$(which icc 2>/dev/null)
case $icc in
"") echo icc: not found >&2
exit 127
;;
esac
;;
esac
$icc "$@"

View file

@ -1,9 +0,0 @@
: OpenBSD cc wrapper
HOSTTYPE=openbsd.generic
case " $* " in
*" -dumpmachine "*) echo $HOSTTYPE; exit ;;
esac
exec /usr/bin/cc -P "$@"

View file

@ -1,18 +0,0 @@
: solaris.i386 cc wrapper for 32 bit : 2021-05-12 :
HOSTTYPE=sol11.i386
case " $* " in
*" -dumpmachine "*) echo $HOSTTYPE; exit ;;
esac
# Solaris build scripts set $CC_EXPLICIT. If not set, function without it.
case ${CC_EXPLICIT:=$CC} in
'' | cc)
PATH=`/usr/bin/getconf PATH` # avoid infinite recursion executing 'cc'
CC_EXPLICIT=cc
esac
# Note: the _XPG6 macro is now defined in src/lib/libast/features/common
$CC_EXPLICIT -m32 -std=c11 "$@"

View file

@ -1,18 +0,0 @@
: solaris.i386-64 cc wrapper for 64 bit : 2021-05-12 :
HOSTTYPE=sol11.i386-64
case " $* " in
*" -dumpmachine "*) echo $HOSTTYPE; exit ;;
esac
# Solaris build scripts set $CC_EXPLICIT. If not set, function without it.
case ${CC_EXPLICIT:=$CC} in
'' | cc)
PATH=`/usr/bin/getconf PATH` # avoid infinite recursion executing 'cc'
CC_EXPLICIT=cc
esac
# Note: the _XPG6 macro is now defined in src/lib/libast/features/common
$CC_EXPLICIT -m64 -std=c11 "$@"

View file

@ -1,18 +0,0 @@
: solaris.sparc cc wrapper for 32 bit : 2021-05-12 :
HOSTTYPE=sol11.sparc
case " $* " in
*" -dumpmachine "*) echo $HOSTTYPE; exit ;;
esac
# Solaris build scripts set $CC_EXPLICIT. If not set, function without it.
case ${CC_EXPLICIT:=$CC} in
'' | cc)
PATH=`/usr/bin/getconf PATH` # avoid infinite recursion executing 'cc'
CC_EXPLICIT=cc
esac
# Note: the _XPG6 macro is now defined in src/lib/libast/features/common
$CC_EXPLICIT -m32 -std=c11 "$@"

View file

@ -1,18 +0,0 @@
: solaris.sparc-64 cc wrapper for 64 bit : 2021-05-12 :
HOSTTYPE=sol11.sparc-64
case " $* " in
*" -dumpmachine "*) echo $HOSTTYPE; exit ;;
esac
# Solaris build scripts set $CC_EXPLICIT. If not set, function without it.
case ${CC_EXPLICIT:=$CC} in
'' | cc)
PATH=`/usr/bin/getconf PATH` # avoid infinite recursion executing 'cc'
CC_EXPLICIT=cc
esac
# Note: the _XPG6 macro is now defined in src/lib/libast/features/common
$CC_EXPLICIT -m64 -std=c11 "$@"

View file

@ -6,44 +6,151 @@ set stdio
# 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. 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 or DragonFly BSD }end compile{
#
# The following tests try to define the features/standards macros that expose
# as much functionality as possible on the current system. We've got our own
# feature test framework, iffe, so we want POSIX + all possible extensions.
#
# The results of these are included in everything that uses libast and
# (as of 2021-12-06) also in all subsequent feature tests run by iffe.
#
# Note: The code between compile{ ... }end is the feature test; the text
# in the subsequent { ... } block is output literally to FEATURE/standards.
#
if tst note{ BSD (Free, Net, Open, et al) }end compile{
/*
* On BSD systems, _POSIX_SOURCE and such are used to *limit* functionality to a known API;
* they don't enable anything. The general intent in BSD is to enable everything by default.
*/
#include <limits.h>
#include <unistd.h>
#include <sys/param.h>
#if (!defined(__FreeBSD__) && !defined(__DragonFly__)) || defined(__APPLE__) || defined(__MACH__)
#error not one of the listed systems
#include <sys/types.h>
#if !(BSD && !__APPLE__ && !__MACH__ && !NeXTBSD) /* NeXT/macOS falsely claim to be BSD */
#error not BSD
#endif
int _do_these_compile_ = _POSIX_PATH_MAX & _SC_PAGESIZE;
#if _typ_u_long
u_long _test_dummy_;
#endif
}end {
/* No standards or features macro here. On BSD, everything is enabled by default */
}
elif tst note{ Darwin (macOS, Mac OS X) }end compile{
/*
* From compat(5) on macOS 10.14.6:
*
* Defining _POSIX_C_SOURCE or _DARWIN_C_SOURCE causes library and kernel calls to
* conform to the SUSv3 standards even if doing so would alter the behavior of func-
* tions used in 10.3. Defining _POSIX_C_SOURCE also removes functions, types, and
* other interfaces that are not part of SUSv3 from the normal C namespace, unless
* _DARWIN_C_SOURCE is also defined (i.e., _DARWIN_C_SOURCE is _POSIX_C_SOURCE with
* non-POSIX extensions).
*/
#define _DARWIN_C_SOURCE 1
#include <limits.h>
#include <unistd.h>
#include <sys/param.h>
#include <sys/types.h>
#if !(__APPLE__ && __MACH__ && NeXTBSD)
#error not Darwin
#endif
int _do_these_compile_ = _POSIX_PATH_MAX & _SC_PAGESIZE;
#if _typ_u_long
u_long _test_dummy_;
#endif
}end {
#ifndef _DARWIN_C_SOURCE
#define _DARWIN_C_SOURCE 1
#endif
}
elif tst note{ SunOS (Solaris, illumos) }end compile{
/*
* On Solaris/illumos, we ignore the standards(5) manual completely because
* defining any standards macro, and even defining __EXTENSIONS__ (!), will
* disable functionality that libast depends on. Instead we define unofficial
* _XPG* macros that enable up-to-date declarations and functionality in
* Solaris system headers.
* (Note that we must also avoid passing any -std=... flag to the compiler,
* because that will disable essential functionality as well.)
*/
#define _XPG7
#define _XPG6
#define _XPG5
#define _XPG4_2
#define _XPG4
#define _XPG3
#define __EXTENSIONS__ 1
#define _XOPEN_SOURCE 9900
#undef _POSIX_C_SOURCE
#include <limits.h>
#include <unistd.h>
#include <sys/types.h>
#if !__sun
#error dark
#endif
int _do_these_compile_ = _POSIX_PATH_MAX & _SC_PAGESIZE;
#if _typ_u_long
u_long _test_dummy_;
#endif
}end {
#define _XPG7 1
#define _XPG6 1
#define _XPG5 1
#define _XPG4 1
#define __EXTENSIONS__ 1
#define _XPG7
#define _XPG6
#define _XPG5
#define _XPG4_2
#define _XPG4
#define _XPG3
#define __EXTENSIONS__ 1
#define _XOPEN_SOURCE 9900
#undef _POSIX_C_SOURCE
}
elif tst note{ _ALL_SOURCE & _POSIX_SOURCE & _POSIX_C_SOURCE & _XOPEN_SOURCE & _GNU_SOURCE & _DARWIN_C_SOURCE & __EXTENSIONS__ works }end compile{
elif tst note{ GNU (glibc) }end compile{
/*
* GNU (GNU's Not UNIX). From feature_test_macros(7) on a GNU/Linux system with glibc 2.32:
*
* _GNU_SOURCE
* Defining this macro (with any value) implicitly defines _ATFILE_SOURCE, _LARGE
* FILE64_SOURCE, _ISOC99_SOURCE, _XOPEN_SOURCE_EXTENDED, _POSIX_SOURCE,
* _POSIX_C_SOURCE with the value 200809L (200112L in glibc versions before 2.10;
* 199506L in glibc versions before 2.5; 199309L in glibc versions before 2.1) and
* _XOPEN_SOURCE with the value 700 (600 in glibc versions before 2.10; 500 in
* glibc versions before 2.2). In addition, various GNU-specific extensions are
* also exposed.
* Since glibc 2.19, defining _GNU_SOURCE also has the effect of implicitly defin
* ing _DEFAULT_SOURCE. In glibc versions before 2.20, defining _GNU_SOURCE also
* had the effect of implicitly defining _BSD_SOURCE and _SVID_SOURCE.
*/
#define _GNU_SOURCE 1
#include <limits.h>
#include <unistd.h>
#include <features.h>
#include <sys/types.h>
#if !__GLIBC__
#error not GNU
#endif
int _do_these_compile_ = _POSIX_PATH_MAX & _SC_PAGESIZE;
#if _typ_u_long
u_long _test_dummy_;
#endif
}end {
#ifndef _GNU_SOURCE
#define _GNU_SOURCE 1
#endif
}
elif tst note{ _ALL_SOURCE & _POSIX_SOURCE & _POSIX_C_SOURCE & _XOPEN_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>
#include <limits.h>
int _do_these_compile_ = _POSIX_PATH_MAX & _SC_PAGESIZE;
#if _typ_u_long
u_long _test_dummy_;
#endif
@ -60,28 +167,22 @@ elif tst note{ _ALL_SOURCE & _POSIX_SOURCE & _POSIX_C_SOURCE & _XOPEN_SOURCE & _
#ifndef _XOPEN_SOURCE
#define _XOPEN_SOURCE 9900
#endif
#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 & _GNU_SOURCE & _DARWIN_C_SOURCE & __EXTENSIONS__ works }end compile{
elif tst note{ _ALL_SOURCE & _POSIX_SOURCE & _XOPEN_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>
#include <limits.h>
int _do_these_compile_ = _POSIX_PATH_MAX & _SC_PAGESIZE;
#if _typ_u_long
u_long _test_dummy;
#endif
@ -95,28 +196,22 @@ elif tst note{ _ALL_SOURCE & _POSIX_SOURCE & _XOPEN_SOURCE & _GNU_SOURCE & _DARW
#ifndef _XOPEN_SOURCE
#define _XOPEN_SOURCE 9900
#endif
#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 & _GNU_SOURCE & _DARWIN_C_SOURCE & __EXTENSIONS__ works }end compile{
elif tst note{ _POSIX_SOURCE & _POSIX_C_SOURCE & _XOPEN_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>
#include <limits.h>
int _do_these_compile_ = _POSIX_PATH_MAX & _SC_PAGESIZE;
#if _typ_u_long
u_long _test_dummy;
#endif
@ -130,12 +225,6 @@ elif tst note{ _POSIX_SOURCE & _POSIX_C_SOURCE & _XOPEN_SOURCE & _GNU_SOURCE & _
#ifndef _XOPEN_SOURCE
#define _XOPEN_SOURCE 9900
#endif
#ifndef _GNU_SOURCE
#define _GNU_SOURCE 1
#endif
#ifndef _DARWIN_C_SOURCE
#define _DARWIN_C_SOURCE 1
#endif
#ifndef __EXTENSIONS__
#define __EXTENSIONS__ 1
#endif
@ -149,6 +238,8 @@ elif tst note{ _POSIX_SOURCE & _XOPEN_SOURCE & __EXTENSIONS__ works }end compile
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <limits.h>
int _do_these_compile_ = _POSIX_PATH_MAX & _SC_PAGESIZE;
#if _typ_u_long
u_long _test_dummy;
#endif
@ -171,6 +262,8 @@ elif tst note{ _XOPEN_SOURCE & __EXTENSIONS__ works }end compile{
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <limits.h>
int _do_these_compile_ = _POSIX_PATH_MAX & _SC_PAGESIZE;
#if _typ_u_long
u_long _test_dummy;
#endif
@ -189,6 +282,8 @@ elif tst note{ _XOPEN_SOURCE works }end compile{
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <limits.h>
int _do_these_compile_ = _POSIX_PATH_MAX & _SC_PAGESIZE;
#if _typ_u_long
u_long _test_dummy;
#endif
@ -202,6 +297,8 @@ else tst note{ __EXTENSIONS__ works }end compile{
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <limits.h>
int _do_these_compile_ = _POSIX_PATH_MAX & _SC_PAGESIZE;
#if _typ_u_long
u_long _test_dummy;
#endif