From e856094ca28a54bc02ab8860d02d6214f7043550 Mon Sep 17 00:00:00 2001 From: Martijn Dekker Date: Wed, 13 May 2020 17:02:38 +0100 Subject: [PATCH] Fix build scripts so ksh compiles on recent macOS (Mac OS X) This updates the cc.darwin* compiler compatibility wrapper scripts and patches bin/package to identify a 64-bit system, allowing ksh to build using a simple 'bin/package make' command on at least on macOS Mojave (10.14.6). Testing on other macOS versions is invited. src/cmd/INIT/cc.darwin: - Remove obsolete compatibility cruft - Update compiler flags: * remove obsolete/unneeded -DCLK_TCK=100 (this is already defined in the system header i386/limits.h included by time.h) * add necessary flags from Apple's Makefile in ksh-27.tar.gz: -DSHOPT_SPAWN=0 -D_ast_int8_t=int64_t -D_lib_memccpy source: https://opensource.apple.com/tarballs/ksh/ * add -Wno-unused-value and -Wno-parentheses to suppress excessive clang warnings that object to David Korn's coding style. - Update linker flags: * remove obsolete -Wl,-m * add flag from Apple's Makefile: -Wl,-search_paths_first src/cmd/INIT/cc.darwin.i386, src/cmd/INIT/cc.darwin.i386-64: - Removed as superfluous (was identical to generic cc.darwin). bin/package, src/cmd/INIT/package.sh: - Fix the recognition of a 64-bit system from the output of a 'file /bin/sh' command (what an ugly hack... never mind), so that the architecture is correctly identified as darwin.i386-64. (cherry picked from commit e74e98b886a2bc5760166c124412474293f85fd8) --- bin/package | 2 +- src/cmd/INIT/cc.darwin | 28 +++---------- src/cmd/INIT/cc.darwin.i386 | 73 ---------------------------------- src/cmd/INIT/cc.darwin.i386-64 | 73 ---------------------------------- src/cmd/INIT/package.sh | 2 +- 5 files changed, 7 insertions(+), 171 deletions(-) delete mode 100755 src/cmd/INIT/cc.darwin.i386 delete mode 100755 src/cmd/INIT/cc.darwin.i386-64 diff --git a/bin/package b/bin/package index 1e7b8309b..d7f880dc7 100755 --- a/bin/package +++ b/bin/package @@ -2487,7 +2487,7 @@ int b() { return 0; } ;; *) case $bits in '') case `file /bin/sh 2>/dev/null` in - *universal*64*) + *universal*64* | *64-bit* | *x86[_-]64*) pwd=`pwd` cd ${TMPDIR:-/tmp} tmp=hi$$ diff --git a/src/cmd/INIT/cc.darwin b/src/cmd/INIT/cc.darwin index 081bd43b5..ef081a0b4 100755 --- a/src/cmd/INIT/cc.darwin +++ b/src/cmd/INIT/cc.darwin @@ -1,4 +1,4 @@ -: unix wrapper for mac osx cc : 2012-01-20 : +: unix wrapper for macOS cc : 2020-05-13 : HOSTTYPE=darwin.generic @@ -45,29 +45,11 @@ init) echo "cc: arguments expected" >&2 ;; cpp) $CC -E "$@" ;; -cc) $CC -DCLK_TCK=100 "$@" +cc) $CC -DSHOPT_SPAWN=0 -D_ast_int8_t=int64_t -D_lib_memccpy \ + -Wno-unused-value -Wno-parentheses "$@" ;; -dll) # what a compatibility mess -- surely they can get the apis to play nice - tmp=/tmp/cc.${USER:-$LOGNAME}.$$.err - trap "rm -f $tmp" EXIT - case `MACOSX_DEPLOYMENT_TARGET=10.3 ld -undefined dynamic_lookup 2>&1` in - *undefined*dynamic_lookup*) - ld -m -flat_namespace -undefined suppress -dylib -dynamic \ - -ldylib1.o "$@" -lcc_dynamic -framework System >$tmp 2>&1 - status=$? - ;; - *) MACOSX_DEPLOYMENT_TARGET=10.3 $CC -Wl,-flat_namespace -dynamiclib -undefined dynamic_lookup "$@" >$tmp 2>&1 - status=$? - ;; - esac - egrep -v ' (warning .*multiple definitions|definition) of ' $tmp >&2 - exit $status +dll) $CC -Wl,-flat_namespace -dynamiclib -undefined dynamic_lookup "$@" ;; -ld) tmp=/tmp/cc.${USER:-$LOGNAME}.$$.err - trap "rm -f $tmp" EXIT - $CC -Wl,-m -DCLK_TCK=100 "$@" >$tmp 2>&1 - status=$? - egrep -v ' (warning .*multiple definitions of|definition of|as lazy binding|not from earlier dynamic) ' $tmp >&2 - exit $status +ld) $CC -Wl,-search_paths_first "$@" ;; esac diff --git a/src/cmd/INIT/cc.darwin.i386 b/src/cmd/INIT/cc.darwin.i386 deleted file mode 100755 index 9afde8dd1..000000000 --- a/src/cmd/INIT/cc.darwin.i386 +++ /dev/null @@ -1,73 +0,0 @@ -: unix wrapper for mac osx cc : 2012-02-29 : - -HOSTTYPE=darwin.i386 - -case " $* " in -*" -dumpmachine "*) echo $HOSTTYPE; exit ;; -esac - -CC='/usr/bin/cc -m32' -op=init -for arg -do case $op in - init) op=ld - set '' - ;; - esac - case $arg in - -c) op=cc - ;; - -E) op=cpp - continue - ;; - -G) op=dll - continue - ;; - -lc) continue - ;; - -lm) continue - ;; - -O) continue - ;; - esac - set "$@" "$arg" -done -case $# in -0) ;; -*) shift ;; -esac -case $* in --v) $CC "$@"; exit ;; -esac -case $op in -init) echo "cc: arguments expected" >&2 - exit 1 - ;; -cpp) $CC -E "$@" - ;; -cc) $CC -DCLK_TCK=100 "$@" - ;; -dll) # what a compatibility mess -- surely they can get the apis to play nice - tmp=/tmp/cc.${USER:-$LOGNAME}.$$.err - trap "rm -f $tmp" EXIT - case `MACOSX_DEPLOYMENT_TARGET=10.3 ld -undefined dynamic_lookup 2>&1` in - *undefined*dynamic_lookup*) - ld -m -flat_namespace -undefined suppress -dylib -dynamic \ - -ldylib1.o "$@" -lcc_dynamic -framework System >$tmp 2>&1 - status=$? - ;; - *) MACOSX_DEPLOYMENT_TARGET=10.3 $CC -Wl,-flat_namespace -dynamiclib -undefined dynamic_lookup "$@" >$tmp 2>&1 - status=$? - ;; - esac - egrep -v ' (warning .*multiple definitions|definition) of ' $tmp >&2 - exit $status - ;; -ld) tmp=/tmp/cc.${USER:-$LOGNAME}.$$.err - trap "rm -f $tmp" EXIT - $CC -Wl,-m -DCLK_TCK=100 "$@" >$tmp 2>&1 - status=$? - egrep -v ' (warning .*multiple definitions of|definition of|as lazy binding|not from earlier dynamic) ' $tmp >&2 - exit $status - ;; -esac diff --git a/src/cmd/INIT/cc.darwin.i386-64 b/src/cmd/INIT/cc.darwin.i386-64 deleted file mode 100755 index 9010d96b2..000000000 --- a/src/cmd/INIT/cc.darwin.i386-64 +++ /dev/null @@ -1,73 +0,0 @@ -: unix wrapper for mac osx cc : 2012-02-29 : - -HOSTTYPE=darwin.i386-64 - -case " $* " in -*" -dumpmachine "*) echo $HOSTTYPE; exit ;; -esac - -CC=/usr/bin/cc -op=init -for arg -do case $op in - init) op=ld - set '' - ;; - esac - case $arg in - -c) op=cc - ;; - -E) op=cpp - continue - ;; - -G) op=dll - continue - ;; - -lc) continue - ;; - -lm) continue - ;; - -O) continue - ;; - esac - set "$@" "$arg" -done -case $# in -0) ;; -*) shift ;; -esac -case $* in --v) $CC "$@"; exit ;; -esac -case $op in -init) echo "cc: arguments expected" >&2 - exit 1 - ;; -cpp) $CC -E "$@" - ;; -cc) $CC -DCLK_TCK=100 "$@" - ;; -dll) # what a compatibility mess -- surely they can get the apis to play nice - tmp=/tmp/cc.${USER:-$LOGNAME}.$$.err - trap "rm -f $tmp" EXIT - case `MACOSX_DEPLOYMENT_TARGET=10.3 ld -undefined dynamic_lookup 2>&1` in - *undefined*dynamic_lookup*) - ld -m -flat_namespace -undefined suppress -dylib -dynamic \ - -ldylib1.o "$@" -lcc_dynamic -framework System >$tmp 2>&1 - status=$? - ;; - *) MACOSX_DEPLOYMENT_TARGET=10.3 $CC -Wl,-flat_namespace -dynamiclib -undefined dynamic_lookup "$@" >$tmp 2>&1 - status=$? - ;; - esac - egrep -v ' (warning .*multiple definitions|definition) of ' $tmp >&2 - exit $status - ;; -ld) tmp=/tmp/cc.${USER:-$LOGNAME}.$$.err - trap "rm -f $tmp" EXIT - $CC -Wl,-m -DCLK_TCK=100 "$@" >$tmp 2>&1 - status=$? - egrep -v ' (warning .*multiple definitions of|definition of|as lazy binding|not from earlier dynamic) ' $tmp >&2 - exit $status - ;; -esac diff --git a/src/cmd/INIT/package.sh b/src/cmd/INIT/package.sh index 42c1ebab3..ca116b56d 100644 --- a/src/cmd/INIT/package.sh +++ b/src/cmd/INIT/package.sh @@ -2486,7 +2486,7 @@ int b() { return 0; } ;; *) case $bits in '') case `file /bin/sh 2>/dev/null` in - *universal*64*) + *universal*64* | *64-bit* | *x86[_-]64*) pwd=`pwd` cd ${TMPDIR:-/tmp} tmp=hi$$