[dm-devel] [PATCH 1/2] multipath-tools: move CPPFLAGS before CFLAGS

mwilck at suse.com mwilck at suse.com
Tue May 10 09:35:37 UTC 2022


From: Martin Wilck <mwilck at suse.com>

Distributions may want to override -D_FORTIFY_SOURCE in the generic
OPTFLAGS variable. That requires that the autodected setting is
evaluated before OPTFLAGS on the compiler command line.
This way, distributions can use OPTFLAGS="-U_FORTIFY_SOURCE
-D_FORTIFY_SOURCE=3 ..." without causing compilation errors.
(Note that the "-U" is required).

Move CPPFLAGS before CFLAGS in the compiler command line. Moreover, make sure
CPPFLAGS is referenced in all compilation steps.

Signed-off-by: Martin Wilck <mwilck at suse.com>
---
 Makefile.inc          | 2 +-
 libmultipath/Makefile | 6 +++---
 multipathd/Makefile   | 2 +-
 tests/Makefile        | 2 +-
 4 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/Makefile.inc b/Makefile.inc
index b915c06..7422666 100644
--- a/Makefile.inc
+++ b/Makefile.inc
@@ -191,7 +191,7 @@ check_var = $(shell \
 
 %.o:	%.c
 	@echo building $@ because of $?
-	$(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $<
+	$(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $<
 
 %.abi:  %.so.0
 	abidw $< >$@
diff --git a/libmultipath/Makefile b/libmultipath/Makefile
index a56dd1e..2fc3f3b 100644
--- a/libmultipath/Makefile
+++ b/libmultipath/Makefile
@@ -70,12 +70,12 @@ OBJS := $(OBJS-O) $(OBJS-U)
 all:	$(DEVLIB)
 
 nvme-lib.o: nvme-lib.c nvme-ioctl.c nvme-ioctl.h
-	$(CC) $(CFLAGS) -Wno-unused-function -c -o $@ $<
+	$(CC) $(CPPFLAGS) $(CFLAGS) -Wno-unused-function -c -o $@ $<
 
 # there are lots of "unused parameters" in dict.c
 # because not all handler / snprint methods need all parameters
 dict.o:	dict.c
-	$(CC) $(CFLAGS) -Wno-unused-parameter -c -o $@ $<
+	$(CC) $(CPPFLAGS) $(CFLAGS) -Wno-unused-parameter -c -o $@ $<
 
 make_static = $(shell sed '/^static/!s/^\([a-z]\{1,\} \)/static \1/' <$1 >$2)
 
@@ -112,7 +112,7 @@ abi:    $(LIBS:%.so.$(SONAME)=%-nv.abi)
 # This rule is invoked from tests/Makefile, overriding configdir and plugindir
 %-test.o: %.c
 	@echo building $@ because of $?
-	$(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $<
+	$(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $<
 
 test-lib:	../tests/$(LIBS)
 
diff --git a/multipathd/Makefile b/multipathd/Makefile
index 9a49144..1449080 100644
--- a/multipathd/Makefile
+++ b/multipathd/Makefile
@@ -52,7 +52,7 @@ $(EXEC): $(OBJS) $(multipathdir)/libmultipath.so $(mpathcmddir)/libmpathcmd.so
 	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) -o $(EXEC) $(LIBDEPS)
 
 cli_handlers.o:	cli_handlers.c
-	$(CC) $(CFLAGS) -Wno-unused-parameter -c -o $@ $<
+	$(CC) $(CPPFLAGS) $(CFLAGS) -Wno-unused-parameter -c -o $@ $<
 
 install:
 	$(INSTALL_PROGRAM) -d $(DESTDIR)$(bindir)
diff --git a/tests/Makefile b/tests/Makefile
index 0b39c30..a069e37 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -72,7 +72,7 @@ endif
 strbuf-test_OBJDEPS := ../libmultipath/strbuf.o
 
 %.o: %.c
-	$(CC) $(CFLAGS) $($*-test_FLAGS) -c -o $@ $<
+	$(CC) $(CPPFLAGS) $(CFLAGS) $($*-test_FLAGS) -c -o $@ $<
 
 lib/libchecktur.so:
 	mkdir -p lib
-- 
2.36.0



More information about the dm-devel mailing list