2011-10-11 06:33:45 +00:00
|
|
|
# ----------------------------------------------------- #
|
|
|
|
# Makefile for the CTF game module for Quake II #
|
|
|
|
# #
|
|
|
|
# Just type "make" to compile the #
|
2012-07-01 08:05:20 +00:00
|
|
|
# - CTF Game (game.so / game.dll) #
|
2011-10-11 06:33:45 +00:00
|
|
|
# #
|
|
|
|
# Dependencies: #
|
|
|
|
# - None, but you need a Quake II to play. #
|
2020-05-21 01:07:15 +00:00
|
|
|
# While in theory every one should work #
|
|
|
|
# Yamagi Quake II is recommended. #
|
2011-10-11 06:33:45 +00:00
|
|
|
# #
|
|
|
|
# Platforms: #
|
|
|
|
# - FreeBSD #
|
2012-07-01 08:05:20 +00:00
|
|
|
# - Linux #
|
2014-02-14 10:47:30 +00:00
|
|
|
# - Mac OS X #
|
|
|
|
# - OpenBSD #
|
2020-04-21 11:31:02 +00:00
|
|
|
# - Windows #
|
2011-10-11 06:33:45 +00:00
|
|
|
# ----------------------------------------------------- #
|
|
|
|
|
2012-07-01 08:05:20 +00:00
|
|
|
# Detect the OS
|
|
|
|
ifdef SystemRoot
|
2020-04-21 11:31:02 +00:00
|
|
|
YQ2_OSTYPE ?= Windows
|
2012-07-01 08:05:20 +00:00
|
|
|
else
|
2020-04-21 11:31:02 +00:00
|
|
|
YQ2_OSTYPE ?= $(shell uname -s)
|
2012-07-01 08:05:20 +00:00
|
|
|
endif
|
2020-04-21 11:31:02 +00:00
|
|
|
|
2014-02-14 10:47:30 +00:00
|
|
|
# Special case for MinGW
|
2020-04-21 11:31:02 +00:00
|
|
|
ifneq (,$(findstring MINGW,$(YQ2_OSTYPE)))
|
|
|
|
YQ2_OSTYPE := Windows
|
|
|
|
endif
|
|
|
|
|
|
|
|
# Detect the architecture
|
|
|
|
ifeq ($(YQ2_OSTYPE), Windows)
|
2021-01-14 01:35:04 +00:00
|
|
|
ifdef MINGW_CHOST
|
|
|
|
ifeq ($(MINGW_CHOST), x86_64-w64-mingw32)
|
|
|
|
YQ2_ARCH ?= x86_64
|
|
|
|
else # i686-w64-mingw32
|
|
|
|
YQ2_ARCH ?= i386
|
|
|
|
endif
|
|
|
|
else # windows, but MINGW_CHOST not defined
|
2020-04-21 11:31:02 +00:00
|
|
|
ifdef PROCESSOR_ARCHITEW6432
|
|
|
|
# 64 bit Windows
|
|
|
|
YQ2_ARCH ?= $(PROCESSOR_ARCHITEW6432)
|
|
|
|
else
|
|
|
|
# 32 bit Windows
|
|
|
|
YQ2_ARCH ?= $(PROCESSOR_ARCHITECTURE)
|
|
|
|
endif
|
2021-01-14 01:35:04 +00:00
|
|
|
endif # windows but MINGW_CHOST not defined
|
2020-04-21 11:31:02 +00:00
|
|
|
else
|
|
|
|
# Normalize some abiguous YQ2_ARCH strings
|
|
|
|
YQ2_ARCH ?= $(shell uname -m | sed -e 's/i.86/i386/' -e 's/amd64/x86_64/' -e 's/^arm.*/arm/')
|
2014-02-14 10:47:30 +00:00
|
|
|
endif
|
2011-10-11 06:33:45 +00:00
|
|
|
|
2018-10-25 17:34:12 +00:00
|
|
|
# On Windows / MinGW $(CC) is undefined by default.
|
|
|
|
ifeq ($(YQ2_OSTYPE),Windows)
|
2020-04-21 11:31:02 +00:00
|
|
|
CC ?= gcc
|
2018-10-25 17:34:12 +00:00
|
|
|
endif
|
|
|
|
|
|
|
|
# Detect the compiler
|
|
|
|
ifeq ($(shell $(CC) -v 2>&1 | grep -c "clang version"), 1)
|
|
|
|
COMPILER := clang
|
|
|
|
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
|
|
|
|
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
|
|
|
|
COMPILER := unknown
|
|
|
|
endif
|
|
|
|
|
2011-10-11 06:33:45 +00:00
|
|
|
# ----------
|
|
|
|
|
2020-04-21 11:31:02 +00:00
|
|
|
# Base CFLAGS. These may be overridden by the environment.
|
|
|
|
# Highest supported optimizations are -O2, higher levels
|
|
|
|
# will likely break this crappy code.
|
|
|
|
ifdef DEBUG
|
|
|
|
CFLAGS ?= -O0 -g -Wall -pipe
|
2012-10-06 07:49:04 +00:00
|
|
|
else
|
2020-04-21 11:31:02 +00:00
|
|
|
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.
|
|
|
|
override CFLAGS += -std=gnu99 -fno-strict-aliasing -fwrapv
|
|
|
|
|
|
|
|
# -MMD to generate header dependencies. Unsupported by
|
|
|
|
# the Clang shipped with OS X.
|
|
|
|
ifneq ($(YQ2_OSTYPE), Darwin)
|
|
|
|
override CFLAGS += -MMD
|
|
|
|
endif
|
|
|
|
|
|
|
|
# OS X architecture.
|
|
|
|
ifeq ($(YQ2_OSTYPE), Darwin)
|
|
|
|
override CFLAGS += -arch $(YQ2_ARCH)
|
2012-10-06 07:49:04 +00:00
|
|
|
endif
|
2011-10-11 06:33:45 +00:00
|
|
|
|
2018-10-25 17:34:12 +00:00
|
|
|
# ----------
|
|
|
|
|
2020-05-21 01:07:15 +00:00
|
|
|
# Switch off some annoying warnings.
|
2018-10-25 17:34:12 +00:00
|
|
|
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
|
|
|
|
|
2011-10-11 06:33:45 +00:00
|
|
|
# ----------
|
|
|
|
|
2020-04-21 11:31:02 +00:00
|
|
|
# Defines the operating system and architecture
|
|
|
|
override CFLAGS += -DYQ2OSTYPE=\"$(YQ2_OSTYPE)\" -DYQ2ARCH=\"$(YQ2_ARCH)\"
|
2011-10-11 06:33:45 +00:00
|
|
|
|
|
|
|
# ----------
|
|
|
|
|
2020-05-21 01:07:15 +00:00
|
|
|
# For reproducible builds, look here for details:
|
2017-09-14 10:23:58 +00:00
|
|
|
# https://reproducible-builds.org/specs/source-date-epoch/
|
|
|
|
ifdef SOURCE_DATE_EPOCH
|
|
|
|
CFLAGS += -DBUILD_DATE=\"$(shell date --utc --date="@${SOURCE_DATE_EPOCH}" +"%b %_d %Y" | sed -e 's/ /\\ /g')\"
|
|
|
|
endif
|
|
|
|
|
|
|
|
# ----------
|
|
|
|
|
2021-01-14 01:35:04 +00:00
|
|
|
# Using the default x87 float math on 32bit x86 causes rounding trouble
|
|
|
|
# -ffloat-store could work around that, but the better solution is to
|
|
|
|
# just enforce SSE - every x86 CPU since Pentium3 supports that
|
|
|
|
# and this should even improve the performance on old CPUs
|
2020-04-21 11:31:02 +00:00
|
|
|
ifeq ($(YQ2_ARCH), i386)
|
2021-01-14 01:35:04 +00:00
|
|
|
override CFLAGS += -msse -mfpmath=sse
|
2020-04-21 11:31:02 +00:00
|
|
|
endif
|
|
|
|
|
|
|
|
# Force SSE math on x86_64. All sane compilers should do this
|
|
|
|
# anyway, just to protect us from broken Linux distros.
|
|
|
|
ifeq ($(YQ2_ARCH), x86_64)
|
|
|
|
override CFLAGS += -mfpmath=sse
|
|
|
|
endif
|
|
|
|
|
|
|
|
# ----------
|
|
|
|
|
|
|
|
# Base LDFLAGS.
|
|
|
|
LDFLAGS ?=
|
|
|
|
|
|
|
|
# It's a shared library.
|
|
|
|
override LDFLAGS += -shared
|
|
|
|
|
2020-05-21 01:07:15 +00:00
|
|
|
# Required libraries
|
2020-04-21 11:31:02 +00:00
|
|
|
ifeq ($(YQ2_OSTYPE), Darwin)
|
|
|
|
override LDFLAGS += -arch $(YQ2_ARCH)
|
2020-04-21 11:39:46 +00:00
|
|
|
else ifeq ($(YQ2_OSTYPE), Windows)
|
2020-04-21 11:31:02 +00:00
|
|
|
override LDFLAGS += -static-libgcc
|
|
|
|
else
|
|
|
|
override LDFLAGS += -lm
|
|
|
|
endif
|
|
|
|
|
|
|
|
# ----------
|
|
|
|
|
2011-10-11 06:33:45 +00:00
|
|
|
# Builds everything
|
|
|
|
all: ctf
|
|
|
|
|
|
|
|
# ----------
|
2020-04-21 11:31:02 +00:00
|
|
|
|
2012-07-01 08:05:20 +00:00
|
|
|
# When make is invoked by "make VERBOSE=1" print
|
|
|
|
# the compiler and linker commands.
|
|
|
|
|
|
|
|
ifdef VERBOSE
|
|
|
|
Q :=
|
|
|
|
else
|
|
|
|
Q := @
|
|
|
|
endif
|
|
|
|
|
|
|
|
# ----------
|
|
|
|
|
|
|
|
# Phony targets
|
|
|
|
.PHONY : all clean ctf
|
2011-10-11 06:33:45 +00:00
|
|
|
|
2012-07-01 08:05:20 +00:00
|
|
|
# ----------
|
2020-04-21 11:31:02 +00:00
|
|
|
|
2011-10-11 06:33:45 +00:00
|
|
|
# Cleanup
|
2012-07-01 08:05:20 +00:00
|
|
|
clean:
|
|
|
|
@echo "===> CLEAN"
|
|
|
|
${Q}rm -Rf build release
|
2020-04-21 11:31:02 +00:00
|
|
|
|
2011-10-11 06:33:45 +00:00
|
|
|
# ----------
|
|
|
|
|
|
|
|
# The ctf game
|
2020-04-21 11:39:46 +00:00
|
|
|
ifeq ($(YQ2_OSTYPE), Windows)
|
2011-10-11 06:33:45 +00:00
|
|
|
ctf:
|
2012-07-01 08:05:20 +00:00
|
|
|
@echo "===> Building game.dll"
|
2014-02-14 10:47:30 +00:00
|
|
|
$(Q)mkdir -p release
|
2012-07-01 08:05:20 +00:00
|
|
|
$(MAKE) release/game.dll
|
2020-04-21 11:39:46 +00:00
|
|
|
else ifeq ($(YQ2_OSTYPE), Darwin)
|
2019-12-21 01:30:16 +00:00
|
|
|
ctf:
|
2019-05-09 16:28:10 +00:00
|
|
|
@echo "===> Building game.dylib"
|
|
|
|
${Q}mkdir -p release
|
|
|
|
$(MAKE) release/game.dylib
|
2012-07-01 08:05:20 +00:00
|
|
|
else
|
|
|
|
ctf:
|
|
|
|
@echo "===> Building game.so"
|
|
|
|
$(Q)mkdir -p release
|
2011-10-11 06:33:45 +00:00
|
|
|
$(MAKE) release/game.so
|
|
|
|
|
2019-05-09 16:28:10 +00:00
|
|
|
release/game.so : CFLAGS += -fPIC
|
|
|
|
endif
|
2020-04-21 11:31:02 +00:00
|
|
|
|
2011-10-11 06:33:45 +00:00
|
|
|
build/%.o: %.c
|
2012-07-01 08:05:20 +00:00
|
|
|
@echo "===> CC $<"
|
|
|
|
$(Q)mkdir -p $(@D)
|
|
|
|
$(Q)$(CC) -c $(CFLAGS) -o $@ $<
|
2011-10-11 06:33:45 +00:00
|
|
|
|
|
|
|
# ----------
|
|
|
|
|
|
|
|
CTF_OBJS_ = \
|
|
|
|
src/g_ai.o \
|
|
|
|
src/g_chase.o \
|
|
|
|
src/g_cmds.o \
|
|
|
|
src/g_combat.o \
|
|
|
|
src/g_ctf.o \
|
|
|
|
src/g_func.o \
|
|
|
|
src/g_items.o \
|
|
|
|
src/g_main.o \
|
|
|
|
src/g_misc.o \
|
|
|
|
src/g_monster.o \
|
|
|
|
src/g_phys.o \
|
|
|
|
src/g_save.o \
|
|
|
|
src/g_spawn.o \
|
|
|
|
src/g_svcmds.o \
|
|
|
|
src/g_target.o \
|
|
|
|
src/g_trigger.o \
|
|
|
|
src/g_utils.o \
|
|
|
|
src/g_weapon.o \
|
2011-10-11 06:57:12 +00:00
|
|
|
src/menu/menu.o \
|
|
|
|
src/monster/move.o \
|
|
|
|
src/player/client.o \
|
|
|
|
src/player/hud.o \
|
|
|
|
src/player/trail.o \
|
|
|
|
src/player/view.o \
|
|
|
|
src/player/weapon.o \
|
2020-04-21 11:31:02 +00:00
|
|
|
src/shared/shared.o
|
2011-10-11 06:33:45 +00:00
|
|
|
|
|
|
|
# ----------
|
|
|
|
|
|
|
|
# Rewrite pathes to our object directory
|
|
|
|
CTF_OBJS = $(patsubst %,build/%,$(CTF_OBJS_))
|
|
|
|
|
|
|
|
# ----------
|
|
|
|
|
|
|
|
# Generate header dependencies
|
|
|
|
CTF_DEPS= $(CTF_OBJS:.o=.d)
|
|
|
|
|
|
|
|
# ----------
|
|
|
|
|
|
|
|
# Suck header dependencies in
|
|
|
|
-include $(CTF_DEPS)
|
|
|
|
|
|
|
|
# ----------
|
|
|
|
|
2020-04-21 11:31:02 +00:00
|
|
|
ifeq ($(YQ2_OSTYPE), Windows)
|
2012-07-01 08:05:20 +00:00
|
|
|
release/game.dll : $(CTF_OBJS)
|
|
|
|
@echo "===> LD $@"
|
2020-04-21 11:31:02 +00:00
|
|
|
$(Q)$(CC) -o $@ $(CTF_OBJS) $(LDFLAGS)
|
|
|
|
else ifeq ($(YQ2_OSTYPE), Darwin)
|
2016-08-14 14:31:46 +00:00
|
|
|
release/game.dylib : $(CTF_OBJS)
|
|
|
|
@echo "===> LD $@"
|
2020-04-21 11:31:02 +00:00
|
|
|
${Q}$(CC) -o $@ $(CTF_OBJS) $(LDFLAGS)
|
2012-07-01 08:05:20 +00:00
|
|
|
else
|
2011-10-11 06:33:45 +00:00
|
|
|
release/game.so : $(CTF_OBJS)
|
2012-07-01 08:05:20 +00:00
|
|
|
@echo "===> LD $@"
|
2020-04-21 11:31:02 +00:00
|
|
|
$(Q)$(CC) -o $@ $(CTF_OBJS) $(LDFLAGS)
|
2012-07-01 08:05:20 +00:00
|
|
|
endif
|
2020-04-21 11:31:02 +00:00
|
|
|
|
2011-10-11 06:33:45 +00:00
|
|
|
# ----------
|