1#############################################################################
2#
3# $Id: Makefile 1114 2014-06-03 23:14:34Z smite-meister $
4# GNU Make makefile for Doom Legacy Program
5#
6# Copyright (C) 1998-2015 by Doom Legacy Team.
7#
8# This program is free software; you can redistribute it and/or
9# modify it under the terms of the GNU General Public License
10# as published by the Free Software Foundation; either version 2
11# of the License, or (at your option) any later version.
12#
13# This program is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	See the
16# GNU General Public License for more details.
17#
18# NOTICE: There is a CMAKE file included that can handle the default
19# compilation for SDL.  You can try that first, instead of this more
20# complicated Make that has all the OS, other SMIF, and more options.
21#
22#
23# On first execution of this Makefile, it will create a make_options file
24# and the build dirs.
25#
26# IMPORTANT: Edit the make_options file, choose OS and SMIF, and
27# put ALL your other options in there too.
28# This is the easiest way to use this Makefile, with the least mistakes.
29# Otherwise you must include the OS, and maybe the SMIF,
30# with almost EVERY make command.
31#   >> make clean OS=DOS
32#
33# The make_options file can be edited to select OS, SMIF, and options.
34# OR you can submit OS, SMIF, and options on the make command line every time.
35# OR you can edit make_options, but override it in special cases with
36# make command line options (like DEBUG=1 or HAVE_MIXER=1).
37#
38# If you already have a make_options file before first compilation, then
39# you may also have to create build directories.
40# The OS is set in the make_options file, so it is not needed on the command.
41#   >> make dirs
42#
43# An example with options on the make command:
44#   >> make OS=OS2 SMIF=SDL HAVE_MIXER=1
45#
46# The preferred system media interface is SDL.
47# To compile the generic Linux SDL version (with sound):
48#    >> make OS=LINUX HAVE_MIXER=1
49#
50# Other target options:
51# To compile the Linux X11 version (OS=LINUX will be assumed)
52#   >> make SMIF=LINUX_X11
53# To compile the FreeBSD X11 version (OS=FREEBSD will be assumed)
54#   >> make SMIF=FREEBSD_X11
55# To compile the OS/2 native version (OS=OS2 will be assumed)
56#   >> make SMIF=OS2_NATIVE
57#
58# To compile with assembly code for some draw functions, specify USEASM
59#   >> make OS=LINUX SMIF=SDL USEASM=1
60#   but the assembly code is not often updated with the latest improvements.
61#
62# To generate a debugging executable, specify DEBUG.
63#   >> make OS=LINUX SMIF=SDL DEBUG=1
64#
65# Command line options have precedence over the make_options file.
66# To have values in the make_options file override those on the make
67# command line, use override in the make_options file:
68#   override SMIF=SDL
69#
70# To use another make_options file, invoke make with MAKE_OPTIONS.
71#   >> make MAKE_OPTIONS=my_other_options
72#
73# This uses GNU Make special commands.  It may work with other make programs,
74# and has work-arounds in some places.  It has been tested with mingw32-make.
75# If you have problems, please use GNU Make, or gmake.
76#
77# If you have a workaround for another make, then submit it as a bug fix.
78# This makefile must work with Linux, BSD, Win, OS2, DOS, Mac, so Linux specific
79# operations must be guarded and limited.  Generic solutions are preferred.
80#
81# To update dependency then "make depend", otherwise it is automatic.
82#   >> make depend OS=LINUX
83#
84# commands:
85#  all  :  compile executable (default)
86#  dirs : create dep, objs, bin directories
87#  clean : delete objs and bin
88#  distclean : delete objs, bin, and make_options
89#  depend : update dependencies
90#  install: install binaries to INSTALL_DIR
91#  uninstall: install binaries from INSTALL_DIR
92# maintenance commands (generally not usable to the end user):
93#  legacywad : legacy.wad missing message
94#  updatewad : update existing legacy.wad
95# developers commands:
96#  disasm  : disasm of the exe
97#  objdump_draw : dump draw functions to assembly
98#  dll  : generate dll for X11
99#############################################################################
100
101# Debug enables, save on reinventing this everytime.
102#DEBUG=1
103#PROFILEMODE=1
104
105# Compile settings.
106# These MUST be setup by the user before compiling, or the wrong code
107# will be generated.
108# Do a "make clean" after any Makefile or make_options changes.
109# Edit these into the make_options file (without the #),
110# or as a parameter on the Make command line, SMIF=LINUX_X11.
111
112# Select one of these operating systems.
113# Linux is the default for SDL, that also applies to most unix-like OS.
114#   OS=LINUX
115#   OS=FREEBSD
116# Windows operating systems.  Also see CC_SELECT.
117# WIN32 is a generic 32bit Windows.
118#   OS=WIN32
119# WIN7 is a generic for Win7/Win8.
120# Win7/Win8 have caused problems, and any solutions found will be enabled
121# by this OS selection.
122# This does  NOT YET  make a version customized to Win7/8.
123#   OS=WIN7
124# Some older Windows, for completeness.
125#   OS=WIN98
126# An OS2 port is present, but has not been tried in ages.
127#   OS=OS2
128# A DOS port, (DJGPPDOS).  Needs old libraries.
129#   OS=DOS
130# MacIntosh operating system.  Also see Mac options.
131# Mac/SDL is currently under re-development.
132# The MACOS port is old, and has not been tried in ages.
133#   OS=MAC
134
135# SMIF - System Media Interface
136# Select one of the following.
137# The SDL library. SDL is the default.
138#   SMIF=SDL
139# The X11 window system native calls.  See some X11 options later.
140#   SMIF=LINUX_X11
141#   SMIF=FREEBSD_X11
142# Windows Direct Draw native calls.  See some Direct Draw options later.
143#   SMIF=WIN32_NATIVE
144#   SMIF=OS2_NATIVE
145#   SMIF=DJGPPDOS_NATIVE
146
147# Select a Compiler.  GCC is the default compiler.
148# Enable one of these to use an alternative compiler.
149#   CC_SELECT=GCC
150# The Makefile will use some alternative compiling switches known to be needed
151# for these compilers.
152#   CC_SELECT=MINGW
153#   CC_SELECT=WATCOM
154#   CC_SELECT=CLANG
155# Enable CC_ENVIRONMENT to allow an environment CC to specify the compiler.
156# This does work as expected if it is not gcc command line equivalent.
157#   CC_ENVIRONMENT=1
158# Use CC_EXPLICIT_CMD to explicitly specify a compiler command.
159# This will be used to set CC.
160#   CC_EXPLICIT_CMD=clang
161
162# SDL Mixer, to get music.
163#   HAVE_MIXER=1
164
165# Music options
166# CD-Music enable/disable, if you don't have the special libraries, etc.
167#   CD_MUSIC=0
168ifdef CD_MUSIC
169  ifeq ("$(CD_MUSIC)","1)
170    CDMUS=1
171  endif
172else
173  # default
174  CDMUS=1
175endif
176MUS_OS_LIST= SCOOS5 SCOUW2 SCOUW7
177# openserver5
178#   MUS_OS=SCOOS5
179# unixware2
180#   MUS_OS=SCOUW2
181# unixware7
182#   MUS_OS=SCOUW7
183# ESD demon for X11 (esound), not needed for SDL.
184#   HAVE_ESD=1
185
186# GGI option on X11
187#   X11_GGI=1
188# Uncomment if you want to use the POLL_POINTER hack in X11
189#   POLL_POINTER=-DPOLL_POINTER
190
191# WIN_NATIVE options
192# For FMOD sound.  Can compile without it.
193# The code that uses FMOD seems incomplete, consider it a work in progress.
194# HAVE_FMOD=1
195# FMODINC="" alternative directory to find fmod.h and other includes
196# FMODLIB="" alternative directory to find fmod libs
197# DDINC="" alternative directory to find ddraw.h and other includes
198# DDLIB="" alternative directory to find ddraw and other libs
199
200# Select MacIntosh operating system.  It has some unique options.
201# Mac compile using Linux SDL includes (MacPorts, Fink)
202# MAC_FRAMEWORK uses the native Mac SDL setup.
203# MAC_FRAMEWORK=1
204
205# When SDL 1.3 is used, some stuff will break.  I don't know what yet.
206# Reported that SDLMain is no longer required for Mac using SDL 1.3.
207# SDL_1_3=1
208
209# Warning flags
210WFLAGS=-Wall
211#WFLAGS=-Wall -Wwrite-strings
212
213# Optimization level, -O0 to -O5
214OPTLEV=-O3
215#OPTLEV=-O5
216
217#Enable the x86 asm code (which is not always up to date).
218# This is only useful if have an old compiler with bad optimization.
219#USEASM=1
220
221# Developers with svn can enable this to have svn revision number in executable.
222# Causes compile error message otherwise.
223# Until can find test for presence of svn, this is best that can be done.
224#SVN_ENABLE=1
225
226# This Makefile may be invoked from within the src directory,
227# or invoked from the Main Makefile with SRC=<directory>.
228# During program development, it is much easier to make from the
229# the working directories.
230
231# The main Makefile will change to the current directory to invoke
232# this Makefile.  So $(SRC) is not needed in this Makefile.
233# Invoke make with SRC= to compile other development directories.
234SRCINC:=-I.
235# The source directory.  With the current system, this is always the
236# current directory.
237SD:=
238
239# Older make, such as Make 3.75 used by FreeDOS, cannot handle else if.
240# Invoke make with BUILD= to compile to other build directories.
241ifdef MAIN_BUILD_DIR
242  # Invoked from Main Makefile
243  BUILD_DIR:=$(MAIN_BUILD_DIR)
244else
245ifndef BUILD
246  BUILD_DIR:=../
247else
248ifeq ("$(BUILD)",".")
249  # BUILD== "." is the main directory.
250  BUILD_DIR:=../
251else
252ifeq ("$(BUILD)","")
253  # BUILD== "" is the main directory.
254  BUILD_DIR:=../
255else
256  # BUILD in a sub-directory of the parent directory.
257  BUILD_DIR:=../$(BUILD)/
258endif
259endif
260endif
261endif
262
263ifneq ("$(findstring %%%/, %%%$(subst \,/,$(BUILD)))","")
264  # Absolute path
265  SERV_BUILD_DIR:=$(BUILD_DIR)
266else
267  # Relative path is more common, so avoid making it absolute.
268  SERV_BUILD_DIR:=../../$(BUILD_DIR)
269endif
270# export this to musserv, sndserv
271export SERV_BUILD_DIR
272
273# Subdirectories for binaries and build intermediates
274BIN =$(BUILD_DIR)bin
275O  = $(BUILD_DIR)objs
276DD = $(BUILD_DIR)dep
277
278# Invoke make with MAKE_OPTIONS= to specify another file or location.
279ifndef MAKE_OPTIONS
280  MAKE_OPTIONS = $(BUILD_DIR)make_options
281endif
282
283# Put user settings in this file, and they will be included with every
284# invocation of make.
285-include $(MAKE_OPTIONS)
286
287ifdef DEBUG
288 # Allow DEBUG=0 to turn debugging off.
289 ifeq ("$(DEBUG)","1")
290  ifndef DEBUGFLAGS
291
292# Customize to your debugging environment here.
293# Normal debug (-g), MACRO info (-g3), stabs or gdb debug info
294#    DEBUGFLAGS=-g3 -DDEBUG_WINDOWED
295    DEBUGFLAGS=-ggdb -DDEBUG_WINDOWED
296# Debuggers do not cope with optimization well, so DEBUG ignores OPTLEV.
297# To debug with optimization, include it here, (-O0, -O1, or $(OPTLEV)).
298#     DEBUGFLAGS+=$(OPTLEV)
299   WFLAGS+=-Wundef
300#  Causes many warning messages due to const strings
301#  WFLAGS+= -Wwrite-strings
302  endif
303# Set DEBUGLIBS to special debugging libraries here.
304
305 endif
306endif
307# End of DEBUG
308
309# standard
310#STD= -std=c99
311  # not ready yet
312  # fails because of alloca, it is not std under c99
313  # std=c89, does not support // commments, no inline, no asm
314
315# End of User tunable settings
316
317
318# MAKECMDGOALS is in GNUMake, MinGW
319ifdef MAKECMDGOALS
320  ifneq ($(MAKECMDGOALS),distclean)
321  ifneq ($(MAKECMDGOALS),clean)
322  ifneq ($(MAKECMDGOALS),dirs)
323  ifneq ($(MAKECMDGOALS),depend)
324    # include deps for all except clean and dirs op
325    INCLUDE_DEPS=1
326  endif
327  endif
328  endif
329  endif
330  ifeq ($(MAKECMDGOALS),depend)
331    FORCE_AUTO_DEP=1
332  endif
333else
334  #default
335  INCLUDE_DEPS=1
336  FORCE_AUTO_DEP=1
337endif
338
339
340# Values changed by system detection
341# file delete command, init value
342RM=rm
343# random stuff
344NASMFORMAT=elf -DLINUX
345
346# Doom Legacy is developed with GCC.  MINGW gets used for Win32.
347# The behavior of the code under other compilers is uncertain.
348# Define CC_EXPLICIT_CMD in make_options to override this setting.
349#  CC_EXPLICT_CMD=my_compiler
350# Define CC_ENVIRONMENT to allow an environment CC to specify the compiler.
351
352ifdef CC_EXPLICIT_CMD
353  CC_CMD:=$(CC_EXPLICIT_CMD)
354else
355  # gcc is default
356  CC_CMD:=gcc
357  ifeq ($(CC_SELECT), MINGW)
358    CC_CMD:=gcc
359  endif
360  ifeq ($(CC_SELECT), WATCOM)
361    CC_CMD:=WATCOMC
362  endif
363  ifeq ($(CC_SELECT), CLANG)
364    CC_CMD:=clang
365  endif
366endif
367ifdef CC_ENVIRONMENT
368  # Give an environment CC precedence in specifing the compiler.
369  CC ?= $(CC_CMD)
370else
371  CC:=$(CC_CMD)
372endif
373
374SMIF_LIST:= SDL LINUX_X11 FREEBSD_X11 WIN_NATIVE OS2_NATIVE DOS_NATIVE
375
376# Default system media interface
377ifdef SMIF
378  # specific SMIF
379  EXT_SMIF:=$(SMIF)
380else
381  SMIF:=SDL
382endif
383
384# Default OS for some SMIF
385ifeq ($(SMIF), SDL)
386  ifndef OS
387    # Do not default OS on initialize of make_options.
388    ifdef MAKE_OPTIONS_PRESENT
389      # Default to Linux
390      OS:=LINUX
391    endif
392  endif
393else
394ifeq ($(SMIF), LINUX_X11)
395  ifdef OS
396    ifneq ($(OS), LINUX)
397      $(error "SMIF=LINUX_X11 requires OS=LINUX")
398    endif
399  else
400    OS=LINUX
401  endif
402else
403ifeq ($(SMIF), FREEBSD_X11)
404  ifdef OS
405    ifneq ($(OS), FREEBSD)
406      $(error "SMIF=FREEBSD_X11 requires OS=FREEBSD")
407    endif
408  else
409    OS=FREEBSD
410  endif
411else
412ifeq ($(SMIF), WIN32_NATIVE)
413  ifdef OS
414    ifneq ($(OS), WIN32)
415    ifneq ($(OS), WIN98)
416    ifneq ($(OS), WIN7)
417      $(error "SMIF=WIN32_NATIVE requires a Windows OS, such as OS=WIN32")
418    endif
419    endif
420    endif
421  else
422    OS=WIN32
423  endif
424else
425ifeq ($(SMIF), OS2_NATIVE)
426  ifdef OS
427    ifneq ($(OS), OS2)
428      $(error "SMIF=OS2_NATIVE requires OS=OS2")
429    endif
430  else
431    OS=OS2
432  endif
433else
434ifeq ($(SMIF), DJGPPDOS_NATIVE)
435  ifdef OS
436    ifneq ($(OS), DOS)
437      $(error "SMIF=DJGPPDOS_NATIVE requires OS=DOS")
438    endif
439  else
440    OS=DOS
441  endif
442else
443  $(error  "Unknown SMIF: $(SMIF)" )
444endif
445endif
446endif
447endif
448endif
449endif
450
451
452OS_LIST:=LINUX FREEBSD NETBSD WIN32 WIN7 WIN98 OS2 DOS MAC
453
454OPTS:=
455
456ifeq ($(OS), LINUX)
457  LINUX=1
458  OPTS+=-DLINUX
459  #Known Compiler symbols
460  # linux  __linux  __linux__
461  # AIX defines: _AIX
462  # HPux defines: hpux __hpux __hpux__
463  # SGI IRIX defines: sgi  __sgi  __sgi__
464  # Solaris defines:  SOLARIS
465  # PPC defines: __PPC__
466  # GCC on PPC defines: _ARCH_PPC  __PPC__
467  # PPC 64 bit defines: __PPC64__
468  # Big Endian machines (PPC) define: __BIG_ENDIAN__
469  # SDL_platform.h for Solaris __SVR4 defines:  __SOLARIS__
470  # SDL_platform.h for SGI variations defines:  __IRIX__
471  # SDL_platform.h for HPux variations defines: __HPUX__
472  # SDL_platform.h for Linux variations defines: __LINUX__
473else
474ifeq ($(OS), FREEBSD)
475  # Has some linking differences from the rest of Linux-like OS.
476  FREEBSD=1
477  OPTS+=-DLINUX -DFREEBSD
478  #Known Compiler symbols
479  # __FreeBSD__  __FreeBSD_kernel__  __DragonFly__
480  # SDL_platform.h for FreeBSD defines: __FREEBSD__
481else
482ifeq ($(OS), NETBSD)
483  # Uses statvfs(5).
484  NETBSD=1
485  OPTS+=-DLINUX -DNETBSD
486  #Known Compiler symbols
487  # __NetBSD__
488  # SDL_platform.h for NetBSD defines: __NETBSD__
489else
490ifeq ($(OS), WIN32)
491  WIN32=1
492  DOSFILE=1
493  OPTS+=-DWIN32
494  # if have windows > Win98, and want large memory reports
495  ifdef WIN_LARGE_MEM
496    OPTS+=-DWIN_LARGE_MEM
497  endif
498  #Known Compiler symbols
499  # WIN32  _WIN32  __WINDOWS__
500  # __WIN32__
501  # Microsoft Visual C++ defines:  __MSC__
502  # Watcom defines:  __WATCOMC__
503  #  doomtype.h fixes Watcom to also define:  WIN32  __WIN32___
504  # MinGW defines:   __MINGW32__
505  # SDL_platform.h for Windows variations defines:  __WIN32__
506else
507ifeq ($(OS), WIN7)
508  # This does  NOT YET  make a version customized to Win7/8.
509  WIN32=1
510  DOSFILE=1
511  OPTS+=-DWIN32
512  # probably want large memory reports
513  OPTS+=-DWIN_LARGE_MEM
514  #Known Compiler symbols
515  # This needs investigation ...
516else
517ifeq ($(OS), WIN98)
518  # One of the development machines is Win98.
519  # If Win98 differences occur, this category can isolate them.
520  WIN32=1
521  DOSFILE=1
522  OPTS+=-DWIN32
523else
524ifeq ($(OS), OS2)
525  OS2=1
526  DOSFILE=1
527  OPTS+=-D__OS2__
528  #Known Compiler symbols
529  # __OS2__
530else
531ifeq ($(OS), DOS)
532  DOS=1
533  DOSFILE=1
534  #Known Compiler symbols
535  # PC_DOS
536else
537ifeq ($(OS), MAC)
538  MAC=1
539  #Known Compiler symbols
540  # __APPLE__  __APPLE_CC__  __MACH__
541  # Apple GNAT, GNU C 4.5 defines __APPLE_CC__ = 1,  __MACH__,  __GNUC__
542  # Apple C 4.2 defines  __APPLE_CC__ = 5666, __MACH__, __GNUC__
543  # When compiling for big endian arch defines:  __BIG_ENDIAN__
544  # SDL_platform.h for MacIntosh defines: __MACOS__
545  # SDL_platform.h for Apple defines:     __MACOSX__
546else
547  $(error  "Unknown OS: $(OS)" )
548endif
549endif
550endif
551endif
552endif
553endif
554endif
555endif
556endif
557export DOSFILE
558
559# OPTS goes to the C compiler and assembler.
560# OPTS is almost all defines using -D. It selects conditional code.
561# CFLAGS only goes to the C compiler.  It gets a copy of OPTS.
562# LDFLAGS goes to the linker.  Some linkers cannot handle OPTS.
563# LIBS goes to the linker.
564
565ifdef COMP_ENVIRONMENT
566  # Things like this will always have an enabling control.
567  # Otherwise, something that is useful on one system, will be a surprise on another system.
568  # And it is very hard to debug other systems when unknown settings
569  # are allowed to influence compiling, without any control or notification.
570
571  # NETBSD: Include the environment CFLAGS in OPTS.
572  # (This is what I got from the NETBSD user, and don't know why it
573  #  goes in OPTS instead of CFLAGS.)
574  OPTS+=$(CFLAGS)
575#  ENV_CFLAGS=$(CFLAGS)
576
577  # NETBSD: Has environment settings that should be used?
578  # Do not reset LIBS, use the LIBS from the environment.
579  # Do not reset LDFLAGS, use the LDFLAGS from the environment.
580else
581  LIBS:=
582  LDFLAGS:=
583endif
584
585# all OPTINC need to have -I. because of how includes are written
586# however the order of -I may be important, so it is left to each SMIF.
587OPTINC:=
588INSTALL_SUPPL:=
589
590#CFLAGS:=
591# Machine architecture.
592# (Ab)using ARCH is very bad idea and can easily break things!
593override undefine ARCH
594ifdef ARCH
595  # if does not have leading -march, -mcpu, -mtune, or similar.
596  ifeq ($(filter -march% -mcpu% -mtune% -m%, $(strip $(ARCH))),)
597    # Apply to most general architecture compiler flag.
598    CFLAGS:=-march=$(ARCH)
599    $(warning Using ARCH as: $(CFLAGS) )
600  else
601    # Looks like a complete switch, use it as is.
602    CFLAGS:=$(ARCH)
603  endif
604endif
605
606ifdef ENV_CFLAGS
607  CFLAGS+=$(ENV_CFLAGS)
608endif
609
610
611#=================================
612ifeq ($(SMIF), SDL)
613# SDL is the default system media interface. This is what all modern systems should use.
614# Requires SDL libs, and optionally SDL_mixer libs.
615# This uses files in sdl directory, and not those linux_x nor macos directories.
616
617# interface directory (where you put all i_*.c)
618  INTERFACE=sdl
619
620  MAINOBJ:=i_main.o
621  CDMUSOBJ:=i_cdmus.o
622  SMIFOBJS:=i_system.o i_video.o i_sound.o i_net.o \
623    hw_bsp.o hw_draw.o hw_light.o hw_main.o hw_md2.o hw_cache.o hw_trick.o \
624    r_opengl.o ogl_sdl.o hwsym_sdl.o \
625    filesrch.o dosstr.o endtxt.o
626
627  DEP_HARD:=1
628  DEP_OPENGL:=1
629
630# platform
631  ifdef WIN32
632    # Windows (MinGW)
633    EXENAME:=doomlegacy.exe
634    LIBS:=-lopengl32 -lglu32 -lwsock32 -lm
635  else
636    ifndef MAC
637      # default is Linux, for all unix SDL
638      EXENAME:=doomlegacy
639      LDFLAGS+=-L/usr/X11R6/lib
640      LIBS+=-lGL -lGLU -lm
641      # -L/usr/X11R6/lib is needed by Linux 2.4 and others that still have
642      # the GLU libraries in an X11 directory.
643      # -lm is needed for pow, powf, and other MATH1 functions.
644    else
645      EXENAME:=doomlegacy
646      LDFLAGS+=-framework OpenGL
647    endif
648
649    SDL_CONFIG:=1
650  endif
651
652  ifdef SDL_CONFIG
653    OPTINC+=$(shell sdl-config --cflags)
654    LIBS+=$(shell sdl-config --libs)
655  else
656    # Extracted from sdl-config script
657    ifeq ($(CC_SELECT), MINGW)
658      OPTS+=-D_GNU_SOURCE=1 -Dmain=SDL_main
659      OPTINC+=-I/SDL/include/SDL
660#      OPTINC+=-I/mingw/include/SDL
661#      OPTINC+=-I/mingw/include
662      LIBS+=-L/SDL/lib
663#      LIBS+=-L/mingw/lib
664#      LIBS+=-L/windows/system32
665      LIBS+=-lsdl -lmingw32 -mwindows
666      LIBS+=-lSDLmain -lSDL
667    endif
668    ifeq ($(CC_SELECT), WATCOM)
669      OPTS+=-D_GNU_SOURCE=1 -Dmain=SDL_main
670      OPTINC+=-I/SDL/include/SDL
671#     OPTINC+=-I/watcom/h/SDL
672      LIBS+=-L/SDL/lib
673#     LIBS+=-L/windows/system32
674      LIBS+=-lsdl -lwatcom -mwindows
675      LIBS+=-lSDLmain -lSDL
676    endif
677    ifdef MAC
678    # Some Mac SDL downloads do not have sdl-config.
679    # Because I do not know of a way for MAKE to test this, comment
680    # out the SDL_CONFIG=1 above if you do not have sdl-config.
681    # Put correct mac sdl-config info here (somebody).
682      OPTS+=-D_GNU_SOURCE=1 -D_REENTRANT
683      OPTINC+=-I/usr/include/SDL
684      LIBS+=-L/usr/lib -Wl,-rpath,/usr/lib -lSDL -lpthread
685    endif
686  endif
687
688  OPTS+=-DHWRENDER -DSMIF_SDL
689  OPTINC+=$(SRCINC)
690
691  ifdef HAVE_MIXER
692    # Allow HAVE_MIXER=0 to turn it off.
693    ifeq ("$(HAVE_MIXER)", "1")
694      # SDL has separate SDL_Mixer library.
695      OPTS+=-DHAVE_MIXER
696      LIBS+=-lSDL_mixer
697    endif
698  endif
699
700  ifdef MAC
701    # Objective-C main program is required for SDL 1.2.x
702    # DoomLegacy has its own SDLmain source, but others may work,
703    # though they would change the default directory according to .app.
704    SMIFOBJS+=SDLmain.o
705    LIBS+=-lobjc
706    # Optional places for include and libraries, unique to Mac.
707    # Enable MAC_FRAMEWORK if you really want to debug frameworks (I don't).
708    ifdef MAC_FRAMEWORK
709      CFLAGS += -DMAC_FRAMEWORK
710      FRAMEWORK = -framework Cocoa -framework OpenGL -framework SDL
711      # Do not remember which example had -F./osx/Frameworks
712      #      LDFLAGS += -F./osx/Frameworks $(FRAMEWORK) -framework Foundation
713      LDFLAGS +=  $(FRAMEWORK) -framework Foundation
714    endif
715  endif
716
717
718#=================================
719else
720ifeq ($(SMIF), LINUX_X11)
721  # Requires X11/Xlib, and xshm or ggi libs
722  INTERFACE=linux_x
723
724  MUSSERV:=linux_x/musserv
725  SNDSERV:=linux_x/sndserv
726
727  DEP_HARD:=1
728  DEP_X11:=1
729  DEP_OPENGL:=1
730
731  #use the x86 asm code
732  #USEASM=1
733
734  # Uncomment if you want to use the POLL_POINTER hack
735  #POLL_POINTER:=-DPOLL_POINTER
736  # Uncomment if you want to use SOUND_RESET, only valid without SNDSERV
737  #OPTS+=-DSOUND_RESET
738
739  OPTS+=-DSMIF_X11 -DSNDSERV -DHWRENDER
740  ifdef CDMUS
741    OPTS+=-DMUSSERV
742  endif
743
744  # objs common to xshm and ggi, video is added later
745  MAINOBJ:=i_main.o
746  CDMUSOBJ:=i_cdmus.o
747  SMIFOBJS:=i_system.o i_sound.o i_net.o \
748    hw_bsp.o hw_draw.o hw_light.o hw_main.o hw_md2.o hw_cache.o hw_trick.o \
749    r_opengl.o ogl_x11.o \
750    searchp.o filesrch.o dosstr.o endtxt.o
751
752  INSTALL_SUPPL:=r_opengl.so
753
754  ifdef X11_GGI
755    # GGI
756    OPTS+=-DSMIF_X11_GGI
757    OPTINC:=$(SRCINC)
758    LDFLAGS:=
759    LIBS:=-lggi -lm
760    # name of the exefile
761    EXENAME:=llggidoom
762    SFLAGS:=-g $(OPTS)
763    SMIFOBJS+=i_video_ggi.o
764  else
765    # standard X11
766    OPTS+=$(POLL_POINTER)
767    OPTINC+=$(SRCINC) -I/usr/X11R6/include
768    LDFLAGS:=-L/usr/X11R6/lib
769    LIBS:=-lGL -lGLU -lXext -lX11 -lm -ldl -lXxf86vm
770
771    #WITH_DGA=1
772    ifdef WITH_DGA
773      OPTS+=-DWITH_DGA
774      LIBS+=-lXxf86dga -lXext
775    endif #WITH_DGA
776
777    # name of the exefile
778    EXENAME:=llxdoom
779    SFLAGS:=-g $(OPTS)
780    SMIFOBJS+=i_video_xshm.o
781  endif
782
783
784#=================================
785else
786ifeq ($(SMIF), FREEBSD_X11)
787  # Requires X11/Xlib, and xshm or ggi libs
788  INTERFACE=linux_x
789
790#  MUSSERV=linux_x/musserv
791  SNDSERV=linux_x/sndserv
792  OSVERSION:=$(shell /sbin/sysctl -n kern.osreldate)
793  OSMAJOR:=$(shell echo $(OSVERSION) | sed 's/.....$$//')
794
795  DEP_HARD:=1
796  DEP_X11:=1
797  DEP_OPENGL:=1
798
799  #use the x86 asm code
800  #USEASM:=1
801
802  # Uncomment if you want to use the POLL_POINTER hack
803  #POLL_POINTER:=-DPOLL_POINTER
804  # Uncomment if you want to use SOUND_RESET, only valid without SNDSERV
805  #OPTS+=-DSOUND_RESET
806
807  OPTS+=-DSMIF_X11 -DSNDSERV -DHWRENDER
808  # objs common to xshm and ggi, video is added later
809  # Note: free-bsd version of cdmus
810  MAINOBJ:=i_main.o
811  CDMUSOBJ:=i_cdmus_fbsd.o
812  SMIFOBJS:=i_system.o i_sound.o i_net.o \
813    hw_bsp.o hw_draw.o hw_light.o hw_main.o hw_md2.o hw_cache.o hw_trick.o \
814    searchp.o filesrch.o dosstr.o endtxt.o
815
816  INSTALL_SUPPL:=r_opengl.so
817
818  ifdef X11_GGI
819    # GGI
820    OPTS+=-DSMIF_X11_GGI
821    OPTINC+=$(SRCINC) -I/usr/local/include
822    LDFLAGS:=
823    LIBS:=-lggi -lm
824    # name of the exefile
825    EXENAME:=llggidoom
826    SFLAGS:=-g $(OPTS)
827    SMIFOBJS+=i_video_ggi.o
828  else
829    # standard X11
830    OPTS+=$(POLL_POINTER)
831    OPTINC+=$(SRCINC) -I/usr/X11R6/include
832    LDFLAGS:=-L/usr/X11R6/lib
833    LIBS:=-lXext -lX11 -lm -lXxf86vm -lkvm -lpthread
834    # name of the exefile
835    EXENAME:=llxdoom
836    SFLAGS:=-g $(OPTS)
837    SMIFOBJS+=i_video_xshm.o
838  endif
839
840#=================================
841else
842ifeq ($(SMIF), OS2_NATIVE)
843  #Requires OS2 libs, os2.h, os2me.h, fourcc.h, DIVE libs, and mmpm2 libs
844  #Does not have cdmusic support
845  DOSFILE=1
846  INTERFACE=os2
847  NASMFORMAT:=coff
848
849#use the x86 asm code
850  NASM:=nasm
851#USEASM=1
852  PROFILEMODE=1
853# options (separate OS2 library and OS2_NATIVE video)
854  OPTS+= -DSMIF_OS2_NATIVE
855  OPTINC+=-Zmt $(SRCINC) -I$(SD)os2
856
857#  DEBUGLIBS:=
858  LIBS:=-g $(INTERFACE)/I_pm.def -lmmpm2 -lsocket
859
860  SFLAGS:=-g $(OPTS)
861
862  MAINOBJ:=main.o
863  CDMUSOBJ:=i_cdmus.o
864  SMIFOBJS:=i_system.o i_video.o i_sound.o i_net.o i_dart.o i_dive.o I_pm.o \
865    printf.o I_pm.res filesrch.o
866
867# name of the exefile
868  EXENAME:=legacy.exe
869
870
871#=================================
872else
873ifeq ($(SMIF), WIN32_NATIVE)
874  # Requires windows.h, windowsx.h, ddraw.h and ddraw libs, and
875  # optionally fmod libs
876  DOSFILE=1
877  INTERFACE=win32
878  NASMFORMAT:=coff
879
880  DEP_HARD:=1
881  DEP_DD:=1
882
883  # DDINC="" alternative directory to find ddraw.h and other includes
884  # DDLIB="" alternative directory to find ddraw and other libs
885  ifndef DDINC
886#    DDINC=-I\MINGW\MX80\include
887  endif
888  ifndef DDLIB
889#    DDLIB=-L\MINGW\MX80\lib
890  endif
891  # FMODINC="" alternative directory to find fmod.h and other includes
892  # FMODLIB="" alternative directory to find fmod libs
893  ifdef HAVE_FMOD
894    ifndef FMODINC
895      FMODINC=-I\MINGW\fmod\include
896    endif
897    ifndef FMODLIB
898      FMODLIB=-L\MINGW\fmod\lib
899    endif
900  endif
901
902#use the x86 asm code
903  #USEASM=1
904
905# options (separate WIN32 library, and WIN_NATIVE video)
906  OPTS+=-DSMIF_WIN_NATIVE
907  OPTINC+=-g $(SRCINC)
908  ifdef DDINC
909    OPTINC+=$(DDINC)
910  endif
911
912#  DEBUGLIBS:=
913  LIBS:=
914  ifdef DDLIB
915    LIBS+=$(DDLIB)
916  endif
917  ifeq ($(CC_SELECT), MINGW)
918    LIBS+=-lwinmm -lwsock32 -lgdi32 -lddraw -ldsound -ldinput -ldxguid
919  else
920    LIBS+=-lwinmm -lsocket -lddraw -ldsound -ldinput
921  endif
922
923  ifdef HAVE_FMOD
924    OPTS+=-DFMOD_SOUND
925    ifdef FMODLIB
926      LIBS+=$(FMODLIB) -lfmod
927    endif
928  endif
929
930  SFLAGS:=
931
932  MAINOBJ:=win_main.o
933  SMIFOBJS:=win_sys.o win_vid.o win_snd.o win_net.o win_cd.o \
934    filesrch.o fabdxlib.o mid2strm.o dx_error.o
935
936# name of the exefile
937  EXENAME:=legacy.exe
938
939#=================================
940else
941ifeq ($(SMIF), DJGPPDOS_NATIVE)
942  # Requires allegro libs, bcd libs (cd-music)
943  RM:=del
944  DOSFILE=1
945  INTERFACE=djgppdos
946  NASMFORMAT:=coff
947
948#  DEP_HARD:=1
949
950#use the x86 asm code
951  #USEASM=1
952
953# options
954  OPTS:=-DSMIF_PC_DOS
955  OPTINC+=-g $(SRCINC)
956
957#  DEBUGLIBS:=
958  LIBS:=-lalleg -lsocket
959  ifdef CDMUS
960     LIBS+=-lbcd
961  endif
962
963  SFLAGS:=
964
965  MAINOBJ:=i_main.o
966  CDMUSOBJ:=i_cdmus.o
967  SMIFOBJS:=i_system.o i_video.o vid_vesa.o i_sound.o i_net.o filesrch.o
968
969# name of the exefile
970  EXENAME:=legacy.exe
971endif
972endif
973endif
974endif
975endif
976endif
977#=================================
978
979#  $(info $(PATH) )
980# DOS/OS2/WIN32 file differences
981ifdef DOSFILE
982  ifndef HAVE_DOSCOMMAND
983    ifneq ("$(findstring "MSYS", "$(SHELL)"),"")
984      $(info HAVE MSYS )
985      # When SHELL = command.com, it chokes on @echo and - $(RM)
986      # When SHELL = cmd.exe, it works for mingw32-make, but MSYS make
987      # does not execute the DOS commands
988#     SHELL:=cmd.exe
989#     .SHELLFLAGS="/C /Q"
990      HAVE_MSYS=1
991    endif
992  endif
993  ifdef HAVE_MSYS
994    # MSYS has its own idea of the root directory.
995    LIBS:=$(subst -L/,-LC:/,$(LIBS))
996    $(info LIBS=$(LIBS) )
997  else
998    $(info HAVE DOSCOMMAND )
999    HAVE_DOSCOMMAND=1
1000    RM:=del
1001  endif
1002  BIN_WIN:=$(subst /,\,$(BIN))
1003  O_WIN:=$(subst /,\,$(O))
1004  DD_WIN:=$(subst /,\,$(DD))
1005else
1006  SHELL:=/bin/sh
1007endif
1008#  $(info HAVE SHELL=$(SHELL) )
1009
1010OPTOBJS:=
1011
1012# use assembly routines?
1013ifdef USEASM
1014   OPTOBJS+=tmap.o vid_copy.o
1015   OPTS+=-DUSEASM
1016endif
1017
1018
1019# CD-Music
1020ifdef CDMUS
1021   OPTOBJS+=$(CDMUSOBJ)
1022   OPTS+=-DCDMUS
1023endif
1024
1025# LIBZIP
1026# For now, Linux only.
1027ifeq ($(OS), LINUX)
1028  ifdef HAVE_LIBZIP
1029    # Option ZIPWAD_OPTIONAL uses lib dlopen.
1030    LIBS+=-lzip
1031    OPTS+=-DHAVE_LIBZIP=$(HAVE_LIBZIP)
1032  endif
1033  ifdef HAVE_DLOPEN
1034    # Option ZIPWAD_OPTIONAL uses lib dlopen.
1035    LIBS+=-ldl
1036    OPTS+=-DHAVE_DLOPEN
1037  endif
1038endif
1039
1040
1041# compiler and linker flags
1042CFLAGS+=$(WFLAGS)
1043
1044ifdef PROFILEMODE
1045# build with gprof profiling information
1046  CFLAGS+=-g -pg -fomit-frame-pointer
1047else
1048ifdef DEBUG
1049# No -fomit-frame-pointer because debugging on some machines depends upon it.
1050  #CFLAGS+=-g3 -O0
1051  CFLAGS+=$(DEBUGFLAGS) -fno-guess-branch-probability
1052  ifdef DEBUGLIBS
1053# Search debug libraries first, otherwise normal library
1054    LIBS:=$(DEBUGLIBS) $(LIBS)
1055  endif
1056else
1057# build a normal optimized version
1058  #CFLAGS+=-O3
1059  #CFLAGS+=$(OPTLEV) -fomit-frame-pointer
1060endif
1061endif
1062
1063#CFLAGS+=-ffast-math -fno-strict-aliasing
1064# WIN98 linking needs LCFLAGS without -D flags and does not need includes
1065LCFLAGS:=$(CFLAGS)
1066CFLAGS+=$(OPTS) $(OPTINC)
1067
1068ifdef MAC
1069  # MAC linker does not accept these flags.
1070else
1071ifdef NETBSD
1072  # NETBSD linker does not accept these flags.
1073else
1074  # Flags to the linker.
1075  LDFLAGS+=-Xlinker --warn-common
1076endif
1077endif
1078
1079SNDSERV_EXTRAFLAGS:=
1080ifdef HAVE_ESD
1081  SNDSERV_EXTRAFLAGS:=HAVE_ESD=1
1082endif
1083
1084
1085# objs that are in main directories
1086MOBJS:=\
1087screen.o v_video.o \
1088r_draw.o r_plane.o r_segs.o r_sky.o r_things.o r_splats.o \
1089r_bsp.o r_data.o r_main.o \
1090z_zone.o \
1091p_sight.o p_mobj.o p_enemy.o p_user.o p_inter.o p_pspr.o \
1092p_lights.o p_ceilng.o p_doors.o p_plats.o p_floor.o p_spec.o \
1093p_switch.o p_genlin.o p_telept.o p_tick.o p_fab.o p_info.o p_setup.o \
1094p_map.o p_maputl.o \
1095p_heretic.o p_hsight.o \
1096p_chex.o \
1097sb_bar.o hu_stuff.o \
1098st_lib.o st_stuff.o \
1099t_array.o t_func.o t_oper.o t_parse.o t_prepro.o t_script.o t_spec.o t_vari.o \
1100sounds.o qmus2mid.o s_sound.o s_amb.o mserv.o \
1101b_game.o b_look.o b_node.o b_search.o \
1102g_input.o g_game.o \
1103f_finale.o f_wipe.o \
1104wi_stuff.o \
1105am_map.o \
1106md5.o \
1107m_menu.o m_misc.o m_argv.o m_bbox.o m_fixed.o m_swap.o m_cheat.o m_random.o \
1108console.o command.o \
1109p_saveg.o \
1110tables.o info.o dstrings.o dehacked.o w_wad.o w_zip.o\
1111d_netcmd.o d_clisrv.o d_net.o d_netfil.o i_tcp.o \
1112d_items.o d_main.o
1113
1114# combine all objs ( main, INTERFACE specific, asm, CDMUS )
1115OBJS:=$(addprefix $(O)/, $(SMIFOBJS) $(OPTOBJS) $(MOBJS))
1116MAINOBJ:=$(addprefix $(O)/, $(MAINOBJ))
1117
1118
1119#=======================================================
1120# rules
1121#=======================================================
1122# Do not have directories as prerequisites because their date is updated
1123# whenever a file is output, which fouls up the rules.
1124
1125.PHONY : all clean distclean dirs asm dll install
1126
1127# prevent compile without make_options file
1128ifndef MAKE_OPTIONS_PRESENT
1129  $(error Create make_options file first, using parent Makefile.)
1130endif
1131
1132# ALL, compile and link
1133ifeq ($(SMIF), LINUX_X11)
1134all: $(BIN)/$(EXENAME) dll musserv sndserv
1135
1136else
1137ifeq ($(SMIF), FREEBSD_X11)
1138all:	 $(BIN)/$(EXENAME) dll sndserv
1139
1140else
1141all:	 $(BIN)/$(EXENAME)
1142
1143endif
1144endif
1145
1146
1147# Directly using $(error) prevents the output of the other commands.
1148
1149
1150# Win32/OS2/DOS sees "/" as a switch, "\" is an escape to make
1151clean:
1152ifdef HAVE_DOSCOMMAND
1153	@echo "Removing dependencies $(DD_WIN)"
1154	- $(RM) $(DD_WIN)\*.dep
1155	@echo "Removing obj  $(O_WIN)"
1156	- $(RM) $(O_WIN)\*.o
1157else
1158	@echo "Removing dependencies $(DD)"
1159	- $(RM) $(DD)/*
1160	@echo "Removing obj  $(O)"
1161	- $(RM) $(O)/*.o
1162endif
1163ifeq ($(SMIF), LINUX_X11)
1164	cd $(SD)$(MUSSERV) && $(MAKE) clean
1165	cd $(SD)$(SNDSERV) && $(MAKE) clean
1166#	- $(RM) $(O)/$(MUSSERV)/*.o
1167#	- $(RM) $(O)/$(SNDSERV)/*.o
1168else
1169ifeq ($(SMIF), FREEBSD_X11)
1170	cd $(SD)$(MUSSERV) && $(MAKE) clean
1171	cd $(SD)$(SNDSERV) && $(MAKE) clean
1172#	- $(RM) $(O)/$(MUSSERV)/*.o
1173#	- $(RM) $(O)/$(SNDSERV)/*.o
1174endif
1175endif
1176
1177distclean:
1178ifdef HAVE_DOSCOMMAND
1179	- $(RM) $(DD_WIN)\*.dep
1180	- $(RM) $(O_WIN)\*.o
1181	- $(RM) $(O_WIN)\*\*.o
1182else
1183	- $(RM) $(DD)/*
1184	- $(RM) $(O)/*.o
1185	- $(RM) $(O)/*/*.o
1186endif
1187
1188
1189.PHONY : versionstring
1190# This may fail because, (a) svn not installed, (b) not a svn directory.
1191# This compiles d_main a second time, with SVN_REV set.
1192versionstring:
1193ifdef SVN_ENABLE
1194	$(CC) -c $(CFLAGS) -DSVN_REV=\"`svn info | grep Revision | sed -e 's/Revision: //'`\" d_main.c -o $(O)/d_main.o
1195endif
1196
1197# Maintenance Functions, mostly Linux only
1198
1199
1200# Make a disasm of the exe
1201disasm: $(BIN)/$(EXENAME)
1202	objdump -d $(BIN)/$(EXENAME) --no-show-raw-insn > $(BIN)/doomlegacy.s
1203
1204# To dump draw functions to assembly
1205objdump_draw: $(O)/r_draw.o
1206	objdump -d $(O)/r_draw.o -l --source --no-show-raw-insn > $(BIN)/r_draw.s
1207
1208
1209# Make dll for X11
1210dll : $(O)/r_opengl.o $(O)/ogl_x11.o
1211	$(CC) -O3 $(OPTS) -o $(BIN)/r_opengl.so -shared -nostartfiles \
1212	  $(O)/r_opengl.o $(O)/ogl_x11.o \
1213	  -L/usr/X11R6/lib -L/usr/local/lib -lX11 -lXext -lGL -lGLU -lm
1214
1215
1216# Linux X11 sound and music servers
1217ifdef MUS_OS
1218  export MUS_OS
1219endif
1220ifdef HAVE_ESD
1221  export HAVE_ESD
1222endif
1223
1224ifdef MUSSERV
1225musserv:
1226	cd $(SD)$(MUSSERV) && $(MAKE)
1227endif
1228
1229ifdef SNDSERV
1230sndserv:
1231	cd $(SD)$(SNDSERV) && $(MAKE) $(SNDSERV_EXTRAFLAGS)
1232endif
1233
1234
1235#=======================================================
1236
1237# executable rule
1238
1239$(BIN)/$(EXENAME): $(OBJS) $(MAINOBJ) versionstring
1240	@echo Linking...
1241ifdef DOSFILE
1242# MinGW on WIN98: linking cannot handle $(OPTS), use $(LCFLAGS) instead of $(CFLAGS)
1243	$(CC) $(LCFLAGS) $(LDFLAGS) -o $(BIN)/$(EXENAME) \
1244	$(MAINOBJ) $(OBJS) \
1245	$(LIBS)
1246else
1247# Linux/BSD
1248ifdef CC_EXE_LAST
1249	$(CC) $(CFLAGS) $(LDFLAGS) $(OBJS) $(MAINOBJ) \
1250	$(LIBS) -o $(BIN)/$(EXENAME)
1251else
1252	$(CC) $(CFLAGS) $(LDFLAGS) -o $(BIN)/$(EXENAME) \
1253	$(MAINOBJ) $(OBJS) \
1254	$(LIBS)
1255endif
1256endif
1257
1258
1259#=======================================================
1260
1261# obj rules
1262
1263vpath %.o $(O)
1264
1265#$(O)/*.o : doomdef.h
1266
1267$(O)/r_draw.o : $(SD)r_draw.c $(SD)r_draw8.c $(SD)r_draw16.c $(SD)r_draw24.c $(SD)r_draw32.c
1268
1269
1270# common obj rules
1271
1272$(O)/%.o: $(SD)%.c
1273	$(CC) $(CFLAGS) -c $< -o $@
1274
1275$(O)/%.o: $(SD)$(INTERFACE)/%.c
1276	$(CC) $(CFLAGS) -c $< -o $@
1277
1278$(O)/%.o: $(SD)hardware/%.c
1279	$(CC) $(CFLAGS) -c $< -o $@
1280
1281ifeq ($(SMIF), OS2_NATIVE)
1282# OS2 rules
1283$(O)/%.res: $(SD)os2/%.rc
1284	rc.exe -i $(SD)os2 -r $< $@
1285endif
1286
1287
1288ifeq ($(SMIF), SDL)
1289# SDL
1290# OpenGL rules
1291$(O)/r_opengl.o: $(SD)hardware/r_opengl/r_opengl.c $(SD)hardware/r_opengl/r_opengl.h
1292	$(CC) $(CFLAGS) -c $< -o $@
1293
1294ifdef MAC
1295# Mac must have Objective-C main for SDL
1296$(O)/SDLmain.o : $(SD)sdl/SDLmain.m
1297	$(CC) -x objective-c $(CFLAGS) $(FRAMEWORK) -c $< -o $@
1298endif
1299
1300else
1301# Not SDL
1302# OpenGL rules
1303# LINUX_X11, FREEBSD_X11 at least
1304$(O)/r_opengl.o: $(SD)hardware/r_opengl/r_opengl.c $(SD)hardware/r_opengl/r_opengl.h
1305	$(CC) $(CFLAGS) -shared -nostartfiles -c $< -o $@
1306endif
1307
1308
1309$(O)/ogl_x11.o:  $(SD)hardware/r_opengl/ogl_x11.c $(SD)hardware/r_opengl/r_opengl.h
1310	$(CC) $(CFLAGS) -shared -nostartfiles -I/usr/X11R6/include -c $< -o $@
1311
1312
1313ifdef USEASM
1314# Assembly rules
1315$(O)/tmap.o: $(SD)tmap.nas
1316	nasm -o $@ -f $(NASMFORMAT) $<
1317
1318$(O)/vid_copy.o: $(SD)vid_copy.s
1319	$(CC) $(OPTS) $(OPTINC) $(SFLAGS) -x assembler-with-cpp -c $< -o $@
1320endif
1321
1322
1323# stop searches for re-building source files
1324
1325*.c :
1326	@:
1327
1328*/*.c :
1329	@:
1330
1331hardware/*/*.c :
1332	@:
1333
1334hardware/*/*/*.c :
1335	@:
1336
1337*.h :
1338	@:
1339
1340*/*.h :
1341	@:
1342
1343hardware/*/*.h :
1344	@:
1345
1346hardware/*/*/*.h :
1347	@:
1348
1349# Do not remake makefile
1350
1351Makefile:
1352	@:
1353
1354#=======================================================
1355#[WDJ] Dependencies, replaces makedep.mak, which was unmaintained.
1356
1357ifndef FORCE_AUTO_DEP
1358# This PHONY disables automatic dep file generation when a file changes.
1359# Define FORCE_AUTO_DEP to have automatic dep file generation.
1360.PHONY : $(DD)/*.dep
1361endif
1362
1363.PHONY : depend
1364depend:  $(DD)/main1.dep $(DD)/main3.dep $(DD)/main4.dep $(DD)/main5.dep \
1365 $(DD)/main_d.dep $(DD)/main_m.dep \
1366 $(DD)/main_p1.dep $(DD)/main_p2.dep $(DD)/main_p3.dep $(DD)/main_ph.dep \
1367 $(DD)/main_r.dep $(DD)/main_t.dep
1368
1369$(DD)/main1.dep : $(SD)a*.c $(SD)b*.c $(SD)c*.c
1370$(DD)/main3.dep : $(SD)q*.c $(SD)s*.c
1371$(DD)/main4.dep : $(SD)f*.c $(SD)g*.c $(SD)h*.c $(SD)i*.c
1372$(DD)/main5.dep : $(SD)v*.c $(SD)w*.c $(SD)z*.c
1373$(DD)/main_d.dep : $(SD)d*.c
1374$(DD)/main_m.dep : $(SD)m*.c
1375$(DD)/main_p1.dep : $(SD)p_c*.c $(SD)p_d*.c $(SD)p_e*.c $(SD)p_f*.c
1376$(DD)/main_p2.dep : $(SD)p_g*.c $(SD)p_i*.c $(SD)p_l*.c $(SD)p_m*.c
1377$(DD)/main_p3.dep : $(SD)p_p*.c $(SD)p_s*.c $(SD)p_t*.c $(SD)p_u*.c
1378$(DD)/main_ph.dep : $(SD)p_h*.c
1379$(DD)/main_r.dep : $(SD)r*.c
1380$(DD)/main_t.dep : $(SD)t*.c
1381# none: e*.c j*.c k*.c l*.c n*.c o*.c u*.c x*.c y*.c
1382
1383ifdef INTERFACE
1384depend: $(DD)/$(INTERFACE).dep
1385endif
1386# $(INTERFACE).dep : $(SD)$(INTERFACE)/*.c
1387$(DD)/djgppdos.dep : $(SD)djgppdos/*.c
1388$(DD)/linux_x.dep : $(SD)linux_x/*.c $(SD)linux_x/musserv/*.c $(SD)linux_x/sndserv/*.c
1389$(DD)/os_2.dep : $(SD)os2/*.c
1390$(DD)/macos.dep : $(SD)macos/*.c
1391$(DD)/sdl.dep : $(SD)sdl/*.c
1392$(DD)/win32.dep : $(SD)win32/*.c
1393
1394ifdef DEP_HARD
1395depend: $(DD)/hard1.dep
1396$(DD)/hard1.dep : $(SD)hardware/*.c
1397endif
1398
1399ifdef DEP_OPENGL
1400depend: $(DD)/hardgl.dep
1401$(DD)/hardgl.dep : $(SD)hardware/r_opengl/r_opengl.c
1402endif
1403
1404ifdef DEP_DD
1405# Direct-draw dependent dep.
1406depend: $(DD)/hardwin.dep
1407$(DD)/hardwin.dep : $(SD)hardware/r_d3d/*.cpp
1408$(DD)/hardwin.dep : $(SD)hardware/s_ds3d/*.c
1409$(DD)/hardwin.dep : $(SD)hardware/r_glide/*.c
1410endif
1411
1412ifdef DEP_MINIGL
1413depend: $(DD)/hardmini.dep
1414$(DD)/hardmini.dep : $(SD)hardware/r_minigl/*.c
1415endif
1416
1417ifdef DEP_X11
1418depend: $(DD)/hardx11.dep
1419$(DD)/hardx11.dep : $(SD)hardware/r_opengl/ogl_x11.c
1420$(DD)/hardx11.dep : $(SD)hardware/r_opengl/r_opengl.c
1421endif
1422
1423ifdef DOSFILE
1424# Fixdep adds the obj directory to the dep entries.
1425# The dep entries use / in MinGW.
1426
1427ifdef HAVE_MSYS
1428  # MSYS make cannot handle DOS directories either.
1429  FIXDEP:=$(BIN)/fixdep.exe
1430else
1431  FIXDEP:=$(BIN_WIN)\fixdep.exe
1432endif
1433
1434$(FIXDEP):
1435	$(MAKE) -C ..  fixdep
1436
1437%.dep : | $(FIXDEP)
1438  ifeq ($(CC_SELECT), MINGW)
1439	@echo "Making MINGW dependencies $(@F)"
1440   ifdef HAVE_DOSCOMMAND
1441	$(CC) $(CFLAGS) -MM $^ > $(DD_WIN)\$(@F)
1442   else
1443	$(CC) $(CFLAGS) -MM $^ > $(DD)/$(@F)
1444   endif
1445	$(FIXDEP)  $(O)/  $(DD_WIN)\$(@F)
1446  else
1447	@echo "Making WIN dependencies $(@F)"
1448	$(CC) $(CFLAGS) -MM $^ > $(DD_WIN)\$(@F)
1449	$(FIXDEP)  $(O_WIN)\  $(DD_WIN)\$(@F)
1450  endif
1451
1452else
1453# Linux uses sed to add the obj directory to the dep entries.
1454
1455%.dep :
1456	@echo "Making dependencies $(@F)"
1457	$(CC) $(CFLAGS) -MM $^ > $(DD)/$(@F)
1458	sed -e "s!^[a-zA-Z0-9_]*\.o:!\$$\(O)/&!" $(DD)/$(@F) > $(DD)/sed.dep
1459	mv $(DD)/sed.dep $(DD)/$(@F)
1460
1461endif
1462
1463
1464# Stop update of include files when clean
1465ifdef MAKE_OPTIONS_PRESENT
1466ifdef INCLUDE_DEPS
1467include $(DD)/main1.dep
1468include $(DD)/main3.dep
1469include $(DD)/main4.dep
1470include $(DD)/main5.dep
1471include $(DD)/main_d.dep
1472include $(DD)/main_p1.dep
1473include $(DD)/main_p2.dep
1474include $(DD)/main_p3.dep
1475include $(DD)/main_ph.dep
1476include $(DD)/main_m.dep
1477include $(DD)/main_r.dep
1478include $(DD)/main_t.dep
1479include $(DD)/hard1.dep
1480ifdef INTERFACE
1481 include $(DD)/$(INTERFACE).dep
1482endif
1483ifdef DEP_OPENGL
1484 include $(DD)/hardgl.dep
1485endif
1486ifdef DEP_DD
1487 include $(DD)/hardwin.dep
1488endif
1489ifdef DEP_MINIGL
1490 include $(DD)/hardmini.dep
1491endif
1492ifdef DEP_X11
1493 include $(DD)/hardx11.dep
1494endif
1495endif
1496endif
1497
1498#=======================================================
1499# Install binaries
1500
1501INSTALL_FILES:=$(addprefix $(BIN)/, $(EXENAME) $(INSTALL_SUPPL))
1502ifdef DOSFILE
1503  ifdef HAVE_DOSCOMMAND
1504    RMFILE ?= del
1505  else
1506    RMFILE ?= rm -v
1507  endif
1508  INSTALL_FILES_WIN:=$(subst /,\,$(INSTALL_FILES))
1509else
1510  RMFILE ?= rm -I -v
1511endif
1512
1513INSTALL ?= install
1514export INSTALL
1515
1516install:
1517ifdef HAVE_DOSCOMMAND
1518	xcopy $(INSTALL_FILES_WIN) $(INSTALL_DIR) /S /E
1519else
1520	$(INSTALL) $(INSTALL_OPTS) -t $(INSTALL_DIR)  $(INSTALL_FILES)
1521endif
1522ifdef MUSSERV
1523	cd $(SD)$(MUSSERV) && $(MAKE) install INSTALL_DIR=$(abspath $(INSTALL_DIR))
1524endif
1525ifdef SNDSERV
1526	cd $(SD)$(SNDSERV) && $(MAKE) install INSTALL_DIR=$(abspath $(INSTALL_DIR))
1527endif
1528
1529uninstall:
1530ifdef HAVE_DOSCOMMAND
1531	- $(RMFILE) $(subst /,\,$(INSTALL_DIR)/$(EXENAME))
1532  ifdef INSTALL_SUPPL
1533	- $(RMFILE) $(subst /,\,$(INSTALL_DIR)/$(INSTALL_SUPPL))
1534  endif
1535else
1536	- cd $(INSTALL_DIR) && $(RMFILE) $(notdir $(INSTALL_FILES))
1537endif
1538ifdef MUSSERV
1539	cd $(SD)$(MUSSERV) && $(MAKE) uninstall INSTALL_DIR=$(abspath $(INSTALL_DIR))
1540endif
1541ifdef SNDSERV
1542	cd $(SD)$(SNDSERV) && $(MAKE) uninstall INSTALL_DIR=$(abspath $(INSTALL_DIR))
1543endif
1544
1545
1546#############################################################
1547#
1548#############################################################
1549