Skip to content

Commit

Permalink
make: Append instead of override CPPFLAGS and CFLAGS passed by user
Browse files Browse the repository at this point in the history
Distribution build scripts commonly assume the CPPFLAGS, CFLAGS and
LDFLAGS passed via command line or environment to be appended to the
base set of flags defined in the Makefile. Follow this assumption
instead of overriding the already defined values.

Also treat these three variables entriely independently instead of
appending CPPFLAGS to CFLAGS.

Reported-by: @pali
Really-fixes: #17
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
  • Loading branch information
tklauser committed Jan 9, 2017
1 parent 7df4b74 commit 6281d3c
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ CC = $(CROSS_COMPILE)gcc
INSTALL = install

CPPFLAGS ?=
CFLAGS ?= -W -Wall -O2 $(CPPFLAGS)
LDFLAGS ?=

ifeq ($(shell git rev-parse > /dev/null 2>&1; echo $$?), 0)
Expand All @@ -27,12 +26,14 @@ else
GIT_VERSION =
endif

CFLAGS += -DVERSION_STRING=\"v$(VERSION)\" -DGIT_VERSION=\"$(GIT_VERSION)\"

CFLAGS_MIN := -W -Wall -DVERSION_STRING=\"v$(VERSION)\" -DGIT_VERSION=\"$(GIT_VERSION)\"
ifeq ($(DEBUG), 1)
CFLAGS += -g -DDEBUG
CFLAGS_MIN += -g -DDEBUG
endif

CFLAGS ?= -O2
override CFLAGS := $(CFLAGS_MIN) $(CFLAGS)

Q ?= @
ifeq ($(Q),)
CCQ = $(CC)
Expand All @@ -57,10 +58,10 @@ $(Q_P): $(Q_OBJS)
$(LDQ) $(LDFLAGS) -o $@ $(Q_OBJS) $(Q_LIBS)

%.o: %.c %.h
$(CCQ) $(CFLAGS) -o $@ -c $<
$(CCQ) $(CFLAGS) $(CPPFLAGS) -o $@ -c $<

%.o: %.c
$(CCQ) $(CFLAGS) -o $@ -c $<
$(CCQ) $(CFLAGS) $(CPPFLAGS) -o $@ -c $<

install_$(D_P): $(D_P)
@echo " INSTALL $(D_P)"
Expand Down

0 comments on commit 6281d3c

Please sign in to comment.