1 # =============================================================================
2 # Rocks'n'Diamonds - McDuffin Strikes Back!
3 # -----------------------------------------------------------------------------
4 # (c) 1995-2015 by Artsoft Entertainment
7 # https://www.artsoft.org/
8 # -----------------------------------------------------------------------------
10 # =============================================================================
12 # -----------------------------------------------------------------------------
14 # -----------------------------------------------------------------------------
16 .EXPORT_ALL_VARIABLES:
18 ifndef PLATFORM # unknown platform -- default to Unix
22 PLATFORM_BASE = $(PLATFORM)
24 ifeq ($(PLATFORM),cross-win32)
25 PLATFORM_BASE = cross-win
27 ifeq ($(PLATFORM),cross-win64)
28 PLATFORM_BASE = cross-win
40 CONVERT_ICON_ARGS = -transparent black -background transparent
42 DEBUGGER = gdb -batch -ex "run" -ex "bt"
44 PROGBASE = rocksndiamonds
45 PROGNAME = ../$(PROGBASE)
50 # -----------------------------------------------------------------------------
51 # configuring platform
52 # -----------------------------------------------------------------------------
54 ifeq ($(PLATFORM),unix) # compiling on Unix/Linux (generic)
58 ifeq ($(PLATFORM_BASE),cross-win) # cross-compiling to Windows
59 PROGNAME = ../$(PROGBASE).exe
60 EXTRA_LDFLAGS = -lshfolder -lwsock32
63 ifeq ($(PLATFORM),emscripten) # compiling with Emscripten
64 PROGNAME = ../$(PROGBASE).js
71 ifeq ($(shell uname -s),Darwin) # compiling on Mac OS X
72 DEBUGGER = lldb --batch -o "run" -k "bt" -k "quit"
73 ifdef BUILD_DIST # distribution build
74 MAC_TARGET_VERSION_MIN = 10.7
75 EXTRA_FLAGS_MAC = -mmacosx-version-min=$(MAC_TARGET_VERSION_MIN)
76 EXTRA_CFLAGS = $(EXTRA_FLAGS_MAC)
77 EXTRA_LDFLAGS = $(EXTRA_FLAGS_MAC)
78 MACOSX_DEPLOYMENT_TARGET = $MAC_TARGET_VERSION_MIN
83 # -----------------------------------------------------------------------------
85 # -----------------------------------------------------------------------------
87 ifndef TARGET # auto-detect compiling for SDL2
88 SDL_VERSION := $(shell sdl2-config --version 2> /dev/null)
92 $(error SDL2 library not found)
96 # $(info Using SDL version $(SDL_VERSION) [TARGET == $(TARGET)])
98 ifeq ($(TARGET),sdl2) # compiling for SDL2 target
99 ifeq ($(PLATFORM),emscripten)
100 SDL_LIBS = -s USE_SDL_IMAGE=2 -s USE_SDL_MIXER=2 -s USE_SDL_NET=2 -s USE_ZLIB=1
101 SDL_FMTS = -s SDL2_IMAGE_FORMATS='["bmp","png","pcx","xpm"]'
102 EXTRA_CFLAGS = $(SDL_LIBS)
103 EXTRA_LDFLAGS = $(SDL_FMTS) -s INITIAL_MEMORY=81920000 -s ALLOW_MEMORY_GROWTH=1 --preload-file ../graphics/ --preload-file ../sounds/ --preload-file ../levels/ --preload-file ../music/ -s NO_EXIT_RUNTIME=0 -s ASYNCIFY -O2 -lidbfs.js
105 SDL_LIBS = -lSDL2_image -lSDL2_mixer -lSDL2_net
108 SYS_CFLAGS := -DTARGET_SDL2 $(shell sdl2-config --cflags)
109 SYS_LDFLAGS := $(SDL_LIBS) $(shell sdl2-config --libs) -lm -lz
113 # -----------------------------------------------------------------------------
114 # configuring compile-time definitions
115 # -----------------------------------------------------------------------------
117 ifdef BASE_PATH # path to read-only game data
118 CONFIG_BASE_PATH = -DBASE_PATH="\"$(BASE_PATH)\""
121 CONFIG = $(CONFIG_BASE_PATH) $(JOYSTICK)
125 # PROFILING = $(PROFILING_FLAGS)
127 # OPTIONS = $(DEBUG) -Wall # only for debugging purposes
128 # OPTIONS = $(DEBUG) -O2 -Wall # only for debugging purposes
129 # OPTIONS = $(DEBUG) -Wall # only for debugging purposes
130 OPTIONS = $(DEBUG) -Wall -Wstrict-prototypes -Wmissing-prototypes
131 # OPTIONS = $(DEBUG) -Wall -ansi -pedantic # only for debugging purposes
132 # OPTIONS = -O2 -Wall -ansi -pedantic
133 # OPTIONS = -O2 -Wall
136 ifdef BUILD_DIST # distribution build
137 SYS_LDFLAGS := $(shell echo $(SYS_LDFLAGS) | \
138 sed -e "s%-rpath,[^ ]*%-rpath,'\$$ORIGIN/lib'%")
142 CFLAGS = $(OPTIONS) $(SYS_CFLAGS) $(EXTRA_CFLAGS) $(CONFIG)
143 LDFLAGS = $(SYS_LDFLAGS) $(EXTRA_LDFLAGS)
200 CNFS_CMD = ../build-scripts/create_element_defs.pl
202 TIMESTAMP_FILE = conftime.h
203 TIMESTAMP_FORMAT = %Y-%m-%d %H:%M
205 # use SOURCE_DATE_EPOCH, or else last Git commit date, or else current date
206 SOURCE_DATE_EPOCH ?= $(shell test -d ../.git && test `git ls-files -m | wc -l` -eq 0 && git show -s --format=%ct || date +%s)
208 # get source date string from either GNU / Linux or BSD / Mac OS X style "date"
209 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)")
211 COMMIT_HASH_FILE = confhash.h
212 COMMIT_HASH_NONE = "[changed files]"
214 # get last Git commit hash, if no files were changed
215 SOURCE_HASH_STRING ?= $(shell test -d ../.git && test `git ls-files -m | wc -l` -eq 0 && git show -s --format=%h || echo "$(COMMIT_HASH_NONE)")
217 LIBGAME_DIR = libgame
218 LIBGAME = $(LIBGAME_DIR)/libgame.a
220 GAME_EM_DIR = game_em
221 GAME_EM = $(GAME_EM_DIR)/game_em.a
223 GAME_SP_DIR = game_sp
224 GAME_SP = $(GAME_SP_DIR)/game_sp.a
226 GAME_MM_DIR = game_mm
227 GAME_MM = $(GAME_MM_DIR)/game_mm.a
229 RNDLIBS = $(LIBGAME) $(GAME_EM) $(GAME_SP) $(GAME_MM)
230 AUTOCONF = conf_gfx.h conf_snd.h conf_mus.h
232 ICONBASE = windows_icon
233 ICON_BASEPATH = ../Special/Icons/windows_icons
235 ifeq ($(PLATFORM_BASE),cross-win)
236 ICON_PATH = $(ICON_BASEPATH)/$(EDITION)
240 GRAPHICS_DIR = ../graphics
243 # -----------------------------------------------------------------------------
245 # -----------------------------------------------------------------------------
247 all: $(AUTOCONF) libgame_dir game_em_dir game_sp_dir game_mm_dir $(PROGNAME) graphics_dir
249 $(PROGNAME): $(RNDLIBS) $(TIMESTAMP_FILE) $(COMMIT_HASH_FILE) $(OBJS) $(ICON)
250 $(CC) $(PROFILING) $(OBJS) $(ICON) $(RNDLIBS) $(LDFLAGS) -o $(PROGNAME)
256 @$(MAKE) -C $(LIBGAME_DIR)
258 @$(MAKE) -C $(LIBGAME_DIR)
261 @$(MAKE) -C $(GAME_EM_DIR)
263 @$(MAKE) -C $(GAME_EM_DIR)
266 @$(MAKE) -C $(GAME_SP_DIR)
268 @$(MAKE) -C $(GAME_SP_DIR)
271 @$(MAKE) -C $(GAME_MM_DIR)
273 @$(MAKE) -C $(GAME_MM_DIR)
276 @for i in $(CNFS); do \
277 echo "$(CNFS_CMD) $$i > $$i"; \
278 $(CNFS_CMD) $$i > $$i; \
282 @for i in $(CNFS); do \
287 conf_gfx.h: conf_gfx.c $(CNFS_CMD)
290 conf_snd.h: conf_snd.c $(CNFS_CMD)
293 conf_mus.h: conf_mus.c $(CNFS_CMD)
297 @echo '#define SOURCE_DATE_STRING "$(SOURCE_DATE_STRING)"' \
301 @echo '#define SOURCE_HASH_STRING "$(SOURCE_HASH_STRING)"' \
302 > $(COMMIT_HASH_FILE)
304 $(TIMESTAMP_FILE): $(SRCS) $(RNDLIBS)
307 $(COMMIT_HASH_FILE): $(SRCS) $(RNDLIBS)
311 # $(CONVERT) $(ICON32X32) $(CONVERT_ICON_ARGS) $(ICONBASE).ico
312 $(CONVERT) $(ICON_PATH)/*.png $(CONVERT_ICON_ARGS) $(ICONBASE).ico
313 echo "$(ICONBASE) ICON $(ICONBASE).ico" | $(WINDRES) -o $(ICON)
316 $(CC) $(PROFILING) $(CFLAGS) -c $*.c
319 @test -f $(GRAPHICS_DIR)/Makefile && $(MAKE) -C $(GRAPHICS_DIR) || true
322 $(MAKE) -C $(LIBGAME_DIR) clean
323 $(MAKE) -C $(GAME_EM_DIR) clean
324 $(MAKE) -C $(GAME_SP_DIR) clean
325 $(MAKE) -C $(GAME_MM_DIR) clean
330 $(RM) $(ICONBASE).ico
335 $(RM) $(PROGNAME).exe
337 $(RM) $(PROGNAME).wasm
338 $(RM) $(PROGNAME).data
340 clean: clean-obj clean-ico clean-bin
342 clean-git: clean auto-conf-clean
343 @$(MAKE) -C $(GRAPHICS_DIR) clean
345 dist-clean: clean-obj clean-ico
348 # -----------------------------------------------------------------------------
349 # run and test targets
350 # -----------------------------------------------------------------------------
353 cd .. && ./$(PROGBASE) --verbose
356 cd .. && $(DEBUGGER) $(PROGBASE)
359 cd .. && valgrind -v --leak-check=yes ./$(PROGBASE) 2> valgrind.out
362 # -----------------------------------------------------------------------------
364 # -----------------------------------------------------------------------------
367 $(ETAGS) *.[ch] $(LIBGAME_DIR)/*.[ch] $(GAME_EM_DIR)/*.[ch] $(GAME_SP_DIR)/*.[ch] $(GAME_MM_DIR)/*.[ch]
370 $(MAKE) -C $(LIBGAME_DIR) depend
371 $(MAKE) -C $(GAME_EM_DIR) depend
372 $(MAKE) -C $(GAME_SP_DIR) depend
373 $(MAKE) -C $(GAME_MM_DIR) depend
374 for i in $(SRCS); do $(CPP) $(CFLAGS) -M $$i; done > .depend
376 ifeq (.depend,$(wildcard .depend))