Makefile: support overriding default optimization flags

Add the user-specified CFLAGS after the default optimization flags
rather than before, so that the default optimization flags can be
overridden.

[EB - updated comment and improved commit message]
This commit is contained in:
Martin Mokrejs 2019-01-24 10:32:52 +01:00 committed by Eric Biggers
parent 96ce0ffcde
commit bc40841abf

View File

@ -13,15 +13,18 @@
# #
############################################################################## ##############################################################################
#### Common compiler flags. #### Common compiler flags. You can add additional flags by defining CFLAGS
#### Flags given here are not intended to be overridden, but you can add more #### in the environment or on the 'make' command line.
#### by defining CFLAGS in the environment or on the 'make' command line. ####
#### The default optimization flags can be overridden, e.g. via CFLAGS="-O3" or
#### CFLAGS="-O0 -fno-omit-frame-pointer". But this usually isn't recommended;
#### you're unlikely to get significantly better performance even with -O3.
cc-option = $(shell if $(CC) $(1) -c -x c /dev/null -o /dev/null \ cc-option = $(shell if $(CC) $(1) -c -x c /dev/null -o /dev/null \
1>&2 2>/dev/null; then echo $(1); fi) 1>&2 2>/dev/null; then echo $(1); fi)
override CFLAGS := \ override CFLAGS := \
$(CFLAGS) -O2 -fomit-frame-pointer -std=c99 -I. -Icommon \ -O2 -fomit-frame-pointer $(CFLAGS) -std=c99 -I. -Icommon \
-Wall -Wundef \ -Wall -Wundef \
$(call cc-option,-Wpedantic) \ $(call cc-option,-Wpedantic) \
$(call cc-option,-Wdeclaration-after-statement) \ $(call cc-option,-Wdeclaration-after-statement) \