Skip to contentSkip to conversation

multipath-tools: move CPPFLAGS before CFLAGS

PATCH In review [email protected] 2 participants 4 messages May 10, 2022 – May 11, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 multipath-tools: move CPPFLAGS before CFLAGS

From: Martin Wilck <[email protected]>

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.

---
 Makefile.inc          | 2 +-
 libmultipath/Makefile | 6 +++---
 multipathd/Makefile   | 2 +-
 tests/Makefile        | 2 +-
 4 files changed, 6 insertions(+), 6 deletions(-)
Makefile.inc +1 -1
index b915c06..7422666 100644
@@ -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 $< >$@
libmultipath/Makefile +3 -3
index a56dd1e..2fc3f3b 100644
@@ -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)
 
multipathd/Makefile +1 -1
index 9a49144..1449080 100644
@@ -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)
tests/Makefile +1 -1
index 0b39c30..a069e37 100644
@@ -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
Signature · 6 lines
2.36.0

--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel
#1 lore raw

PATCH 2/2 multipath-tools: cleanly separate CPPFLAGS and CFLAGS

From: Martin Wilck <[email protected]>

Move all preprocessor-related options (-D, -I) into CPPFLAGS. This is cleaner, and has the side effect of creating a better-readable output from "make".

---
 Makefile.inc                       |  4 ++--
 kpartx/Makefile                    |  5 +++--
 libdmmp/Makefile                   |  4 ++--
 libdmmp/test/Makefile              |  2 +-
 libmpathvalid/Makefile             |  3 ++-
 libmultipath/Makefile              | 19 ++++++++++---------
 libmultipath/checkers/Makefile     |  3 ++-
 libmultipath/foreign/Makefile      |  3 ++-
 libmultipath/prioritizers/Makefile |  5 +++--
 mpathpersist/Makefile              |  3 ++-
 multipath/Makefile                 |  3 ++-
 multipathd/Makefile                | 23 ++++++++++++-----------
 tests/Makefile                     |  4 ++--
 13 files changed, 45 insertions(+), 36 deletions(-)
Makefile.inc +2 -2
index 7422666..bcd2212 100644
@@ -140,10 +140,10 @@ OPTFLAGS	:= -O2 -g $(STACKPROT) --param=ssp-buffer-size=4
 WARNFLAGS	:= -Werror -Wall -Wextra -Wformat=2 $(WFORMATOVERFLOW) -Werror=implicit-int \
 		  -Werror=implicit-function-declaration -Werror=format-security \
 		  $(WNOCLOBBERED) -Werror=cast-qual $(ERROR_DISCARDED_QUALIFIERS)
-CPPFLAGS	:= $(FORTIFY_OPT)
-CFLAGS		:= --std=gnu99 $(CFLAGS) $(OPTFLAGS) $(WARNFLAGS) -pipe \
+CPPFLAGS	:= $(FORTIFY_OPT) \
 		   -DBIN_DIR=\"$(bindir)\" -DMULTIPATH_DIR=\"$(plugindir)\" -DRUN_DIR=\"${RUN}\" \
 		   -DCONFIG_DIR=\"$(configdir)\" -DEXTRAVERSION=\"$(EXTRAVERSION)\" -MMD -MP
+CFLAGS		:= --std=gnu99 $(CFLAGS) $(OPTFLAGS) $(WARNFLAGS) -pipe
 BIN_CFLAGS	= -fPIE -DPIE
 LIB_CFLAGS	= -fPIC
 SHARED_FLAGS	= -shared
kpartx/Makefile +3 -2
index e9900fb..742d3bc 100644
@@ -3,13 +3,14 @@
 #
 include ../Makefile.inc
 
-CFLAGS += $(BIN_CFLAGS) -I. -I$(multipathdir) -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
+CPPFLAGS += -I. -I$(multipathdir) -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
+CFLAGS += $(BIN_CFLAGS)
 LDFLAGS += $(BIN_LDFLAGS)
 
 LIBDEPS += -ldevmapper
 
 ifneq ($(call check_func,dm_task_set_cookie,$(DEVMAPPER_INCDIR)/libdevmapper.h),0)
-	CFLAGS += -DLIBDM_API_COOKIE
+	CPPFLAGS += -DLIBDM_API_COOKIE
 endif
 
 OBJS = bsd.o dos.o kpartx.o solaris.o unixware.o dasd.o sun.o \
libdmmp/Makefile +2 -2
index 00fc852..2e99b3e 100644
@@ -15,8 +15,8 @@ HEADERS = libdmmp/libdmmp.h
 
 OBJS = libdmmp.o libdmmp_mp.o libdmmp_pg.o libdmmp_path.o libdmmp_misc.o
 
-CFLAGS += $(LIB_CFLAGS) -fvisibility=hidden -I$(libdmmpdir) -I$(mpathcmddir) \
-	  $(shell $(PKGCONFIG) --cflags json-c)
+CPPFLAGS += -I$(libdmmpdir) -I$(mpathcmddir) $(shell $(PKGCONFIG) --cflags json-c)
+CFLAGS += $(LIB_CFLAGS) -fvisibility=hidden
 
 LIBDEPS += $(shell $(PKGCONFIG) --libs json-c) -L$(mpathcmddir) -lmpathcmd -lpthread
 
libdmmp/test/Makefile +1 -1
index 20b3945..76b24d6 100644
@@ -9,7 +9,7 @@ _mpathcmddir=../$(mpathcmddir)
 
 TEST_EXEC = libdmmp_test
 SPD_TEST_EXEC = libdmmp_speed_test
-CFLAGS += -I$(_libdmmpdir)
+CPPFLAGS += -I$(_libdmmpdir)
 LDFLAGS += -L$(_libdmmpdir) -ldmmp
 
 all: $(TEST_EXEC) $(SPD_TEST_EXEC)
libmpathvalid/Makefile +2 -1
index fefeb2a..0a51925 100644
@@ -5,7 +5,8 @@ DEVLIB = libmpathvalid.so
 LIBS = $(DEVLIB).$(SONAME)
 VERSION_SCRIPT := libmpathvalid.version
 
-CFLAGS += $(LIB_CFLAGS) -I$(multipathdir) -I$(mpathcmddir)
+CPPFLAGS += -I$(multipathdir) -I$(mpathcmddir)
+CFLAGS += $(LIB_CFLAGS)
 
 LIBDEPS += -lpthread -ldevmapper -ldl -L$(multipathdir) \
 	   -lmultipath -L$(mpathcmddir) -lmpathcmd -ludev
libmultipath/Makefile +10 -9
index 2fc3f3b..fb03200 100644
@@ -8,12 +8,13 @@ DEVLIB = libmultipath.so
 LIBS = $(DEVLIB).$(SONAME)
 VERSION_SCRIPT := libmultipath.version
 
-CFLAGS += $(LIB_CFLAGS) -I$(mpathcmddir) -I$(mpathpersistdir) -I$(nvmedir)
+CPPFLAGS += -I$(mpathcmddir) -I$(mpathpersistdir) -I$(nvmedir)
+CFLAGS += $(LIB_CFLAGS)
 
 LIBDEPS += -lpthread -ldl -ldevmapper -ludev -L$(mpathcmddir) -lmpathcmd -lurcu -laio
 
 ifdef SYSTEMD
-	CFLAGS += -DUSE_SYSTEMD=$(SYSTEMD)
+	CPPFLAGS += -DUSE_SYSTEMD=$(SYSTEMD)
 	ifeq ($(shell test $(SYSTEMD) -gt 209 && echo 1), 1)
 		LIBDEPS += -lsystemd
 	else
@@ -22,31 +23,31 @@ ifdef SYSTEMD
 endif
 
 ifneq ($(call check_func,dm_task_no_flush,$(DEVMAPPER_INCDIR)/libdevmapper.h),0)
-	CFLAGS += -DLIBDM_API_FLUSH -D_GNU_SOURCE
+	CPPFLAGS += -DLIBDM_API_FLUSH -D_GNU_SOURCE
 endif
 
 ifneq ($(call check_func,dm_task_get_errno,$(DEVMAPPER_INCDIR)/libdevmapper.h),0)
-	CFLAGS += -DLIBDM_API_GET_ERRNO
+	CPPFLAGS += -DLIBDM_API_GET_ERRNO
 endif
 
 ifneq ($(call check_func,dm_task_set_cookie,$(DEVMAPPER_INCDIR)/libdevmapper.h),0)
-	CFLAGS += -DLIBDM_API_COOKIE
+	CPPFLAGS += -DLIBDM_API_COOKIE
 endif
 
 ifneq ($(call check_func,udev_monitor_set_receive_buffer_size,$(LIBUDEV_INCDIR)/libudev.h),0)
-	CFLAGS += -DLIBUDEV_API_RECVBUF
+	CPPFLAGS += -DLIBUDEV_API_RECVBUF
 endif
 
 ifneq ($(call check_func,dm_task_deferred_remove,$(DEVMAPPER_INCDIR)/libdevmapper.h),0)
-	CFLAGS += -DLIBDM_API_DEFERRED
+	CPPFLAGS += -DLIBDM_API_DEFERRED
 endif
 
 ifneq ($(call check_func,dm_hold_control_dev,$(DEVMAPPER_INCDIR)/libdevmapper.h),0)
-	CFLAGS += -DLIBDM_API_HOLD_CONTROL
+	CPPFLAGS += -DLIBDM_API_HOLD_CONTROL
 endif
 
 ifneq ($(call check_var,ELS_DTAG_LNK_INTEGRITY,$(LINUX_HEADERS_INCDIR)/scsi/fc/fc_els.h),0)
-	CFLAGS += -DFPIN_EVENT_HANDLER
+	CPPFLAGS += -DFPIN_EVENT_HANDLER
 endif
 
 # object files referencing MULTIPATH_DIR or CONFIG_DIR
libmultipath/checkers/Makefile +2 -1
index 8e0ed5e..8d8e45e 100644
@@ -3,7 +3,8 @@
 #
 include ../../Makefile.inc
 
-CFLAGS += $(LIB_CFLAGS) -I..
+CPPFLAGS += -I..
+CFLAGS += $(LIB_CFLAGS)
 LDFLAGS += -L.. -lmultipath
 LIBDEPS = -lmultipath -laio -lpthread -lrt
 
libmultipath/foreign/Makefile +2 -1
index f447a1c..42cea4d 100644
@@ -4,7 +4,8 @@
 TOPDIR=../..
 include ../../Makefile.inc
 
-CFLAGS += $(LIB_CFLAGS) -I.. -I$(nvmedir)
+CPPFLAGS += -I.. -I$(nvmedir)
+CFLAGS += $(LIB_CFLAGS)
 LDFLAGS += -L..
 LIBDEPS = -lmultipath -ludev -lpthread -lrt
 
libmultipath/prioritizers/Makefile +3 -2
index 16c6397..a5ab5e1 100644
@@ -3,7 +3,8 @@
 #
 include ../../Makefile.inc
 
-CFLAGS += $(LIB_CFLAGS) -I..
+CPPFLAGS += -I..
+CFLAGS += $(LIB_CFLAGS)
 LDFLAGS += -L..
 LIBDEPS = -lmultipath -lm -lpthread -lrt
 
@@ -25,7 +26,7 @@ LIBS = \
 
 ifneq ($(call check_file,$(LINUX_HEADERS_INCDIR)/linux/nvme_ioctl.h),0)
 	LIBS += libprioana.so
-	CFLAGS += -I../nvme
+	CPPFLAGS += -I../nvme
 endif
 
 all: $(LIBS)
mpathpersist/Makefile +2 -1
index eb26970..2e4d483 100644
@@ -1,6 +1,7 @@
 include ../Makefile.inc
 
-CFLAGS += $(BIN_CFLAGS) -I$(multipathdir) -I$(mpathpersistdir)
+CPPFLAGS += -I$(multipathdir) -I$(mpathpersistdir)
+CFLAGS += $(BIN_CFLAGS)
 LDFLAGS += $(BIN_LDFLAGS)
 
 LIBDEPS += -L$(mpathpersistdir) -lmpathpersist -L$(multipathdir) -lmultipath \
multipath/Makefile +2 -1
index c930499..bcb0453 100644
@@ -3,7 +3,8 @@
 #
 include ../Makefile.inc
 
-CFLAGS += $(BIN_CFLAGS) -I$(multipathdir) -I$(mpathcmddir)
+CPPFLAGS += -I$(multipathdir) -I$(mpathcmddir)
+CFLAGS += $(BIN_CFLAGS)
 LDFLAGS += $(BIN_LDFLAGS)
 LIBDEPS += -L$(multipathdir) -lmultipath -L$(mpathcmddir) -lmpathcmd \
 	-lpthread -ldevmapper -ldl -ludev
multipathd/Makefile +12 -11
index 1449080..c937cd5 100644
@@ -1,30 +1,31 @@
 include ../Makefile.inc
 
 ifneq ($(call check_func,dm_task_get_errno,$(DEVMAPPER_INCDIR)/libdevmapper.h),0)
-	CFLAGS += -DLIBDM_API_GET_ERRNO
+	CPPFLAGS += -DLIBDM_API_GET_ERRNO
 endif
 
 ifneq ($(call check_var,ELS_DTAG_LNK_INTEGRITY,$(LINUX_HEADERS_INCDIR)/scsi/fc/fc_els.h),0)
-	CFLAGS += -DFPIN_EVENT_HANDLER
+	CPPFLAGS += -DFPIN_EVENT_HANDLER
 	FPIN_SUPPORT = 1
 endif
 #
 # debugging stuff
 #
-#CFLAGS += -DLCKDBG
-#CFLAGS += -D_DEBUG_
-#CFLAGS += -DLOGDBG
-CFLAGS += $(BIN_CFLAGS) -I$(multipathdir) -I$(mpathpersistdir) \
-	  -I$(mpathcmddir) -I$(thirdpartydir)
+#CPPFLAGS += -DLCKDBG
+#CPPFLAGS += -D_DEBUG_
+#CPPFLAGS += -DLOGDBG
+
+CPPFLAGS += -I$(multipathdir) -I$(mpathpersistdir) -I$(mpathcmddir) -I$(thirdpartydir) \
+	$(shell $(PKGCONFIG) --modversion liburcu 2>/dev/null | \
+		awk -F. '{ printf("-DURCU_VERSION=0x%06x", 256 * ( 256 * $$1 + $$2) + $$3); }')
+CFLAGS += $(BIN_CFLAGS)
 LDFLAGS += $(BIN_LDFLAGS)
 LIBDEPS += -L$(multipathdir) -lmultipath -L$(mpathpersistdir) -lmpathpersist \
 	   -L$(mpathcmddir) -lmpathcmd -ludev -ldl -lurcu -lpthread \
 	   -ldevmapper -lreadline
-CFLAGS += $(shell $(PKGCONFIG) --modversion liburcu 2>/dev/null | \
-	awk -F. '{ printf("-DURCU_VERSION=0x%06x", 256 * ( 256 * $$1 + $$2) + $$3); }')
 
 ifdef SYSTEMD
-	CFLAGS += -DUSE_SYSTEMD=$(SYSTEMD)
+	CPPFLAGS += -DUSE_SYSTEMD=$(SYSTEMD)
 	ifeq ($(shell test $(SYSTEMD) -gt 209 && echo 1), 1)
 		LIBDEPS += -lsystemd
 	else
@@ -32,7 +33,7 @@ ifdef SYSTEMD
 	endif
 endif
 ifeq ($(ENABLE_DMEVENTS_POLL),0)
-	CFLAGS += -DNO_DMEVENTS_POLL
+	CPPFLAGS += -DNO_DMEVENTS_POLL
 endif
 
 OBJS = main.o pidfile.o uxlsnr.o uxclnt.o cli.o cli_handlers.o waiter.o \
tests/Makefile +2 -2
index a069e37..d20ef23 100644
@@ -11,8 +11,8 @@ TEST_MISSING_INITIALIZERS = $(shell \
 	|| echo -Wno-missing-field-initializers)
 W_MISSING_INITIALIZERS := $(call TEST_MISSING_INITIALIZERS)
 
-CFLAGS += $(BIN_CFLAGS) -I$(multipathdir) -I$(mpathcmddir) \
-	-Wno-unused-parameter $(W_MISSING_INITIALIZERS) -DTESTCONFDIR=\"$(TESTDIR)/conf.d\"
+CPPFLAGS += -I$(multipathdir) -I$(mpathcmddir) -DTESTCONFDIR=\"$(TESTDIR)/conf.d\"
+CFLAGS += $(BIN_CFLAGS) -Wno-unused-parameter $(W_MISSING_INITIALIZERS)
 LIBDEPS += -L. -L$(mpathcmddir) -lmultipath -lmpathcmd -lcmocka
 
 TESTS := uevent parser util dmevents hwtable blacklist unaligned vpd pgpolicy \
Signature · 6 lines
2.36.0

--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel
Reviewed-by on v1 2/2
#2 lore raw

Re: [dm-devel] [PATCH 2/2] multipath-tools: cleanly separate CPPFLAGS and CFLAGS

Quoted 7 lines · On 5/10/22 11:35, [email protected] wrote:

From: Martin Wilck <[email protected]>

Move all preprocessor-related options (-D, -I) into CPPFLAGS. This is cleaner, and has the side effect of creating a better-readable output from "make".

Quoted 293 lines
---
 Makefile.inc                       |  4 ++--
 kpartx/Makefile                    |  5 +++--
 libdmmp/Makefile                   |  4 ++--
 libdmmp/test/Makefile              |  2 +-
 libmpathvalid/Makefile             |  3 ++-
 libmultipath/Makefile              | 19 ++++++++++---------
 libmultipath/checkers/Makefile     |  3 ++-
 libmultipath/foreign/Makefile      |  3 ++-
 libmultipath/prioritizers/Makefile |  5 +++--
 mpathpersist/Makefile              |  3 ++-
 multipath/Makefile                 |  3 ++-
 multipathd/Makefile                | 23 ++++++++++++-----------
 tests/Makefile                     |  4 ++--
 13 files changed, 45 insertions(+), 36 deletions(-)
Makefile.inc +2 -2
index 7422666..bcd2212 100644
@@ -140,10 +140,10 @@ OPTFLAGS	:= -O2 -g $(STACKPROT) --param=ssp-buffer-size=4
 WARNFLAGS	:= -Werror -Wall -Wextra -Wformat=2 $(WFORMATOVERFLOW) -Werror=implicit-int \
 		  -Werror=implicit-function-declaration -Werror=format-security \
 		  $(WNOCLOBBERED) -Werror=cast-qual $(ERROR_DISCARDED_QUALIFIERS)
-CPPFLAGS	:= $(FORTIFY_OPT)
-CFLAGS		:= --std=gnu99 $(CFLAGS) $(OPTFLAGS) $(WARNFLAGS) -pipe \
+CPPFLAGS	:= $(FORTIFY_OPT) \
 		   -DBIN_DIR=\"$(bindir)\" -DMULTIPATH_DIR=\"$(plugindir)\" -DRUN_DIR=\"${RUN}\" \
 		   -DCONFIG_DIR=\"$(configdir)\" -DEXTRAVERSION=\"$(EXTRAVERSION)\" -MMD -MP
+CFLAGS		:= --std=gnu99 $(CFLAGS) $(OPTFLAGS) $(WARNFLAGS) -pipe
 BIN_CFLAGS	= -fPIE -DPIE
 LIB_CFLAGS	= -fPIC
 SHARED_FLAGS	= -shared
kpartx/Makefile +3 -2
index e9900fb..742d3bc 100644
@@ -3,13 +3,14 @@
 #
 include ../Makefile.inc
 
-CFLAGS += $(BIN_CFLAGS) -I. -I$(multipathdir) -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
+CPPFLAGS += -I. -I$(multipathdir) -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
+CFLAGS += $(BIN_CFLAGS)
 LDFLAGS += $(BIN_LDFLAGS)
 
 LIBDEPS += -ldevmapper
 
 ifneq ($(call check_func,dm_task_set_cookie,$(DEVMAPPER_INCDIR)/libdevmapper.h),0)
-	CFLAGS += -DLIBDM_API_COOKIE
+	CPPFLAGS += -DLIBDM_API_COOKIE
 endif
 
 OBJS = bsd.o dos.o kpartx.o solaris.o unixware.o dasd.o sun.o \
libdmmp/Makefile +2 -2
index 00fc852..2e99b3e 100644
@@ -15,8 +15,8 @@ HEADERS = libdmmp/libdmmp.h
 
 OBJS = libdmmp.o libdmmp_mp.o libdmmp_pg.o libdmmp_path.o libdmmp_misc.o
 
-CFLAGS += $(LIB_CFLAGS) -fvisibility=hidden -I$(libdmmpdir) -I$(mpathcmddir) \
-	  $(shell $(PKGCONFIG) --cflags json-c)
+CPPFLAGS += -I$(libdmmpdir) -I$(mpathcmddir) $(shell $(PKGCONFIG) --cflags json-c)
+CFLAGS += $(LIB_CFLAGS) -fvisibility=hidden
 
 LIBDEPS += $(shell $(PKGCONFIG) --libs json-c) -L$(mpathcmddir) -lmpathcmd -lpthread
 
libdmmp/test/Makefile +1 -1
index 20b3945..76b24d6 100644
@@ -9,7 +9,7 @@ _mpathcmddir=../$(mpathcmddir)
 
 TEST_EXEC = libdmmp_test
 SPD_TEST_EXEC = libdmmp_speed_test
-CFLAGS += -I$(_libdmmpdir)
+CPPFLAGS += -I$(_libdmmpdir)
 LDFLAGS += -L$(_libdmmpdir) -ldmmp
 
 all: $(TEST_EXEC) $(SPD_TEST_EXEC)
libmpathvalid/Makefile +2 -1
index fefeb2a..0a51925 100644
@@ -5,7 +5,8 @@ DEVLIB = libmpathvalid.so
 LIBS = $(DEVLIB).$(SONAME)
 VERSION_SCRIPT := libmpathvalid.version
 
-CFLAGS += $(LIB_CFLAGS) -I$(multipathdir) -I$(mpathcmddir)
+CPPFLAGS += -I$(multipathdir) -I$(mpathcmddir)
+CFLAGS += $(LIB_CFLAGS)
 
 LIBDEPS += -lpthread -ldevmapper -ldl -L$(multipathdir) \
 	   -lmultipath -L$(mpathcmddir) -lmpathcmd -ludev
libmultipath/Makefile +10 -9
index 2fc3f3b..fb03200 100644
@@ -8,12 +8,13 @@ DEVLIB = libmultipath.so
 LIBS = $(DEVLIB).$(SONAME)
 VERSION_SCRIPT := libmultipath.version
 
-CFLAGS += $(LIB_CFLAGS) -I$(mpathcmddir) -I$(mpathpersistdir) -I$(nvmedir)
+CPPFLAGS += -I$(mpathcmddir) -I$(mpathpersistdir) -I$(nvmedir)
+CFLAGS += $(LIB_CFLAGS)
 
 LIBDEPS += -lpthread -ldl -ldevmapper -ludev -L$(mpathcmddir) -lmpathcmd -lurcu -laio
 
 ifdef SYSTEMD
-	CFLAGS += -DUSE_SYSTEMD=$(SYSTEMD)
+	CPPFLAGS += -DUSE_SYSTEMD=$(SYSTEMD)
 	ifeq ($(shell test $(SYSTEMD) -gt 209 && echo 1), 1)
 		LIBDEPS += -lsystemd
 	else
@@ -22,31 +23,31 @@ ifdef SYSTEMD
 endif
 
 ifneq ($(call check_func,dm_task_no_flush,$(DEVMAPPER_INCDIR)/libdevmapper.h),0)
-	CFLAGS += -DLIBDM_API_FLUSH -D_GNU_SOURCE
+	CPPFLAGS += -DLIBDM_API_FLUSH -D_GNU_SOURCE
 endif
 
 ifneq ($(call check_func,dm_task_get_errno,$(DEVMAPPER_INCDIR)/libdevmapper.h),0)
-	CFLAGS += -DLIBDM_API_GET_ERRNO
+	CPPFLAGS += -DLIBDM_API_GET_ERRNO
 endif
 
 ifneq ($(call check_func,dm_task_set_cookie,$(DEVMAPPER_INCDIR)/libdevmapper.h),0)
-	CFLAGS += -DLIBDM_API_COOKIE
+	CPPFLAGS += -DLIBDM_API_COOKIE
 endif
 
 ifneq ($(call check_func,udev_monitor_set_receive_buffer_size,$(LIBUDEV_INCDIR)/libudev.h),0)
-	CFLAGS += -DLIBUDEV_API_RECVBUF
+	CPPFLAGS += -DLIBUDEV_API_RECVBUF
 endif
 
 ifneq ($(call check_func,dm_task_deferred_remove,$(DEVMAPPER_INCDIR)/libdevmapper.h),0)
-	CFLAGS += -DLIBDM_API_DEFERRED
+	CPPFLAGS += -DLIBDM_API_DEFERRED
 endif
 
 ifneq ($(call check_func,dm_hold_control_dev,$(DEVMAPPER_INCDIR)/libdevmapper.h),0)
-	CFLAGS += -DLIBDM_API_HOLD_CONTROL
+	CPPFLAGS += -DLIBDM_API_HOLD_CONTROL
 endif
 
 ifneq ($(call check_var,ELS_DTAG_LNK_INTEGRITY,$(LINUX_HEADERS_INCDIR)/scsi/fc/fc_els.h),0)
-	CFLAGS += -DFPIN_EVENT_HANDLER
+	CPPFLAGS += -DFPIN_EVENT_HANDLER
 endif
 
 # object files referencing MULTIPATH_DIR or CONFIG_DIR
libmultipath/checkers/Makefile +2 -1
index 8e0ed5e..8d8e45e 100644
@@ -3,7 +3,8 @@
 #
 include ../../Makefile.inc
 
-CFLAGS += $(LIB_CFLAGS) -I..
+CPPFLAGS += -I..
+CFLAGS += $(LIB_CFLAGS)
 LDFLAGS += -L.. -lmultipath
 LIBDEPS = -lmultipath -laio -lpthread -lrt
 
libmultipath/foreign/Makefile +2 -1
index f447a1c..42cea4d 100644
@@ -4,7 +4,8 @@
 TOPDIR=../..
 include ../../Makefile.inc
 
-CFLAGS += $(LIB_CFLAGS) -I.. -I$(nvmedir)
+CPPFLAGS += -I.. -I$(nvmedir)
+CFLAGS += $(LIB_CFLAGS)
 LDFLAGS += -L..
 LIBDEPS = -lmultipath -ludev -lpthread -lrt
 
libmultipath/prioritizers/Makefile +3 -2
index 16c6397..a5ab5e1 100644
@@ -3,7 +3,8 @@
 #
 include ../../Makefile.inc
 
-CFLAGS += $(LIB_CFLAGS) -I..
+CPPFLAGS += -I..
+CFLAGS += $(LIB_CFLAGS)
 LDFLAGS += -L..
 LIBDEPS = -lmultipath -lm -lpthread -lrt
 
@@ -25,7 +26,7 @@ LIBS = \
 
 ifneq ($(call check_file,$(LINUX_HEADERS_INCDIR)/linux/nvme_ioctl.h),0)
 	LIBS += libprioana.so
-	CFLAGS += -I../nvme
+	CPPFLAGS += -I../nvme
 endif
 
 all: $(LIBS)
mpathpersist/Makefile +2 -1
index eb26970..2e4d483 100644
@@ -1,6 +1,7 @@
 include ../Makefile.inc
 
-CFLAGS += $(BIN_CFLAGS) -I$(multipathdir) -I$(mpathpersistdir)
+CPPFLAGS += -I$(multipathdir) -I$(mpathpersistdir)
+CFLAGS += $(BIN_CFLAGS)
 LDFLAGS += $(BIN_LDFLAGS)
 
 LIBDEPS += -L$(mpathpersistdir) -lmpathpersist -L$(multipathdir) -lmultipath \
multipath/Makefile +2 -1
index c930499..bcb0453 100644
@@ -3,7 +3,8 @@
 #
 include ../Makefile.inc
 
-CFLAGS += $(BIN_CFLAGS) -I$(multipathdir) -I$(mpathcmddir)
+CPPFLAGS += -I$(multipathdir) -I$(mpathcmddir)
+CFLAGS += $(BIN_CFLAGS)
 LDFLAGS += $(BIN_LDFLAGS)
 LIBDEPS += -L$(multipathdir) -lmultipath -L$(mpathcmddir) -lmpathcmd \
 	-lpthread -ldevmapper -ldl -ludev
multipathd/Makefile +12 -11
index 1449080..c937cd5 100644
@@ -1,30 +1,31 @@
 include ../Makefile.inc
 
 ifneq ($(call check_func,dm_task_get_errno,$(DEVMAPPER_INCDIR)/libdevmapper.h),0)
-	CFLAGS += -DLIBDM_API_GET_ERRNO
+	CPPFLAGS += -DLIBDM_API_GET_ERRNO
 endif
 
 ifneq ($(call check_var,ELS_DTAG_LNK_INTEGRITY,$(LINUX_HEADERS_INCDIR)/scsi/fc/fc_els.h),0)
-	CFLAGS += -DFPIN_EVENT_HANDLER
+	CPPFLAGS += -DFPIN_EVENT_HANDLER
 	FPIN_SUPPORT = 1
 endif
 #
 # debugging stuff
 #
-#CFLAGS += -DLCKDBG
-#CFLAGS += -D_DEBUG_
-#CFLAGS += -DLOGDBG
-CFLAGS += $(BIN_CFLAGS) -I$(multipathdir) -I$(mpathpersistdir) \
-	  -I$(mpathcmddir) -I$(thirdpartydir)
+#CPPFLAGS += -DLCKDBG
+#CPPFLAGS += -D_DEBUG_
+#CPPFLAGS += -DLOGDBG
+
+CPPFLAGS += -I$(multipathdir) -I$(mpathpersistdir) -I$(mpathcmddir) -I$(thirdpartydir) \
+	$(shell $(PKGCONFIG) --modversion liburcu 2>/dev/null | \
+		awk -F. '{ printf("-DURCU_VERSION=0x%06x", 256 * ( 256 * $$1 + $$2) + $$3); }')
+CFLAGS += $(BIN_CFLAGS)
 LDFLAGS += $(BIN_LDFLAGS)
 LIBDEPS += -L$(multipathdir) -lmultipath -L$(mpathpersistdir) -lmpathpersist \
 	   -L$(mpathcmddir) -lmpathcmd -ludev -ldl -lurcu -lpthread \
 	   -ldevmapper -lreadline
-CFLAGS += $(shell $(PKGCONFIG) --modversion liburcu 2>/dev/null | \
-	awk -F. '{ printf("-DURCU_VERSION=0x%06x", 256 * ( 256 * $$1 + $$2) + $$3); }')
 
 ifdef SYSTEMD
-	CFLAGS += -DUSE_SYSTEMD=$(SYSTEMD)
+	CPPFLAGS += -DUSE_SYSTEMD=$(SYSTEMD)
 	ifeq ($(shell test $(SYSTEMD) -gt 209 && echo 1), 1)
 		LIBDEPS += -lsystemd
 	else
@@ -32,7 +33,7 @@ ifdef SYSTEMD
 	endif
 endif
 ifeq ($(ENABLE_DMEVENTS_POLL),0)
-	CFLAGS += -DNO_DMEVENTS_POLL
+	CPPFLAGS += -DNO_DMEVENTS_POLL
 endif
 
 OBJS = main.o pidfile.o uxlsnr.o uxclnt.o cli.o cli_handlers.o waiter.o \
tests/Makefile +0 -0
index a069e37..d20ef23 100644

tests/Makefile TEST_MISSING_INITIALIZERS = $(shell \ · line 18

Quoted 10 lines
tests/Makefile +2 -2
@@ -11,8 +11,8 @@ TEST_MISSING_INITIALIZERS = $(shell \
 	|| echo -Wno-missing-field-initializers)
 W_MISSING_INITIALIZERS := $(call TEST_MISSING_INITIALIZERS)
 
-CFLAGS += $(BIN_CFLAGS) -I$(multipathdir) -I$(mpathcmddir) \
-	-Wno-unused-parameter $(W_MISSING_INITIALIZERS) -DTESTCONFDIR=\"$(TESTDIR)/conf.d\"
+CPPFLAGS += -I$(multipathdir) -I$(mpathcmddir) -DTESTCONFDIR=\"$(TESTDIR)/conf.d\"
+CFLAGS += $(BIN_CFLAGS) -Wno-unused-parameter $(W_MISSING_INITIALIZERS)
 LIBDEPS += -L. -L$(mpathcmddir) -lmultipath -lmpathcmd -lcmocka
 
 TESTS := uevent parser util dmevents hwtable blacklist unaligned vpd pgpolicy \

--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel

Reviewed-by on v1 1/2
#3 lore raw
In reply to [email protected]
Quoted 9 lines · On 5/10/22 11:35, [email protected] wrote:

From: Martin Wilck <[email protected]>

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).

Quoted 4 lines

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

Quoted 66 lines
---
 Makefile.inc          | 2 +-
 libmultipath/Makefile | 6 +++---
 multipathd/Makefile   | 2 +-
 tests/Makefile        | 2 +-
 4 files changed, 6 insertions(+), 6 deletions(-)
Makefile.inc +1 -1
index b915c06..7422666 100644
@@ -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 $< >$@
libmultipath/Makefile +3 -3
index a56dd1e..2fc3f3b 100644
@@ -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)
 
multipathd/Makefile +1 -1
index 9a49144..1449080 100644
@@ -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)
tests/Makefile +0 -0
index 0b39c30..a069e37 100644

tests/Makefile endif · line 78

Quoted 8 lines
tests/Makefile +1 -1
@@ -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

--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel