From mboxrd@z Thu Jan 1 00:00:00 1970 From: Stefano Brivio To: passt-dev@passt.top Subject: [PATCH] Makefile: Allow define overrides by prepending, not appending, CFLAGS Date: Wed, 14 Sep 2022 15:45:44 +0200 Message-ID: <20220914134544.2868226-1-sbrivio@redhat.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============5988573054950591946==" --===============5988573054950591946== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable If we append CFLAGS to the ones passed via command line (if any), -D options we append will override -D options passed on command line (if any). For example, OpenSUSE build flags include -D_FORTIFY_SOURCE=3D3, and we want to have -D_FORTIFY_SOURCE=3D2, if and only if not overridden. The current behaviour implies we redefine _FORTIFY_SOURCE as 2, though. Instead of appending CFLAGS, prepend them by adding all the default build flags to another variable, a simply expanded one (defined with :=3D), named FLAGS, and pass that *before* CFLAGS in targets, so that defines from command line can override default flags. Reported-by: Dario Faggioli Signed-off-by: Stefano Brivio --- Makefile | 49 +++++++++++++++++++++++++------------------------ 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/Makefile b/Makefile index af3d1ff..6805c23 100644 --- a/Makefile +++ b/Makefile @@ -23,13 +23,13 @@ AUDIT_ARCH :=3D $(shell echo $(AUDIT_ARCH) | sed 's/I[456= ]86/I386/') AUDIT_ARCH :=3D $(shell echo $(AUDIT_ARCH) | sed 's/PPC64/PPC/') AUDIT_ARCH :=3D $(shell echo $(AUDIT_ARCH) | sed 's/PPCLE/PPC64LE/') =20 -CFLAGS +=3D -Wall -Wextra -pedantic -std=3Dc99 -D_XOPEN_SOURCE=3D700 -D_GNU_= SOURCE -CFLAGS +=3D -D_FORTIFY_SOURCE=3D2 -O2 -pie -fPIE -CFLAGS +=3D -DPAGE_SIZE=3D$(shell getconf PAGE_SIZE) -CFLAGS +=3D -DNETNS_RUN_DIR=3D\"/run/netns\" -CFLAGS +=3D -DPASST_AUDIT_ARCH=3DAUDIT_ARCH_$(AUDIT_ARCH) -CFLAGS +=3D -DRLIMIT_STACK_VAL=3D$(RLIMIT_STACK_VAL) -CFLAGS +=3D -DARCH=3D\"$(TARGET_ARCH)\" +FLAGS :=3D -Wall -Wextra -pedantic -std=3Dc99 -D_XOPEN_SOURCE=3D700 -D_GNU_S= OURCE +FLAGS +=3D -D_FORTIFY_SOURCE=3D2 -O2 -pie -fPIE +FLAGS +=3D -DPAGE_SIZE=3D$(shell getconf PAGE_SIZE) +FLAGS +=3D -DNETNS_RUN_DIR=3D\"/run/netns\" +FLAGS +=3D -DPASST_AUDIT_ARCH=3DAUDIT_ARCH_$(AUDIT_ARCH) +FLAGS +=3D -DRLIMIT_STACK_VAL=3D$(RLIMIT_STACK_VAL) +FLAGS +=3D -DARCH=3D\"$(TARGET_ARCH)\" =20 PASST_SRCS =3D arch.c arp.c checksum.c conf.c dhcp.c dhcpv6.c icmp.c igmp.c \ isolation.c lineread.c mld.c ndp.c netlink.c packet.c passt.c pasta.c \ @@ -50,36 +50,36 @@ HEADERS =3D $(PASST_HEADERS) # from the pointer arithmetic used from the tcp_tap_handler() path to get the # remote connection address. ifeq ($(shell $(CC) -dumpversion),11) -ifneq (,$(filter -flto%,$(CFLAGS))) -ifneq (,$(filter -O2,$(CFLAGS))) - CFLAGS +=3D -DTCP_HASH_NOINLINE - CFLAGS +=3D -DSIPHASH_20B_NOINLINE +ifneq (,$(filter -flto%,$(FLAGS) $(CFLAGS))) +ifneq (,$(filter -O2,$(FLAGS) $(CFLAGS))) + FLAGS +=3D -DTCP_HASH_NOINLINE + FLAGS +=3D -DSIPHASH_20B_NOINLINE endif endif endif =20 C :=3D \#include \nstruct tcp_info x =3D { .tcpi_snd_wnd =3D 0 = }; ifeq ($(shell printf "$(C)" | $(CC) -S -xc - -o - >/dev/null 2>&1; echo $$?)= ,0) - CFLAGS +=3D -DHAS_SND_WND + FLAGS +=3D -DHAS_SND_WND endif =20 C :=3D \#include \nstruct tcp_info x =3D { .tcpi_bytes_acked = =3D 0 }; ifeq ($(shell printf "$(C)" | $(CC) -S -xc - -o - >/dev/null 2>&1; echo $$?)= ,0) - CFLAGS +=3D -DHAS_BYTES_ACKED + FLAGS +=3D -DHAS_BYTES_ACKED endif =20 C :=3D \#include \nstruct tcp_info x =3D { .tcpi_min_rtt =3D 0 = }; ifeq ($(shell printf "$(C)" | $(CC) -S -xc - -o - >/dev/null 2>&1; echo $$?)= ,0) - CFLAGS +=3D -DHAS_MIN_RTT + FLAGS +=3D -DHAS_MIN_RTT endif =20 C :=3D \#include \nint main(){int a=3Dgetrandom(0, 0, 0);} ifeq ($(shell printf "$(C)" | $(CC) -S -xc - -o - >/dev/null 2>&1; echo $$?)= ,0) - CFLAGS +=3D -DHAS_GETRANDOM + FLAGS +=3D -DHAS_GETRANDOM endif =20 ifeq ($(shell :|$(CC) -fstack-protector-strong -S -xc - -o - >/dev/null 2>&1= ; echo $$?),0) - CFLAGS +=3D -fstack-protector-strong + FLAGS +=3D -fstack-protector-strong endif =20 prefix ?=3D /usr/local @@ -98,18 +98,19 @@ endif =20 all: $(BIN) $(MANPAGES) docs =20 -static: CFLAGS +=3D -static -DGLIBC_NO_STATIC_NSS +static: FLAGS +=3D -static -DGLIBC_NO_STATIC_NSS static: clean all =20 seccomp.h: $(PASST_SRCS) $(PASST_HEADERS) @ EXTRA_SYSCALLS=3D$(EXTRA_SYSCALLS) ./seccomp.sh $^ =20 passt: $(PASST_SRCS) $(PASST_HEADERS) seccomp.h - $(CC) $(CFLAGS) $(PASST_SRCS) -o passt $(LDFLAGS) + $(CC) $(FLAGS) $(CFLAGS) $(PASST_SRCS) -o passt $(LDFLAGS) =20 -passt.avx2: CFLAGS +=3D -Ofast -mavx2 -ftree-vectorize -funroll-loops +passt.avx2: FLAGS +=3D -Ofast -mavx2 -ftree-vectorize -funroll-loops passt.avx2: $(PASST_SRCS) $(PASST_HEADERS) seccomp.h - $(CC) $(filter-out -O2,$(CFLAGS)) $(PASST_SRCS) -o passt.avx2 $(LDFLAGS) + $(CC) $(filter-out -O2,$(FLAGS) $(CFLAGS)) \ + $(PASST_SRCS) -o passt.avx2 $(LDFLAGS) =20 passt.avx2: passt =20 @@ -117,12 +118,12 @@ pasta.avx2 pasta.1 pasta: pasta%: passt% ln -s $< $@ =20 qrap: $(QRAP_SRCS) passt.h - $(CC) $(CFLAGS) $(QRAP_SRCS) -o qrap $(LDFLAGS) + $(CC) $(FLAGS) $(CFLAGS) $(QRAP_SRCS) -o qrap $(LDFLAGS) =20 valgrind: EXTRA_SYSCALLS=3D"rt_sigprocmask rt_sigtimedwait rt_sigaction \ getpid gettid kill clock_gettime mmap munmap open \ unlink gettimeofday futex" -valgrind: CFLAGS:=3D-g -O0 $(filter-out -O%,$(CFLAGS)) +valgrind: FLAGS:=3D-g -O0 $(filter-out -O%,$(FLAGS)) valgrind: all =20 .PHONY: clean @@ -261,7 +262,7 @@ clang-tidy: $(SRCS) $(HEADERS) -altera-struct-pack-align,\ -concurrency-mt-unsafe \ -config=3D'{CheckOptions: [{key: bugprone-suspicious-string-compare.WarnOnI= mplicitComparison, value: "false"}]}' \ - --warnings-as-errors=3D* $(SRCS) -- $(filter-out -pie,$(CFLAGS)) + --warnings-as-errors=3D* $(SRCS) -- $(filter-out -pie,$(FLAGS) $(CFLAGS)) =20 ifeq ($(shell $(CC) -v 2>&1 | grep -c "gcc version"),1) TARGET :=3D $(shell ${CC} -v 2>&1 | sed -n 's/Target: \(.*\)/\1/p') @@ -304,5 +305,5 @@ cppcheck: $(SRCS) $(HEADERS) --suppress=3DunmatchedSuppression:udp.c \ --suppress=3DunmatchedSuppression:util.c \ --suppress=3DunmatchedSuppression:util.h \ - $(filter -D%,$(CFLAGS)) \ + $(filter -D%,$(FLAGS) $(CFLAGS)) \ . --=20 2.35.1 --===============5988573054950591946==--