Fix some build problems on MacOS X.

- Linking shared libraries needs slightly different options.

- We were trying to detect mach_time.h but needed to detect
  mach/mach_time.h instead.

While we're here, add a --disable-shared option to ./configure, which
is different from --enable-static.  --disable-shared does not build
*new* share libraries, but doesn't pass -static to the linker
(apparently there is no static linking posible on MacOS).
This commit is contained in:
Avery Pennarun 2019-02-24 22:29:19 -05:00
commit 328d4ead7a
7 changed files with 59 additions and 13 deletions

View file

@ -2,8 +2,9 @@
rc_include rc/CC.rc
base="${1#*/}"
h="${base%.rc}"
H=$(echo "$h" | tr 'a-z.' 'A-Z_')
h1="${base%.rc}"
h=$(echo "$h1" | sed -e 's,__,/,g') # x__y_z.h.rc.od -> <x/y_z.h>
H=$(echo "$h1" | tr 'a-z.' 'A-Z_')
if rc_compile cc nolink "#include <$h>"; then
rc_replaceln "HAVE_$H" 1

View file

@ -1,21 +1,43 @@
. ./redoconf.rc
rc_include rc/CC.rc
appendln CFLAGS "-fPIC"
appendln LDFLAGS "-shared"
prog='
#include <stdlib.h>
void f() { atoi(""); }
'
try_unix_style() {
(
appendln CFLAGS "-fPIC"
appendln LDFLAGS "-shared"
appendln LDFLAGS "-Wl,-soname,x.so"
RCC_NO_MAIN=1 rc_compile cc link "$prog"
)
}
try_macos_style() {
(
appendln CFLAGS "-fPIC"
appendln LDFLAGS "-dynamiclib"
appendln LDFLAGS "-current_version"
appendln LDFLAGS "1.0"
RCC_NO_MAIN=1 rc_compile cc link "$prog"
)
}
if [ -n "$STATIC" ]; then
echo "--enable-static specified; not building shared libraries." >&2
rc_replaceln HAVE_SHLIB ""
elif RCC_NO_MAIN=1 rc_compile cc link "$prog"; then
rc_replaceln HAVE_SHLIB 1
elif [ -n "$NOSHARED" ]; then
echo "--disable-shared specified; not building shared libraries." >&2
rc_replaceln HAVE_SHLIB ""
elif try_unix_style; then
rc_replaceln HAVE_SHLIB UNIX
elif try_macos_style; then
rc_replaceln HAVE_SHLIB MACOS
else
echo "Not building shared libraries on this platform." >&2
rc_undo
rc_replaceln HAVE_SHLIB ""
fi
rc_save