renamed functions (after removing parameter in previous commit)
[rocksndiamonds.git] / src / Makefile
1 # =============================================================================
2 # Rocks'n'Diamonds - McDuffin Strikes Back!
3 # -----------------------------------------------------------------------------
4 # (c) 1995-2015 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 PROGNAME = ../$(PROGBASE)
34
35 EDITION ?= default
36
37
38 # -----------------------------------------------------------------------------
39 # configuring platform
40 # -----------------------------------------------------------------------------
41
42 ifeq ($(PLATFORM),macosx)               # compiling on Mac OS X
43 EXTRA_LDFLAGS = -lstdc++
44 override PLATFORM = unix
45 endif
46
47 ifeq ($(PLATFORM),unix)                 # compiling on Unix/Linux (generic)
48 PROFILING_FLAGS = -pg
49 endif
50
51 ifeq ($(PLATFORM),cross-win32)          # cross-compiling to Windows
52 PROGNAME = ../$(PROGBASE).exe
53 EXTRA_LDFLAGS = -lshfolder -lwsock32
54 endif
55
56
57 # -----------------------------------------------------------------------------
58 # configuring target
59 # -----------------------------------------------------------------------------
60
61 ifndef TARGET                           # auto-detect compiling for SDL or SDL2
62   SDL_VERSION := $(shell sdl2-config --version 2> /dev/null)
63   ifdef SDL_VERSION
64     TARGET = sdl2
65   else
66     SDL_VERSION := $(shell sdl-config --version 2> /dev/null)
67     ifdef SDL_VERSION
68       TARGET = sdl
69     else
70       $(error SDL/SDL2 library not found)
71     endif
72   endif
73 endif
74
75 # $(info Using SDL version $(SDL_VERSION) [TARGET == $(TARGET)])
76
77 ifeq ($(TARGET),sdl)                    # compiling for SDL target
78 SYS_CFLAGS = -DTARGET_SDL $(shell sdl-config --cflags)
79 SDL_LIBS = -lSDL_image -lSDL_mixer -lSDL_net
80 SYS_LDFLAGS = $(SDL_LIBS) $(shell sdl-config --libs)
81 endif
82
83 ifeq ($(TARGET),sdl2)                   # compiling for SDL2 target
84 SYS_CFLAGS = -DTARGET_SDL2 $(shell sdl2-config --cflags)
85 SDL_LIBS = -lSDL2_image -lSDL2_mixer -lSDL2_net
86 SYS_LDFLAGS = $(SDL_LIBS) $(shell sdl2-config --libs)
87 endif
88
89
90 # -----------------------------------------------------------------------------
91 # configuring compile-time definitions
92 # -----------------------------------------------------------------------------
93
94 ifdef RO_GAME_DIR                       # path to read-only game data specified
95 CONFIG_RO_GAME_DIR = -DRO_GAME_DIR="\"$(RO_GAME_DIR)\""
96 endif
97
98 ifdef RW_GAME_DIR                       # path to writable game data specified
99 CONFIG_RW_GAME_DIR = -DRW_GAME_DIR="\"$(RW_GAME_DIR)\""
100 endif
101
102 CONFIG = $(CONFIG_RO_GAME_DIR) $(CONFIG_RW_GAME_DIR) $(JOYSTICK)
103
104 DEBUG = -DDEBUG -g
105
106 # PROFILING = $(PROFILING_FLAGS)
107
108 # OPTIONS = $(DEBUG) -Wall                      # only for debugging purposes
109 # OPTIONS = $(DEBUG) -O3 -Wall                  # only for debugging purposes
110 # OPTIONS = $(DEBUG) -Wall                      # only for debugging purposes
111 OPTIONS = $(DEBUG) -Wall -Wstrict-prototypes -Wmissing-prototypes
112 # OPTIONS = $(DEBUG) -Wall -ansi -pedantic      # only for debugging purposes
113 # OPTIONS = -O3 -Wall -ansi -pedantic
114 # OPTIONS = -O3 -Wall
115 # OPTIONS = -O3
116
117 ifdef BUILD_DIST                        # distribution build
118 SYS_LDFLAGS := $(shell echo $(SYS_LDFLAGS) |    \
119                        sed -e "s%-rpath,[^ ]*%-rpath,'\$$ORIGIN/lib'%")
120 OPTIONS = -O3 -Wall
121 endif
122
123 CFLAGS = $(OPTIONS) $(SYS_CFLAGS)  $(EXTRA_CFLAGS) $(CONFIG)
124 LDFLAGS =           $(SYS_LDFLAGS) $(EXTRA_LDFLAGS) -lm
125
126
127 SRCS =  main.c          \
128         conf_gfx.c      \
129         conf_snd.c      \
130         conf_mus.c      \
131         conf_hlp.c      \
132         init.c          \
133         config.c        \
134         events.c        \
135         tools.c         \
136         screens.c       \
137         game.c          \
138         editor.c        \
139         files.c         \
140         tape.c          \
141         anim.c          \
142         network.c       \
143         netserv.c
144
145 OBJS =  main.o          \
146         conf_gfx.o      \
147         conf_snd.o      \
148         conf_mus.o      \
149         conf_hlp.o      \
150         init.o          \
151         config.o        \
152         events.o        \
153         tools.o         \
154         screens.o       \
155         game.o          \
156         editor.o        \
157         files.o         \
158         tape.o          \
159         anim.o          \
160         network.o       \
161         netserv.o
162
163 CNFS =  conf_gfx.h      \
164         conf_snd.h      \
165         conf_mus.h      \
166         conf_chr.c      \
167         conf_chr.h      \
168         conf_cus.c      \
169         conf_cus.h      \
170         conf_grp.c      \
171         conf_grp.h      \
172         conf_e2g.c      \
173         conf_esg.c      \
174         conf_e2s.c      \
175         conf_fnt.c      \
176         conf_g2s.c      \
177         conf_g2m.c      \
178         conf_var.c      \
179         conf_act.c
180
181 CNFS_CMD = ../build-scripts/create_element_defs.pl
182
183 TIMESTAMP_FILE = conftime.h
184 TIMESTAMP_FORMAT = %Y-%m-%d %H:%M
185
186 # use SOURCE_DATE_EPOCH, or else last Git commit date, or else current date
187 SOURCE_DATE_EPOCH ?= $(shell test -d ../.git && test `git ls-files -m | wc -l` -eq 0 && git show -s --format=%ct || date +%s)
188
189 # get source date string from either GNU / Linux or BSD / Mac OS X style "date"
190 SOURCE_DATE_STRING := $(shell date -u -d "@$(SOURCE_DATE_EPOCH)" "+$(TIMESTAMP_FORMAT)"  2>/dev/null || date -u -r "$(SOURCE_DATE_EPOCH)" "+$(TIMESTAMP_FORMAT)" 2>/dev/null || date -u "+$(TIMESTAMP_FORMAT)")
191
192 LIBGAME_DIR = libgame
193 LIBGAME = $(LIBGAME_DIR)/libgame.a
194
195 GAME_EM_DIR = game_em
196 GAME_EM = $(GAME_EM_DIR)/game_em.a
197
198 GAME_SP_DIR = game_sp
199 GAME_SP = $(GAME_SP_DIR)/game_sp.a
200
201 GAME_MM_DIR = game_mm
202 GAME_MM = $(GAME_MM_DIR)/game_mm.a
203
204 RNDLIBS = $(LIBGAME) $(GAME_EM) $(GAME_SP) $(GAME_MM)
205 AUTOCONF = conf_gfx.h conf_snd.h conf_mus.h
206
207 ICONBASE = windows_icon
208 ICON_BASEPATH = ../Special/Icons/windows_icons
209
210 ifeq ($(PLATFORM),cross-win32)
211 ICON_PATH = $(ICON_BASEPATH)/$(EDITION)
212 ICON = $(ICONBASE).o
213 endif
214
215 GRAPHICS_DIR = ../graphics
216
217
218 # -----------------------------------------------------------------------------
219 # build targets
220 # -----------------------------------------------------------------------------
221
222 all: $(AUTOCONF) libgame_dir game_em_dir game_sp_dir game_mm_dir $(PROGNAME) graphics_dir
223
224 $(PROGNAME): $(RNDLIBS) $(TIMESTAMP_FILE) $(OBJS) $(ICON)
225         $(CC) $(PROFILING) $(OBJS) $(ICON) $(RNDLIBS) $(LDFLAGS) -o $(PROGNAME)
226 ifdef BUILD_DIST
227         strip $(PROGNAME)
228 endif
229
230 libgame_dir:
231         @$(MAKE) -C $(LIBGAME_DIR)
232 $(LIBGAME):
233         @$(MAKE) -C $(LIBGAME_DIR)
234
235 game_em_dir:
236         @$(MAKE) -C $(GAME_EM_DIR)
237 $(GAME_EM):
238         @$(MAKE) -C $(GAME_EM_DIR)
239
240 game_sp_dir:
241         @$(MAKE) -C $(GAME_SP_DIR)
242 $(GAME_SP):
243         @$(MAKE) -C $(GAME_SP_DIR)
244
245 game_mm_dir:
246         @$(MAKE) -C $(GAME_MM_DIR)
247 $(GAME_MM):
248         @$(MAKE) -C $(GAME_MM_DIR)
249
250 auto-conf:
251         @for i in $(CNFS); do                   \
252                 echo "$(CNFS_CMD) $$i > $$i";   \
253                 $(CNFS_CMD) $$i > $$i;          \
254         done
255
256 auto-conf-clean:
257         @for i in $(CNFS); do                   \
258                 echo "$(RM) $$i";               \
259                 $(RM) $$i;                      \
260         done
261
262 conf_gfx.h: conf_gfx.c $(CNFS_CMD)
263         @$(MAKE) auto-conf
264
265 conf_snd.h: conf_snd.c $(CNFS_CMD)
266         @$(MAKE) auto-conf
267
268 conf_mus.h: conf_mus.c $(CNFS_CMD)
269         @$(MAKE) auto-conf
270
271 $(TIMESTAMP_FILE): $(SRCS) $(RNDLIBS)
272         @echo '#define SOURCE_DATE_STRING "$(SOURCE_DATE_STRING)"' \
273         > $(TIMESTAMP_FILE)
274
275 $(ICON):
276 #       $(CONVERT) $(ICON32X32) $(CONVERT_ICON_ARGS) $(ICONBASE).ico
277         $(CONVERT) $(ICON_PATH)/*.png $(CONVERT_ICON_ARGS) $(ICONBASE).ico
278         echo "$(ICONBASE) ICON $(ICONBASE).ico" | $(WINDRES) -o $(ICON)
279
280 .c.o:
281         $(CC) $(PROFILING) $(CFLAGS) -c $*.c
282
283 graphics_dir:
284         @test -f $(GRAPHICS_DIR)/Makefile && $(MAKE) -C $(GRAPHICS_DIR) || true
285
286 clean-obj:
287         $(MAKE) -C $(LIBGAME_DIR) clean
288         $(MAKE) -C $(GAME_EM_DIR) clean
289         $(MAKE) -C $(GAME_SP_DIR) clean
290         $(MAKE) -C $(GAME_MM_DIR) clean
291         $(RM) $(OBJS)
292         $(RM) $(RNDLIBS)
293
294 clean-ico:
295         $(RM) $(ICONBASE).ico
296         $(RM) $(ICONBASE).o
297
298 clean-bin:
299         $(RM) $(PROGNAME)
300         $(RM) ../*.exe
301
302 clean: clean-obj clean-ico clean-bin
303
304 clean-git: clean auto-conf-clean
305         @$(MAKE) -C $(GRAPHICS_DIR) clean
306
307 dist-clean: clean-obj clean-ico
308
309
310 # -----------------------------------------------------------------------------
311 # run and test targets
312 # -----------------------------------------------------------------------------
313
314 run:
315         cd .. && ./$(PROGBASE) --verbose
316
317 gdb:
318         cd .. && gdb -batch -x GDB_COMMANDS ./$(PROGBASE)
319
320 valgrind:
321         cd .. && valgrind -v --leak-check=yes ./$(PROGBASE) 2> valgrind.out
322
323
324 # -----------------------------------------------------------------------------
325 # development only
326 # -----------------------------------------------------------------------------
327
328 tags:
329         $(ETAGS) *.[ch] $(LIBGAME_DIR)/*.[ch] $(GAME_EM_DIR)/*.[ch] $(GAME_SP_DIR)/*.[ch] $(GAME_MM_DIR)/*.[ch]
330
331 depend:
332         $(MAKE) -C $(LIBGAME_DIR) depend
333         $(MAKE) -C $(GAME_EM_DIR) depend
334         $(MAKE) -C $(GAME_SP_DIR) depend
335         $(MAKE) -C $(GAME_MM_DIR) depend
336         for i in $(SRCS); do $(CPP) $(CFLAGS) -M $$i; done > .depend
337
338 ifeq (.depend,$(wildcard .depend))
339 include .depend
340 endif