File: Makefile

package info (click to toggle)
uhexen2 1.5.6+dfsg-1
  • links: PTS
  • area: contrib
  • in suites: jessie, jessie-kfreebsd
  • size: 16,340 kB
  • ctags: 23,477
  • sloc: ansic: 188,956; asm: 14,958; makefile: 3,475; sh: 3,325; objc: 330; pascal: 213; cpp: 19
file content (1125 lines) | stat: -rw-r--r-- 26,532 bytes parent folder | download
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
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
# GNU Makefile for hexenworld clients using GCC.
# $Id: Makefile 5162 2013-03-06 09:21:08Z sezero $
#
# Remember to "make clean" between different types of builds or targets.
# Unix platforms require SDL !!!
#
# To cross-compile for Win32 on Unix: either pass the W32BUILD=1
# argument to make, or export it.  Also see build_cross_win32.sh.
# Requires: a mingw or mingw-w64 compiler toolchain.
#
# To cross-compile for Win64 on Unix: either pass the W64BUILD=1
# argument to make, or export it. Also see build_cross_win64.sh.
# Requires: a mingw-w64 compiler toolchain.
#
# To cross-compile for MacOSX on Unix: either pass the OSXBUILD=1
# argument to make, or export it.  You would also need to pass a
# suitable MACH_TYPE=xxx (ppc, x86, x86_64, or ppc64) argument to
# make. Also see build_cross_osx.sh.
#
# To (cross-)compile for DOS: either pass the DOSBUILD=1 argument
# to make, or export it. Also see build_cross_dos.sh. Requires: a
# djgpp compiler toolchain.
#
# To see valid targets:			make help
#
# To use a compiler other than gcc:	make CC=compiler_name [other stuff]
#
# To use a different nasm-compatible assembler, such as yasm:
#					make NASM=yasm [other stuff]
#
# To specify X installation at somewhere other than /usr/X11R6
# such as /usr/X11R7 :			make X11BASE=/your/x11/path [other stuff]
#
# To build for the demo version:	make DEMO=1 [other stuff]
#
# To build a debug version:		make DEBUG=1 [other stuff]
#

# PATH SETTINGS:
UHEXEN2_TOP:=../../..
ENGINE_TOP:=../..
HW_TOP:=..
COMMONDIR:=$(ENGINE_TOP)/h2shared
COMMON_HW:=$(HW_TOP)/shared
UHEXEN2_SHARED:=$(UHEXEN2_TOP)/common
LIBS_DIR:=$(UHEXEN2_TOP)/libs
OSLIBS:=$(UHEXEN2_TOP)/oslibs

# GENERAL OPTIONS (customize as required)

# X directory
X11BASE    =/usr/X11R6
# the sdl-config command
SDL_CONFIG =sdl-config
SDL_CFLAGS = $(shell $(SDL_CONFIG) --cflags 2> /dev/null)
SDL_LIBS   = $(shell $(SDL_CONFIG) --libs 2> /dev/null)

# compile only as a 32 bit binary even on a 64 bit platform?
COMPILE_32BITS=no

# use fast x86 assembly on ia32 machines? (auto-disabled for
# any other cpu.)
USE_X86_ASM=yes

# link to the opengl libraries at compile time? (defaults
# to no, so the binaries will dynamically load the necessary
# libraries and functions at runtime.)
LINK_GL_LIBS=no

# enable evil 3dfx glide hacks for native hardware gamma for
# the old Voodoo Graphics and Voodoo2 cards?  (Linux/FreeBSD)
USE_3DFXGAMMA=no

# enable sound support?
USE_SOUND=yes
# ALSA audio support? (req: alsa-lib and alsa-kernel modules
# >= 1.0.1.  v0.9.8 and v1.0.0 might work, but not supported.
# If not Linux, ALSA will be automatically be disabled.)
USE_ALSA=yes
# OSS audio support? (for Unix. enabled on Linux and FreeBSD.
# automatically disabled on other platforms: see snd_sys.h)
USE_OSS=yes
# SUN audio support? (enabled on OpenBSD, NetBSD and SUN.
# automatically disabled on others: see snd_sys.h)
USE_SUNAUDIO=yes
# SDL audio support? (enabled on all unix-like platforms.)
USE_SDLAUDIO=yes

# include target's MIDI driver if available?
USE_MIDI=yes

# CDAudio support?
USE_CDAUDIO=yes
# use SDL cdaudio? (otherwise platform specific cdrom code will
# be used.  The only problem with SDL_cdrom is that it lacks
# proper volume controls.  See cd_unix.h for the availability of
# platform specific cdaudio drivers.
# NOTE: SDL dropped cdaudio support in version 1.3.0 and later!)
USE_SDLCD=no

# link to the directx libraries at compile time? (otherwise, link
# to the dynamically load the necessary dll files and functions at
# runtime which ensures our exe to run on ancient windows versions
# without a directx installation.)
LINK_DIRECTX=no

# enable startup splash screens? (windows)
WITH_SPLASHES=yes

# use SciTech MGL for Win32 software video driver? (Default to yes
# for x86, auto-disabled for Win64.  if disabled, the DIB/GDI-only
# compatibility software video driver will be used.)
USE_MGL=yes

# use WinSock2 instead of WinSock-1.1? (disabled for w32 for compat.
# with old Win95 machines.) (enabled for Win64 in the win64 section.)
USE_WINSOCK2=no

# Enable/disable codecs for streaming music support:
USE_CODEC_WAVE=yes
USE_CODEC_MP3=yes
USE_CODEC_VORBIS=yes
USE_CODEC_OPUS=no
# either timidity or wildmidi (both possible
# but not needed nor meaningful)
USE_CODEC_TIMIDITY=yes
USE_CODEC_WILDMIDI=no
# compile timidity with DLS instruments support? (no:
# the dls code isn't good enough and isn't used in unix
# where timidity is normally needed, either.)
TIMIDITY_USE_DLS=no
# which library to use for mp3 decoding: mad or mpg123
MP3LIB=mad
# which library to use for ogg decoding: vorbis or tremor
VORBISLIB=vorbis
# whether the codecs allocate on the zone instead of
# system memory (set to yes for DOS builds, for example)
CODECS_USE_ZONE=no

# include the common dirty stuff
include $(UHEXEN2_TOP)/scripts/makefile.inc

# Names of the binaries
SW_BINARY:=hwcl$(exe_ext)
GL_BINARY:=glhwcl$(exe_ext)

#############################################################
# Compiler flags
#############################################################

ifeq ($(MACH_TYPE),x86)
CPU_X86=-march=i586
endif
# Overrides for the default CPUFLAGS
CPUFLAGS=$(CPU_X86)

CFLAGS += -g -Wall
CFLAGS += $(CPUFLAGS)
ifndef DEBUG
# optimization flags
CFLAGS += -O2 -DNDEBUG=1 -ffast-math -fomit-frame-pointer
endif

CPPFLAGS +=
LDFLAGS +=

# compiler includes
INCLUDES= -I. -I$(COMMON_HW) -I$(COMMONDIR) -I$(UHEXEN2_SHARED)
# nasm includes: the trailing directory separator matters
NASM_INC= -I./ -I$(COMMON_HW)/ -I$(COMMONDIR)/
# windows resource compiler includes
RES_INC = -I. -I$(COMMON_HW) -I$(COMMONDIR)

ifeq ($(COMPILE_32BITS),yes)
CFLAGS += -m32
LDFLAGS+= -m32
endif

# end of compiler flags
#############################################################


#############################################################
# Other build flags
#############################################################
CPPFLAGS+= -DH2W

# disable x86 assembly if it is not an x86.
ifneq ($(MACH_TYPE),x86)
ifeq ($(MACH_TYPE),x86_64)
#  but keep the ia32 assembly on x86_64 if
#  compiling as 32 bits for the s/w renderer
ifneq ($(COMPILE_32BITS),yes)
USE_X86_ASM=no
endif
else
USE_X86_ASM=no
endif
endif

ifdef DEMO
CPPFLAGS+= -DDEMOBUILD
endif

ifdef DEBUG
# This activates some extra code in hexen2/hexenworld C source
CPPFLAGS+= -DDEBUG=1 -DDEBUG_BUILD=1
endif


#############################################################
# OpenGL settings
#############################################################
GL_DEFS = -DGLQUAKE
GL_LIBS =

#############################################################
# streaming music initial setup
#############################################################
ifneq ($(USE_SOUND),yes)
USE_CODEC_WAVE=no
USE_CODEC_TIMIDITY=no
USE_CODEC_WILDMIDI=no
USE_CODEC_MP3=no
USE_CODEC_VORBIS=no
USE_CODEC_OPUS=no
endif
# sanity checking for decoder library options
ifneq ($(VORBISLIB),vorbis)
ifneq ($(VORBISLIB),tremor)
$(error Invalid VORBISLIB setting)
endif
endif
ifneq ($(MP3LIB),mpg123)
ifneq ($(MP3LIB),mad)
$(error Invalid MP3LIB setting)
endif
endif


#############################################################
# Mac OS X flags/settings and overrides:
#############################################################
ifeq ($(TARGET_OS),darwin)

NASMFLAGS=-f macho
CPUFLAGS=
ifeq ($(MACH_TYPE),x86)
# x86 requires 10.4. gcc adds the 10.4 flag by itself.
endif
ifeq ($(MACH_TYPE),ppc)
# require 10.2 for ppc builds (midi_osx.c requirement.)
CFLAGS  +=-mmacosx-version-min=10.2
LDFLAGS +=-mmacosx-version-min=10.2
endif
ifeq ($(MACH_TYPE),ppc64)
# require 10.5 for ppc64 (actually SDL doesn't support ppc64.)
CFLAGS  +=-mmacosx-version-min=10.5
LDFLAGS +=-mmacosx-version-min=10.5
endif
ifeq ($(MACH_TYPE),x86_64)
# require 10.6 for amd64 builds (not 10.5: SDL's requirement.)
# bundle1.o is needed for dyld_stub_binding_helper
CFLAGS  +=-mmacosx-version-min=10.6
LDFLAGS +=-mmacosx-version-min=10.6 -Wl,-lbundle1.o
endif

# no need for timidity, we have a midi driver
USE_CODEC_TIMIDITY=no
USE_CODEC_WILDMIDI=no
ifeq ($(USE_MIDI),yes)
# note: midi_mac.c requires -Wl,-framework,QuickTime which we are not using anymore.
LDFLAGS += -Wl,-framework,AudioToolbox -Wl,-framework,AudioUnit -Wl,-framework,CoreServices
endif

ifeq ($(USE_SOUND),yes)
ifneq ($(USE_SDLAUDIO),yes)
CPPFLAGS+= -DNO_SDL_AUDIO
endif
endif

USE_SDLCD=yes
ifeq ($(USE_CDAUDIO),yes)
ifeq ($(USE_SDLCD),yes)
CPPFLAGS+= -DWITH_SDLCD
endif
endif

# Unix builds rely on SDL:
# SDLQUAKE must be defined for all SDL using platforms/targets
CPPFLAGS+= -DSDLQUAKE
# not relying on sdl-config command and assuming
# /Library/Frameworks/SDL.framework is available
SDL_CFLAGS =-D_GNU_SOURCE=1 -D_THREAD_SAFE
SDL_CFLAGS+=-DSDL_FRAMEWORK -DNO_SDL_CONFIG
SDL_LIBS   =-Wl,-framework,SDL -Wl,-framework,Cocoa
CFLAGS  += $(SDL_CFLAGS)
LDFLAGS += $(SDL_LIBS)

GL_LINK=-Wl,-framework,OpenGL

ifeq ($(USE_CODEC_VORBIS),yes)
CODEC_INC = -I$(OSLIBS)/macosx/codecs/include
CODEC_LINK= -L$(OSLIBS)/macosx/codecs/lib
endif
ifeq ($(USE_CODEC_MP3),yes)
CODEC_INC = -I$(OSLIBS)/macosx/codecs/include
CODEC_LINK= -L$(OSLIBS)/macosx/codecs/lib
endif
ifeq ($(USE_CODEC_OPUS),yes)
CODEC_INC = -I$(OSLIBS)/macosx/codecs/include
CODEC_LINK= -L$(OSLIBS)/macosx/codecs/lib
endif
INCLUDES += $(CODEC_INC)
LDFLAGS += $(CODEC_LINK)

endif
# End of Mac OS X settings
#############################################################


#############################################################
# Unix flags/settings and overrides:
#############################################################
ifeq ($(TARGET_OS),unix)
# common unix:

NASMFLAGS=-f elf -d_NO_PREFIX

ifneq ($(X11BASE),)
INCLUDES+= -I$(X11BASE)/include
endif
ifeq ($(HOST_OS),qnx)
LDFLAGS += -lsocket
endif
ifeq ($(HOST_OS),sunos)
LDFLAGS += -lsocket -lnsl -lresolv
endif
LDFLAGS += -lm

ifneq ($(X11BASE),)
GL_LINK=-L$(X11BASE)/lib -lGL
else
GL_LINK=-lGL
endif

ifeq ($(USE_SOUND),yes)
ifneq ($(HOST_OS),linux)
# alsa is only for linux
USE_ALSA=no
endif
ifneq ($(USE_ALSA),yes)
CPPFLAGS+= -DNO_ALSA_AUDIO
else
# snd_alsa uses dlopen() & co.
LDFLAGS += -ldl
endif
ifneq ($(USE_OSS),yes)
CPPFLAGS+= -DNO_OSS_AUDIO
endif
ifneq ($(USE_SUNAUDIO),yes)
CPPFLAGS+= -DNO_SUN_AUDIO
endif
ifneq ($(USE_SDLAUDIO),yes)
CPPFLAGS+= -DNO_SDL_AUDIO
endif
endif

ifeq ($(USE_CDAUDIO),yes)
ifeq ($(USE_SDLCD),yes)
CPPFLAGS+= -DWITH_SDLCD
endif
endif

# Unix builds rely on SDL:
# SDLQUAKE must be defined for all SDL using platforms/targets
CPPFLAGS+= -DSDLQUAKE
CFLAGS  += $(SDL_CFLAGS)
LDFLAGS += $(SDL_LIBS)

ifeq ($(USE_CODEC_OPUS),yes)
# opus and opusfile put their *.h under <includedir>/opus,
# but they include the headers without the opus directory
# prefix and rely on pkg-config. ewww...
INCLUDES+= $(shell pkg-config --cflags opusfile)
LDFLAGS += $(shell pkg-config --libs   opusfile)
endif

endif
# End of Unix settings
#############################################################


#############################################################
# DOS flags/settings and overrides:
#############################################################
ifeq ($(TARGET_OS),dos)

NASMFLAGS=-f coff
# Use x86 assembly for DOS
USE_X86_ASM=yes

USE_CODEC_TIMIDITY=no
USE_CODEC_WILDMIDI=no
# no need for Opus or DOS
USE_CODEC_OPUS=no
# use Tremor as Vorbis decoder for DOS?
VORBISLIB=tremor
# make DOS decoders allocate on the zone
CODECS_USE_ZONE=yes

INCLUDES += -I$(OSLIBS)/dos
# WATT-32 is needed for DOS
CPPFLAGS+= -DUSE_WATT32
INCLUDES+= -I$(OSLIBS)/dos/watt32/inc
LDFLAGS += -L$(OSLIBS)/dos/watt32/lib -lwatt
LDFLAGS += -lc -lgcc -lm

ifeq ($(USE_CODEC_VORBIS),yes)
CODEC_INC = -I$(OSLIBS)/dos/codecs/include
CODEC_LINK= -L$(OSLIBS)/dos/codecs/lib
endif
ifeq ($(USE_CODEC_MP3),yes)
CODEC_INC = -I$(OSLIBS)/dos/codecs/include
CODEC_LINK= -L$(OSLIBS)/dos/codecs/lib
endif
ifeq ($(USE_CODEC_OPUS),yes)
CODEC_INC = -I$(OSLIBS)/dos/codecs/include
CODEC_LINK= -L$(OSLIBS)/dos/codecs/lib
endif
INCLUDES += $(CODEC_INC)
LDFLAGS += $(CODEC_LINK)

endif
# End of DOS settings
#############################################################


#############################################################
# Win32 flags/settings and overrides:
#############################################################
ifeq ($(TARGET_OS),win32)

NASMFLAGS=-f win32
GL_LINK=-lopengl32

# timidity not needed, we have a midi driver. if you want it,
# comment out the following
USE_CODEC_TIMIDITY=no
USE_CODEC_WILDMIDI=no

ifeq ($(USE_WINSOCK2),yes)
CPPFLAGS+= -D_USE_WINSOCK2
LIBWINSOCK=-lws2_32
else
LIBWINSOCK=-lwsock32
endif

CPPFLAGS+= -DWIN32_LEAN_AND_MEAN
INCLUDES+= -I$(OSLIBS)/windows -I$(OSLIBS)/windows/dxsdk/include
LDFLAGS += $(LIBWINSOCK) -lwinmm -mwindows

ifneq ($(LINK_DIRECTX),yes)
CPPFLAGS+= -DDX_DLSYM
else
LDFLAGS += -L$(OSLIBS)/windows/dxsdk/x86 -ldsound -ldinput -ldxguid
endif

ifneq ($(WITH_SPLASHES),yes)
CPPFLAGS+= -DNO_SPLASHES
endif

ifeq ($(USE_CODEC_VORBIS),yes)
CODEC_INC = -I$(OSLIBS)/windows/codecs/include
CODEC_LINK= -L$(OSLIBS)/windows/codecs/x86
endif
ifeq ($(USE_CODEC_MP3),yes)
CODEC_INC = -I$(OSLIBS)/windows/codecs/include
CODEC_LINK= -L$(OSLIBS)/windows/codecs/x86
endif
ifeq ($(USE_CODEC_OPUS),yes)
CODEC_INC = -I$(OSLIBS)/windows/codecs/include
CODEC_LINK= -L$(OSLIBS)/windows/codecs/x86
endif
INCLUDES += $(CODEC_INC)
LDFLAGS += $(CODEC_LINK)

endif
# End of Win32 settings
#############################################################


#############################################################
# Win64 flags/settings and overrides:
#############################################################
ifeq ($(TARGET_OS),win64)

NASMFLAGS=-f win64 -d_NO_PREFIX
GL_LINK=-lopengl32

# timidity not needed, we have a midi driver. if you want it,
# comment out the following
USE_CODEC_TIMIDITY=no
USE_CODEC_WILDMIDI=no

# cant use MGL for Win64
USE_MGL=no
# use winsock2 for win64
USE_WINSOCK2=yes

ifeq ($(USE_WINSOCK2),yes)
CPPFLAGS+= -D_USE_WINSOCK2
LIBWINSOCK=-lws2_32
else
LIBWINSOCK=-lwsock32
endif

CPPFLAGS+= -DWIN32_LEAN_AND_MEAN
INCLUDES+= -I$(OSLIBS)/windows -I$(OSLIBS)/windows/dxsdk/include
LDFLAGS += $(LIBWINSOCK) -lwinmm -mwindows

ifneq ($(LINK_DIRECTX),yes)
CPPFLAGS+= -DDX_DLSYM
else
LDFLAGS += -L$(OSLIBS)/windows/dxsdk/x64 -ldsound -ldinput -ldxguid
endif

ifneq ($(WITH_SPLASHES),yes)
CPPFLAGS+= -DNO_SPLASHES
endif

ifeq ($(USE_CODEC_VORBIS),yes)
CODEC_INC = -I$(OSLIBS)/windows/codecs/include
CODEC_LINK= -L$(OSLIBS)/windows/codecs/x64
endif
ifeq ($(USE_CODEC_MP3),yes)
CODEC_INC = -I$(OSLIBS)/windows/codecs/include
CODEC_LINK= -L$(OSLIBS)/windows/codecs/x64
endif
ifeq ($(USE_CODEC_OPUS),yes)
CODEC_INC = -I$(OSLIBS)/windows/codecs/include
CODEC_LINK= -L$(OSLIBS)/windows/codecs/x64
endif
INCLUDES += $(CODEC_INC)
LDFLAGS += $(CODEC_LINK)

endif
# End of Win64 settings
#############################################################


#############################################################
# MorphOS flags/settings and overrides:
#############################################################
ifeq ($(TARGET_OS),morphos)

# MorphOS builds can use SDL or native code
USE_SDL=no
ifneq ($(USE_SDL),yes)
USE_SDLCD=no
USE_SDLAUDIO=no
# no native cdaudio code yet
USE_CDAUDIO=no
endif

CFLAGS  += -noixemul
LDFLAGS += -noixemul
LDFLAGS += -lm

GL_LINK=-lGL
# dynamic loading of ogl functions doesn't work
LINK_GL_LIBS=yes

USE_CODEC_VORBIS=yes
USE_CODEC_MP3=no
USE_CODEC_OPUS=no

ifeq ($(USE_SOUND),yes)
ifneq ($(USE_SDLAUDIO),yes)
CPPFLAGS+= -DNO_SDL_AUDIO
endif
endif

ifeq ($(USE_CDAUDIO),yes)
ifeq ($(USE_SDLCD),yes)
CPPFLAGS+= -DWITH_SDLCD
endif
endif

ifeq ($(USE_SDL),yes)
# SDLQUAKE must be defined for all SDL using platforms/targets
CPPFLAGS+= -DSDLQUAKE
CFLAGS  += $(SDL_CFLAGS)
LDFLAGS += $(SDL_LIBS)
endif

endif
# End of MorphOS settings
#############################################################


#############################################################
# AROS flags/settings and overrides:
#############################################################
ifeq ($(TARGET_OS),aros)

# AROS builds can use SDL or native code
USE_SDL=no
ifneq ($(USE_SDL),yes)
USE_SDLCD=no
USE_SDLAUDIO=no
# no native cdaudio code yet
USE_CDAUDIO=no
# native ogl code need this:
LINK_GL_LIBS=yes
endif

# Don't use x86 assembly for AROS
USE_X86_ASM=no

GL_LINK=-lGL

# both WildMidi and the local timidity work nice on AROS
USE_CODEC_WILDMIDI=no
USE_CODEC_TIMIDITY=yes

ifeq ($(USE_SOUND),yes)
ifneq ($(USE_SDLAUDIO),yes)
CPPFLAGS+= -DNO_SDL_AUDIO
endif
endif

ifeq ($(USE_CDAUDIO),yes)
ifeq ($(USE_SDLCD),yes)
CPPFLAGS+= -DWITH_SDLCD
endif
endif

ifeq ($(USE_SDL),yes)
# SDLQUAKE must be defined for all SDL using platforms/targets
CPPFLAGS+= -DSDLQUAKE
CFLAGS  += $(SDL_CFLAGS)
LDFLAGS += $(SDL_LIBS)
endif

endif
# End of AROS settings
#############################################################


#############################################################
# Streaming music settings
#############################################################
ifeq ($(MP3LIB),mad)
mp3_obj=snd_mp3.o
lib_mp3dec=-lmad
endif
ifeq ($(MP3LIB),mpg123)
mp3_obj=snd_mpg123.o
lib_mp3dec=-lmpg123
endif
ifeq ($(VORBISLIB),vorbis)
cpp_vorbisdec=
ifneq ($(TARGET_OS),morphos)
lib_vorbisdec=-lvorbisfile -lvorbis -logg
endif
endif
ifeq ($(VORBISLIB),tremor)
cpp_vorbisdec=-DVORBIS_USE_TREMOR
lib_vorbisdec=-lvorbisidec -logg
endif

ifeq ($(USE_CODEC_WAVE),yes)
CPPFLAGS+= -DUSE_CODEC_WAVE
endif
ifeq ($(USE_CODEC_OPUS),yes)
CPPFLAGS+= -DUSE_CODEC_OPUS
ifneq ($(TARGET_OS),unix)
# we use pkg-config on unix
LDFLAGS+= -lopusfile -lopus -logg
endif
endif
ifeq ($(USE_CODEC_VORBIS),yes)
CPPFLAGS+= -DUSE_CODEC_VORBIS $(cpp_vorbisdec)
LDFLAGS+= $(lib_vorbisdec)
endif
ifeq ($(USE_CODEC_MP3),yes)
CPPFLAGS+= -DUSE_CODEC_MP3
LDFLAGS+= $(lib_mp3dec)
endif
ifeq ($(USE_CODEC_TIMIDITY),yes)
CPPFLAGS+= -DUSE_CODEC_TIMIDITY
ifeq ($(TIMIDITY_USE_DLS),yes)
CPPFLAGS+= -DTIMIDITY_USE_DLS
endif
LDFLAGS+= -L$(LIBS_DIR)/timidity -ltimidity
TIMIDEPS=$(LIBS_DIR)/timidity/libtimidity.a
else
TIMIDEPS=
endif
ifeq ($(USE_CODEC_WILDMIDI),yes)
CPPFLAGS+= -DUSE_CODEC_WILDMIDI
LDFLAGS+= -lWildMidi
endif

ifeq ($(CODECS_USE_ZONE),yes)
CPPFLAGS+=-DCODECS_USE_ZONE
endif

# End of streaming music settings
#############################################################

#############################################################
# Finalize things after the system specific overrides:
#############################################################

ifeq ($(USE_X86_ASM),yes)
CPPFLAGS+= -DUSE_INTEL_ASM
endif

ifeq ($(USE_3DFXGAMMA),yes)
# linux 3dfx gamma evil hack
GL_DEFS+= -DUSE_3DFXGAMMA
endif
ifneq ($(LINK_GL_LIBS),yes)
GL_DEFS+= -DGL_DLSYM
else
GL_LIBS+= $(GL_LINK)
endif
#
#############################################################


# Rules for turning source files into .o files
%.o: %.c
	$(CC) -c $(INCLUDES) $(CPPFLAGS) $(CFLAGS) -o $@ $<
%.o: $(COMMON_HW)/%.c
	$(CC) -c $(INCLUDES) $(CPPFLAGS) $(CFLAGS) -o $@ $<
%.o: $(COMMONDIR)/%.c
	$(CC) -c $(INCLUDES) $(CPPFLAGS) $(CFLAGS) -o $@ $<
%.o: $(UHEXEN2_SHARED)/%.c
	$(CC) -c $(INCLUDES) $(CPPFLAGS) $(CFLAGS) -o $@ $<
%.o: %.m
	$(CC) -c $(INCLUDES) $(CPPFLAGS) $(CFLAGS) -o $@ $<
%.o: $(COMMONDIR)/%.m
	$(CC) -c $(INCLUDES) $(CPPFLAGS) $(CFLAGS) -o $@ $<
%.o: $(UHEXEN2_SHARED)/%.m
	$(CC) -c $(INCLUDES) $(CPPFLAGS) $(CFLAGS) -o $@ $<
%.o: %.asm
	$(NASM) $(NASM_INC) $(NASMFLAGS) -o $@ $<
%.o: $(COMMON_HW)/%.asm
	$(NASM) $(NASM_INC) $(NASMFLAGS) -o $@ $<
%.o: $(COMMONDIR)/%.asm
	$(NASM) $(NASM_INC) $(NASMFLAGS) -o $@ $<
%.res: %.rc
	$(WINDRES) $(RES_INC) $(CPPFLAGS) --output-format=coff -o $@ $<
%.res: $(COMMON_HW)/%.rc
	$(WINDRES) $(RES_INC) $(CPPFLAGS) --output-format=coff -o $@ $<
%.res: $(COMMONDIR)/%.rc
	$(WINDRES) $(RES_INC) $(CPPFLAGS) --output-format=coff -o $@ $<

# Objects

# Intel asm objects
ifeq ($(USE_X86_ASM),yes)
COMMON_ASM= math.o \
	sys_ia32.o

SOFT_ASM = \
	d_draw.o \
	d_draw16.o \
	d_draw16t.o \
	d_parta.o \
	d_partb.o \
	d_polysa.o \
	d_polysa2.o \
	d_polysa3.o \
	d_polysa4.o \
	d_polysa5.o \
	d_scana.o \
	d_spr8.o \
	d_spr8t.o \
	d_spr8t2.o \
	d_varsa.o \
	r_aclipa.o \
	r_aliasa.o \
	r_drawa.o \
	r_edgea.o \
	r_edgeb.o \
	r_varsa.o \
	surf8.o \
	surf16.o

SOUND_ASM = snd_mixa.o

else

SOFT_ASM =
COMMON_ASM =
SOUND_ASM =

endif

# Sound objects
ifneq ($(USE_SOUND),yes)
MUSIC_OBJS:= bgmnull.o
SOUND_ASM :=
CPPFLAGS += -D_NO_SOUND
SYSOBJ_SND :=
COMOBJ_SND := snd_null.o $(MUSIC_OBJS)
else
MUSIC_OBJS:= bgmusic.o \
	snd_codec.o \
	snd_wave.o \
	snd_vorbis.o \
	snd_opus.o \
	$(mp3_obj) \
	snd_timidity.o \
	snd_wildmidi.o
COMOBJ_SND := snd_sys.o snd_dma.o snd_mix.o $(SOUND_ASM) snd_mem.o $(MUSIC_OBJS)
ifeq ($(TARGET_OS),win32)
SYSOBJ_SND := snd_win.o snd_dsound.o
endif
ifeq ($(TARGET_OS),win64)
SYSOBJ_SND := snd_win.o snd_dsound.o
endif
ifeq ($(TARGET_OS),dos)
SYSOBJ_SND := snd_sb.o snd_gus.o
endif
ifeq ($(TARGET_OS),unix)
SYSOBJ_SND := snd_oss.o snd_alsa.o snd_sun.o snd_sdl.o
endif
ifeq ($(TARGET_OS),darwin)
SYSOBJ_SND := snd_sdl.o
endif
ifeq ($(TARGET_OS),aros)
SYSOBJ_SND := snd_ahi.o snd_sdl.o
endif
ifeq ($(TARGET_OS),morphos)
SYSOBJ_SND := snd_ahi.o snd_sdl.o
endif
# end of Sound objects
endif

# MIDI objects
ifneq ($(USE_MIDI),yes)
SYSOBJ_MIDI:= midi_nul.o
CPPFLAGS += -D_NO_MIDIDRV
else
ifeq ($(TARGET_OS),win32)
SYSOBJ_MIDI:= midi_win.o mid2strm.o
endif
ifeq ($(TARGET_OS),win64)
SYSOBJ_MIDI:= midi_win.o mid2strm.o
endif
ifeq ($(TARGET_OS),dos)
SYSOBJ_MIDI:= midi_nul.o
CPPFLAGS += -D_NO_MIDIDRV
endif
ifeq ($(TARGET_OS),unix)
SYSOBJ_MIDI:= midi_nul.o
CPPFLAGS += -D_NO_MIDIDRV
endif
ifeq ($(TARGET_OS),darwin)
# not using midi_mac.c
SYSOBJ_MIDI:= midi_osx.o
endif
ifeq ($(TARGET_OS),aros)
SYSOBJ_MIDI:= midi_nul.o
CPPFLAGS += -D_NO_MIDIDRV
endif
ifeq ($(TARGET_OS),morphos)
SYSOBJ_MIDI:= midi_nul.o
CPPFLAGS += -D_NO_MIDIDRV
endif
# end of MIDI objects
endif

# CDAudio objects
ifneq ($(USE_CDAUDIO),yes)
SYSOBJ_CDA:= cd_null.o
CPPFLAGS += -D_NO_CDAUDIO
else
ifeq ($(TARGET_OS),win32)
SYSOBJ_CDA := cd_win.o
endif
ifeq ($(TARGET_OS),win64)
SYSOBJ_CDA := cd_win.o
endif
ifeq ($(TARGET_OS),dos)
SYSOBJ_CDA := cd_dos.o
endif
ifeq ($(TARGET_OS),unix)
SYSOBJ_CDA := cd_sdl.o cd_bsd.o cd_linux.o
endif
ifeq ($(TARGET_OS),darwin)
SYSOBJ_CDA := cd_sdl.o
endif
ifeq ($(TARGET_OS),aros)
SYSOBJ_CDA := cd_sdl.o
endif
ifeq ($(TARGET_OS),morphos)
SYSOBJ_CDA := cd_sdl.o
endif
# end of CDAudio objects
endif

# Other platform specific object settings
ifeq ($(TARGET_OS),win32)
SYSOBJ_INPUT := in_win.o
SYSOBJ_GL_VID:= gl_vidnt.o
ifeq ($(USE_MGL),yes)
SYSOBJ_SOFT_VID:= vid_mgl4.o
else
SYSOBJ_SOFT_VID:= vid_win.o
endif
SYSOBJ_SYS := sys_win.o win32res.res
endif
ifeq ($(TARGET_OS),win64)
SYSOBJ_INPUT := in_win.o
SYSOBJ_GL_VID:= gl_vidnt.o
SYSOBJ_SOFT_VID:= vid_win.o
SYSOBJ_SYS := sys_win.o win32res.res
endif
ifeq ($(TARGET_OS),dos)
SYSOBJ_INPUT := in_dos.o
SYSOBJ_SOFT_VID:= vid_vga.o vid_ext.o vid_dos.o vregset.o
ifeq ($(USE_X86_ASM),yes)
SYSOBJ_SOFT_VID+= d_copy.o
endif
SYSOBJ_SYS := dos_v2.o sys_dos.o
#	dosasm.o
endif
ifeq ($(TARGET_OS),unix)
# unix clients use SDL:
SYSOBJ_INPUT := in_sdl.o
SYSOBJ_GL_VID:= gl_vidsdl.o fx_gamma.o
SYSOBJ_SOFT_VID:= vid_sdl.o
SYSOBJ_SYS := sys_unix.o
SYSOBJ_SYS += sys_sdl.o
endif
ifeq ($(TARGET_OS),darwin)
# unix clients use SDL:
SYSOBJ_INPUT := in_sdl.o
SYSOBJ_GL_VID:= gl_vidsdl.o fx_gamma.o
SYSOBJ_SOFT_VID:= vid_sdl.o
SYSOBJ_NET := net_bsd.o net_udp.o
SYSOBJ_SYS := sys_unix.o
SYSOBJ_SYS += sys_osx.o
SYSOBJ_SYS += SDLMain.o
endif
ifeq ($(TARGET_OS),aros)
ifeq ($(USE_SDL),yes)
SYSOBJ_INPUT := in_sdl.o
SYSOBJ_GL_VID:= gl_vidsdl.o
SYSOBJ_SOFT_VID:= vid_sdl.o
else
SYSOBJ_INPUT := in_amiga.o
SYSOBJ_GL_VID:= gl_vidamiga.o
SYSOBJ_SOFT_VID:= vid_cgx.o
endif
SYSOBJ_SYS := sys_amiga.o
endif
ifeq ($(TARGET_OS),morphos)
ifeq ($(USE_SDL),yes)
SYSOBJ_INPUT := in_sdl.o
SYSOBJ_GL_VID:= gl_vidsdl.o
SYSOBJ_SOFT_VID:= vid_sdl.o
else
SYSOBJ_INPUT := in_amiga.o
SYSOBJ_GL_VID:= gl_vidamiga.o
SYSOBJ_SOFT_VID:= vid_cgx.o
endif
SYSOBJ_SYS := sys_amiga.o
endif

# Final list of objects
SOFTOBJS = \
	d_edge.o \
	d_fill.o \
	d_init.o \
	d_modech.o \
	d_part.o \
	d_polyse.o \
	d_scan.o \
	d_sky.o \
	d_sprite.o \
	d_surf.o \
	d_vars.o \
	d_zpoint.o \
	r_aclip.o \
	r_alias.o \
	r_bsp.o \
	r_draw.o \
	r_edge.o \
	r_efrag.o \
	r_light.o \
	r_main.o \
	r_misc.o \
	r_part.o \
	r_sky.o \
	r_sprite.o \
	r_surf.o \
	r_vars.o \
	screen.o \
	$(SYSOBJ_SOFT_VID) \
	draw.o \
	model.o

GLOBJS = \
	gl_refrag.o \
	gl_rlight.o \
	gl_rmain.o \
	gl_rmisc.o \
	gl_ngraph.o \
	r_part.o \
	gl_rsurf.o \
	gl_screen.o \
	gl_warp.o \
	$(SYSOBJ_GL_VID) \
	gl_draw.o \
	gl_mesh.o \
	gl_model.o

COMMONOBJS = \
	$(SYSOBJ_INPUT) \
	$(COMOBJ_SND) \
	$(SYSOBJ_SND) \
	$(SYSOBJ_CDA) \
	$(SYSOBJ_MIDI) \
	huffman.o \
	net_udp.o \
	net_chan.o \
	cl_cam.o \
	cl_demo.o \
	cl_effect.o \
	cl_ents.o \
	cl_inlude.o \
	cl_input.o \
	cl_main.o \
	cl_parse.o \
	cl_pred.o \
	cl_tent.o \
	cl_cmd.o \
	console.o \
	keys.o \
	menu.o \
	sbar.o \
	skin.o \
	view.o \
	wad.o \
	cmd.o \
	q_endian.o \
	link_ops.o \
	sizebuf.o \
	strlcat.o \
	strlcpy.o \
	qsnprint.o \
	msg_io.o \
	common.o \
	debuglog.o \
	quakefs.o \
	info_str.o \
	crc.o \
	cvar.o \
	cfgfile.o \
	host_string.o \
	mathlib.o \
	pmove.o \
	pmovetst.o \
	zone.o \
	$(SYSOBJ_SYS)


# Targets
.PHONY: help clean distclean localclean report $(TIMIDEPS)

#default: glhw
#all: default

help: report
	@echo
	@echo "Valid targets: (read/edit the makefile for several options)"
	@echo
	@echo "* $(MAKE) help        : this help"
	@echo "* $(MAKE) clean       : delete all files produced by the build"
	@echo "* $(MAKE) hw          : hexenworld client, software renderer"
	@echo "* $(MAKE) glhw        : hexenworld client, opengl renderer"
	@echo

hw: $(SW_BINARY)
glhw: $(GL_BINARY)

ifeq ($(TARGET_OS),win32)
ifeq ($(USE_MGL),yes)
$(SW_BINARY): CPPFLAGS+= -DMGL_DLL
$(SW_BINARY): INCLUDES+= -I$(OSLIBS)/windows/scitech/include
$(SW_BINARY): LDFLAGS += -L$(OSLIBS)/windows/scitech/x86 -lmglfx
endif
endif
$(GL_BINARY): CPPFLAGS+= $(GL_DEFS)

# extra rule for snd_timidity.c because of timidity/timidity.h and libtimidity.a
snd_timidity.o: $(COMMONDIR)/snd_timidity.c
	$(CC) -c $(INCLUDES) -I$(LIBS_DIR) $(CPPFLAGS) $(CFLAGS) -o $@ $(COMMONDIR)/snd_timidity.c

include $(LIBS_DIR)/timidity/_timi.mak

$(SW_BINARY): $(SOFT_ASM) $(SOFTOBJS) $(COMMON_ASM) $(COMMONOBJS) $(TIMIDEPS)
	$(LINKER) $(SOFT_ASM) $(SOFTOBJS) $(COMMON_ASM) $(COMMONOBJS) $(LDFLAGS) -o $@

$(GL_BINARY): $(GLOBJS) $(COMMON_ASM) $(COMMONOBJS) $(TIMIDEPS)
	$(LINKER) $(GLOBJS) $(COMMON_ASM) $(COMMONOBJS) $(LDFLAGS) $(GL_LIBS) -o $@

localclean:
	rm -f *.o *.res core
clean: localclean timi_clean
distclean: clean
	rm -f $(SW_BINARY) $(GL_BINARY)

report:
	@echo "Host OS  :" $(HOST_OS)
	@echo "Target OS:" $(TARGET_OS)
	@echo "Machine  :" $(MACH_TYPE)