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 PROGBASE = rocksndiamonds
43 PROGNAME = ../$(PROGBASE)
48 # -----------------------------------------------------------------------------
49 # configuring platform
50 # -----------------------------------------------------------------------------
52 ifeq ($(PLATFORM),unix) # compiling on Unix/Linux (generic)
56 ifeq ($(PLATFORM_BASE),cross-win) # cross-compiling to Windows
57 PROGNAME = ../$(PROGBASE).exe
58 EXTRA_LDFLAGS = -lshfolder -lwsock32
61 ifeq ($(PLATFORM),emscripten) # compiling with Emscripten
62 PROGNAME = ../$(PROGBASE).js
69 ifdef BUILD_DIST # distribution build
70 ifeq ($(shell uname -s),Darwin) # compiling on Mac OS X
71 MAC_TARGET_VERSION_MIN = 10.7
72 EXTRA_FLAGS_MAC = -mmacosx-version-min=$(MAC_TARGET_VERSION_MIN)
73 EXTRA_CFLAGS = $(EXTRA_FLAGS_MAC)
74 EXTRA_LDFLAGS = $(EXTRA_FLAGS_MAC)
75 MACOSX_DEPLOYMENT_TARGET = $MAC_TARGET_VERSION_MIN
80 # -----------------------------------------------------------------------------
82 # -----------------------------------------------------------------------------
84 ifndef TARGET # auto-detect compiling for SDL2
85 SDL_VERSION := $(shell sdl2-config --version 2> /dev/null)
89 $(error SDL2 library not found)
93 # $(info Using SDL version $(SDL_VERSION) [TARGET == $(TARGET)])
95 ifeq ($(TARGET),sdl2) # compiling for SDL2 target
96 ifeq ($(PLATFORM),emscripten)
97 SDL_LIBS = -s USE_SDL_IMAGE=2 -s USE_SDL_MIXER=2 -s USE_SDL_NET=2 -s USE_ZLIB=1
98 SDL_FMTS = -s SDL2_IMAGE_FORMATS='["bmp","png","pcx","xpm"]'
99 EXTRA_CFLAGS = $(SDL_LIBS)
100 EXTRA_LDFLAGS = $(SDL_FMTS) -s INITIAL_MEMORY=65536000 -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
102 SDL_LIBS = -lSDL2_image -lSDL2_mixer -lSDL2_net
105 SYS_CFLAGS := -DTARGET_SDL2 $(shell sdl2-config --cflags)
106 SYS_LDFLAGS := $(SDL_LIBS) $(shell sdl2-config --libs) -lm -lz
110 # -----------------------------------------------------------------------------
111 # configuring compile-time definitions
112 # -----------------------------------------------------------------------------
114 ifdef RO_GAME_DIR # path to read-only game data specified
115 CONFIG_RO_GAME_DIR = -DRO_GAME_DIR="\"$(RO_GAME_DIR)\""
118 ifdef RW_GAME_DIR # path to writable game data specified
119 CONFIG_RW_GAME_DIR = -DRW_GAME_DIR="\"$(RW_GAME_DIR)\""
122 CONFIG = $(CONFIG_RO_GAME_DIR) $(CONFIG_RW_GAME_DIR) $(JOYSTICK)
126 # PROFILING = $(PROFILING_FLAGS)
128 # OPTIONS = $(DEBUG) -Wall # only for debugging purposes
129 # OPTIONS = $(DEBUG) -O2 -Wall # only for debugging purposes
130 # OPTIONS = $(DEBUG) -Wall # only for debugging purposes
131 OPTIONS = $(DEBUG) -Wall -Wstrict-prototypes -Wmissing-prototypes
132 # OPTIONS = $(DEBUG) -Wall -ansi -pedantic # only for debugging purposes
133 # OPTIONS = -O2 -Wall -ansi -pedantic
134 # OPTIONS = -O2 -Wall
137 ifdef BUILD_DIST # distribution build
138 SYS_LDFLAGS := $(shell echo $(SYS_LDFLAGS) | \
139 sed -e "s%-rpath,[^ ]*%-rpath,'\$$ORIGIN/lib'%")
143 CFLAGS = $(OPTIONS) $(SYS_CFLAGS) $(EXTRA_CFLAGS) $(CONFIG)
144 LDFLAGS = $(SYS_LDFLAGS) $(EXTRA_LDFLAGS)
201 CNFS_CMD = ../build-scripts/create_element_defs.pl
203 TIMESTAMP_FILE = conftime.h
204 TIMESTAMP_FORMAT = %Y-%m-%d %H:%M
206 # use SOURCE_DATE_EPOCH, or else last Git commit date, or else current date
207 SOURCE_DATE_EPOCH ?= $(shell test -d ../.git && test `git ls-files -m | wc -l` -eq 0 && git show -s --format=%ct || date +%s)
209 # get source date string from either GNU / Linux or BSD / Mac OS X style "date"
210 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)")
212 COMMIT_HASH_FILE = confhash.h
213 COMMIT_HASH_NONE = "[changed files]"
215 # get last Git commit hash, if no files were changed
216 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)")
218 LIBGAME_DIR = libgame
219 LIBGAME = $(LIBGAME_DIR)/libgame.a
221 GAME_EM_DIR = game_em
222 GAME_EM = $(GAME_EM_DIR)/game_em.a
224 GAME_SP_DIR = game_sp
225 GAME_SP = $(GAME_SP_DIR)/game_sp.a
227 GAME_MM_DIR = game_mm
228 GAME_MM = $(GAME_MM_DIR)/game_mm.a
230 RNDLIBS = $(LIBGAME) $(GAME_EM) $(GAME_SP) $(GAME_MM)
231 AUTOCONF = conf_gfx.h conf_snd.h conf_mus.h
233 ICONBASE = windows_icon
234 ICON_BASEPATH = ../Special/Icons/windows_icons
236 ifeq ($(PLATFORM_BASE),cross-win)
237 ICON_PATH = $(ICON_BASEPATH)/$(EDITION)
241 GRAPHICS_DIR = ../graphics
244 # -----------------------------------------------------------------------------
246 # -----------------------------------------------------------------------------
248 all: $(AUTOCONF) libgame_dir game_em_dir game_sp_dir game_mm_dir $(PROGNAME) graphics_dir
250 $(PROGNAME): $(RNDLIBS) $(TIMESTAMP_FILE) $(COMMIT_HASH_FILE) $(OBJS) $(ICON)
251 $(CC) $(PROFILING) $(OBJS) $(ICON) $(RNDLIBS) $(LDFLAGS) -o $(PROGNAME)
257 @$(MAKE) -C $(LIBGAME_DIR)
259 @$(MAKE) -C $(LIBGAME_DIR)
262 @$(MAKE) -C $(GAME_EM_DIR)
264 @$(MAKE) -C $(GAME_EM_DIR)
267 @$(MAKE) -C $(GAME_SP_DIR)
269 @$(MAKE) -C $(GAME_SP_DIR)
272 @$(MAKE) -C $(GAME_MM_DIR)
274 @$(MAKE) -C $(GAME_MM_DIR)
277 @for i in $(CNFS); do \
278 echo "$(CNFS_CMD) $$i > $$i"; \
279 $(CNFS_CMD) $$i > $$i; \
283 @for i in $(CNFS); do \
288 conf_gfx.h: conf_gfx.c $(CNFS_CMD)
291 conf_snd.h: conf_snd.c $(CNFS_CMD)
294 conf_mus.h: conf_mus.c $(CNFS_CMD)
298 @echo '#define SOURCE_DATE_STRING "$(SOURCE_DATE_STRING)"' \
302 @echo '#define SOURCE_HASH_STRING "$(SOURCE_HASH_STRING)"' \
303 > $(COMMIT_HASH_FILE)
305 $(TIMESTAMP_FILE): $(SRCS) $(RNDLIBS)
308 $(COMMIT_HASH_FILE): $(SRCS) $(RNDLIBS)
312 # $(CONVERT) $(ICON32X32) $(CONVERT_ICON_ARGS) $(ICONBASE).ico
313 $(CONVERT) $(ICON_PATH)/*.png $(CONVERT_ICON_ARGS) $(ICONBASE).ico
314 echo "$(ICONBASE) ICON $(ICONBASE).ico" | $(WINDRES) -o $(ICON)
317 $(CC) $(PROFILING) $(CFLAGS) -c $*.c
320 @test -f $(GRAPHICS_DIR)/Makefile && $(MAKE) -C $(GRAPHICS_DIR) || true
323 $(MAKE) -C $(LIBGAME_DIR) clean
324 $(MAKE) -C $(GAME_EM_DIR) clean
325 $(MAKE) -C $(GAME_SP_DIR) clean
326 $(MAKE) -C $(GAME_MM_DIR) clean
331 $(RM) $(ICONBASE).ico
336 $(RM) $(PROGNAME).exe
338 $(RM) $(PROGNAME).wasm
339 $(RM) $(PROGNAME).data
341 clean: clean-obj clean-ico clean-bin
343 clean-git: clean auto-conf-clean
344 @$(MAKE) -C $(GRAPHICS_DIR) clean
346 dist-clean: clean-obj clean-ico
349 # -----------------------------------------------------------------------------
350 # run and test targets
351 # -----------------------------------------------------------------------------
354 cd .. && ./$(PROGBASE) --verbose
357 cd .. && gdb -batch -x GDB_COMMANDS ./$(PROGBASE)
360 cd .. && valgrind -v --leak-check=yes ./$(PROGBASE) 2> valgrind.out
363 # -----------------------------------------------------------------------------
365 # -----------------------------------------------------------------------------
368 $(ETAGS) *.[ch] $(LIBGAME_DIR)/*.[ch] $(GAME_EM_DIR)/*.[ch] $(GAME_SP_DIR)/*.[ch] $(GAME_MM_DIR)/*.[ch]
371 $(MAKE) -C $(LIBGAME_DIR) depend
372 $(MAKE) -C $(GAME_EM_DIR) depend
373 $(MAKE) -C $(GAME_SP_DIR) depend
374 $(MAKE) -C $(GAME_MM_DIR) depend
375 for i in $(SRCS); do $(CPP) $(CFLAGS) -M $$i; done > .depend
377 ifeq (.depend,$(wildcard .depend))