-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
645 lines (502 loc) · 15.1 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
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
#
# Derelict QVM Makefile
#
# Nov '98 by Zoid <[email protected]>
#
# Loki Hacking by Bernd Kreimeier
# and a little more by Ryan C. Gordon.
# and a little more by Rafael Barrero
# and a little more by the ioq3 cr3w
# and a little more by Tim Angus
#
# GNU Make required
#
COMPILE_PLATFORM=$(shell uname|sed -e s/_.*//|tr '[:upper:]' '[:lower:]')
ifeq ($(COMPILE_PLATFORM),darwin)
# Apple does some things a little differently...
COMPILE_ARCH=$(shell uname -p | sed -e s/i.86/x86/)
else
COMPILE_ARCH=$(shell uname -m | sed -e s/i.86/x86/)
endif
BUILD_GAME_SO ?= 1
BUILD_GAME_QVM ?= 1
#############################################################################
#
# If you require a different configuration from the defaults below, create a
# new file named "Makefile.local" in the same directory as this file and define
# your parameters there. This allows you to change configuration without
# causing problems with keeping up to date with the repository.
#
#############################################################################
-include Makefile.local
ifndef PLATFORM
PLATFORM=$(COMPILE_PLATFORM)
endif
export PLATFORM
ifndef ARCH
ARCH=$(COMPILE_ARCH)
endif
ifeq ($(ARCH),powerpc)
ARCH=ppc
endif
export ARCH
ifneq ($(PLATFORM),$(COMPILE_PLATFORM))
CROSS_COMPILING=1
else
CROSS_COMPILING=0
ifneq ($(ARCH),$(COMPILE_ARCH))
CROSS_COMPILING=1
endif
endif
export CROSS_COMPILING
ifndef COPYDIR
COPYDIR="/usr/local/games/tremulous"
endif
ifndef MOUNT_DIR
MOUNT_DIR=src
endif
ifndef BUILD_DIR
BUILD_DIR=build
endif
ifndef GENERATE_DEPENDENCIES
GENERATE_DEPENDENCIES=1
endif
ifndef USE_CCACHE
USE_CCACHE=0
endif
export USE_CCACHE
ifndef USE_LOCAL_HEADERS
USE_LOCAL_HEADERS=1
endif
#############################################################################
BD=$(BUILD_DIR)/debug-$(PLATFORM)-$(ARCH)
BR=$(BUILD_DIR)/release-$(PLATFORM)-$(ARCH)
CMDIR=$(MOUNT_DIR)/qcommon
GDIR=$(MOUNT_DIR)/game
CGDIR=$(MOUNT_DIR)/cgame
UIDIR=$(MOUNT_DIR)/ui
TOOLSDIR=$(MOUNT_DIR)/tools
# extract version info
VERSION=$(shell grep "\#define VERSION_NUMBER" $(CMDIR)/q_shared.h | \
sed -e 's/[^"]*"\(.*\)"/\1/')
USE_SVN=
ifeq ($(wildcard .svn),.svn)
SVN_REV=$(shell LANG=C svnversion .)
ifneq ($(SVN_REV),)
SVN_VERSION=$(VERSION)_SVN$(SVN_REV)
USE_SVN=1
endif
endif
ifneq ($(USE_SVN),1)
SVN_VERSION=$(VERSION)
endif
#############################################################################
# SETUP AND BUILD -- LINUX
#############################################################################
## Defaults
LIB=lib
INSTALL=install
MKDIR=mkdir
ifeq ($(PLATFORM),linux)
ifeq ($(ARCH),alpha)
ARCH=axp
else
ifeq ($(ARCH),x86_64)
LIB=lib64
else
ifeq ($(ARCH),ppc64)
LIB=lib64
else
ifeq ($(ARCH),s390x)
LIB=lib64
endif
endif
endif
endif
BASE_CFLAGS = -Wall -fno-strict-aliasing -Wimplicit -Wstrict-prototypes -pipe
OPTIMIZE = -O3 -funroll-loops -fomit-frame-pointer
ifeq ($(ARCH),x86_64)
OPTIMIZE = -O3 -fomit-frame-pointer -funroll-loops \
-falign-loops=2 -falign-jumps=2 -falign-functions=2 \
-fstrength-reduce
# experimental x86_64 jit compiler! you need GNU as
HAVE_VM_COMPILED = true
else
ifeq ($(ARCH),x86)
OPTIMIZE = -O3 -march=i586 -fomit-frame-pointer \
-funroll-loops -falign-loops=2 -falign-jumps=2 \
-falign-functions=2 -fstrength-reduce
HAVE_VM_COMPILED=true
else
ifeq ($(ARCH),ppc)
BASE_CFLAGS += -maltivec
HAVE_VM_COMPILED=false
endif
endif
endif
ifneq ($(HAVE_VM_COMPILED),true)
BASE_CFLAGS += -DNO_VM_COMPILED
endif
DEBUG_CFLAGS = $(BASE_CFLAGS) -g -O0
RELEASE_CFLAGS=$(BASE_CFLAGS) -DNDEBUG $(OPTIMIZE)
SHLIBEXT=so
SHLIBCFLAGS=-fPIC
SHLIBLDFLAGS=-shared $(LDFLAGS)
ifeq ($(ARCH),x86)
# linux32 make ...
BASE_CFLAGS += -m32
endif
else # ifeq Linux
#############################################################################
# SETUP AND BUILD -- MAC OS X
#############################################################################
ifeq ($(PLATFORM),darwin)
HAVE_VM_COMPILED=true
BASE_CFLAGS=
LDFLAGS=
OPTIMIZE=
BASE_CFLAGS += -Wall -Wimplicit -Wstrict-prototypes
ifeq ($(ARCH),ppc)
OPTIMIZE += -faltivec -O3
endif
ifeq ($(ARCH),x86)
OPTIMIZE += -march=prescott -mfpmath=sse
# x86 vm will crash without -mstackrealign since MMX instructions will be
# used no matter what and they corrupt the frame pointer in VM calls
BASE_CFLAGS += -mstackrealign
endif
BASE_CFLAGS += -fno-strict-aliasing -DMACOS_X -fno-common -pipe
# Always include debug symbols...you can strip the binary later...
BASE_CFLAGS += -gfull
OPTIMIZE += -falign-loops=16
ifneq ($(HAVE_VM_COMPILED),true)
BASE_CFLAGS += -DNO_VM_COMPILED
endif
DEBUG_CFLAGS = $(BASE_CFLAGS) -g -O0
RELEASE_CFLAGS=$(BASE_CFLAGS) -DNDEBUG $(OPTIMIZE)
SHLIBEXT=dylib
SHLIBCFLAGS=-fPIC -fno-common
SHLIBLDFLAGS=-dynamiclib $(LDFLAGS)
NOTSHLIBCFLAGS=-mdynamic-no-pic
else # ifeq darwin
#############################################################################
# SETUP AND BUILD -- MINGW32
#############################################################################
ifeq ($(PLATFORM),mingw32)
ifndef WINDRES
WINDRES=windres
endif
ARCH=x86
BASE_CFLAGS = -Wall -fno-strict-aliasing -Wimplicit -Wstrict-prototypes
OPTIMIZE = -O3 -march=i586 -fomit-frame-pointer -falign-loops=2 \
-funroll-loops -falign-jumps=2 -falign-functions=2 -fstrength-reduce
HAVE_VM_COMPILED = true
DEBUG_CFLAGS=$(BASE_CFLAGS) -g -O0
RELEASE_CFLAGS=$(BASE_CFLAGS) -DNDEBUG $(OPTIMIZE)
SHLIBEXT=dll
SHLIBCFLAGS=
SHLIBLDFLAGS=-shared $(LDFLAGS)
BINEXT=.exe
ifeq ($(ARCH),x86)
# build 32bit
BASE_CFLAGS += -m32
endif
else # ifeq mingw32
#############################################################################
# SETUP AND BUILD -- FREEBSD
#############################################################################
ifeq ($(PLATFORM),freebsd)
ifneq (,$(findstring alpha,$(shell uname -m)))
ARCH=axp
else #default to x86
ARCH=x86
endif #alpha test
BASE_CFLAGS = -Wall -fno-strict-aliasing -Wimplicit -Wstrict-prototypes \
-I/usr/X11R6/include
DEBUG_CFLAGS=$(BASE_CFLAGS) -g
ifeq ($(ARCH),axp)
BASE_CFLAGS += -DNO_VM_COMPILED
RELEASE_CFLAGS=$(BASE_CFLAGS) -DNDEBUG -O3 -funroll-loops \
-fomit-frame-pointer -fexpensive-optimizations
else
ifeq ($(ARCH),x86)
RELEASE_CFLAGS=$(BASE_CFLAGS) -DNDEBUG -O3 -mtune=pentiumpro \
-march=pentium -fomit-frame-pointer -pipe \
-falign-loops=2 -falign-jumps=2 -falign-functions=2 \
-funroll-loops -fstrength-reduce
HAVE_VM_COMPILED=true
else
BASE_CFLAGS += -DNO_VM_COMPILED
endif
endif
SHLIBEXT=so
SHLIBCFLAGS=-fPIC
SHLIBLDFLAGS=-shared $(LDFLAGS)
else # ifeq freebsd
#############################################################################
# SETUP AND BUILD -- GENERIC
#############################################################################
BASE_CFLAGS=-DNO_VM_COMPILED
DEBUG_CFLAGS=$(BASE_CFLAGS) -g
RELEASE_CFLAGS=$(BASE_CFLAGS) -DNDEBUG -O3
SHLIBEXT=so
SHLIBCFLAGS=-fPIC
SHLIBLDFLAGS=-shared
endif #Linux
endif #darwin
endif #mingw32
endif #FreeBSD
TARGETS =
ifneq ($(BUILD_GAME_SO),0)
TARGETS += \
$(B)/base/cgame$(ARCH).$(SHLIBEXT) \
$(B)/base/game$(ARCH).$(SHLIBEXT) \
$(B)/base/ui$(ARCH).$(SHLIBEXT)
endif
ifneq ($(BUILD_GAME_QVM),0)
ifneq ($(CROSS_COMPILING),1)
TARGETS += \
$(B)/base/vm/cgame.qvm \
$(B)/base/vm/game.qvm \
$(B)/base/vm/ui.qvm
endif
endif
ifeq ($(USE_CCACHE),1)
CC := ccache $(CC)
endif
ifdef DEFAULT_BASEDIR
BASE_CFLAGS += -DDEFAULT_BASEDIR=\\\"$(DEFAULT_BASEDIR)\\\"
endif
ifeq ($(USE_LOCAL_HEADERS),1)
BASE_CFLAGS += -DUSE_LOCAL_HEADERS=1
endif
ifeq ($(GENERATE_DEPENDENCIES),1)
BASE_CFLAGS += -MMD
endif
ifeq ($(USE_SVN),1)
BASE_CFLAGS += -DSVN_VERSION=\\\"$(SVN_VERSION)\\\"
endif
ifeq ($(GENERATE_DEPENDENCIES),1)
DO_QVM_DEP=cat $(@:%.o=%.d) | sed -e 's/\.o/\.asm/g' >> $(@:%.o=%.d)
endif
define DO_SHLIB_CC
@echo "SHLIB_CC $<"
@$(CC) $(CFLAGS) $(SHLIBCFLAGS) -o $@ -c $<
@$(DO_QVM_DEP)
endef
#############################################################################
# MAIN TARGETS
#############################################################################
default: release
all: debug release
debug:
@$(MAKE) targets B=$(BD) CFLAGS="$(CFLAGS) $(DEBUG_CFLAGS)"
release:
@$(MAKE) targets B=$(BR) CFLAGS="$(CFLAGS) $(RELEASE_CFLAGS)"
test: debug
@B=$(BD) SHLIBEXT=$(SHLIBEXT) python deploy.py
deploy: release
@B=$(BR) SHLIBEXT=$(SHLIBEXT) python deploy.py
# Create the build directories and tools, print out
# an informational message, then start building
targets: makedirs tools
@echo ""
@echo "Building Tremulous in $(B):"
@echo " CC: $(CC)"
@echo ""
@echo " CFLAGS:"
@for i in $(CFLAGS); \
do \
echo " $$i"; \
done
@echo ""
@echo " Output:"
@for i in $(TARGETS); \
do \
echo " $$i"; \
done
@echo ""
@$(MAKE) $(TARGETS)
makedirs:
@if [ ! -d $(BUILD_DIR) ];then $(MKDIR) $(BUILD_DIR);fi
@if [ ! -d $(B) ];then $(MKDIR) $(B);fi
@if [ ! -d $(B)/base ];then $(MKDIR) $(B)/base;fi
@if [ ! -d $(B)/base/cgame ];then $(MKDIR) $(B)/base/cgame;fi
@if [ ! -d $(B)/base/game ];then $(MKDIR) $(B)/base/game;fi
@if [ ! -d $(B)/base/ui ];then $(MKDIR) $(B)/base/ui;fi
@if [ ! -d $(B)/base/qcommon ];then $(MKDIR) $(B)/base/qcommon;fi
@if [ ! -d $(B)/base/vm ];then $(MKDIR) $(B)/base/vm;fi
#############################################################################
# QVM BUILD TOOLS
#############################################################################
Q3LCC=$(TOOLSDIR)/q3lcc$(BINEXT)
Q3ASM=$(TOOLSDIR)/q3asm$(BINEXT)
ifeq ($(CROSS_COMPILING),1)
tools:
@echo QVM tools not built when cross-compiling
else
tools:
$(MAKE) -C $(TOOLSDIR)/lcc install
$(MAKE) -C $(TOOLSDIR)/asm install
endif
define DO_Q3LCC
@echo "Q3LCC $<"
@$(Q3LCC) -o $@ $<
endef
#############################################################################
## TREMULOUS CGAME
#############################################################################
CGOBJ_ = \
$(B)/base/cgame/cg_main.o \
$(B)/base/game/bg_misc.o \
$(B)/base/game/bg_pmove.o \
$(B)/base/game/bg_slidemove.o \
$(B)/base/cgame/cg_consolecmds.o \
$(B)/base/cgame/cg_buildable.o \
$(B)/base/cgame/cg_animation.o \
$(B)/base/cgame/cg_animmapobj.o \
$(B)/base/cgame/cg_draw.o \
$(B)/base/cgame/cg_drawtools.o \
$(B)/base/cgame/cg_ents.o \
$(B)/base/cgame/cg_event.o \
$(B)/base/cgame/cg_marks.o \
$(B)/base/cgame/cg_players.o \
$(B)/base/cgame/cg_playerstate.o \
$(B)/base/cgame/cg_predict.o \
$(B)/base/cgame/cg_servercmds.o \
$(B)/base/cgame/cg_snapshot.o \
$(B)/base/cgame/cg_view.o \
$(B)/base/cgame/cg_weapons.o \
$(B)/base/cgame/cg_mem.o \
$(B)/base/cgame/cg_scanner.o \
$(B)/base/cgame/cg_attachment.o \
$(B)/base/cgame/cg_trails.o \
$(B)/base/cgame/cg_particles.o \
$(B)/base/cgame/cg_ptr.o \
$(B)/base/cgame/cg_tutorial.o \
$(B)/base/ui/ui_shared.o \
\
$(B)/base/qcommon/q_math.o \
$(B)/base/qcommon/q_shared.o
CGOBJ = $(CGOBJ_) $(B)/base/cgame/cg_syscalls.o
CGVMOBJ = $(CGOBJ_:%.o=%.asm) $(B)/base/game/bg_lib.asm
$(B)/base/cgame$(ARCH).$(SHLIBEXT) : $(CGOBJ)
@echo "LD $@"
@$(CC) $(SHLIBLDFLAGS) -o $@ $(CGOBJ)
$(B)/base/vm/cgame.qvm: $(CGVMOBJ) $(CGDIR)/cg_syscalls.asm
@echo "Q3ASM $@"
@$(Q3ASM) -o $@ $(CGVMOBJ) $(CGDIR)/cg_syscalls.asm
#############################################################################
## TREMULOUS GAME
#############################################################################
GOBJ_ = \
$(B)/base/game/g_main.o \
$(B)/base/game/bg_misc.o \
$(B)/base/game/bg_pmove.o \
$(B)/base/game/bg_slidemove.o \
$(B)/base/game/g_mem.o \
$(B)/base/game/g_active.o \
$(B)/base/game/g_client.o \
$(B)/base/game/g_cmds.o \
$(B)/base/game/g_combat.o \
$(B)/base/game/g_physics.o \
$(B)/base/game/g_buildable.o \
$(B)/base/game/g_misc.o \
$(B)/base/game/g_missile.o \
$(B)/base/game/g_mover.o \
$(B)/base/game/g_session.o \
$(B)/base/game/g_spawn.o \
$(B)/base/game/g_svcmds.o \
$(B)/base/game/g_target.o \
$(B)/base/game/g_team.o \
$(B)/base/game/g_trigger.o \
$(B)/base/game/g_utils.o \
$(B)/base/game/g_maprotation.o \
$(B)/base/game/g_ptr.o \
$(B)/base/game/g_weapon.o \
$(B)/base/game/g_admin.o \
\
$(B)/base/qcommon/q_math.o \
$(B)/base/qcommon/q_shared.o
GOBJ = $(GOBJ_) $(B)/base/game/g_syscalls.o
GVMOBJ = $(GOBJ_:%.o=%.asm) $(B)/base/game/bg_lib.asm
$(B)/base/game$(ARCH).$(SHLIBEXT) : $(GOBJ)
@echo "LD $@"
@$(CC) $(SHLIBLDFLAGS) -o $@ $(GOBJ)
$(B)/base/vm/game.qvm: $(GVMOBJ) $(GDIR)/g_syscalls.asm
@echo "Q3ASM $@"
@$(Q3ASM) -o $@ $(GVMOBJ) $(GDIR)/g_syscalls.asm
#############################################################################
## TREMULOUS UI
#############################################################################
UIOBJ_ = \
$(B)/base/ui/ui_main.o \
$(B)/base/ui/ui_atoms.o \
$(B)/base/ui/ui_players.o \
$(B)/base/ui/ui_shared.o \
$(B)/base/ui/ui_gameinfo.o \
\
$(B)/base/game/bg_misc.o \
$(B)/base/qcommon/q_math.o \
$(B)/base/qcommon/q_shared.o
UIOBJ = $(UIOBJ_) $(B)/base/ui/ui_syscalls.o
UIVMOBJ = $(UIOBJ_:%.o=%.asm) $(B)/base/game/bg_lib.asm
$(B)/base/ui$(ARCH).$(SHLIBEXT) : $(UIOBJ)
@echo "LD $@"
@$(CC) $(CFLAGS) $(SHLIBLDFLAGS) -o $@ $(UIOBJ)
$(B)/base/vm/ui.qvm: $(UIVMOBJ) $(UIDIR)/ui_syscalls.asm
@echo "Q3ASM $@"
@$(Q3ASM) -o $@ $(UIVMOBJ) $(UIDIR)/ui_syscalls.asm
#############################################################################
## GAME MODULE RULES
#############################################################################
$(B)/base/cgame/%.o: $(CGDIR)/%.c
$(DO_SHLIB_CC)
$(B)/base/cgame/%.asm: $(CGDIR)/%.c
$(DO_Q3LCC)
$(B)/base/game/%.o: $(GDIR)/%.c
$(DO_SHLIB_CC)
$(B)/base/game/%.asm: $(GDIR)/%.c
$(DO_Q3LCC)
$(B)/base/ui/%.o: $(UIDIR)/%.c
$(DO_SHLIB_CC)
$(B)/base/ui/%.asm: $(UIDIR)/%.c
$(DO_Q3LCC)
$(B)/base/qcommon/%.o: $(CMDIR)/%.c
$(DO_SHLIB_CC)
$(B)/base/qcommon/%.asm: $(CMDIR)/%.c
$(DO_Q3LCC)
#############################################################################
# MISC
#############################################################################
clean: clean-debug clean-release
clean2:
@echo "CLEAN $(B)"
@if [ -d $(B) ];then (find $(B) -name '*.d' -exec rm {} \;)fi
@rm -f $(GOBJ) $(CGOBJ) $(UIOBJ) \
$(GVMOBJ) $(CGVMOBJ) $(UIVMOBJ)
@rm -f $(TARGETS)
clean-debug:
@$(MAKE) clean2 B=$(BD)
clean-release:
@$(MAKE) clean2 B=$(BR)
toolsclean:
@$(MAKE) -C $(TOOLSDIR)/asm clean uninstall
@$(MAKE) -C $(TOOLSDIR)/lcc clean uninstall
distclean: clean toolsclean
@rm -rf $(BUILD_DIR)
dist:
rm -rf tremulous-$(SVN_VERSION)
svn export . tremulous-$(SVN_VERSION)
tar --owner=root --group=root --force-local -cjf tremulous-$(SVN_VERSION).tar.bz2 tremulous-$(SVN_VERSION)
rm -rf tremulous-$(SVN_VERSION)
#############################################################################
# DEPENDENCIES
#############################################################################
D_FILES=$(shell find . -name '*.d')
ifneq ($(strip $(D_FILES)),)
include $(D_FILES)
endif
.PHONY: all clean clean2 clean-debug clean-release \
debug default dist distclean deploy makedirs release \
targets test tools toolsclean