summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2021-01-14 06:41:28 -0800
committerKaz Kylheku <kaz@kylheku.com>2021-01-14 06:41:28 -0800
commit3fdd7328a2f901db16305827ad664abc7736cd83 (patch)
tree5b2316e1598e0ad8ab435bce4d01e134119c3557
parenta8c95c296c3996869862b47590c69e54373907b2 (diff)
downloadtxr-3fdd7328a2f901db16305827ad664abc7736cd83.tar.gz
txr-3fdd7328a2f901db16305827ad664abc7736cd83.tar.bz2
txr-3fdd7328a2f901db16305827ad664abc7736cd83.zip
build: support linker flags/libs separation.
Our build system lumps all linker options together. The correct way is that linker flags are separated info flags and libs. Also, we respond to the LDFLAGS variable but ignore LDLIBS which is incorrect. Other issues are fixed. All that is fixed here. * Makefile (TXR_CFLAGS): Interpolate $(CFLAGS) last, so that options coming from CFLAGS can override previous options. (TXR_LDFLAGS): Interpolate $(LDFLAGS) last; same reason. (TXR_LDLIBS): New variable. (LINK_PROG): Put $(TXR_LDFLAGS) with the options, before the -o, and put $(TXR_LDLIBS) at the end. * configure (conf_ldlibs, platform_ldlibs): New variables. (usage text): Document platform-ldlibs and adjust documentation of platform-ldflags. (gen_config_make): Generate PLATFORM_LDLIBS and CONF_LDLIBS now needed by Makefile. (mainline): Adjusts various recipes to use conf_ldlibs instead of conf_ldflags, or in some cases both. In the case of libffi where we use pkg-config, we use the special pgk-config options to separately extract the flags and libs. We use EXTRA_LDLIBS instead of EXTRA_LDFLAGS in some conftest invocations, as necessary.
-rw-r--r--Makefile11
-rwxr-xr-xconfigure42
2 files changed, 33 insertions, 20 deletions
diff --git a/Makefile b/Makefile
index 35f95b5c..1c67c488 100644
--- a/Makefile
+++ b/Makefile
@@ -29,13 +29,12 @@
-include config.make
VERBOSE :=
-TXR_CFLAGS := $(CFLAGS)
-TXR_CFLAGS += -iquote . $(if $(top_srcdir), -iquote $(top_srcdir)) \
+TXR_CFLAGS := -iquote . $(if $(top_srcdir), -iquote $(top_srcdir)) \
$(LANG_FLAGS) $(DIAG_FLAGS) \
- $(DBG_FLAGS) $(PLATFORM_CFLAGS) $(EXTRA_FLAGS)
+ $(DBG_FLAGS) $(PLATFORM_CFLAGS) $(EXTRA_FLAGS) $(CFLAGS)
TXR_CFLAGS := $(filter-out $(REMOVE_FLAGS),$(TXR_CFLAGS))
-TXR_LDFLAGS := $(LDFLAGS)
-TXR_LDFLAGS += -lm $(CONF_LDFLAGS) $(PLATFORM_LDFLAGS) $(EXTRA_LDFLAGS)
+TXR_LDFLAGS := $(CONF_LDFLAGS) $(PLATFORM_LDFLAGS) $(EXTRA_LDFLAGS) $(LDFLAGS)
+TXR_LDLIBS := -lm $(CONF_LDLIBS) $(PLAFORM_LDLIBS) $(EXTRA_LDLIBS) $(LDLIBS)
ifneq ($(subst g++,@,$(notdir $(TXR_CC))),$(notdir $(TXR_CC)))
TXR_CFLAGS := $(filter-out -Wmissing-prototypes -Wstrict-prototypes,$(TXR_CFLAGS))
@@ -139,7 +138,7 @@ endef
define LINK_PROG
$(call ABBREVN,LINK)
-$(call SH,$(TXR_CC) $(1) $(TXR_CFLAGS) -o $@ $^ $(TXR_LDFLAGS))
+$(call SH,$(TXR_CC) $(1) $(TXR_CFLAGS) $(TXR_LDFLAGS) -o $@ $^ $(TXR_LDLIBS))
endef
define WINDRES
diff --git a/configure b/configure
index 88dd6a36..4754ef22 100755
--- a/configure
+++ b/configure
@@ -170,7 +170,9 @@ platform_cflags=
remove_flags=
lex_dbg_flags=
conf_ldflags=
+conf_ldlibs=
platform_ldflags=
+platform_ldlibs=
txr_dbg_opts=--gc-debug
valgrind=
lit_align=
@@ -485,8 +487,15 @@ platform-cflags [$platform_cflags]
platform-ldflags [$platform_ldflags]
Specify additional linker flags for anything else, such as hardening,
+ linking as needed, et cetera. Flas specifying librariews (-l options)
+ should be specified using platform-ldlibs instead. Note that these are in
+ addition to any LDFLAGS from the environment or make command line.
+
+platform-ldlibs [$platform_ldlibs]
+
+ Specify additional linker flags for just libraries (-l options)
linking as needed, et cetera. Note that these are in addition to
- any LDFLAGS from the environment or make command line.
+ any LDLIBS from the environment or make command line.
remove-flags [$remove_flags]
@@ -901,7 +910,9 @@ BUILD_TARGETS := $(if [ $debug_also ] ; then
echo '$(PROG)'; fi)
PLATFORM_CFLAGS := $platform_cflags
PLATFORM_LDFLAGS := $platform_ldflags
+PLATFORM_LDLIBS := $platform_ldlibs
CONF_LDFLAGS := $conf_ldflags
+CONF_LDLIBS := $conf_ldlibs
REMOVE_FLAGS := $remove_flags
LEX_DBG_FLAGS := $lex_dbg_flags
TXR_DBG_OPTS := $txr_dbg_opts
@@ -3063,11 +3074,11 @@ for try_lcrypt in "" "-lcrypt" "no" ; do
printf "no\n"
break
fi
- if conftest EXTRA_LDFLAGS=$try_lcrypt; then
+ if conftest EXTRA_LDLIBS=$try_lcrypt; then
printf "yes\n"
printf "#define HAVE_CRYPT 1\n" >> config.h
if [ -n "$try_lcrypt" ] ; then
- conf_ldflags="${conf_ldflags:+"$conf_ldflags "}-lcrypt"
+ conf_ldlibs="${conf_ldlibs:+"$conf_ldlibs "}-lcrypt"
fi
break;
fi
@@ -3091,11 +3102,11 @@ for try_lcrypt in "" "-lcrypt" "no" ; do
printf "no\n"
break
fi
- if conftest EXTRA_LDFLAGS=$try_lcrypt; then
+ if conftest EXTRA_LDLIBS=$try_lcrypt; then
printf "yes\n"
printf "#define HAVE_CRYPT_R 1\n" >> config.h
if [ -n "$try_lcrypt" ] ; then
- conf_ldflags="${conf_ldflags:+"$conf_ldflags "}-lcrypt"
+ conf_ldlibs="${conf_ldlibs:+"$conf_ldlibs "}-lcrypt"
fi
break;
fi
@@ -3394,12 +3405,12 @@ if conftest ; then
printf "#define HAVE_SOCKETS 1\n" >> config.h
have_sockets=y
have_sys_types=y
-elif conftest EXTRA_LDFLAGS="-lsocket -lnsl" ; then
+elif conftest EXTRA_LDLIBS="-lsocket -lnsl" ; then
printf "yes\n"
printf "#define HAVE_SOCKETS 1\n" >> config.h
have_sockets=y
have_sys_types=y
- conf_ldflags="${conf_ldflags:+"$conf_ldflags "}-lsocket -lnsl"
+ conf_ldlibs="${conf_ldlibs:+"$conf_ldlibs "}-lsocket -lnsl"
printf "Need libs for sockets: regenerating config.make ..."
gen_config_make
printf "done\n"
@@ -3522,16 +3533,16 @@ int main(void)
if conftest ; then
printf "yes\n"
printf "#define HAVE_DLOPEN 1\n" >> config.h
-elif conftest EXTRA_LDFLAGS=-ldl ; then
+elif conftest EXTRA_LDLIBS=-ldl ; then
printf "yes\n"
printf "#define HAVE_DLOPEN 1\n" >> config.h
- conf_ldflags="${conf_ldflags:+"$conf_ldflags "}-ldl"
+ conf_ldlibs="${conf_ldlibs:+"$conf_ldlibs "}-ldl"
else
printf "no\n"
fi
printf "Checking for dlvsym ... "
-if conftest CONF_LDFLAGS="$conf_ldflags" EXTRA_FLAGS=-DTEST_DLVSYM=1 ; then
+if conftest CONF_LDLIBS="$conf_ldlibs" EXTRA_FLAGS=-DTEST_DLVSYM=1 ; then
printf "yes\n"
printf "#define HAVE_DLVSYM 1\n" >> config.h
else
@@ -3568,16 +3579,19 @@ int main(void)
if conftest ; then
printf "yes\n"
printf "#define HAVE_LIBFFI 1\n" >> config.h
-elif conftest EXTRA_LDFLAGS=-lffi ; then
+elif conftest EXTRA_LDLIBS=-lffi ; then
printf "yes\n"
printf "#define HAVE_LIBFFI 1\n" >> config.h
- conf_ldflags="${conf_ldflags:+"$conf_ldflags "}-lffi"
+ conf_ldlibs="${conf_ldlibs:+"$conf_ldlibs "}-lffi"
elif [ -n "$have_pkgconfig" ] && pkg-config --exists libffi ; then
libffi_cflags=$(pkg-config --cflags libffi)
- libffi_ldflags=$(pkg-config --libs libffi)
- if conftest EXTRA_FLAGS="$libffi_cflags" EXTRA_LDFLAGS="$libffi_ldflags" ; then
+ libffi_ldlibs=$(pkg-config --libs-only-l libffi)
+ libffi_ldflags=$(pkg-config --libs-only-L libffi)
+ if conftest EXTRA_FLAGS="$libffi_cflags" EXTRA_LDFLAGS="$libffi_ldflags" \
+ EXTRA_LDLIBS="$libffi_ldlibs"; then
printf "yes\n"
printf "#define HAVE_LIBFFI 1\n" >> config.h
+ conf_ldlibs="${conf_ldlibs:+"$conf_ldlibs "}$libffi_ldlibs"
conf_ldflags="${conf_ldflags:+"$conf_ldflags "}$libffi_ldflags"
else
printf "no\n"