[hackers] [dmenu][PATCH] don't mangle CPPFLAGS with CFLAGS

From: NRK <nrk_AT_disroot.org>
Date: Mon, 4 Jul 2022 15:01:35 +0600

currently, doing something like the following would fail to build:

        $ make CFLAGS="-O3 -march=native"

this is because CPPFLAGS get mangled with CFLAGS and so changing CFLAGS
kills the build.

similarly it's conventional to have library flags in LDLIBS, so that
user can change LDFLAGS to add "-flto" or other flags they might want
without the build unnecessarily failing.
---
P.S: Could also drop `-std=c99` from CFLAGS and set CC to c99. But
didn't do that since it wasn't needed for my goal of being able to do
something like the following:
	$ make CFLAGS="-O3 -flto" LDFLAGS="-O3 -flto"
 Makefile  | 8 +++++---
 config.mk | 6 +++---
 2 files changed, 8 insertions(+), 6 deletions(-)
diff --git a/Makefile b/Makefile
index a03a95c..8d25ad0 100644
--- a/Makefile
+++ b/Makefile
_AT_@ -11,11 +11,13 @@ all: options dmenu stest
 options:
 	_AT_echo dmenu build options:
 	_AT_echo "CFLAGS   = $(CFLAGS)"
+	_AT_echo "CPPFLAGS = $(CPPFLAGS)"
 	_AT_echo "LDFLAGS  = $(LDFLAGS)"
+	_AT_echo "LDLIBS   = $(LDLIBS)"
 	_AT_echo "CC       = $(CC)"
 
 .c.o:
-	$(CC) -c $(CFLAGS) $<
+	$(CC) -c $(CPPFLAGS) $(CFLAGS) $<
 
 config.h:
 	cp config.def.h $_AT_
_AT_@ -23,10 +25,10 @@ config.h:
 $(OBJ): arg.h config.h config.mk drw.h
 
 dmenu: dmenu.o drw.o util.o
-	$(CC) -o $_AT_ dmenu.o drw.o util.o $(LDFLAGS)
+	$(CC) -o $_AT_ dmenu.o drw.o util.o $(LDFLAGS) $(LDLIBS)
 
 stest: stest.o
-	$(CC) -o $_AT_ stest.o $(LDFLAGS)
+	$(CC) -o $_AT_ stest.o $(LDFLAGS) $(LDLIBS)
 
 clean:
 	rm -f dmenu stest $(OBJ) dmenu-$(VERSION).tar.gz
diff --git a/config.mk b/config.mk
index b0bd246..a513b74 100644
--- a/config.mk
+++ b/config.mk
_AT_@ -24,9 +24,9 @@ INCS = -I$(X11INC) -I$(FREETYPEINC)
 LIBS = -L$(X11LIB) -lX11 $(XINERAMALIBS) $(FREETYPELIBS)
 
 # flags
-CPPFLAGS = -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_XOPEN_SOURCE=700 -D_POSIX_C_SOURCE=200809L -DVERSION=\"$(VERSION)\" $(XINERAMAFLAGS)
-CFLAGS   = -std=c99 -pedantic -Wall -Os $(INCS) $(CPPFLAGS)
-LDFLAGS  = $(LIBS)
+CPPFLAGS = $(INCS) -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_XOPEN_SOURCE=700 -D_POSIX_C_SOURCE=200809L -DVERSION=\"$(VERSION)\" $(XINERAMAFLAGS)
+CFLAGS   = -std=c99 -pedantic -Wall -Os
+LDLIBS   = $(LIBS)
 
 # compiler and linker
 CC = cc
-- 
2.35.1
Received on Mon Jul 04 2022 - 11:01:35 CEST

This archive was generated by hypermail 2.3.0 : Mon Jul 04 2022 - 11:12:29 CEST