# # TyrQuake Makefile (tested under Linux and MinGW/Msys) # # By default, all executables will be built. If you want to just build one, # just type e.g. "make tyr-quake". If the build dirs haven't been created yet, # you might need to type "make prepare" first. # TYR_VERSION_MAJOR = 0 TYR_VERSION_MINOR = 58 TYR_VERSION_BUILD = TYR_VERSION = $(TYR_VERSION_MAJOR).$(TYR_VERSION_MINOR)$(TYR_VERSION_BUILD) # ============================================================================ # User configurable options here: # ============================================================================ BUILD_DIR ?= build DEBUG ?= N# Compile with debug info OPTIMIZED_CFLAGS ?= Y# Enable compiler optimisations (if DEBUG != Y) USE_X86_ASM ?= Y# Compile with x86 asm X11BASE ?= $(X11BASE_GUESS) QBASEDIR ?= .# Default basedir for quake data files (Linux/BSD only) TARGET_OS ?= $(HOST_OS) # ============================================================================ .PHONY: default clean # ============================================================================ SYSNAME := $(shell uname -s) ifneq (,$(findstring MINGW32,$(SYSNAME))) HOST_OS = WIN32 TOPDIR := $(shell pwd -W) else ifneq (,$(findstring $(SYSNAME),FreeBSD NetBSD OpenBSD)) HOST_OS = UNIX UNIX = bsd TOPDIR := $(shell pwd) else ifneq (,$(findstring $(SYSNAME),Linux)) HOST_OS = UNIX UNIX = linux #UNIX = null TOPDIR := $(shell pwd) else $(error OS type not detected.) endif endif endif ifeq ($(TARGET_OS),WIN32) EXT = .exe ifneq ($(HOST_OS),WIN32) TARGET ?= $(MINGW_CROSS_GUESS) CC = $(TARGET)-gcc STRIP = $(TARGET)-strip WINDRES = $(TARGET)-windres endif else EXT = endif # ============================================================================ # Helper functions # ============================================================================ # ---------------------------------------------- # Try to guess the location of X11 includes/libs # ---------------------------------------------- X11DIRS = /usr/X11R7 /usr/local/X11R7 /usr/X11R6 /usr/local/X11R6 X11BASE_GUESS := $(shell \ if [ -e /usr/include/X11/Xlib.h ] && \ [ -e /usr/lib/libX11.a ]; then exit 0; fi; \ if [ -e /usr/local/include/X11/Xlib.h ] && \ [ -e /usr/local/lib/libX11.a ]; then exit 0; fi; \ for DIR in $(X11DIRS); do \ if [ -e $$DIR/include/X11/Xlib.h ] && \ [ -e $$DIR/lib/libX11.a ]; then echo $$DIR; break; fi; \ done ) # -------------------------------------------------------------------- # Try to guess the MinGW cross compiler # - I think i386-... is the standard naming, but Debian uses i586-... # -------------------------------------------------------------------- MINGW_CROSS_GUESS := $(shell \ if which i586-mingw32msvc-gcc > /dev/null 2>&1; then \ echo i586-mingw32msvc; \ else \ echo i386-mingw32msvc; \ fi) # -------------------------------- # GCC version and option checking # -------------------------------- cc-version = $(shell sh $(TOPDIR)/scripts/gcc-version \ $(if $(1), $(1), $(CC))) cc-option = $(shell if $(CC) $(CFLAGS) $(1) -S -o /dev/null -xc /dev/null \ > /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi ;) GCC_VERSION := $(call cc-version) # --------------------- # Special include dirs # --------------------- DX_INC = $(TOPDIR)/dxsdk/sdk/inc ST_INC = $(TOPDIR)/scitech/include # -------------- # Library stuff # -------------- NQ_ST_LIBDIR = scitech/lib/win32/vc QW_ST_LIBDIR = scitech/lib/win32/vc NQ_W32_COMMON_LIBS = wsock32 winmm dxguid NQ_W32_SW_LIBS = mgllt ddraw NQ_W32_GL_LIBS = opengl32 comctl32 NQ_UNIX_COMMON_LIBS = m X11 Xext Xxf86dga Xxf86vm NQ_UNIX_GL_LIBS = GL NQ_W32_SW_LFLAGS := $(patsubst %,-l%,$(NQ_W32_SW_LIBS) $(NQ_W32_COMMON_LIBS)) NQ_W32_GL_LFLAGS := $(patsubst %,-l%,$(NQ_W32_GL_LIBS) $(NQ_W32_COMMON_LIBS)) NQ_UNIX_SW_LFLAGS := $(patsubst %,-l%,$(NQ_UNIX_COMMON_LIBS)) NQ_UNIX_GL_LFLAGS := $(patsubst %,-l%,$(NQ_UNIX_COMMON_LIBS) $(NQ_UNIX_GL_LIBS)) ifneq ($(X11BASE),) NQ_UNIX_SW_LFLAGS += -L$(X11BASE)/lib NQ_UNIX_GL_LFLAGS += -L$(X11BASE)/lib endif # --------------------------------------- # Define some build variables # --------------------------------------- STRIP ?= strip WINDRES ?= windres CFLAGS := $(CFLAGS) -Wall -Wno-trigraphs ifeq ($(DEBUG),Y) CFLAGS += -g else ifeq ($(OPTIMIZED_CFLAGS),Y) CFLAGS += -O2 # -funit-at-a-time is buggy for MinGW GCC > 3.2 # I'm assuming it's fixed for MinGW GCC >= 4.0 when that comes about CFLAGS += $(shell if [ $(GCC_VERSION) -lt 0400 ] ;\ then echo $(call cc-option,-fno-unit-at-a-time); fi ;) CFLAGS += $(call cc-option,-fweb,) CFLAGS += $(call cc-option,-frename-registers,) CFLAGS += $(call cc-option,-ffast-math,) endif endif # -------------------------------------------------------------------------- # Each binary needs to build it's own object files in separate directories # due to the {NQ,QW}_HACK ifdefs still present in the common files. # -------------------------------------------------------------------------- # (sw = software renderer, gl = OpenGL renderer, sv = server) NQSWDIR = $(BUILD_DIR)/nqsw NQGLDIR = $(BUILD_DIR)/nqgl QWSWDIR = $(BUILD_DIR)/qwsw QWGLDIR = $(BUILD_DIR)/qwgl QWSVDIR = $(BUILD_DIR)/qwsv BUILD_DIRS = $(NQSWDIR) $(NQGLDIR) $(QWSWDIR) $(QWGLDIR) $(QWSVDIR) APPS = tyr-quake$(EXT) tyr-glquake$(EXT) \ tyr-qwcl$(EXT) tyr-glqwcl$(EXT) \ tyr-qwsv$(EXT) default: all all: prepare $(APPS) .PHONY: prepare prepare: $(BUILD_DIRS) COMMON_CPPFLAGS := -DTYR_VERSION=$(TYR_VERSION) -DQBASEDIR="$(QBASEDIR)" ifeq ($(DEBUG),Y) COMMON_CPPFLAGS += -DDEBUG else COMMON_CPPFLAGS += -DNDEBUG endif ifeq ($(USE_X86_ASM),Y) COMMON_CPPFLAGS += -DUSE_X86_ASM endif ifneq ($(X11BASE),) COMMON_CPPFLAGS += -I$(X11BASE)/include endif COMMON_CPPFLAGS += -I$(TOPDIR)/include NQSW_CPPFLAGS := $(COMMON_CPPFLAGS) -DNQ_HACK NQGL_CPPFLAGS := $(COMMON_CPPFLAGS) -DNQ_HACK -DGLQUAKE QWSW_CPPFLAGS := $(COMMON_CPPFLAGS) -DQW_HACK QWGL_CPPFLAGS := $(COMMON_CPPFLAGS) -DQW_HACK -DGLQUAKE QWSV_CPPFLAGS := $(COMMON_CPPFLAGS) -DQW_HACK -DSERVERONLY NQSW_CPPFLAGS += -I$(TOPDIR)/NQ NQGL_CPPFLAGS += -I$(TOPDIR)/NQ QWSW_CPPFLAGS += -I$(TOPDIR)/QW/client QWGL_CPPFLAGS += -I$(TOPDIR)/QW/client QWSV_CPPFLAGS += -I$(TOPDIR)/QW/server -I$(TOPDIR)/QW/client ifeq ($(TARGET_OS),WIN32) NQSW_CPPFLAGS += -idirafter $(DX_INC) -idirafter $(ST_INC) NQGL_CPPFLAGS += -idirafter $(DX_INC) QWSW_CPPFLAGS += -idirafter $(DX_INC) -idirafter $(ST_INC) QWGL_CPPFLAGS += -idirafter $(DX_INC) endif ifeq ($(TARGET_OS),UNIX) NQSW_CPPFLAGS += -DELF -DX11 NQGL_CPPFLAGS += -DELF -DX11 QWSW_CPPFLAGS += -DELF -DX11 QWGL_CPPFLAGS += -DELF -DX11 -DGL_EXT_SHARED QWSV_CPPFLAGS += -DELF endif $(BUILD_DIR)/nqsw/%.o: CPPFLAGS = $(NQSW_CPPFLAGS) $(BUILD_DIR)/nqgl/%.o: CPPFLAGS = $(NQGL_CPPFLAGS) $(BUILD_DIR)/qwsw/%.o: CPPFLAGS = $(QWSW_CPPFLAGS) $(BUILD_DIR)/qwgl/%.o: CPPFLAGS = $(QWGL_CPPFLAGS) $(BUILD_DIR)/qwsv/%.o: CPPFLAGS = $(QWSV_CPPFLAGS) # To make warnings more obvious, be less verbose as default # Use 'make V=1' to see the full commands ifdef V quiet = else quiet = quiet_ endif quiet_cmd_mkdir = ' MKDIR $@' cmd_mkdir = mkdir -p $@ define do_mkdir @if [ ! -d $@ ]; then \ echo $($(quiet)cmd_mkdir); \ $(cmd_mkdir); \ fi; endef # cmd_fixdep => Turn all pre-requisites into targets with no commands, to # prevent errors when moving files around between builds (e.g. from NQ or QW # dirs to the common dir.) cmd_fixdep = \ cp $(@D)/.$(@F).d $(@D)/.$(@F).d.tmp ; \ sed -e 's/\#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' -e '/^$$/ d' \ -e 's/$$/ :/' < $(@D)/.$(@F).d.tmp >> $(@D)/.$(@F).d ; \ rm -f $(@D)/.$(@F).d.tmp cmd_cc_dep_c = \ $(CC) -MM -MT $@ $(CPPFLAGS) -o $(@D)/.$(@F).d $< ; \ $(cmd_fixdep) quiet_cmd_cc_o_c = ' CC $@' cmd_cc_o_c = $(CC) -c $(CPPFLAGS) $(CFLAGS) -o $@ $< define do_cc_o_c @$(cmd_cc_dep_c); @echo $($(quiet)cmd_cc_o_c); @$(cmd_cc_o_c); endef cmd_cc_dep_rc = \ $(CC) -x c-header -MM -MT $@ $(CPPFLAGS) -o $(@D)/.$(@F).d $< ; \ $(cmd_fixdep) quiet_cmd_windres_res_rc = ' WINDRES $@' cmd_windres_res_rc = $(WINDRES) -I $(