commit f65cd7e93eeb39d7ebb4066793345dd45051abe2
parent 88805f471a66064c778ea49ef22287fcd37deb93
Author: Laurent Bercot <ska-skaware@skarnet.org>
Date: Mon, 30 Oct 2017 10:37:05 +0000
Make all-pic a user option
Diffstat:
2 files changed, 22 insertions(+), 13 deletions(-)
diff --git a/Makefile b/Makefile
@@ -22,7 +22,6 @@ version_M := $(basename $(version_m))
version_l := $(basename $(version_M))
CPPFLAGS_ALL := $(CPPFLAGS_AUTO) $(CPPFLAGS)
CFLAGS_ALL := $(CFLAGS_AUTO) $(CFLAGS)
-CFLAGS_SHARED := -fPIC
LDFLAGS_ALL := $(LDFLAGS_AUTO) $(LDFLAGS)
LDLIBS_ALL := $(LDLIBS_AUTO) $(LDLIBS)
REALCC = $(CROSS_COMPILE)$(CC)
@@ -35,10 +34,12 @@ TYPES := size uid gid pid time dev ino
ALL_SRCS := $(wildcard src/lib*/*.c)
ALL_DOBJS := $(ALL_SRCS:%.c=%.lo)
-ifeq ($(strip $(DEFAULT_PIE)),)
+ifeq ($(strip $(STATIC_LIBS_ARE_PIC)),)
ALL_SOBJS := $(ALL_SRCS:%.c=%.o)
+CFLAGS_SHARED := -fPIC
else
ALL_SOBJS := $(ALL_DOBJS)
+CFLAGS_SHARED :=
endif
ALL_LIBS := $(SHARED_LIBS) $(STATIC_LIBS)
BUILT_INCLUDES := \
diff --git a/configure b/configure
@@ -34,6 +34,7 @@ Dependencies:
Optional features:
--disable-shared do not build shared libraries [enabled]
--disable-static do not build static libraries [enabled]
+ --enable-all-pic build everything as PIC [enabled iff toolchain builds PIE]
--enable-slashpackage[=ROOT] assume /package installation at ROOT [disabled]
$package options:
@@ -230,6 +231,7 @@ sysdepdir='$prefix/lib/$package/sysdeps'
sysdeps=
shared=true
static=true
+allpic=detect
slashpackage=false
ipv6=true
select=false
@@ -249,7 +251,6 @@ vpaths=''
vpathd=''
build=
-
for arg ; do
case "$arg" in
--help) usage ;;
@@ -267,6 +268,8 @@ for arg ; do
--disable-shared|--enable-shared=no) shared=false ;;
--enable-static|--enable-static=yes) static=true ;;
--disable-static|--enable-static=no) static=false ;;
+ --enable-all-pic|--enable-all-pic=yes) allpic=true ;;
+ --disable-all-pic|--enable-all-pic=no) allpic=false ;;
--enable-slashpackage=*) sproot=${arg#*=} ; slashpackage=true ; ;;
--enable-slashpackage) sproot= ; slashpackage=true ;;
--disable-slashpackage) sproot= ; slashpackage=false ;;
@@ -377,13 +380,18 @@ if test -z "$target" ; then
fi
echo " ... $target"
-defaultpie=false
-echo "Checking whether we're building PIE..."
-if $CC_AUTO $CPPFLAGS_AUTO $CPPFLAGS $CPPFLAGS_POST $CFLAGS_AUTO $CFLAGS $CFLAGS_POST -dM -E - < /dev/null | grep -qF __PIE__ ; then
- defaultpie=true
- echo " ... yes"
-else
- echo " ... no"
+if test $allpic = detect ; then
+ echo "Checking whether we need to build everything as PIC..."
+ if $CC_AUTO $CPPFLAGS_AUTO $CPPFLAGS $CPPFLAGS_POST $CFLAGS_AUTO $CFLAGS $CFLAGS_POST -dM -E - < /dev/null | grep -qF __PIE__ ; then
+ allpic=true
+ echo " ... yes"
+ else
+ allpic=false
+ echo " ... no"
+ fi
+fi
+if $allpic ; then
+ tryflag CFLAGS_AUTO -fPIC
fi
tryflag CFLAGS_AUTO -std=c99
@@ -595,10 +603,10 @@ if $shared ; then
else
echo "SHARED_LIBS :="
fi
-if $defaultpie ; then
- echo "DEFAULT_PIE := true"
+if $allpic ; then
+ echo "STATIC_LIBS_ARE_PIC := 1"
else
- echo "DEFAULT_PIE :="
+ echo "STATIC_LIBS_ARE_PIC :="
fi
exec 1>&3 3>&-