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