build: Make the base CFLAGS overridable

Only the optimization level, warning level and debug stuff may be
overridden. All other options are enforced because they're required.

While here add a new variable to force a debug build: `make DEBUG=1`.

Based on <https://github.com/yquake2/yquake2/commits/cflags>.

Signed-off-by: Simon McVittie <smcv@debian.org>
This commit is contained in:
Simon McVittie 2020-03-11 11:04:01 +00:00
parent e7cb7e1e48
commit 4bb77517bc

View file

@ -47,30 +47,31 @@ endif
# ----------
# Base CFLAGS.
#
# -O2 are enough optimizations.
#
# -fno-strict-aliasing since the source doesn't comply
# with strict aliasing rules and it's next to impossible
# to get it there...
#
# -fomit-frame-pointer since the framepointer is mostly
# useless for debugging Quake II and slows things down.
#
# -g to build allways with debug symbols. Please do not
# change this, since it's our only chance to debug this
# crap when random crashes happen!
#
# -fPIC for position independend code.
#
# -MMD to generate header dependencies.
ifeq ($(OSTYPE), Darwin)
CFLAGS := -O2 -fno-strict-aliasing -fomit-frame-pointer \
-Wall -pipe -g -fwrapv -arch x86_64
# Base CFLAGS. These may be overridden by the environment.
# Highest supported optimizations are -O2, higher levels
# will likely break things.
ifdef DEBUG
CFLAGS ?= -O0 -g -Wall -pipe
else
CFLAGS := -O2 -fno-strict-aliasing -fomit-frame-pointer \
-Wall -pipe -g -MMD -fwrapv
CFLAGS ?= -O2 -Wall -pipe -fomit-frame-pointer
endif
# Always needed are:
# -fno-strict-aliasing since the source doesn't comply
# with strict aliasing rules and it's next to impossible
# to get it there...
# -fwrapv for defined integer wrapping. MSVC6 did this
# and the game code requires it.
CFLAGS += -fno-strict-aliasing -fwrapv
# -MMD to generate header dependencies. Unsupported by
# the Clang shipped with OS X.
ifneq ($(OSTYPE), Darwin)
CFLAGS += -MMD
endif
ifeq ($(OSTYPE), Darwin)
CFLAGS += -arch x86_64
endif
# ----------