From 6edcfca97fb01418cfdb8a2595060a63b7471d48 Mon Sep 17 00:00:00 2001 From: Omar Polo Date: Tue, 6 Jul 2021 13:01:11 +0000 Subject: try to preserve as much as possible CFLAGS and LDFLAGS from env but still try to autodetect with pkg-config if they aren't provided. Passing CFLAGS/LDFLAGS from the command line will still override the guessed ones. --- ChangeLog | 4 ++++ configure | 47 ++++++++++++++++++++++++++++++++++++----------- 2 files changed, 40 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index ec62a46..1b4b649 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2021-07-06 Omar Polo + + * configure (guessing_cflags): try to preserve CFLAGS/LDFLAGS + 2021-07-02 Omar Polo * sandbox.c (filter): seccomp filter reworked: now it should work on x86 and possibly other arches too! diff --git a/configure b/configure index b201655..2cfcff2 100755 --- a/configure +++ b/configure @@ -32,13 +32,25 @@ echo "file config.log: writing..." # -------- # default settings: initialize all vars here such that nothing is -# leaked from the environment except for CC and CFLAGS +# leaked from the environment except for CC, CFLAGS and LDFLAGS CC=`printf "all:\\n\\t@echo \\\$(CC)\\n" | make ${MAKE_FLAGS} -sf -` -CFLAGS=`printf "all:\\n\\t@echo \\\$(CFLAGS)\\n" | make ${MAKE_FLAGS} -sf -` -CFLAGS="${CFLAGS} -g -W -Wall -Wextra -Wmissing-prototypes -Wstrict-prototypes" -CFLAGS="${CFLAGS} -Wwrite-strings -Wno-unused-parameter" -LDFLAGS="-ltls -levent" + +guessing_cflags=0 +if [ -z "${CFLAGS}" ]; then + guessing_cflags=1 + CFLAGS=`printf "all:\\n\\t@echo \\\$(CFLAGS)\\n" | make ${MAKE_FLAGS} -sf -` + CFLAGS="${CFLAGS} -W -Wall -Wextra -Wmissing-prototypes -Wstrict-prototypes" + CFLAGS="${CFLAGS} -Wwrite-strings -Wno-unused-parameter" +fi + +guessing_ldflags=0 +if [ -z "${LDFLAGS}" ]; then + guessing_ldflags=1 + LDFLAGS=`printf "all:\\n\\t@echo \\\$(LDFLAGS)\\n" | make ${MAKE_FLAGS} -sf -` + LDFLAGS="-ltls -levent -lcrypto" +fi + LD_IMSG= STATIC= YACC=yacc @@ -53,15 +65,28 @@ BINDIR= INSTALL="install" +add_cflags() { + if [ $guessing_cflags = 1 ]; then + CFLAGS="${CFLAGS} $1" + fi +} + +add_ldflags() { + if [ $guessing_ldflags = 1 ]; then + LDFLAGS="${LDFLAGS} $1" + fi +} + # try to auto detect CFLAGS and LDFLAGS if which pkg-config 2>/dev/null 1>&2; then if pkg-config libtls; then - CFLAGS="${CFLAGS} $(pkg-config --cflags libtls)" - LDFLAGS="$(pkg-config --libs libtls)" + add_cflags "$(pkg-config --cflags libtls)" + add_ldflags "$(pkg-config --libs libtls)" fi + if pkg-config openssl; then - CFLAGS="${CFLAGS} $(pkg-config --cflags openssl)" - LDFLAGS="${LDFLAGS} $(pkg-config --libs openssl)" + add_cflags "$(pkg-config --cflags openssl)" + add_ldflags "$(pkg-config --libs openssl)" fi case "$(uname)" in @@ -70,8 +95,8 @@ if which pkg-config 2>/dev/null 1>&2; then ;; *) if pkg-config libevent; then - CFLAGS="${CFLAGS} $(pkg-config --cflags libevent)" - LDFLAGS="${LDFLAGS} $(pkg-config --libs libevent)" + add_cflags "$(pkg-config --cflags libevent)" + add_ldflags "$(pkg-config --libs libevent)" fi ;; esac -- cgit v1.2.3