added sending level file (and level template) for network games
[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 -ansi -pedantic      # only for debugging purposes
112 # OPTIONS = -O3 -Wall -ansi -pedantic
113 # OPTIONS = -O3 -Wall
114 # OPTIONS = -O3
115
116 ifdef BUILD_DIST                        # distribution build
117 SYS_LDFLAGS := $(shell echo $(SYS_LDFLAGS) |    \
118                        sed -e "s%-rpath,[^ ]*%-rpath,'\$$ORIGIN/lib'%")
119 OPTIONS = -O3 -Wall
120 endif
121
122 CFLAGS = $(OPTIONS) $(SYS_CFLAGS)  $(EXTRA_CFLAGS) $(CONFIG)
123 LDFLAGS =           $(SYS_LDFLAGS) $(EXTRA_LDFLAGS) -lm
124
125
126 SRCS =  main.c          \
127         conf_gfx.c      \
128         conf_snd.c      \
129         conf_mus.c      \
130         conf_hlp.c      \
131         init.c          \
132         config.c        \
133         events.c        \
134         tools.c         \
135         screens.c       \
136         game.c          \
137         editor.c        \
138         files.c         \
139         tape.c          \
140         anim.c          \
141         network.c       \
142         netserv.c
143
144 OBJS =  main.o          \
145         conf_gfx.o      \
146         conf_snd.o      \
147         conf_mus.o      \
148         conf_hlp.o      \
149         init.o          \
150         config.o        \
151         events.o        \
152         tools.o         \
153         screens.o       \
154         game.o          \
155         editor.o        \
156         files.o         \
157         tape.o          \
158         anim.o          \
159         network.o       \
160         netserv.o
161
162 CNFS =  conf_gfx.h      \
163         conf_snd.h      \
164         conf_mus.h      \
165         conf_chr.c      \
166         conf_chr.h      \
167         conf_cus.c      \
168         conf_cus.h      \
169         conf_grp.c      \
170         conf_grp.h      \
171         conf_e2g.c      \
172         conf_esg.c      \
173         conf_e2s.c      \
174         conf_fnt.c      \
175         conf_g2s.c      \
176         conf_g2m.c      \
177         conf_var.c      \
178         conf_act.c
179
180 CNFS_CMD = ../build-scripts/create_element_defs.pl
181
182 TIMESTAMP_FILE = conftime.h
183 TIMESTAMP_FORMAT = %Y-%m-%d %H:%M
184
185 # use SOURCE_DATE_EPOCH, or else last Git commit date, or else current date
186 SOURCE_DATE_EPOCH ?= $(shell test -d ../.git && test `git ls-files -m | wc -l` -eq 0 && git show -s --format=%ct || date +%s)
187
188 # get source date string from either GNU / Linux or BSD / Mac OS X style "date"
189 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)")
190
191 LIBGAME_DIR = libgame
192 LIBGAME = $(LIBGAME_DIR)/libgame.a
193
194 GAME_EM_DIR = game_em
195 GAME_EM = $(GAME_EM_DIR)/game_em.a
196
197 GAME_SP_DIR = game_sp
198 GAME_SP = $(GAME_SP_DIR)/game_sp.a
199
200 GAME_MM_DIR = game_mm
201 GAME_MM = $(GAME_MM_DIR)/game_mm.a
202
203 RNDLIBS = $(LIBGAME) $(GAME_EM) $(GAME_SP) $(GAME_MM)
204 AUTOCONF = conf_gfx.h conf_snd.h conf_mus.h
205
206 ICONBASE = windows_icon
207 ICON_BASEPATH = ../Special/Icons/windows_icons
208
209 ifeq ($(PLATFORM),cross-win32)
210 ICON_PATH = $(ICON_BASEPATH)/$(EDITION)
211 ICON = $(ICONBASE).o
212 endif
213
214 GRAPHICS_DIR = ../graphics
215
216
217 # -----------------------------------------------------------------------------
218 # build targets
219 # -----------------------------------------------------------------------------
220
221 all: $(AUTOCONF) libgame_dir game_em_dir game_sp_dir game_mm_dir $(PROGNAME) graphics_dir
222
223 $(PROGNAME): $(RNDLIBS) $(TIMESTAMP_FILE) $(OBJS) $(ICON)
224         $(CC) $(PROFILING) $(OBJS) $(ICON) $(RNDLIBS) $(LDFLAGS) -o $(PROGNAME)
225 ifdef BUILD_DIST
226         strip $(PROGNAME)
227 endif
228
229 libgame_dir:
230         @$(MAKE) -C $(LIBGAME_DIR)
231 $(LIBGAME):
232         @$(MAKE) -C $(LIBGAME_DIR)
233
234 game_em_dir:
235         @$(MAKE) -C $(GAME_EM_DIR)
236 $(GAME_EM):
237         @$(MAKE) -C $(GAME_EM_DIR)
238
239 game_sp_dir:
240         @$(MAKE) -C $(GAME_SP_DIR)
241 $(GAME_SP):
242         @$(MAKE) -C $(GAME_SP_DIR)
243
244 game_mm_dir:
245         @$(MAKE) -C $(GAME_MM_DIR)
246 $(GAME_MM):
247         @$(MAKE) -C $(GAME_MM_DIR)
248
249 auto-conf:
250         @for i in $(CNFS); do                   \
251                 echo "$(CNFS_CMD) $$i > $$i";   \
252                 $(CNFS_CMD) $$i > $$i;          \
253         done
254
255 auto-conf-clean:
256         @for i in $(CNFS); do                   \
257                 echo "$(RM) $$i";               \
258                 $(RM) $$i;                      \
259         done
260
261 conf_gfx.h: conf_gfx.c $(CNFS_CMD)
262         @$(MAKE) auto-conf
263
264 conf_snd.h: conf_snd.c $(CNFS_CMD)
265         @$(MAKE) auto-conf
266
267 conf_mus.h: conf_mus.c $(CNFS_CMD)
268         @$(MAKE) auto-conf
269
270 $(TIMESTAMP_FILE): $(SRCS) $(RNDLIBS)
271         @echo '#define SOURCE_DATE_STRING "$(SOURCE_DATE_STRING)"' \
272         > $(TIMESTAMP_FILE)
273
274 $(ICON):
275 #       $(CONVERT) $(ICON32X32) $(CONVERT_ICON_ARGS) $(ICONBASE).ico
276         $(CONVERT) $(ICON_PATH)/*.png $(CONVERT_ICON_ARGS) $(ICONBASE).ico
277         echo "$(ICONBASE) ICON $(ICONBASE).ico" | $(WINDRES) -o $(ICON)
278
279 .c.o:
280         $(CC) $(PROFILING) $(CFLAGS) -c $*.c
281
282 graphics_dir:
283         @test -f $(GRAPHICS_DIR)/Makefile && $(MAKE) -C $(GRAPHICS_DIR) || true
284
285 clean-obj:
286         $(MAKE) -C $(LIBGAME_DIR) clean
287         $(MAKE) -C $(GAME_EM_DIR) clean
288         $(MAKE) -C $(GAME_SP_DIR) clean
289         $(MAKE) -C $(GAME_MM_DIR) clean
290         $(RM) $(OBJS)
291         $(RM) $(RNDLIBS)
292
293 clean-ico:
294         $(RM) $(ICONBASE).ico
295         $(RM) $(ICONBASE).o
296
297 clean-bin:
298         $(RM) $(PROGNAME)
299         $(RM) ../*.exe
300
301 clean: clean-obj clean-ico clean-bin
302
303 clean-git: clean auto-conf-clean
304         @$(MAKE) -C $(GRAPHICS_DIR) clean
305
306 dist-clean: clean-obj clean-ico
307
308
309 # -----------------------------------------------------------------------------
310 # run and test targets
311 # -----------------------------------------------------------------------------
312
313 run:
314         cd .. && ./$(PROGBASE) --verbose
315
316 gdb:
317         cd .. && gdb -batch -x GDB_COMMANDS ./$(PROGBASE)
318
319 valgrind:
320         cd .. && valgrind -v --leak-check=yes ./$(PROGBASE) 2> valgrind.out
321
322
323 # -----------------------------------------------------------------------------
324 # development only
325 # -----------------------------------------------------------------------------
326
327 tags:
328         $(ETAGS) *.[ch] $(LIBGAME_DIR)/*.[ch] $(GAME_EM_DIR)/*.[ch] $(GAME_SP_DIR)/*.[ch] $(GAME_MM_DIR)/*.[ch]
329
330 depend:
331         $(MAKE) -C $(LIBGAME_DIR) depend
332         $(MAKE) -C $(GAME_EM_DIR) depend
333         $(MAKE) -C $(GAME_SP_DIR) depend
334         $(MAKE) -C $(GAME_MM_DIR) depend
335         for i in $(SRCS); do $(CPP) $(CFLAGS) -M $$i; done > .depend
336
337 ifeq (.depend,$(wildcard .depend))
338 include .depend
339 endif