-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
563 lines (475 loc) · 14 KB
/
Makefile
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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
# ----------------------------------------------------------------- #
# Makefile for the gladiator game and botlib modules for Quake II #
# #
# Just type "make" to compile the #
# - Gladiator Game (game.so) #
# - BSPC tool for the Gladiator Bot #
# - Gladiator Botlib (botlib.so) #
# #
# Dependencies: #
# - None, but you need a Quake II to play. #
# While in theory every client should work #
# Yamagi Quake II ist recommended. #
# #
# Platforms: #
# - FreeBSD #
# - Linux #
# - Mac OS X #
# - OpenBSD #
# - Windows #
# ----------------------------------------------------------------- #
# Detect the OS
ifdef SystemRoot
YQ2_OSTYPE ?= Windows
else
YQ2_OSTYPE ?= $(shell uname -s)
endif
# Special case for MinGW
ifneq (,$(findstring MINGW,$(YQ2_OSTYPE)))
YQ2_OSTYPE := Windows
endif
# Detect the architecture
ifeq ($(YQ2_OSTYPE), Windows)
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
ifdef PROCESSOR_ARCHITEW6432
# 64 bit Windows
YQ2_ARCH ?= $(PROCESSOR_ARCHITEW6432)
else
# 32 bit Windows
YQ2_ARCH ?= $(PROCESSOR_ARCHITECTURE)
endif
endif # windows but MINGW_CHOST not defined
else
ifneq ($(YQ2_OSTYPE), Darwin)
# Normalize some abiguous YQ2_ARCH strings
YQ2_ARCH ?= $(shell uname -m | sed -e 's/i.86/i386/' -e 's/amd64/x86_64/' -e 's/arm64/aarch64/' -e 's/^arm.*/arm/')
else
YQ2_ARCH ?= $(shell uname -m)
endif
endif
# On Windows / MinGW $(CC) is undefined by default.
ifeq ($(YQ2_OSTYPE),Windows)
CC ?= gcc
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
# ----------
# 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
else
CFLAGS ?= -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)
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
override CFLAGS += -DYQ2OSTYPE=\"$(YQ2_OSTYPE)\" -DYQ2ARCH=\"$(YQ2_ARCH)\"
# ----------
# For reproduceable builds, look here for details:
# 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
# ----------
# 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
ifeq ($(YQ2_ARCH), i386)
override CFLAGS += -msse -mfpmath=sse
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
ifeq ($(YQ2_OSTYPE), Linux)
override CFLAGS += -DARCH_STRING=\"$(YQ2_ARCH)\"
endif
BOTCFLAGS=-O0
# ----------
# Base LDFLAGS.
LDFLAGS ?=
# Required libaries
ifeq ($(YQ2_OSTYPE), Darwin)
override LDFLAGS += -arch $(YQ2_ARCH)
else ifeq ($(YQ2_OSTYPE), Windows)
override LDFLAGS += -static-libgcc
else
override LDFLAGS += -lm
endif
# ----------
# Phony targets
.PHONY : all clean game bspc botlib
# ----------
# Builds everything
all: game bspc botlib
# ----------
# Cleanup
clean:
rm -Rf build release/*
cleanall:
rm -Rf build release
# ----------
# The gladiator game
ifeq ($(YQ2_OSTYPE), Windows)
game:
mkdir -p release/game
$(MAKE) release/game/game.dll
build/game/%.o: %.c
mkdir -p $(@D)
$(CC) -c $(CFLAGS) $(INCLUDE) -o $@ $<
release/game/game.dll : LDFLAGS += -shared
else ifeq ($(YQ2_OSTYPE), Darwin)
game:
mkdir -p release/game
$(MAKE) release/game/game.dylib
build/game/%.o: %.c
mkdir -p $(@D)
$(CC) -c $(CFLAGS) $(INCLUDE) -o $@ $<
release/game/game.dylib : CFLAGS += -fPIC
release/game/game.dylib : LDFLAGS += -shared
else # not Windows or Darwin
game:
mkdir -p release/game
$(MAKE) release/game/game.so
build/game/%.o: %.c
mkdir -p $(@D)
$(CC) -c $(CFLAGS) $(INCLUDE) -o $@ $<
release/game/game.so : CFLAGS += -fPIC -Wno-unused-result
release/game/game.so : LDFLAGS += -shared
endif
# ----------
# The BSPC tool for the Gladiator Bot
ifeq ($(YQ2_OSTYPE), Windows)
bspc:
mkdir -p release/bspc
$(MAKE) release/bspc/bspc.exe
build/bspc/%.o: %.c
mkdir -p $(@D)
$(CC) -c $(CFLAGS) $(INCLUDE) -Dstricmp=strcasecmp -DMAC_STATIC= -DQDECL= -DBSPC -D_FORTIFY_SOURCE=2 -o $@ $<
release/bspc/bspc.exe : LDFLAGS += -Wl,--allow-multiple-definition
else ifeq ($(YQ2_OSTYPE), Darwin)
bspc:
mkdir -p release/bspc
$(MAKE) release/bspc/bspc
build/bspc/%.o: %.c
mkdir -p $(@D)
$(CC) -c $(CFLAGS) $(INCLUDE) -Dstricmp=strcasecmp -DMAC_STATIC= -DQDECL= -DBSPC -D_FORTIFY_SOURCE=2 -o $@ $<
release/bspc/bspc : CFLAGS += -fPIC
release/bspc/bspc : LDFLAGS += -Wl,--allow-multiple-definition
else # not Windows or Darwin
bspc:
mkdir -p release/bspc
$(MAKE) release/bspc/bspc
build/bspc/%.o: %.c
mkdir -p $(@D)
$(CC) -c $(CFLAGS) $(INCLUDE) -Dstricmp=strcasecmp -DMAC_STATIC= -DQDECL= -DBSPC -D_FORTIFY_SOURCE=2 -o $@ $<
release/bspc/bspc : CFLAGS += -fPIC -Wno-unused-result
release/bspc/bspc : LDFLAGS += -Wl,--allow-multiple-definition
endif
# ----------
# The gladiator botlib
ifeq ($(YQ2_OSTYPE), Windows)
botlib:
mkdir -p release/botlib
$(MAKE) release/botlib/botlib.dll
build/botlib/%.o: %.c
mkdir -p $(@D)
$(CC) -c $(CFLAGS) $(INCLUDE) $(BOTCFLAGS) -DBOTLIB -o $@ $<
release/botlib/botlib.dll : LDFLAGS += -shared
else ifeq ($(YQ2_OSTYPE), Darwin)
botlib:
mkdir -p release/botlib
$(MAKE) release/botlib/botlib.dylib
build/botlib/%.o: %.c
mkdir -p $(@D)
$(CC) -c $(CFLAGS) $(INCLUDE) $(BOTCFLAGS) -DBOTLIB -o $@ $<
release/botlib/botlib.dylib : CFLAGS += -fPIC
release/botlib/botlib.dylib : LDFLAGS += -shared
else # not Windows or Darwin
botlib:
mkdir -p release/botlib
$(MAKE) release/botlib/botlib.so
build/botlib/%.o: %.c
mkdir -p $(@D)
$(CC) -c $(CFLAGS) $(INCLUDE) $(BOTCFLAGS) -DBOTLIB -o $@ $<
release/botlib/botlib.so : CFLAGS += -fPIC -Wno-unused-result
release/botlib/botlib.so : LDFLAGS += -shared
endif
# ----------
GAME_OBJS_ = \
game_q2/bl_cmd.o \
game_q2/bl_botcfg.o \
game_q2/bl_debug.o \
game_q2/bl_main.o \
game_q2/bl_redirgi.o \
game_q2/bl_spawn.o \
game_q2/dm_ball_rogue.o \
game_q2/dm_tag_rogue.o \
game_q2/g_ai.o \
game_q2/g_arena.o \
game_q2/g_ch.o \
game_q2/g_chase.o \
game_q2/g_cmds.o \
game_q2/g_combat.o \
game_q2/g_ctf.o \
game_q2/g_func.o \
game_q2/g_items.o \
game_q2/g_log.o \
game_q2/g_main.o \
game_q2/g_misc.o \
game_q2/g_monster.o \
game_q2/g_newai_rogue.o \
game_q2/g_newdm_rogue.o \
game_q2/g_newfnc_rogue.o \
game_q2/g_newtarg_rogue.o \
game_q2/g_newtrig_rogue.o \
game_q2/g_newweap_rogue.o \
game_q2/g_phys.o \
game_q2/g_save.o \
game_q2/g_spawn.o \
game_q2/g_sphere_rogue.o \
game_q2/g_svcmds.o \
game_q2/g_target.o \
game_q2/g_trigger.o \
game_q2/g_turret.o \
game_q2/g_utils.o \
game_q2/g_weapon.o \
game_q2/m_actor.o \
game_q2/m_berserk.o \
game_q2/m_boss2.o \
game_q2/m_boss3.o \
game_q2/m_boss31.o \
game_q2/m_boss32.o \
game_q2/m_boss5_xatrix.o \
game_q2/m_brain.o \
game_q2/m_carrier_rogue.o \
game_q2/m_chick.o \
game_q2/m_fixbot_xatrix.o \
game_q2/m_flash.o \
game_q2/m_flipper.o \
game_q2/m_float.o \
game_q2/m_flyer.o \
game_q2/m_gekk_xatrix.o \
game_q2/m_gladb_xatrix.o \
game_q2/m_gladiator.o \
game_q2/m_gunner.o \
game_q2/m_hover.o \
game_q2/m_infantry.o \
game_q2/m_insane.o \
game_q2/m_medic.o \
game_q2/m_move.o \
game_q2/m_move2_rogue.o \
game_q2/m_mutant.o \
game_q2/m_parasite.o \
game_q2/m_soldier.o \
game_q2/m_stalker_rogue.o \
game_q2/m_supertank.o \
game_q2/m_tank.o \
game_q2/m_turret_rogue.o \
game_q2/m_widow2_rogue.o \
game_q2/m_widow_rogue.o \
game_q2/p_botmenu.o \
game_q2/p_client.o \
game_q2/p_hud.o \
game_q2/p_lag.o \
game_q2/p_menu.o \
game_q2/p_menulib.o \
game_q2/p_trail.o \
game_q2/p_view.o \
game_q2/p_weapon.o \
game_q2/q_shared.o
# qcommon_q2/files.o
# game_q2/p_observer.o \
# ----------
BSPC_OBJS_ = \
botlib/be_aas_bspq2.o \
botlib/be_aas_cluster.o \
botlib/be_aas_move.o \
botlib/be_aas_optimize.o \
botlib/be_aas_reach.o \
botlib/be_aas_sample.o \
botlib/l_libvar.o \
botlib/l_precomp.o \
botlib/l_script.o \
botlib/l_struct.o \
bspc/aas_areamerging.o \
bspc/aas_cfg.o \
bspc/aas_create.o \
bspc/aas_edgemelting.o \
bspc/aas_facemerging.o \
bspc/aas_file.o \
bspc/aas_gsubdiv.o \
bspc/aas_map.o \
bspc/aas_prunenodes.o \
bspc/aas_store.o \
bspc/be_aas_bspc.o \
bspc/brushbsp.o \
bspc/bspc.o \
bspc/csg.o \
bspc/glfile.o \
bspc/leakfile.o \
bspc/l_bsp_ent.o \
bspc/l_bsp_hl.o \
bspc/l_bsp_q1.o \
bspc/l_bsp_q2.o \
bspc/l_bsp_q3.o \
bspc/l_bsp_sin.o \
bspc/l_cmd.o \
bspc/l_log.o \
bspc/l_math.o \
bspc/l_mem.o \
bspc/l_poly.o \
bspc/l_qfiles.o \
bspc/l_threads.o \
bspc/l_utils.o \
bspc/map.o \
bspc/map_hl.o \
bspc/map_q1.o \
bspc/map_q2.o \
bspc/map_q3.o \
bspc/map_sin.o \
bspc/nodraw.o \
bspc/portals.o \
bspc/textures.o \
bspc/tree.o \
bspc/_files.o \
qcommon_q3/cm_load.o \
qcommon_q3/cm_patch.o \
qcommon_q3/cm_test.o \
qcommon_q3/cm_trace.o \
qcommon_q3/md4.o \
qcommon_q3/unzip.o
#bspc/faces.o \
#bspc/prtfile.o \
#bspc/writebsp.o
# ----------
BOTLIB_OBJS_ = \
botlib/be_aas_bspq2.o \
botlib/be_aas_cluster.o \
botlib/be_aas_debug.o \
botlib/be_aas_entity.o \
botlib/be_aas_file.o \
botlib/be_aas_main.o \
botlib/be_aas_move.o \
botlib/be_aas_optimize.o \
botlib/be_aas_reach.o \
botlib/be_aas_route.o \
botlib/be_aas_routealt.o \
botlib/be_aas_sample.o \
botlib/be_ai_char.o \
botlib/be_ai_chat.o \
botlib/be_ai_gen.o \
botlib/be_ai_goal.o \
botlib/be_ai_move.o \
botlib/be_ai_weap.o \
botlib/be_ai_weight.o \
botlib/be_ea.o \
botlib/be_interface.o \
botlib/l_crc.o \
botlib/l_libvar.o \
botlib/l_log.o \
botlib/l_memory.o \
botlib/l_precomp.o \
botlib/l_script.o \
botlib/l_struct.o \
botlib/standalone.o \
bspc/l_utils.o \
game_q2/q_shared.o
# ----------
# Rewrite pathes to our object directory
GAME_OBJS = $(patsubst %,build/game/%,$(GAME_OBJS_))
BSPC_OBJS = $(patsubst %,build/bspc/%,$(BSPC_OBJS_))
BOTLIB_OBJS = $(patsubst %,build/botlib/%,$(BOTLIB_OBJS_))
# ----------
# Generate header dependencies
GAME_DEPS= $(GAME_OBJS:.o=.d)
BSPC_DEPS= $(BSPC_OBJS:.o=.d)
BOTLIB_DEPS= $(BOTLIB_OBJS:.o=.d)
# ----------
# Suck header dependencies in
-include $(GAME_DEPS)
-include $(BSPC_DEPS)
-include $(BOTLIB_DEPS)
# ----------
# release/baseq2/game.so
ifeq ($(YQ2_OSTYPE), Windows)
release/game/game.dll : $(GAME_OBJS)
$(CC) -o $@ $(GAME_OBJS) $(LDFLAGS)
else ifeq ($(YQ2_OSTYPE), Darwin)
release/game/game.dylib : $(GAME_OBJS)
$(CC) -o $@ $(GAME_OBJS) $(LDFLAGS)
else
release/game/game.so : $(GAME_OBJS)
$(CC) -o $@ $(GAME_OBJS) $(LDFLAGS)
endif
# ----------
# release/bspc/bspc
ifeq ($(YQ2_OSTYPE), Windows)
release/bspc/bspc.exe : $(BSPC_OBJS)
$(CC) -o $@ $(BSPC_OBJS) $(LDFLAGS)
else ifeq ($(YQ2_OSTYPE), Darwin)
release/bspc/bspc : $(BSPC_OBJS)
$(CC) -o $@ $(BSPC_OBJS) $(LDFLAGS)
else
release/bspc/bspc : $(BSPC_OBJS)
$(CC) -o $@ $(BSPC_OBJS) $(LDFLAGS)
endif
# ----------
ifeq ($(YQ2_OSTYPE), Windows)
release/botlib/botlib.dll : $(BOTLIB_OBJS)
$(CC) -o $@ $(BOTLIB_OBJS) $(LDFLAGS)
else ifeq ($(YQ2_OSTYPE), Darwin)
release/botlib/botlib.dylib : $(BOTLIB_OBJS)
$(CC) -o $@ $(BOTLIB_OBJS) $(LDFLAGS)
else
release/botlib/botlib.so : $(BOTLIB_OBJS)
$(CC) -o $@ $(BOTLIB_OBJS) $(LDFLAGS)
endif
# ----------