This repository was archived by the owner on Mar 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMakefile
749 lines (614 loc) · 20.5 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
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
#####################################
# Tyrann's Quake utilities Makefile #
#####################################
.PHONY: all clean docs snapshot
default: all
# ============================================================================
BUILD_DIR ?= build
BIN_DIR ?= bin
DOC_DIR ?= doc
DIST_DIR ?= dist
DEBUG ?= N# Compile with debug info
OPTIMIZED_CFLAGS ?= Y# Enable compiler optimisations (if DEBUG != Y)
TARGET_OS ?= $(HOST_OS)
TARGET_UNIX ?= $(if $(filter UNIX,$(TARGET_OS)),$(HOST_UNIX),)
# ============================================================================
TYR_RELEASE := v0.17
TYR_GIT := $(shell git describe --dirty 2> /dev/null)
TYR_VERSION := $(if $(TYR_GIT),$(TYR_GIT),$(TYR_RELEASE))
TYR_VERSION_NUM ?= $(patsubst v%,%,$(TYR_VERSION))
# Create/update the build version file
# Any source files which use TYR_VERSION will depend on this
BUILD_VER = $(BUILD_DIR)/.build_version
$(shell \
if [ ! -d "$(BUILD_DIR)" ]; then mkdir -p "$(BUILD_DIR)"; fi ; \
if [ ! -f "$(BUILD_VER)" ] || \
[ "`cat $(BUILD_VER)`" != "$(TYR_VERSION)" ]; then \
printf '%s' "$(TYR_VERSION)" > "$(BUILD_VER)"; \
fi)
# ---------------------------------------
# Attempt detection of the build host OS
# ---------------------------------------
SYSNAME := $(shell uname -s)
TOPDIR := $(shell pwd)
ifneq (,$(findstring MINGW32,$(SYSNAME)))
HOST_OS = WIN32
else
ifneq (,$(findstring MINGW64,$(SYSNAME)))
HOST_OS = WIN64
else
ifneq (,$(findstring $(SYSNAME),FreeBSD NetBSD OpenBSD))
HOST_OS = UNIX
HOST_UNIX = bsd
else
ifneq (,$(findstring $(SYSNAME),Linux))
HOST_OS = UNIX
HOST_UNIX = linux
else
ifneq (,$(findstring $(SYSNAME),Darwin))
HOST_OS = UNIX
HOST_UNIX = darwin
else
$(error OS type not detected.)
endif
endif
endif
endif
endif
ifeq ($(TARGET_OS),WIN32)
EXT=.exe
DPTHREAD=
LPTHREAD=
SNAPSHOT_TARGET = $(DIST_DIR)/tyrutils-$(TYR_VERSION_NUM)-win32.zip
ifneq ($(HOST_OS),WIN32)
TARGET ?= $(MINGW32_CROSS_GUESS)
CC = $(TARGET)-gcc
STRIP = $(TARGET)-strip
endif
else
ifeq ($(TARGET_OS),WIN64)
EXT=.exe
DPTHREAD=
LPTHREAD=
SNAPSHOT_TARGET = $(DIST_DIR)/tyrutils-$(TYR_VERSION_NUM)-win64.zip
ifneq ($(HOST_OS),WIN64)
TARGET ?= $(MINGW64_CROSS_GUESS)
CC = $(TARGET)-gcc
STRIP = $(TARGET)-strip
endif
else
EXT=
DPTHREAD=-DUSE_PTHREADS -pthread
LPTHREAD=-lpthread
ifeq ($(TARGET_UNIX),darwin)
SNAPSHOT_TARGET = $(DIST_DIR)/tyrutils-$(TYR_VERSION_NUM)-osx.zip
endif
endif
endif
#BIN_PFX ?= tyr-
BIN_PFX ?=
# ============================================================================
# Helper functions
# ============================================================================
# --------------------------------
# GCC version and option checking
# --------------------------------
cc-version = $(shell sh $(TOPDIR)/scripts/gcc-version \
$(if $(1), $(1), $(CC)))
if-cc-option = $(shell if $(CC) $(CFLAGS) -Werror $(1) -S -o /dev/null -xc /dev/null \
> /dev/null 2>&1; then echo "$(2)"; else echo "$(3)"; fi ;)
cc-option = $(call if-cc-option,$(1),$(1),$(2))
GCC_VERSION := $(call cc-version,)
# ------------------------------------------------------------------------
# Try to guess the MinGW cross compiler executables
# - I've seen i386-mingw32msvc, i586-mingw32msvc (Debian) and now
# i486-mingw32 (Arch).
# ------------------------------------------------------------------------
MINGW32_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)
MINGW64_CROSS_GUESS := $(shell \
if which x86_64-w64-mingw32-gcc > /dev/null 2>&1; then \
echo x86_64-w64-mingw32; \
else \
echo x86_64-w64-mingw32; \
fi)
# ---------------------------------------
# Define some build variables
# ---------------------------------------
STRIP ?= strip
GROFF ?= groff
CFLAGS := $(CFLAGS) -Wall -Wno-trigraphs -Wwrite-strings -Wcast-qual
CFLAGS += $(call cc-option,-std=gnu99)
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,)
# Enable some math optimisations, but not the full -fast-math
# or -funsafe-math-optimisations which might negatively affect qbsp in particular
CFLAGS += $(call cc-option,-fno-math-errno)
CFLAGS += $(call cc-option,-ffinite-math-only)
CFLAGS += $(call cc-option,-fno-signaling-nans)
endif
endif
# ---------------------------------------------------------------------------
# Build commands
# ---------------------------------------------------------------------------
# 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
quiet_cmd_cp = ' CP $@'
cmd_cp = cp $< $@
define do_cp
$(do_mkdir)
@echo $($(quiet)cmd_cp)
@$(cmd_cp)
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 && \
if grep -q TYRUTILS_VERSION $<; then \
printf '%s: %s\n' $@ $(BUILD_VER) >> $(@D)/.$(@F).d ; \
fi
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
quiet_cmd_cc_link = ' LINK $@'
cmd_cc_link = $(CC) $(LDFLAGS) -o $@ $^ $(1)
define do_cc_link
@$(do_mkdir)
@echo $($(quiet)cmd_cc_link);
@$(call cmd_cc_link,$(1))
endef
quiet_cmd_strip = ' STRIP $(1)'
cmd_strip = $(STRIP) $(1)
ifeq ($(DEBUG),Y)
do_strip=
else
ifeq ($(STRIP),)
do_strip =
else
define do_strip
@echo $(call $(quiet)cmd_strip,$(1));
@$(call cmd_strip,$(1));
endef
endif
endif
git_date = $(shell git log -1 --date=short --format="%ad" -- $< 2>/dev/null)
doc_version = $(git_date) $(TYR_VERSION)
quiet_cmd_man2man = ' MAN2MAN $@'
cmd_man2man = \
sed -e 's/TYR_VERSION/$(doc_version)/' < $< > $(@D)/.$(@F).tmp && \
mv $(@D)/.$(@F).tmp $@
define do_man2man
@$(do_mkdir)
@echo $(if $(quiet),$(quiet_cmd_man2man),"$(cmd_man2man)");
@$(cmd_man2man);
endef
# The sed/awk magic is a little ugly, but I wanted something that
# would work across Linux/BSD/Msys/Darwin
quiet_cmd_man2txt = ' MAN2TXT $@'
cmd_man2txt = \
$(GROFF) -man -Tascii $< | cat -v | \
sed -e 's/\^\[\[\([0-9]\)\{1,2\}[a-z]//g' \
-e 's/.\^H//g' | \
awk '{ gsub("$$", "\r"); print $$0;}' - > $(@D)/.$(@F).tmp && \
mv $(@D)/.$(@F).tmp $@
loud_cmd_man2txt = \
$(subst ",\",$(subst $$,\$$,$(subst "\r","\\r",$(cmd_man2txt))))
define do_man2txt
@$(do_mkdir)
@echo $(if $(quiet),$(quiet_cmd_man2txt),"$(loud_cmd_man2txt)");
@$(cmd_man2txt);
endef
quiet_cmd_man2html = ' MAN2HTML $@'
cmd_man2html = \
$(GROFF) -man -Thtml $< > $(@D)/.$(@F).tmp && \
mv $(@D)/.$(@F).tmp $@
define do_man2html
@$(do_mkdir)
@echo $(if $(quiet),$(quiet_cmd_man2html),"$(cmd_man2html)");
@$(cmd_man2html);
endef
# cmd_zip ~ takes a leading path to be stripped from the archive members
# (basically simulates tar's -C option).
# $(1) - leading path to strip from files
NOTHING:=
SPACE:=$(NOTHING) $(NOTHING)
quiet_cmd_zip = ' ZIP $@'
cmd_zip = ( \
cd $(1) && \
zip -q $(subst $(SPACE),/,$(patsubst %,..,$(subst /, ,$(1))))/$@ \
$(patsubst $(1)/%,%,$^) )
# $@ - the archive file
# $^ - files to be added
# $(1) - leading path to strip from files
define do_zip
@$(do_mkdir)
@echo $(if $(quiet),$(quiet_cmd_zip),"$(call cmd_zip,$(1))")
@$(call cmd_zip,$(1))
endef
DEPFILES := \
$(wildcard $(BUILD_DIR)/*/.*.d $(BUILD_DIR)/*/*/.*.d)
ifneq ($(DEPFILES),)
-include $(DEPFILES)
endif
# --------------------------------------------------------------------------
# Build in separate directories for now to avoid problems with name/symbol
# clashes, etc. Qbsp may never be merged because we use doubles instead of
# floats everywhere to help with inprecisions.
# --------------------------------------------------------------------------
BUILD_DIRS = \
$(BUILD_DIR)/common \
$(BUILD_DIR)/qbsp \
$(BUILD_DIR)/light \
$(BUILD_DIR)/vis \
$(BUILD_DIR)/bspinfo \
$(BUILD_DIR)/bsputil \
$(BIN_DIR)
APPS = \
$(BIN_PFX)light$(EXT) \
$(BIN_PFX)vis$(EXT) \
$(BIN_PFX)bspinfo$(EXT) \
$(BIN_PFX)bsputil$(EXT) \
$(BIN_PFX)qbsp$(EXT)
all: $(patsubst %,$(BIN_DIR)/%,$(APPS))
COMMON_CPPFLAGS := -DTYRUTILS_VERSION=$(TYR_VERSION)
COMMON_CPPFLAGS += -I$(TOPDIR)/include -DLINUX $(DPTHREAD)
ifeq ($(DEBUG),Y)
COMMON_CPPFLAGS += -DDEBUG
else
COMMON_CPPFLAGS += -DNDEBUG
endif
# ----------------------------------------------------------------------------
# Build rule generation
# ----------------------------------------------------------------------------
# Because I want to do nasty things like build for multiple architectures
# with a single make invocation (and not resort to recursion) I generate the
# rules for building using defines.
# define rulesets for building object files
# $(1) - the build directory
# $(2) - CPPFLAGS
# $(3) - CFLAGS
define OBJECT_RULES
$(1)/qbsp/%.o: CPPFLAGS = $(2) -DDOUBLEVEC_T
$(1)/common/%.o: CPPFLAGS = $(2)
$(1)/light/%.o: CPPFLAGS = $(2)
$(1)/vis/%.o: CPPFLAGS = $(2)
$(1)/bspinfo/%.o: CPPFLAGS = $(2)
$(1)/bsputil/%.o: CPPFLAGS = $(2)
$(1)/common/%.o: CPPFLAGS = $(2)
$(1)/qbsp/%.o: CFLAGS += $(3)
$(1)/common/%.o: CFLAGS += $(3)
$(1)/light/%.o: CFLAGS += $(3)
$(1)/vis/%.o: CFLAGS += $(3)
$(1)/bspinfo/%.o: CFLAGS += $(3)
$(1)/bsputil/%.o: CFLAGS += $(3)
$(1)/common/%.o: CFLAGS += $(3)
$(1)/qbsp/%.o: qbsp/%.c ; $$(do_cc_o_c)
$(1)/common/%.o: common/%.c ; $$(do_cc_o_c)
$(1)/light/%.o: light/%.c ; $$(do_cc_o_c)
$(1)/vis/%.o: vis/%.c ; $$(do_cc_o_c)
$(1)/bspinfo/%.o: bspinfo/%.c ; $$(do_cc_o_c)
$(1)/bsputil/%.o: bsputil/%.c ; $$(do_cc_o_c)
endef
# Another level of indirection
# (mainly for consistency with TyrQuake build system...
# $(1) - build sub-directory
# $(2) - extra cflags for arch
define TARGET_RULES
$(eval $(call OBJECT_RULES,$$(BUILD_DIR)/$(1),$$(COMMON_CPPFLAGS),$(2)))
endef
# Standard build rules
$(eval $(call OBJECT_RULES,$$(BUILD_DIR),$$(COMMON_CPPFLAGS),))
# OSX building for two intel archs, two ppc archs
$(eval $(call TARGET_RULES,osx-intel-32,-arch i386 -mmacosx-version-min=10.5))
$(eval $(call TARGET_RULES,osx-intel-64,-arch x86_64 -mmacosx-version-min=10.5))
$(eval $(call TARGET_RULES,osx-ppc-32,-arch ppc))
$(eval $(call TARGET_RULES,osx-ppc-64,-arch ppc64))
# Win32 and Win64 builds ?? - cross compiler...
$(eval $(call TARGET_RULES,win32,))
$(eval $(call TARGET_RULES,win64,))
#########
# Light #
#########
LIGHT_OBJS = \
light/entities.o \
light/litfile.o \
light/ltface.o \
light/trace.o \
light/light.o \
common/bspfile.o \
common/cmdlib.o \
common/mathlib.o \
common/log.o \
common/threads.o
$(BIN_DIR)/$(BIN_PFX)light$(EXT): $(patsubst %,$(BUILD_DIR)/%,$(LIGHT_OBJS))
$(call do_cc_link,-lm $(LPTHREAD))
$(call do_strip,$@)
#######
# Vis #
#######
VIS_OBJS = \
vis/flow.o \
vis/vis.o \
vis/soundpvs.o \
vis/state.o \
common/cmdlib.o \
common/mathlib.o \
common/bspfile.o \
common/log.o \
common/threads.o
$(BIN_DIR)/$(BIN_PFX)vis$(EXT): $(patsubst %,$(BUILD_DIR)/%,$(VIS_OBJS))
$(call do_cc_link,-lm $(LPTHREAD))
$(call do_strip,$@)
###########
# BSPInfo #
###########
BSPINFO_OBJS = \
bspinfo/bspinfo.o \
common/cmdlib.o \
common/bspfile.o \
common/log.o \
common/threads.o
$(BIN_DIR)/$(BIN_PFX)bspinfo$(EXT): $(patsubst %,$(BUILD_DIR)/%,$(BSPINFO_OBJS))
$(call do_cc_link,-lm $(LPTHREAD))
$(call do_strip,$@)
###########
# BSPUtil #
###########
BSPUTIL_OBJS = \
bsputil/bsputil.o \
common/cmdlib.o \
common/bspfile.o \
common/log.o \
common/threads.o
$(BIN_DIR)/$(BIN_PFX)bsputil$(EXT): $(patsubst %,$(BUILD_DIR)/%,$(BSPUTIL_OBJS))
$(call do_cc_link,-lm $(LPTHREAD))
$(call do_strip,$@)
########
# Qbsp #
########
QBSP_OBJS = \
common/threads.o \
common/log.o \
qbsp/brush.o \
qbsp/bspfile.o \
qbsp/cmdlib.o \
qbsp/csg4.o \
qbsp/file.o \
qbsp/globals.o \
qbsp/map.o \
qbsp/mathlib.o \
qbsp/merge.o \
qbsp/outside.o \
qbsp/parser.o \
qbsp/portals.o \
qbsp/qbsp.o \
qbsp/solidbsp.o \
qbsp/surfaces.o \
qbsp/tjunc.o \
qbsp/util.o \
qbsp/wad.o \
qbsp/winding.o \
qbsp/writebsp.o
$(BIN_DIR)/$(BIN_PFX)qbsp$(EXT): $(patsubst %,$(BUILD_DIR)/%,$(QBSP_OBJS))
$(call do_cc_link,-lm $(LPTHREAD))
$(call do_strip,$@)
clean:
@rm -rf $(BUILD_DIR)
@rm -rf $(BIN_DIR)
@rm -rf $(DOC_DIR)
@rm -rf $(DIST_DIR)
@rm -f $(shell find . \( \
-name '*~' -o -name '#*#' -o -name '*.o' -o -name '*.res' \
\) -print)
# --------------------------------------------------------------------------
# Documentation
# --------------------------------------------------------------------------
# Build text and/or html docs from man page source
$(DOC_DIR)/%.1: man/%.1 $(BUILD_VER) ; $(do_man2man)
$(DOC_DIR)/%.txt: $(DOC_DIR)/%.1 ; $(do_man2txt)
$(DOC_DIR)/%.html: $(DOC_DIR)/%.1 ; $(do_man2html)
SRC_DOCS = qbsp.1 light.1 vis.1 bsputil.1 bspinfo.1
MAN_DOCS = $(patsubst %.1,$(DOC_DIR)/%.1,$(SRC_DOCS))
HTML_DOCS = $(patsubst %.1,$(DOC_DIR)/%.html,$(SRC_DOCS))
TEXT_DOCS = $(patsubst %.1,$(DOC_DIR)/%.txt,$(SRC_DOCS))
docs: $(MAN_DOCS) $(HTML_DOCS) $(TEXT_DOCS)
# --------------------------------------------------------------------------
# Release Management
# --------------------------------------------------------------------------
# DIST_FILES
# $(1) = distribution directory
DIST_FILES = \
$(patsubst %,$(1)/bin/%,$(APPS)) \
$(1)/README.txt \
$(1)/COPYING \
$(1)/changelog.txt \
$(patsubst %.1,$(1)/doc/%.1,$(SRC_DOCS)) \
$(patsubst %.1,$(1)/doc/%.txt,$(SRC_DOCS)) \
$(patsubst %.1,$(1)/doc/%.html,$(SRC_DOCS))
# ----------------------------------------------------------------------------
# OSX Packaging Tools
# ----------------------------------------------------------------------------
LIPO ?= lipo
quiet_cmd_lipo = ' LIPO $@'
cmd_lipo = lipo -create $^ -output $@
define do_lipo
$(do_mkdir)
@echo $($(quiet)cmd_lipo)
@$(cmd_lipo)
endef
# ----------------------------------------------------------------------------
# Packaging Rules
# ----------------------------------------------------------------------------
# OSX
OSX_DIR = $(DIST_DIR)/osx
# OSX arch binary rules
# $(1) = arch build dir
# $(2) = arch linker flags
define OSX_ARCH_BIN_RULES
$(1)/bin/$$(BIN_PFX)light$$(EXT): $$(patsubst %,$(1)/%,$$(LIGHT_OBJS))
$$(call do_cc_link,-lm $$(LPTHREAD) $(2))
$$(call do_strip,$$@)
$(1)/bin/$$(BIN_PFX)vis$$(EXT): $$(patsubst %,$(1)/%,$$(VIS_OBJS))
$$(call do_cc_link,-lm $$(LPTHREAD) $(2))
$$(call do_strip,$$@)
$(1)/bin/$$(BIN_PFX)bspinfo$$(EXT): $$(patsubst %,$(1)/%,$$(BSPINFO_OBJS))
$$(call do_cc_link,-lm $$(LPTHREAD) $(2))
$$(call do_strip,$$@)
$(1)/bin/$$(BIN_PFX)bsputil$$(EXT): $$(patsubst %,$(1)/%,$$(BSPUTIL_OBJS))
$$(call do_cc_link,-lm $$(LPTHREAD) $(2))
$$(call do_strip,$$@)
$(1)/bin/$$(BIN_PFX)qbsp$$(EXT): $$(patsubst %,$(1)/%,$$(QBSP_OBJS))
$$(call do_cc_link,-lm $$(LPTHREAD) $(2))
$$(call do_strip,$$@)
endef
$(eval $(call OSX_ARCH_BIN_RULES,$(BUILD_DIR)/osx-intel-32,-arch i386))
$(eval $(call OSX_ARCH_BIN_RULES,$(BUILD_DIR)/osx-intel-64,-arch x86_64))
$(eval $(call OSX_ARCH_BIN_RULES,$(BUILD_DIR)/osx-ppc-32,-arch ppc))
$(eval $(call OSX_ARCH_BIN_RULES,$(BUILD_DIR)/osx-ppc-64,-arch ppc64))
OSX_ARCHS :=
OSX_ARCHS += $(call if-cc-option,-arch i386,intel-32)
OSX_ARCHS += $(call if-cc-option,-arch x86_64,intel-64)
OSX_ARCHS += $(call if-cc-option,-arch ppc,ppc-32)
OSX_ARCHS += $(call if-cc-option,-arch ppc64,ppc-64)
# Combine the arch binaries with lipo
osx-arch-bins = $(foreach ARCH,$(OSX_ARCHS),$(BUILD_DIR)/osx-$(ARCH)/bin/$(1))
osx-fat-bin = $(OSX_DIR)/bin/$(1): $(call osx-arch-bins,$(1)) ; $$(do_lipo)
$(eval $(call osx-fat-bin,$(BIN_PFX)light$(EXT)))
$(eval $(call osx-fat-bin,$(BIN_PFX)vis$(EXT)))
$(eval $(call osx-fat-bin,$(BIN_PFX)bspinfo$(EXT)))
$(eval $(call osx-fat-bin,$(BIN_PFX)bsputil$(EXT)))
$(eval $(call osx-fat-bin,$(BIN_PFX)qbsp$(EXT)))
# Simple rules to copy distribution files
$(DIST_DIR)/osx/%.txt: %.txt ; $(do_cp)
$(DIST_DIR)/osx/doc/%.1: doc/%.1 ; $(do_cp)
$(DIST_DIR)/osx/doc/%.txt: doc/%.txt ; $(do_cp)
$(DIST_DIR)/osx/doc/%.html: doc/%.html ; $(do_cp)
$(DIST_DIR)/osx/COPYING: COPYING ; $(do_cp)
DIST_FILES_OSX = $(call DIST_FILES,$(OSX_DIR))
$(DIST_DIR)/tyrutils-$(TYR_VERSION_NUM)-osx.zip: $(DIST_FILES_OSX)
$(call do_zip,$(DIST_DIR)/osx)
# ----------------------------------------------------------------------------
# WIN32
WIN32_DIR = $(DIST_DIR)/win32
# Nothing too special required for the binaries...
$(BUILD_DIR)/win32/bin/$(BIN_PFX)light$(EXT): $(patsubst %,$(BUILD_DIR)/win32/%,$(LIGHT_OBJS))
$(call do_cc_link,-lm $(LPTHREAD))
$(call do_strip,$@)
$(BUILD_DIR)/win32/bin/$(BIN_PFX)vis$(EXT): $(patsubst %,$(BUILD_DIR)/win32/%,$(VIS_OBJS))
$(call do_cc_link,-lm $(LPTHREAD))
$(call do_strip,$@)
$(BUILD_DIR)/win32/bin/$(BIN_PFX)bspinfo$(EXT): $(patsubst %,$(BUILD_DIR)/win32/%,$(BSPINFO_OBJS))
$(call do_cc_link,-lm $(LPTHREAD))
$(call do_strip,$@)
$(BUILD_DIR)/win32/bin/$(BIN_PFX)bsputil$(EXT): $(patsubst %,$(BUILD_DIR)/win32/%,$(BSPUTIL_OBJS))
$(call do_cc_link,-lm $(LPTHREAD))
$(call do_strip,$@)
$(BUILD_DIR)/win32/bin/$(BIN_PFX)qbsp$(EXT): $(patsubst %,$(BUILD_DIR)/win32/%,$(QBSP_OBJS))
$(call do_cc_link,-lm $(LPTHREAD))
$(call do_strip,$@)
# Simple rules to copy distribution files
$(DIST_DIR)/win32/bin/%.exe: $(BUILD_DIR)/win32/bin/%.exe ; $(do_cp)
$(DIST_DIR)/win32/%.txt: %.txt ; $(do_cp)
$(DIST_DIR)/win32/doc/%.1: doc/%.1 ; $(do_cp)
$(DIST_DIR)/win32/doc/%.txt: doc/%.txt ; $(do_cp)
$(DIST_DIR)/win32/doc/%.html: doc/%.html ; $(do_cp)
$(DIST_DIR)/win32/COPYING: COPYING ; $(do_cp)
DIST_FILES_WIN32 = $(call DIST_FILES,$(WIN32_DIR))
$(DIST_DIR)/tyrutils-$(TYR_VERSION_NUM)-win32.zip: $(DIST_FILES_WIN32)
$(call do_zip,$(DIST_DIR)/win32)
# ----------------------------------------------------------------------------
# WIN64
WIN64_DIR = $(DIST_DIR)/win64
# Nothing too special required for the binaries...
$(BUILD_DIR)/win64/bin/$(BIN_PFX)light$(EXT): $(patsubst %,$(BUILD_DIR)/win64/%,$(LIGHT_OBJS))
$(call do_cc_link,-lm $(LPTHREAD))
$(call do_strip,$@)
$(BUILD_DIR)/win64/bin/$(BIN_PFX)vis$(EXT): $(patsubst %,$(BUILD_DIR)/win64/%,$(VIS_OBJS))
$(call do_cc_link,-lm $(LPTHREAD))
$(call do_strip,$@)
$(BUILD_DIR)/win64/bin/$(BIN_PFX)bspinfo$(EXT): $(patsubst %,$(BUILD_DIR)/win64/%,$(BSPINFO_OBJS))
$(call do_cc_link,-lm $(LPTHREAD))
$(call do_strip,$@)
$(BUILD_DIR)/win64/bin/$(BIN_PFX)bsputil$(EXT): $(patsubst %,$(BUILD_DIR)/win64/%,$(BSPUTIL_OBJS))
$(call do_cc_link,-lm $(LPTHREAD))
$(call do_strip,$@)
$(BUILD_DIR)/win64/bin/$(BIN_PFX)qbsp$(EXT): $(patsubst %,$(BUILD_DIR)/win64/%,$(QBSP_OBJS))
$(call do_cc_link,-lm $(LPTHREAD))
$(call do_strip,$@)
# Simple rules to copy distribution files
$(DIST_DIR)/win64/bin/%.exe: $(BUILD_DIR)/win64/bin/%.exe ; $(do_cp)
$(DIST_DIR)/win64/%.txt: %.txt ; $(do_cp)
$(DIST_DIR)/win64/doc/%.1: doc/%.1 ; $(do_cp)
$(DIST_DIR)/win64/doc/%.txt: doc/%.txt ; $(do_cp)
$(DIST_DIR)/win64/doc/%.html: doc/%.html ; $(do_cp)
$(DIST_DIR)/win64/COPYING: COPYING ; $(do_cp)
DIST_FILES_WIN64 = $(call DIST_FILES,$(WIN64_DIR))
$(DIST_DIR)/tyrutils-$(TYR_VERSION_NUM)-win64.zip: $(DIST_FILES_WIN64)
$(call do_zip,$(DIST_DIR)/win64)
# ----------------------------------------------------------------------------
# Source tarball creation
quiet_cmd_git_archive = ' GIT-ARCV $@'
cmd_git_archive = \
git archive --format=tar --prefix=tyrutils-$(TYR_VERSION_NUM)/ HEAD \
> $(@D)/.$(@F).tmp && \
mv $(@D)/.$(@F).tmp $@
define do_git_archive
$(do_mkdir)
@echo $(if $(quiet),$(quiet_cmd_git_archive),"$(cmd_git_archive)");
@$(cmd_git_archive)
endef
$(DIST_DIR)/tyrutils-$(TYR_VERSION_NUM).tar:
$(do_git_archive)
quiet_cmd_gzip = ' GZIP $@'
cmd_gzip = gzip -S .gz $<
define do_gzip
$(do_mkdir)
@echo $($(quiet)cmd_gzip)
@$(cmd_gzip)
endef
%.gz: %
$(do_gzip)
# ----------------------------------------------------------------------------
.PHONY: snapshot tarball
tarball: $(DIST_DIR)/tyrutils-$(TYR_VERSION_NUM).tar.gz
snapshot: $(SNAPSHOT_TARGET)