General cleanup to the Makefile.

This commit is contained in:
Yamagi Burmeister 2018-08-14 15:01:45 +02:00
parent 93aa8270ad
commit f7e80c1428
1 changed files with 67 additions and 45 deletions

112
Makefile
View File

@ -2,17 +2,17 @@
# Makefile for the "Yamagi Quake 2 Client" # # Makefile for the "Yamagi Quake 2 Client" #
# # # #
# Just type "make" to compile the # # Just type "make" to compile the #
# - SDL Client (quake2) # # - Client (quake2) #
# - Server (q2ded) # # - Server (q2ded) #
# - Quake II Game (baseq2) # # - Quake II Game (baseq2) #
# - Renderer libraries (gl1, gl3, soft) #
# # # #
# Base dependencies: # # Base dependencies: #
# - SDL 2.0 # # - SDL 2.0 #
# - libGL # # - libGL #
# # # #
# Further dependencies: # # Optional dependencies: #
# - OpenAL # # - OpenAL #
# - zlib #
# # # #
# Platforms: # # Platforms: #
# - FreeBSD # # - FreeBSD #
@ -89,19 +89,22 @@ else
YQ2_ARCH ?= $(shell uname -m | sed -e 's/i.86/i386/' -e 's/amd64/x86_64/' -e 's/^arm.*/arm/') YQ2_ARCH ?= $(shell uname -m | sed -e 's/i.86/i386/' -e 's/amd64/x86_64/' -e 's/^arm.*/arm/')
endif endif
# On Windows / MinGW $(CC) is undefined by default.
ifeq ($(YQ2_OSTYPE),Windows)
CC := gcc
endif
# Detect the compiler # Detect the compiler
ifeq ($(shell $(CC) -v 2>&1 | grep -c "clang version"), 1) ifeq ($(shell $(CC) -v 2>&1 | grep -c "clang version"), 1)
COMPILER := clang COMPILER := clang
else ifeq ($(shell $(CC) -v 2>&1 | grep -c "gcc version"), 1) COMPILERVER := $(shell $(CC) -dumpversion | sed -e 's/\.\([0-9][0-9]\)/\1/g' -e 's/\.\([0-9]\)/0\1/g' -e 's/^[0-9]\{3,4\}$$/&00/')
else ifeq ($(shell $(CC) -v 2>&1 | grep -c -E "(gcc version|gcc-Version)"), 1)
COMPILER := gcc COMPILER := gcc
COMPILERVER := $(shell $(CC) -dumpversion | sed -e 's/\.\([0-9][0-9]\)/\1/g' -e 's/\.\([0-9]\)/0\1/g' -e 's/^[0-9]\{3,4\}$$/&00/')
else else
COMPILER := unknown COMPILER := unknown
endif endif
# Used to detect libraries. Override to foobar-linux-gnu-pkg-config when
# cross-compiling.
PKG_CONFIG ?= pkg-config
# ---------- # ----------
# Base CFLAGS. # Base CFLAGS.
@ -121,6 +124,9 @@ PKG_CONFIG ?= pkg-config
# #
# -MMD to generate header dependencies. (They cannot be # -MMD to generate header dependencies. (They cannot be
# generated if building universal binaries on OSX) # generated if building universal binaries on OSX)
#
# -fwrapv for defined integer wrapping. MSVC6 did this
# and the game code requires it.
ifeq ($(YQ2_OSTYPE), Darwin) ifeq ($(YQ2_OSTYPE), Darwin)
CFLAGS := -O2 -fno-strict-aliasing -fomit-frame-pointer \ CFLAGS := -O2 -fno-strict-aliasing -fomit-frame-pointer \
-Wall -pipe -g -fwrapv -Wall -pipe -g -fwrapv
@ -132,11 +138,28 @@ endif
# ---------- # ----------
# Switch of some annoying warnings.
ifeq ($(COMPILER), clang)
# -Wno-missing-braces because otherwise clang complains
# about totally valid 'vec3_t bla = {0}' constructs.
CFLAGS += -Wno-missing-braces
else ifeq ($(COMPILER), gcc)
# GCC 8.0 or higher.
ifeq ($(shell test $(COMPILERVER) -ge 80000; echo $$?),0)
# -Wno-format-truncation and -Wno-format-overflow
# because GCC spams about 50 false positives.
CFLAGS += -Wno-format-truncation -Wno-format-overflow
endif
endif
# ----------
# Defines the operating system and architecture # Defines the operating system and architecture
CFLAGS += -DYQ2OSTYPE=\"$(YQ2_OSTYPE)\" -DYQ2ARCH=\"$(YQ2_ARCH)\" CFLAGS += -DYQ2OSTYPE=\"$(YQ2_OSTYPE)\" -DYQ2ARCH=\"$(YQ2_ARCH)\"
# ---------- # ----------
# Fore reproduceable builds, look here for details:
# https://reproducible-builds.org/specs/source-date-epoch/ # https://reproducible-builds.org/specs/source-date-epoch/
ifdef SOURCE_DATE_EPOCH ifdef SOURCE_DATE_EPOCH
CFLAGS += -DBUILD_DATE=\"$(shell date --utc --date="@${SOURCE_DATE_EPOCH}" +"%b %_d %Y" | sed -e 's/ /\\ /g')\" CFLAGS += -DBUILD_DATE=\"$(shell date --utc --date="@${SOURCE_DATE_EPOCH}" +"%b %_d %Y" | sed -e 's/ /\\ /g')\"
@ -161,7 +184,7 @@ endif
# ---------- # ----------
# Systemwide installation # Systemwide installation.
ifeq ($(WITH_SYSTEMWIDE),yes) ifeq ($(WITH_SYSTEMWIDE),yes)
CFLAGS += -DSYSTEMWIDE CFLAGS += -DSYSTEMWIDE
ifneq ($(WITH_SYSTEMDIR),"") ifneq ($(WITH_SYSTEMDIR),"")
@ -171,14 +194,6 @@ endif
# ---------- # ----------
# On Windows / MinGW $(CC) is
# undefined by default.
ifeq ($(YQ2_OSTYPE),Windows)
CC := gcc
endif
# ----------
# Just set IOAPI_NO_64 on everything that's not Linux or Windows, # Just set IOAPI_NO_64 on everything that's not Linux or Windows,
# otherwise minizip will use fopen64(), fseek64() and friends that # otherwise minizip will use fopen64(), fseek64() and friends that
# may be unavailable. This is - of course - not really correct, in # may be unavailable. This is - of course - not really correct, in
@ -201,7 +216,7 @@ ZIPCFLAGS += -DNOUNCRYPT
# ---------- # ----------
# Extra CFLAGS for SDL # Extra CFLAGS for SDL.
SDLCFLAGS := $(shell sdl2-config --cflags) SDLCFLAGS := $(shell sdl2-config --cflags)
# ---------- # ----------
@ -219,7 +234,7 @@ endif
# ---------- # ----------
# Extra includes for GLAD # Local includes for GLAD.
GLAD_INCLUDE = -Isrc/client/refresh/gl3/glad/include GLAD_INCLUDE = -Isrc/client/refresh/gl3/glad/include
# ---------- # ----------
@ -237,13 +252,16 @@ else ifeq ($(YQ2_OSTYPE), Darwin)
LDFLAGS := $(OSX_ARCH) -lm LDFLAGS := $(OSX_ARCH) -lm
endif endif
# Keep symbols hidden.
CFLAGS += -fvisibility=hidden CFLAGS += -fvisibility=hidden
LDFLAGS += -fvisibility=hidden LDFLAGS += -fvisibility=hidden
ifneq ($(YQ2_OSTYPE), $(filter $(YQ2_OSTYPE), Darwin OpenBSD)) ifneq ($(YQ2_OSTYPE), Darwin)
# for some reason the OSX & OpenBSD linker doesn't support this ifneq ($(YQ2_OSTYPE), OpenBSD)
# for some reason the OSX & OpenBSD linker doesn't support this...
LDFLAGS += -Wl,--no-undefined LDFLAGS += -Wl,--no-undefined
endif endif
endif
# ---------- # ----------
@ -254,11 +272,15 @@ else # not Darwin
SDLLDFLAGS := $(shell sdl2-config --libs) SDLLDFLAGS := $(shell sdl2-config --libs)
endif # Darwin endif # Darwin
# The renderer libs don't need libSDL2main, libmingw32 or -mwindows.
ifeq ($(YQ2_OSTYPE), Windows)
DLL_SDLLDFLAGS = $(subst -mwindows,,$(subst -lmingw32,,$(subst -lSDL2main,,$(SDLLDFLAGS))))
endif
# ---------- # ----------
# When make is invoked by "make VERBOSE=1" print # When make is invoked by "make VERBOSE=1" print
# the compiler and linker commands. # the compiler and linker commands.
ifdef VERBOSE ifdef VERBOSE
Q := Q :=
else else
@ -289,8 +311,7 @@ config:
# ---------- # ----------
# Special target to compile # Special target to compile the icon on Windows
# the icon on Windows
ifeq ($(YQ2_OSTYPE), Windows) ifeq ($(YQ2_OSTYPE), Windows)
icon: icon:
@echo "===> WR build/icon/icon.res" @echo "===> WR build/icon/icon.res"
@ -325,12 +346,12 @@ build/client/%.o: %.c
${Q}mkdir -p $(@D) ${Q}mkdir -p $(@D)
${Q}$(CC) -c $(CFLAGS) $(SDLCFLAGS) $(ZIPCFLAGS) $(INCLUDE) -o $@ $< ${Q}$(CC) -c $(CFLAGS) $(SDLCFLAGS) $(ZIPCFLAGS) $(INCLUDE) -o $@ $<
release/yquake2.exe : LDFLAGS += -mwindows
ifeq ($(WITH_OPENAL),yes) ifeq ($(WITH_OPENAL),yes)
release/yquake2.exe : CFLAGS += -DUSE_OPENAL -DDEFAULT_OPENAL_DRIVER='"openal32.dll"' release/yquake2.exe : CFLAGS += -DUSE_OPENAL -DDEFAULT_OPENAL_DRIVER='"openal32.dll"'
endif endif
release/yquake2.exe : LDFLAGS += -mwindows
else # not Windows else # not Windows
client: client:
@ -338,16 +359,16 @@ client:
${Q}mkdir -p release ${Q}mkdir -p release
$(MAKE) release/quake2 $(MAKE) release/quake2
build/client/%.o: %.c
@echo "===> CC $<"
${Q}mkdir -p $(@D)
${Q}$(CC) -c $(CFLAGS) $(SDLCFLAGS) $(ZIPCFLAGS) $(INCLUDE) -o $@ $<
ifeq ($(YQ2_OSTYPE), Darwin) ifeq ($(YQ2_OSTYPE), Darwin)
build/client/%.o : %.m build/client/%.o : %.m
@echo "===> CC $<" @echo "===> CC $<"
${Q}mkdir -p $(@D) ${Q}mkdir -p $(@D)
${Q}$(CC) $(OSX_ARCH) -x objective-c -c $< -o $@ ${Q}$(CC) $(OSX_ARCH) -x objective-c -c $< -o $@
else
build/client/%.o: %.c
@echo "===> CC $<"
${Q}mkdir -p $(@D)
${Q}$(CC) -c $(CFLAGS) $(SDLCFLAGS) $(ZIPCFLAGS) $(INCLUDE) -o $@ $<
endif endif
release/quake2 : CFLAGS += -Wno-unused-result release/quake2 : CFLAGS += -Wno-unused-result
@ -361,7 +382,11 @@ release/quake2 : LDFLAGS += -L/usr/local/opt/openal-soft/lib -rpath /usr/local/o
else else
release/quake2 : CFLAGS += -DUSE_OPENAL -DDEFAULT_OPENAL_DRIVER='"libopenal.so.1"' release/quake2 : CFLAGS += -DUSE_OPENAL -DDEFAULT_OPENAL_DRIVER='"libopenal.so.1"'
endif endif
endif # WITH_OPENAL endif
ifeq ($(YQ2_OSTYPE), FreeBSD)
release/quake2 : LDFLAGS += -lexecinfo
endif
ifeq ($(YQ2_OSTYPE), FreeBSD) ifeq ($(YQ2_OSTYPE), FreeBSD)
release/quake2 : LDFLAGS += -Wl,-z,origin,-rpath='$$ORIGIN/lib' -lexecinfo release/quake2 : LDFLAGS += -Wl,-z,origin,-rpath='$$ORIGIN/lib' -lexecinfo
@ -433,10 +458,6 @@ ref_gl1:
release/ref_gl1.dll : LDFLAGS += -lopengl32 -shared release/ref_gl1.dll : LDFLAGS += -lopengl32 -shared
# don't want the dll to link against libSDL2main or libmingw32, and no -mwindows either
# that's for the .exe only
DLL_SDLLDFLAGS = $(subst -mwindows,,$(subst -lmingw32,,$(subst -lSDL2main,,$(SDLLDFLAGS))))
else ifeq ($(YQ2_OSTYPE), Darwin) else ifeq ($(YQ2_OSTYPE), Darwin)
ref_gl1: ref_gl1:
@ -456,7 +477,7 @@ ref_gl1:
release/ref_gl1.so : CFLAGS += -fPIC release/ref_gl1.so : CFLAGS += -fPIC
release/ref_gl1.so : LDFLAGS += -shared -lGL release/ref_gl1.so : LDFLAGS += -shared -lGL
endif # OS specific ref_gl1 shit endif # OS specific ref_gl1 stuff
build/ref_gl1/%.o: %.c build/ref_gl1/%.o: %.c
@echo "===> CC $<" @echo "===> CC $<"
@ -494,7 +515,7 @@ ref_gl3:
release/ref_gl3.so : CFLAGS += -fPIC release/ref_gl3.so : CFLAGS += -fPIC
release/ref_gl3.so : LDFLAGS += -shared release/ref_gl3.so : LDFLAGS += -shared
endif # OS specific ref_gl3 shit endif # OS specific ref_gl3 stuff
build/ref_gl3/%.o: %.c build/ref_gl3/%.o: %.c
@echo "===> CC $<" @echo "===> CC $<"
@ -530,7 +551,7 @@ ref_soft:
release/ref_soft.so : CFLAGS += -fPIC release/ref_soft.so : CFLAGS += -fPIC
release/ref_soft.so : LDFLAGS += -shared release/ref_soft.so : LDFLAGS += -shared
endif # OS specific ref_soft shit endif # OS specific ref_soft stuff
build/ref_soft/%.o: %.c build/ref_soft/%.o: %.c
@echo "===> CC $<" @echo "===> CC $<"
@ -552,7 +573,9 @@ build/baseq2/%.o: %.c
${Q}$(CC) -c $(CFLAGS) $(INCLUDE) -o $@ $< ${Q}$(CC) -c $(CFLAGS) $(INCLUDE) -o $@ $<
release/baseq2/game.dll : LDFLAGS += -shared release/baseq2/game.dll : LDFLAGS += -shared
else ifeq ($(YQ2_OSTYPE), Darwin) else ifeq ($(YQ2_OSTYPE), Darwin)
game: game:
@echo "===> Building baseq2/game.dylib" @echo "===> Building baseq2/game.dylib"
${Q}mkdir -p release/baseq2 ${Q}mkdir -p release/baseq2
@ -565,7 +588,9 @@ build/baseq2/%.o: %.c
release/baseq2/game.dylib : CFLAGS += -fPIC release/baseq2/game.dylib : CFLAGS += -fPIC
release/baseq2/game.dylib : LDFLAGS += -shared release/baseq2/game.dylib : LDFLAGS += -shared
else # not Windows or Darwin else # not Windows or Darwin
game: game:
@echo "===> Building baseq2/game.so" @echo "===> Building baseq2/game.so"
${Q}mkdir -p release/baseq2 ${Q}mkdir -p release/baseq2
@ -868,7 +893,7 @@ endif
# ---------- # ----------
# Rewrite pathes to our object directory # Rewrite pathes to our object directory.
CLIENT_OBJS = $(patsubst %,build/client/%,$(CLIENT_OBJS_)) CLIENT_OBJS = $(patsubst %,build/client/%,$(CLIENT_OBJS_))
REFGL1_OBJS = $(patsubst %,build/ref_gl1/%,$(REFGL1_OBJS_)) REFGL1_OBJS = $(patsubst %,build/ref_gl1/%,$(REFGL1_OBJS_))
REFGL3_OBJS = $(patsubst %,build/ref_gl3/%,$(REFGL3_OBJS_)) REFGL3_OBJS = $(patsubst %,build/ref_gl3/%,$(REFGL3_OBJS_))
@ -878,7 +903,7 @@ GAME_OBJS = $(patsubst %,build/baseq2/%,$(GAME_OBJS_))
# ---------- # ----------
# Generate header dependencies # Generate header dependencies.
CLIENT_DEPS= $(CLIENT_OBJS:.o=.d) CLIENT_DEPS= $(CLIENT_OBJS:.o=.d)
REFGL1_DEPS= $(REFGL1_OBJS:.o=.d) REFGL1_DEPS= $(REFGL1_OBJS:.o=.d)
REFGL3_DEPS= $(REFGL3_OBJS:.o=.d) REFGL3_DEPS= $(REFGL3_OBJS:.o=.d)
@ -886,9 +911,7 @@ REFSOFT_DEPS= $(REFSOFT_OBJS:.o=.d)
SERVER_DEPS= $(SERVER_OBJS:.o=.d) SERVER_DEPS= $(SERVER_OBJS:.o=.d)
GAME_DEPS= $(GAME_OBJS:.o=.d) GAME_DEPS= $(GAME_OBJS:.o=.d)
# ---------- # Suck header dependencies in.
# Suck header dependencies in
-include $(CLIENT_DEPS) -include $(CLIENT_DEPS)
-include $(REFGL1_DEPS) -include $(REFGL1_DEPS)
-include $(REFGL3_DEPS) -include $(REFGL3_DEPS)
@ -903,7 +926,6 @@ release/yquake2.exe : $(CLIENT_OBJS) icon
@echo "===> LD $@" @echo "===> LD $@"
${Q}$(CC) build/icon/icon.res $(CLIENT_OBJS) $(LDFLAGS) $(SDLLDFLAGS) -o $@ ${Q}$(CC) build/icon/icon.res $(CLIENT_OBJS) $(LDFLAGS) $(SDLLDFLAGS) -o $@
$(Q)strip $@ $(Q)strip $@
# the wrappper, quick'n'dirty
release/quake2.exe : src/win-wrapper/wrapper.c icon release/quake2.exe : src/win-wrapper/wrapper.c icon
$(Q)$(CC) -Wall -mwindows build/icon/icon.res src/win-wrapper/wrapper.c -o $@ $(Q)$(CC) -Wall -mwindows build/icon/icon.res src/win-wrapper/wrapper.c -o $@
$(Q)strip $@ $(Q)strip $@