fixed using parameters not defined in function signature
[rocksndiamonds.git] / src / Makefile
1 # =============================================================================
2 # Rocks'n'Diamonds - McDuffin Strikes Back!
3 # -----------------------------------------------------------------------------
4 # (c) 1995-2014 by Artsoft Entertainment
5 #                  Holger Schemel
6 #                  info@artsoft.org
7 #                  http://www.artsoft.org/
8 # -----------------------------------------------------------------------------
9 # src/Makefile
10 # =============================================================================
11
12 # -----------------------------------------------------------------------------
13 # configuration
14 # -----------------------------------------------------------------------------
15
16 .EXPORT_ALL_VARIABLES:
17
18 ifndef PLATFORM                         # unknown platform -- default to Unix
19 PLATFORM = unix
20 endif
21
22 AR = ar
23 RANLIB = ranlib
24 ETAGS = etags
25 RM = rm -f
26
27 CONVERT = convert
28 WINDRES = windres
29
30 CONVERT_ICON_ARGS = -transparent black -background transparent
31
32 PROGBASE = rocksndiamonds
33
34 ifdef SPECIAL_EDITION                   # create special edition
35 PROGBASE = $(SPECIAL_EDITION)
36 endif
37
38 PROGNAME = ../$(PROGBASE)
39
40
41 # -----------------------------------------------------------------------------
42 # configuring platform
43 # -----------------------------------------------------------------------------
44
45 ifeq ($(PLATFORM),solaris)              # compiling on Solaris
46 EXTRA_LDFLAGS = -lnsl -lsocket -R$(XLIB_PATH)
47 override PLATFORM = unix
48 endif
49
50 ifeq ($(PLATFORM),macosx)               # compiling on Mac OS X
51 EXTRA_LDFLAGS = -lstdc++
52 override PLATFORM = unix
53 endif
54
55 ifeq ($(PLATFORM),unix)                 # compiling on Unix/Linux (generic)
56 PROFILING_FLAGS = -pg
57 endif
58
59 ifeq ($(PLATFORM),cross-win32)          # cross-compiling to Windows
60 PROGNAME = ../$(PROGBASE).exe
61 EXTRA_LDFLAGS = -lshfolder -lwsock32
62 endif
63
64
65 # -----------------------------------------------------------------------------
66 # configuring target
67 # -----------------------------------------------------------------------------
68
69 ifndef TARGET                           # auto-detect compiling for SDL or SDL2
70   SDL_VERSION := $(shell sdl2-config --version 2> /dev/null)
71   ifdef SDL_VERSION
72     TARGET = sdl2
73   else
74     SDL_VERSION := $(shell sdl-config --version 2> /dev/null)
75     ifdef SDL_VERSION
76       TARGET = sdl
77     else
78       $(error SDL/SDL2 library not found)
79     endif
80   endif
81 endif
82
83 ifeq ($(STATIC),true)                   # check for static linking
84 override TARGET := $(TARGET)-static
85 endif
86
87 # $(info Using SDL version $(SDL_VERSION) [TARGET == $(TARGET)])
88
89 ifeq ($(TARGET),sdl)                    # compiling for SDL target
90 SYS_CFLAGS = -DTARGET_SDL $(shell sdl-config --cflags)
91 SDL_LIBS = -lSDL_image -lSDL_mixer -lSDL_net -lsmpeg
92 SYS_LDFLAGS = $(SDL_LIBS) $(shell sdl-config --libs)
93 endif
94
95 ifeq ($(TARGET),sdl2)                   # compiling for SDL2 target
96 SYS_CFLAGS = -DTARGET_SDL2 $(shell sdl2-config --cflags)
97 SDL_LIBS = -lSDL2_image -lSDL2_mixer -lSDL2_net -lsmpeg2
98 SYS_LDFLAGS = $(SDL_LIBS) $(shell sdl2-config --libs)
99 endif
100
101 ifeq ($(TARGET),sdl-static)             # compiling for SDL target (static)
102 SYS_CFLAGS = -DTARGET_SDL $(shell sdl-config --cflags)
103 SDL_LIBS = -lSDL_image -lSDL_mixer -lSDL_net -lsmpeg -lmikmod
104 SYS_LDFLAGS = $(SDL_LIBS) $(shell sdl-config --static-libs)
105 endif
106
107 ifeq ($(TARGET),sdl2-static)            # compiling for SDL2 target (static)
108 SYS_CFLAGS = -DTARGET_SDL2 $(shell sdl2-config --cflags)
109 SDL_LIBS = -lSDL2_image -lSDL2_mixer -lSDL2_net -lsmpeg2 -lmikmod
110 SYS_LDFLAGS = $(SDL_LIBS) $(shell sdl2-config --static-libs)
111 endif
112
113
114 # -----------------------------------------------------------------------------
115 # configuring compile-time definitions
116 # -----------------------------------------------------------------------------
117
118 ifdef RO_GAME_DIR                       # path to read-only game data specified
119 CONFIG_RO_GAME_DIR = -DRO_GAME_DIR="\"$(RO_GAME_DIR)\""
120 endif
121
122 ifdef RW_GAME_DIR                       # path to writable game data specified
123 CONFIG_RW_GAME_DIR = -DRW_GAME_DIR="\"$(RW_GAME_DIR)\""
124 endif
125
126 ifdef SCORE_ENTRIES                     # number of score entries per player
127 CONFIG_SCORE_ENTRIES = -D$(SCORE_ENTRIES)
128 endif
129
130 ifdef SPECIAL_EDITION
131 ifeq ($(SPECIAL_EDITION),rnd_jue)       # create special edition
132 CONFIG_SPECIAL = -DCREATE_SPECIAL_EDITION -DCREATE_SPECIAL_EDITION_RND_JUE
133 endif
134 endif
135
136 CONFIG_GAME_DIR = $(CONFIG_RO_GAME_DIR) $(CONFIG_RW_GAME_DIR)
137 CONFIG_GAME = $(CONFIG_GAME_DIR) $(CONFIG_SCORE_ENTRIES) $(CONFIG_SPECIAL)
138
139 CONFIG = $(CONFIG_GAME) $(JOYSTICK)
140 DEBUG = -DDEBUG -g
141 # PROFILING = $(PROFILING_FLAGS)
142
143 # OPTIONS = $(DEBUG) -Wall                      # only for debugging purposes
144 # OPTIONS = $(DEBUG) -O3 -Wall                  # only for debugging purposes
145 OPTIONS = $(DEBUG) -Wall                        # only for debugging purposes
146 # OPTIONS = $(DEBUG) -Wall -ansi -pedantic      # only for debugging purposes
147 # OPTIONS = -O3 -Wall -ansi -pedantic
148 # OPTIONS = -O3 -Wall
149 # OPTIONS = -O3
150 # OPTIONS = -DSYSV -Ae                  # may be needed for HP-UX
151
152 ifdef BUILD_DIST                        # distribution build
153 OPTIONS = -O3 -Wall
154 endif
155
156 CFLAGS = $(OPTIONS) $(SYS_CFLAGS)  $(EXTRA_CFLAGS) $(CONFIG)
157 LDFLAGS =           $(SYS_LDFLAGS) $(EXTRA_LDFLAGS) -lm
158
159
160 SRCS =  main.c          \
161         conf_gfx.c      \
162         conf_snd.c      \
163         conf_mus.c      \
164         conf_hlp.c      \
165         init.c          \
166         config.c        \
167         events.c        \
168         tools.c         \
169         screens.c       \
170         game.c          \
171         editor.c        \
172         files.c         \
173         tape.c          \
174         cartoons.c      \
175         network.c       \
176         netserv.c
177
178 OBJS =  main.o          \
179         conf_gfx.o      \
180         conf_snd.o      \
181         conf_mus.o      \
182         conf_hlp.o      \
183         init.o          \
184         config.o        \
185         events.o        \
186         tools.o         \
187         screens.o       \
188         game.o          \
189         editor.o        \
190         files.o         \
191         tape.o          \
192         cartoons.o      \
193         network.o       \
194         netserv.o
195
196 CNFS =  conf_gfx.h      \
197         conf_snd.h      \
198         conf_mus.h      \
199         conf_chr.c      \
200         conf_chr.h      \
201         conf_cus.c      \
202         conf_cus.h      \
203         conf_grp.c      \
204         conf_grp.h      \
205         conf_e2g.c      \
206         conf_esg.c      \
207         conf_e2s.c      \
208         conf_fnt.c      \
209         conf_g2s.c      \
210         conf_g2m.c      \
211         conf_var.c      \
212         conf_act.c
213
214 CNFS_CMD = ../build-scripts/create_element_defs.pl
215
216 TIMESTAMP_FILE = conftime.h
217
218 LIBGAME_DIR = libgame
219 LIBGAME = $(LIBGAME_DIR)/libgame.a
220
221 GAME_EM_DIR = game_em
222 GAME_EM = $(GAME_EM_DIR)/game_em.a
223
224 GAME_SP_DIR = game_sp
225 GAME_SP = $(GAME_SP_DIR)/game_sp.a
226
227 RNDLIBS = $(LIBGAME) $(GAME_EM) $(GAME_SP)
228 AUTOCONF = conf_gfx.h conf_snd.h conf_mus.h
229
230 ICONBASE = windows_icon
231 ICON_BASEPATH = ../Special/Icons/windows_icons
232 ifeq ($(PLATFORM),cross-win32)
233 ifdef SPECIAL_EDITION
234 # ICONSUFFIX = 32x32_$(SPECIAL_EDITION)
235 ICON_PATH = $(ICON_BASEPATH)/$(SPECIAL_EDITION)
236 else
237 # ICONSUFFIX = 32x32
238 ICON_PATH = $(ICON_BASEPATH)/default
239 endif
240 # ICON32X32 = ../graphics/$(ICONBASE)_$(ICONSUFFIX).bmp
241 ICON = $(ICONBASE).o
242 endif
243
244 GRAPHICS_DIR = ../graphics
245
246
247 # -----------------------------------------------------------------------------
248 # build targets
249 # -----------------------------------------------------------------------------
250
251 all: $(AUTOCONF) libgame_dir game_em_dir game_sp_dir $(PROGNAME) graphics_dir
252
253 $(PROGNAME): $(RNDLIBS) $(TIMESTAMP_FILE) $(OBJS) $(ICON)
254         $(CC) $(PROFILING) $(OBJS) $(ICON) $(RNDLIBS) $(LDFLAGS) -o $(PROGNAME)
255
256 libgame_dir:
257         @$(MAKE) -C $(LIBGAME_DIR)
258 $(LIBGAME):
259         @$(MAKE) -C $(LIBGAME_DIR)
260
261 game_em_dir:
262         @$(MAKE) -C $(GAME_EM_DIR)
263 $(GAME_EM):
264         @$(MAKE) -C $(GAME_EM_DIR)
265
266 game_sp_dir:
267         @$(MAKE) -C $(GAME_SP_DIR)
268 $(GAME_SP):
269         @$(MAKE) -C $(GAME_SP_DIR)
270
271 auto-conf:
272         @for i in $(CNFS); do                   \
273                 echo "$(CNFS_CMD) $$i > $$i";   \
274                 $(CNFS_CMD) $$i > $$i;          \
275         done
276
277 auto-conf-clean:
278         @for i in $(CNFS); do                   \
279                 echo "$(RM) $$i";               \
280                 $(RM) $$i;                      \
281         done
282
283 conf_gfx.h: conf_gfx.c $(CNFS_CMD)
284         @$(MAKE) auto-conf
285
286 conf_snd.h: conf_snd.c $(CNFS_CMD)
287         @$(MAKE) auto-conf
288
289 conf_mus.h: conf_mus.c $(CNFS_CMD)
290         @$(MAKE) auto-conf
291
292 # $(TIMESTAMP_FILE): $(SRCS) $(LIBGAME) $(GAME_EM) $(GAME_SP)
293 $(TIMESTAMP_FILE): $(SRCS) $(RNDLIBS)
294         @date '+"%Y-%m-%d %H:%M"' \
295         | sed -e 's/^/#define COMPILE_DATE_STRING /' \
296         > $(TIMESTAMP_FILE)
297
298 $(ICON):
299 #       $(CONVERT) $(ICON32X32) $(CONVERT_ICON_ARGS) $(ICONBASE).ico
300         $(CONVERT) $(ICON_PATH)/*.png $(CONVERT_ICON_ARGS) $(ICONBASE).ico
301         echo "$(ICONBASE) ICON $(ICONBASE).ico" | $(WINDRES) -o $(ICON)
302
303 .c.o:
304         $(CC) $(PROFILING) $(CFLAGS) -c $*.c
305
306 graphics_dir:
307         @$(MAKE) -C $(GRAPHICS_DIR)
308
309 clean-obj:
310         $(MAKE) -C $(LIBGAME_DIR) clean
311         $(MAKE) -C $(GAME_EM_DIR) clean
312         $(MAKE) -C $(GAME_SP_DIR) clean
313         $(RM) $(OBJS)
314         $(RM) $(RNDLIBS)
315 #       $(RM) $(LIBGAME)
316 #       $(RM) $(GAME_EM)
317 #       $(RM) $(GAME_SP)
318
319 clean-ico:
320         $(RM) $(ICONBASE).ico
321         $(RM) $(ICONBASE).o
322
323 clean-bin:
324         $(RM) $(PROGNAME)
325         $(RM) ../*.exe
326
327 clean: clean-obj clean-ico clean-bin
328
329 clean-git: clean auto-conf-clean
330         @$(MAKE) -C $(GRAPHICS_DIR) clean
331
332
333 # -----------------------------------------------------------------------------
334 # run and test targets
335 # -----------------------------------------------------------------------------
336
337 run:
338         cd .. && ./$(PROGBASE) --verbose
339
340 gdb:
341         cd .. && gdb -batch -x GDB_COMMANDS ./$(PROGBASE)
342
343 valgrind:
344         cd .. && valgrind -v --leak-check=yes ./$(PROGBASE) 2> valgrind.out
345
346
347 # -----------------------------------------------------------------------------
348 # development only
349 # -----------------------------------------------------------------------------
350
351 dist-clean: clean-obj
352
353 tags:
354         $(ETAGS) *.[ch] $(LIBGAME_DIR)/*.[ch] $(GAME_EM_DIR)/*.[ch] $(GAME_SP_DIR)/*.[ch]
355
356 depend:
357         $(MAKE) -C $(LIBGAME_DIR) depend
358         $(MAKE) -C $(GAME_EM_DIR) depend
359         $(MAKE) -C $(GAME_SP_DIR) depend
360         for i in $(SRCS); do $(CPP) $(CFLAGS) -M $$i; done > .depend
361
362 ifeq (.depend,$(wildcard .depend))
363 include .depend
364 endif