[PATCH libaio 03/16] build: Honor user build flags
authorGuillem Jover <guillem@hadrons.org>
Sun, 12 Apr 2020 02:01:27 +0000 (04:01 +0200)
committerGuillem Jover <guillem@debian.org>
Sun, 6 Aug 2023 19:12:34 +0000 (20:12 +0100)
CPPFLAGS, CFLAGS and LDFLAGS are user flags, which we need to preserve,
regardless of the user passing them over the environment or the
command-line. Any required flag that the build system needs, has to be
set in some other flag (which we will namespace with «MK_») so that the
build will use even if the user flags are passed, even though the user
should be able to override by appending after them. We pass CPPFLAGS to
any compilation command that missed them.

Signed-off-by: Guillem Jover <guillem@hadrons.org>
Gbp-Pq: Name 0003-build-Honor-user-build-flags.patch

harness/Makefile
src/Makefile

index 4f225d3ff3bc816d210b92312136e52381cb93bc..8cb27fa2f58db680a1b902b07a4d8dda7eca0919 100644 (file)
@@ -6,13 +6,16 @@ PROGS:=$(PARTPROGS) $(EXTRAPROGS)
 HARNESS_SRCS:=main.c
 # io_queue.c
 
-CFLAGS+=-Wall -Werror -I../src -g -O2
+MK_CPPFLAGS = -I../src $(CPPFLAGS)
+CFLAGS ?= -Wall -Werror -g -O2
+MK_CFLAGS = $(CFLAGS)
 #-lpthread -lrt
+MK_LDFLAGS = main.c $(LIBAIO) -lpthread $(LDFLAGS)
 
 # gcc-11 does not like the test case in 3.t that
 # passes an invalid pointer (-1) to the kernel, so
 # tell the compiler we do not need a warning here
-cases/3.p:     CFLAGS+=-Wno-stringop-overflow
+cases/3.p:     MK_CFLAGS+=-Wno-stringop-overflow
 
 # Change this on the build line to run tests against the installed libraries:
 # make LIBAIO=-laio partcheck
@@ -21,7 +24,7 @@ LIBAIO?=../src/libaio.a
 all: $(PROGS)
 
 $(PROGS): %.p: %.t $(HARNESS_SRCS)
-       $(CC) $(CFLAGS) -DTEST_NAME=\"$<\" -o $@ main.c $(LIBAIO) -lpthread
+       $(CC) $(MK_CPPFLAGS) $(MK_CFLAGS) -DTEST_NAME=\"$<\" -o $@ $(MK_LDFLAGS)
 
 clean:
        rm -f $(PROGS) *.o runtests.out rofile wofile rwfile
index 9a36d0d03fba1fb91c263f8d4927a53e5395af82..9a1ba514ffd25f99fa06b9b8c82efaf0af0d8cec 100644 (file)
@@ -2,12 +2,12 @@ prefix ?= /usr
 includedir ?= $(prefix)/include
 libdir ?= $(prefix)/lib
 
-CFLAGS ?= -g -fomit-frame-pointer -O2
-CFLAGS += -Wall -I. -fPIC
-SO_CFLAGS=-shared $(CFLAGS)
-L_CFLAGS=$(CFLAGS)
-LINK_FLAGS=
-LINK_FLAGS+=$(LDFLAGS)
+MK_CPPFLAGS = -I. $(CPPFLAGS)
+CFLAGS ?= -Wall -g -fomit-frame-pointer -O2
+MK_CFLAGS = -fPIC $(CFLAGS)
+SO_CFLAGS = -shared $(MK_CFLAGS)
+L_CFLAGS = $(MK_CFLAGS)
+MK_LDFLAGS = $(LDFLAGS)
 ENABLE_SHARED ?= 1
 
 soname=libaio.so.1
@@ -42,10 +42,10 @@ libaio_sobjs := $(patsubst %.c,%.os,$(libaio_srcs))
 $(libaio_objs) $(libaio_sobjs): libaio.h vsys_def.h
 
 %.os: %.c
-       $(CC) $(SO_CFLAGS) -c -o $@ $<
+       $(CC) $(MK_CPPFLAGS) $(SO_CFLAGS) -c -o $@ $<
 
 %.ol: %.c
-       $(CC) $(L_CFLAGS) -c -o $@ $<
+       $(CC) $(MK_CPPFLAGS) $(L_CFLAGS) -c -o $@ $<
 
 AR ?= ar
 RANLIB ?= ranlib
@@ -55,8 +55,8 @@ libaio.a: $(libaio_objs)
        $(RANLIB) libaio.a
 
 $(libname): $(libaio_sobjs) libaio.map
-       $(CC) $(CFLAGS) -c struct_offsets.c
-       $(CC) $(SO_CFLAGS) -Wl,--version-script=libaio.map -Wl,-soname=$(soname) -o $@ $(libaio_sobjs) $(LINK_FLAGS)
+       $(CC) $(MK_CPPFLAGS) $(MK_CFLAGS) -c struct_offsets.c
+       $(CC) $(SO_CFLAGS) -Wl,--version-script=libaio.map -Wl,-soname=$(soname) -o $@ $(libaio_sobjs) $(MK_LDFLAGS)
 
 install: $(all_targets)
        install -D -m 644 libaio.h $(DESTDIR)$(includedir)/libaio.h