From 9cc93ae2b58676c23fd02cf0c686fa15b7a3ff81 Mon Sep 17 00:00:00 2001 From: "Kyle J. McKay" Date: Fri, 27 Oct 2017 22:59:16 -0700 Subject: [PATCH] buildlib: supply -fPIC or -fpic if supported Although this is the "blocks" runtime support library, it does not necessarily need to be built by a compiler that supports the compilation of blocks. It's possible that the runtime support library is being built by a compiler that does not support or understand either the -fPIC or the -fpic option. For this reason be cautious and only add the option (preferring -fPIC) if the compiler actually groks it. Suggested-by: Ron Olson Signed-off-by: Kyle J. McKay --- buildlib | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/buildlib b/buildlib index c6f20bb20..5106ebe56 100755 --- a/buildlib +++ b/buildlib @@ -8,6 +8,7 @@ Env: CC explicit "cc" compiler to use AR explicit "ar" to use RANLIB explicit "ranlib" to use CFLAGS explicit compiler options to use + FPIC explicit -fPIC/-fpic (or none) option to use EOT exit 0 esac @@ -65,6 +66,21 @@ if [ "${CFLAGS+set}" != "set" ]; then ;; esac fi + +has_cc_opt() +{ + "$CC" "$1" -o /tmp/cc.$$ -c -x c /dev/null >/dev/null 2>&1 && + rm -f /tmp/cc.$$ +} +if [ "${FPIC+set}" != "set" ]; then + if has_cc_opt "-fPIC"; then + FPIC="-fPIC" + elif has_cc_opt "-fpic"; then + FPIC="-fpic" + fi +fi +[ -z "$FPIC" ] || echo "FPIC=$FPIC" + echo "CFLAGS=$CFLAGS" echo "LIB=$LIB" @@ -84,13 +100,13 @@ echo "SRC=$SRC" ) || exit ( PS4= && set -ex - "$CC" -c $CFLAGS -o $SRC/data.o $SRC/data.c && - "$CC" -c $CFLAGS -o $SRC/runtime.o -I . $SRC/runtime.c && + "$CC" -c $FPIC $CFLAGS -o $SRC/data.o $SRC/data.c && + "$CC" -c $FPIC $CFLAGS -o $SRC/runtime.o -I . $SRC/runtime.c && "$AR" cr $LIB $SRC/data.o $SRC/runtime.o && "$RANLIB" $LIB ) || exit [ -z "$shared" ] || ( PS4= && set -ex - "$CC" $CFLAGS -o "$SHLIB" $SHOPT $LIB $SHOPT2 + "$CC" $FPIC $CFLAGS -o "$SHLIB" $SHOPT $LIB $SHOPT2 ) || exit -- 2.11.4.GIT