summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobias Klauser <tklauser@distanz.ch>2017-01-09 13:46:04 +0100
committerTobias Klauser <tklauser@distanz.ch>2017-01-09 13:46:04 +0100
commit6281d3c3633fb1de98ff6010212325e45c226f3c (patch)
tree080315c094b898fbcf552cc240136c8569d47222
parent7df4b7477a6ac53a6514c1d5f86cbd96929f3602 (diff)
make: Append instead of override CPPFLAGS and CFLAGS passed by user
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>
-rw-r--r--Makefile13
1 files changed, 7 insertions, 6 deletions
diff --git a/Makefile b/Makefile
index a0d55bf..0de1919 100644
--- a/Makefile
+++ b/Makefile
@@ -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)
@@ -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)
@@ -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)"