Skip to content

Commit

Permalink
Make all-pic a user option
Browse files Browse the repository at this point in the history
  • Loading branch information
skarnet committed Oct 30, 2017
1 parent 5dd1598 commit 38dc9bd
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 13 deletions.
4 changes: 4 additions & 0 deletions Makefile
Expand Up @@ -42,7 +42,11 @@ version_M := $(basename $(version_m))
version_l := $(basename $(version_M))
CPPFLAGS_ALL := $(CPPFLAGS_AUTO) $(CPPFLAGS)
CFLAGS_ALL := $(CFLAGS_AUTO) $(CFLAGS)
ifeq ($(strip $(STATIC_LIBS_ARE_PIC)),)
CFLAGS_SHARED := -fPIC
else
CFLAGS_SHARED :=
endif
LDFLAGS_ALL := $(LDFLAGS_AUTO) $(LDFLAGS)
REALCC = $(CROSS_COMPILE)$(CC)
AR := $(CROSS_COMPILE)ar
Expand Down
30 changes: 19 additions & 11 deletions configure
Expand Up @@ -41,6 +41,7 @@ Optional features:
--disable-static do not build static libraries [enabled]
--disable-allstatic do not prefer linking against static libraries [enabled]
--enable-static-libc make entirely static binaries [disabled]
--enable-all-pic build everything as PIC [enabled iff toolchain builds PIE]
--enable-slashpackage[=ROOT] assume /package installation at ROOT [disabled]
--enable-absolute-paths do not rely on PATH to access this package's binaries,
hardcode absolute BINDIR/foobar paths instead [disabled]
Expand Down Expand Up @@ -145,6 +146,7 @@ sysdeps='$prefix/lib/skalibs/sysdeps'
manualsysdeps=false
shared=false
static=true
allpic=detect
slashpackage=false
abspath=false
sproot=
Expand Down Expand Up @@ -182,6 +184,8 @@ for arg ; do
--disable-allstatic|--enable-allstatic=no) allstatic=false ; evenmorestatic=false ;;
--enable-static-libc|--enable-static-libc=yes) allstatic=true ; evenmorestatic=true ;;
--disable-static-libc|--enable-static-libc=no) evenmorestatic=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 ;;
Expand Down Expand Up @@ -299,14 +303,18 @@ if [ "x$target" != "x$(cat $sysdeps/target)" ] ; then
exit 1
fi

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
CFLAGS_AUTO="$CFLAGS_AUTO -fPIC"
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

spawn_lib=$(cat $sysdeps/spawn.lib)
Expand Down Expand Up @@ -421,10 +429,10 @@ if $shared ; then
else
echo "DO_SHARED :="
fi
if $defaultpie ; then
echo "DEFAULT_PIE := 1"
if $allpic ; then
echo "STATIC_LIBS_ARE_PIC := 1"
else
echo "DEFAULT_PIE :="
echo "STATIC_LIBS_ARE_PIC :="
fi

exec 1>&3 3>&-
Expand Down
2 changes: 1 addition & 1 deletion package/deps.mak
Expand Up @@ -164,7 +164,7 @@ wait: EXTRA_LIBS :=
wait: src/execline/wait.o ${LIBEXECLINE} -lskarnet
withstdinas: EXTRA_LIBS :=
withstdinas: src/execline/withstdinas.o -lskarnet
ifeq ($(strip $(DEFAULT_PIE)),)
ifeq ($(strip $(STATIC_LIBS_ARE_PIC)),)
libexecline.a.xyzzy: src/libexecline/el_execsequence.o src/libexecline/el_getstrict.o src/libexecline/el_parse.o src/libexecline/el_parse_from_buffer.o src/libexecline/el_parse_from_string.o src/libexecline/el_popenv.o src/libexecline/el_pushenv.o src/libexecline/el_semicolon.o src/libexecline/el_spawn0.o src/libexecline/el_spawn1.o src/libexecline/el_substandrun.o src/libexecline/el_substandrun_str.o src/libexecline/el_substitute.o src/libexecline/el_transform.o src/libexecline/el_vardupl.o src/libexecline/exlsn_define.o src/libexecline/exlsn_elglob.o src/libexecline/exlsn_import.o src/libexecline/exlsn_multidefine.o src/libexecline/exlsn_exlp.o src/libexecline/exlsn_main.o src/libexecline/exlsn_free.o src/libexecline/exlp.o
else
libexecline.a.xyzzy: src/libexecline/el_execsequence.lo src/libexecline/el_getstrict.lo src/libexecline/el_parse.lo src/libexecline/el_parse_from_buffer.lo src/libexecline/el_parse_from_string.lo src/libexecline/el_popenv.lo src/libexecline/el_pushenv.lo src/libexecline/el_semicolon.lo src/libexecline/el_spawn0.lo src/libexecline/el_spawn1.lo src/libexecline/el_substandrun.lo src/libexecline/el_substandrun_str.lo src/libexecline/el_substitute.lo src/libexecline/el_transform.lo src/libexecline/el_vardupl.lo src/libexecline/exlsn_define.lo src/libexecline/exlsn_elglob.lo src/libexecline/exlsn_import.lo src/libexecline/exlsn_multidefine.lo src/libexecline/exlsn_exlp.lo src/libexecline/exlsn_main.lo src/libexecline/exlsn_free.lo src/libexecline/exlp.lo
Expand Down
2 changes: 1 addition & 1 deletion tools/gen-deps.sh
Expand Up @@ -65,7 +65,7 @@ for dir in $(ls -1 src | grep -v ^include) ; do
deps="$deps src/$dir/$dep"
fi
done < src/$dir/deps-lib/$file
echo 'ifeq ($(strip $(DEFAULT_PIE)),)'
echo 'ifeq ($(strip $(STATIC_LIBS_ARE_PIC)),)'
echo "lib${file}.a.xyzzy:$deps"
echo else
echo "lib${file}.a.xyzzy:$(echo "$deps" | sed 's/\.o/.lo/g')"
Expand Down

0 comments on commit 38dc9bd

Please sign in to comment.