# # 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". # TYR_VERSION_MAJOR = 0 TYR_VERSION_MINOR = 61 TYR_VERSION_BUILD = TYR_VERSION = $(TYR_VERSION_MAJOR).$(TYR_VERSION_MINOR)$(TYR_VERSION_BUILD) # ============================================================================ # User configurable options here: # ============================================================================ BUILD_DIR ?= build BIN_DIR ?= bin DEBUG ?= N# Compile with debug info OPTIMIZED_CFLAGS ?= Y# Enable compiler optimisations (if DEBUG != Y) USE_X86_ASM ?= $(I386_GUESS) USE_SDL ?= N# New (experimental) SDL video implementation for Win32 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) 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 # Adjust object files and libs for SDL choice ifeq ($(USE_SDL),Y) VID_WIN = vid_sdl VID_WIN_LIBS_NQ = sdl VID_WIN_LIBS_QW = sdl IN_WIN = in_sdl else VID_WIN = vid_win VID_WIN_LIBS_NQ = mgllt gdi32 ddraw VID_WIN_LIBS_QW = mgllt gdi32 IN_WIN = in_win 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 executables # - I've seen i386-mingw32msvc, i586-mingw32msvc (Debian) and now # i486-mingw32 (Arch). # ------------------------------------------------------------------------ MINGW_CROSS_GUESS := $(shell \ if which i486-mingw32-gcc > /dev/null 2>&1; then \ echo i486-mingw32; \ elif 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 ;) cc-i386 = $(if $(subst __i386,,$(shell echo __i386 | $(CC) -E -xc - | tail -n 1)),Y,N) GCC_VERSION := $(call cc-version) I386_GUESS := $(call cc-i386) # --------------------- # 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 = $(VID_WIN_LIBS_NQ) NQ_W32_GL_LIBS = opengl32 comctl32 gdi32 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 WINMODE = console else WINMODE = windows 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 APPS = tyr-quake$(EXT) tyr-glquake$(EXT) \ tyr-qwcl$(EXT) tyr-glqwcl$(EXT) \ tyr-qwsv$(EXT) default: all all: $(patsubst %,$(BIN_DIR)/%,$(APPS)) 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 $(NQSWDIR)/%.o: CPPFLAGS = $(NQSW_CPPFLAGS) $(NQGLDIR)/%.o: CPPFLAGS = $(NQGL_CPPFLAGS) $(QWSWDIR)/%.o: CPPFLAGS = $(QWSW_CPPFLAGS) $(QWGLDIR)/%.o: CPPFLAGS = $(QWGL_CPPFLAGS) $(QWSVDIR)/%.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 $(@D)' cmd_mkdir = mkdir -p $(@D) define do_mkdir @if [ ! -d $(@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 @$(do_mkdir); @$(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 $(