-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathGNUmakefile
242 lines (205 loc) · 7.97 KB
/
GNUmakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
######################################################################
# Linux Makefile for Quake2 v1.4
# Robert "Arras" LeBlanc <rjl@renaissoft.com>
#
# This Makefile is based on the "authoritative" Makefile released
# by Zoid <zoid@idsoftware.com> and refined somewhat by Jet
# <jet@poboxes.com>, and now finally refined a bit more by me to
# make it more useful to mod authors.
#
# To use this Makefile to build your own mod, follow the steps below:
#
# Step 1: Get the 03/14 source distribution from id Software
# and copy the contents (*.c, *.h) to a working directory.
#
# Step 2: Copy this Makefile into the working directory. If you have
# a Redhat Linux distribution, comment out the LDFLAGS
# definition below--you don't need "-ldl -lm", and in fact the
# presence of these flags will cause your build to crash and
# burn. Slackware users can leave them untouched.
#
# Step 3: Copy any mod-related source files of yours into the working
# directory.
#
# Step 4: If you developed your source files on a Win32 machine, type
# "make stripcr" to get rid of any stray carriage returns that
# may be lurking in your files.
# MJD - If make complains that it cannot find a separator, then
# your makefile has been contaminated, too! Somehow, you
# need to run stripcr on your makefile so you can use
# the makefile! Neat catch-22, there. I suggest a little
# set of utils called unix2dos and dos2unix.
#
# Step 5: Add your custom mod-related files to the C_OBJS list below,
# so that the Makefile knows to build them. For every *.c
# file in your mod you should have a corresponding *.o file
# listed under C_OBJS. Don't list files that are already
# part of id's sources (e.g. g_cmds.o, p_client.o, etc.),
# they're already known to the Makefile; just list any *.c
# files specific to your mod.
# MJD - If you get a bunch of messages about a function
# already being defined, and it shows you the same line
# twice -- that means you put the same file in the list
# of objects twice. Oops.
#
# Step 6: Type "make dep" to build a list of dependencies based on
# the total set of source files in the working directory.
#
# Step 7: Type "make" to build your mod.
######################################################################
PLATFORM := $(shell uname 2>/dev/null || echo Windows)
PLATFORM := $(patsubst CYGWIN%,Cygwin,$(PLATFORM))
PLATFORM := $(patsubst MSYS%,Cygwin,$(PLATFORM))
PLATFORM := $(patsubst MINGW%,Windows,$(PLATFORM))
PLATFORM := $(patsubst UCRT%,Windows,$(PLATFORM))
PLATFORM := $(patsubst CLANG%,Windows,$(PLATFORM))
# this nice line comes from the linux kernel makefile
ARCH := $(shell uname -m | sed -e s/i.86/i386/ \
-e s/sun4u/sparc64/ -e s/arm.*/arm/ \
-e s/sa110/arm/ -e s/alpha/axp/)
ifeq ($(PLATFORM),Windows)
ifeq ($(patsubst MINGW32%,,$(shell uname 2>/dev/null)),)
ARCH := x86
endif
ifeq ($(patsubst CLANG32%,,$(shell uname 2>/dev/null)),)
ARCH := x86
endif
ifeq ($(ARCH),i386)
ARCH := x86
endif
endif
# On 64-bit OS use the command: 'setarch i386 make' after 'make clean'
# to obtain the 32-bit binary DLL on 64-bit Linux.
# on x64 machines do this preparation:
# sudo apt-get install ia32-libs
# sudo apt-get install libc6-dev-i386
# On Ubuntu 16.x use sudo apt install libc6-dev-i386
# this will let you build 32-bits on ia64 systems
#
ifndef REV
REV := $(shell git rev-list HEAD | wc -l)
endif
ifndef VER
VER := r$(REV)~$(shell git rev-parse --short HEAD)
endif
# This is for native build
CFLAGS=-O3 -DARCH="$(ARCH)" -DSTDC_HEADERS -DVER='"$(VER)"'
# This is for 32-bit build on 64-bit host
ifeq ($(ARCH),i386)
CFLAGS =-m32 -O3 -DARCH="$(ARCH)" -DSTDC_HEADERS -DVER='"$(VER)"' -I/usr/include
endif
######################################################################
# C_OBJS (Custom Objects): Mod authors should use this group below to
# specify any custom files required by their mods that are not
# included in id's sources. e.g. if your mod requires the addition
# of custom files "foo.c" and "bar.c", you'd add:
#
# C_OBJS = foo.o bar.o
#
# Leave this empty if you just want to build id's default gamei386.so.
######################################################################
C_OBJS = g_menu.o g_replace.o g_runes.o g_ctffunc.o \
g_skins.o g_tourney.o plasma.o \
p_observer.o g_chase.o p_stats.o \
stdlog.o gslog.o bat.o g_vote.o
######################################################################
# End of user-customizable section - you shouldn't have to touch
# anything below this point.
# MJD - With the exception of if you want massive debugging turned
# on or not...
######################################################################
# Game-related objects
G_OBJS = g_ai.o g_cmds.o g_combat.o g_func.o g_items.o g_main.o \
g_misc.o g_monster.o g_phys.o g_save.o g_spawn.o g_svcmds.o \
g_target.o g_trigger.o g_turret.o g_utils.o g_weapon.o
# Monster-related objects
M_OBJS = m_actor.o m_berserk.o m_boss2.o m_boss3.o m_boss31.o \
m_boss32.o m_brain.o m_chick.o m_flash.o m_flipper.o \
m_float.o m_flyer.o m_gladiator.o m_gunner.o m_hover.o \
m_infantry.o m_insane.o m_medic.o m_move.o m_mutant.o \
m_parasite.o m_soldier.o m_supertank.o m_tank.o
# Player-related objects
P_OBJS = p_client.o p_hud.o p_trail.o p_view.o p_weapon.o
# Quake2-related objects
Q_OBJS = q_shared.o
# Lithium II ZBot detection object (uncomment the appropriate binary)
L_OBJS =
#L_OBJS = l2zbot/Linux_x86/zbotcheck.o
#L_OBJS = l2zbot/Linux_AXP/zbotcheck.o
# Note that the mod author's Custom Objects (C_OBJS) are built first,
# which should speed up the detection of compilation errors; if they
# build properly, the rest of id's code should build without complaint,
# at least until link time :)
#
OBJS = $(C_OBJS) $(G_OBJS) $(M_OBJS) $(P_OBJS) $(Q_OBJS)
TARGET = game$(ARCH)-lmctf-$(VER).so
CC = gcc -std=c11
SHELL = /bin/sh
#for Windows or when we don't know the OS.
LIBTOOL = ldd
CFLAGS += -g -Wall
# Windows / MinGW (incl. MSYS2 MinGW)
ifeq ($(PLATFORM),Windows)
TARGET = game$(ARCH)-lmctf-$(VER).dll
endif
# MSYS2 / Cygwin
ifeq ($(PLATFORM),Cygwin)
TARGET = game$(ARCH)-lmctf-$(VER).dll
CFLAGS += -DLINUX
LDFLAGS = -ldl -lm
endif
# flavors of Linux
ifeq ($(shell uname),Linux)
CFLAGS += -DLINUX
LDFLAGS = -ldl -lm
ifeq ("$(wildcard /etc/alpine-release)","")
LIBTOOL = ldd -r
endif
endif
# OS X wants to be Linux and FreeBSD too.
ifeq ($(shell uname),Darwin)
CFLAGS += -DLINUX
LDFLAGS = -ldl -lm
LIBTOOL = otool
endif
# Linker flags for building a shared library (*.so).
#
# Redhat Linux users don't need -ldl or -lm...
# MJD - I'm not sure I buy this. My Slackware system works fine without
# linking in the DynaLink and Math libs. It may be more of a function of
# library version than RHS/Slackware... Try both!
#LDFLAGS =
# but Slackware people do
#LDFLAGS = -ldl -lm
SHLIBCFLAGS = -fPIC
SHLIBLDFLAGS = -shared
######################################################################
# Targets
######################################################################
all: GitRevisionInfo dep $(TARGET)
GitRevisionInfo:
sed -e 's/\$$//g' GitRevisionInfo.tmpl | sed -e "s/WCLOGCOUNT+2/${REV}/g" | sed -e "s/WCREV=7/${VER}/g" | sed -e "s/WCNOW=%Y/$(shell date +%Y)/g" > GitRevisionInfo.h
.c.o:
$(CC) $(CFLAGS) $(SHLIBCFLAGS) -o $@ -c $<
$(TARGET): $(OBJS) $(L_OBJS)
$(CC) $(CFLAGS) $(SHLIBLDFLAGS) -o $@ $(OBJS) $(L_OBJS) $(LDFLAGS)
$(LIBTOOL) $@
dep:
@echo "Updating dependencies..."
@$(CC) -MM $(OBJS:.o=.c) > .depend
stripcr: .
@echo "Stripping carriage returns from source files..."
@for f in *.[ch]; do \
cat $$f | tr -d '\015' > .stripcr; \
mv .stripcr $$f; \
done; \
rm -f .stripcr
clean:
@echo "Deleting temporary files..."
@rm -f $(OBJS) GitRevisionInfo.h *.orig ~* core
distclean: clean
@echo "Deleting everything that can be rebuilt..."
@rm -f $(TARGET) .depend
ifeq (.depend,$(wildcard .depend))
include .depend
endif