On Mon, Jul 04, 2022 at 03:01:35PM +0600, NRK wrote: > 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 > @@ -11,11 +11,13 @@ all: options dmenu stest > options: > @echo dmenu build options: > @echo "CFLAGS = $(CFLAGS)" > + @echo "CPPFLAGS = $(CPPFLAGS)" > @echo "LDFLAGS = $(LDFLAGS)" > + @echo "LDLIBS = $(LDLIBS)" > @echo "CC = $(CC)" > > .c.o: > - $(CC) -c $(CFLAGS) $< > + $(CC) -c $(CPPFLAGS) $(CFLAGS) $< > > config.h: > cp config.def.h $@ > @@ -23,10 +25,10 @@ config.h: > $(OBJ): arg.h config.h config.mk drw.h > > dmenu: dmenu.o drw.o util.o > - $(CC) -o $@ dmenu.o drw.o util.o $(LDFLAGS) > + $(CC) -o $@ dmenu.o drw.o util.o $(LDFLAGS) $(LDLIBS) > > stest: stest.o > - $(CC) -o $@ stest.o $(LDFLAGS) > + $(CC) -o $@ 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 > @@ -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 > >
Any comment on this? Or any specific reason for deviating from the conventional approach and mangling `CFLAGS` and `CPPFLAGS`? - NRK
