1 # =============================================================================
2 # Rocks'n'Diamonds - McDuffin Strikes Back!
3 # -----------------------------------------------------------------------------
4 # (c) 1995-2015 by Artsoft Entertainment
7 # http://www.artsoft.org/
8 # -----------------------------------------------------------------------------
10 # =============================================================================
12 # -----------------------------------------------------------------------------
14 # -----------------------------------------------------------------------------
16 .EXPORT_ALL_VARIABLES:
18 ifndef PLATFORM # unknown platform -- default to Unix
30 CONVERT_ICON_ARGS = -transparent black -background transparent
32 PROGBASE = rocksndiamonds
33 PROGNAME = ../$(PROGBASE)
38 # -----------------------------------------------------------------------------
39 # configuring platform
40 # -----------------------------------------------------------------------------
42 ifeq ($(PLATFORM),macosx) # compiling on Mac OS X
43 EXTRA_LDFLAGS = -lstdc++
44 override PLATFORM = unix
47 ifeq ($(PLATFORM),unix) # compiling on Unix/Linux (generic)
51 ifeq ($(PLATFORM),cross-win32) # cross-compiling to Windows
52 PROGNAME = ../$(PROGBASE).exe
53 EXTRA_LDFLAGS = -lshfolder -lwsock32
57 # -----------------------------------------------------------------------------
59 # -----------------------------------------------------------------------------
61 ifndef TARGET # auto-detect compiling for SDL or SDL2
62 SDL_VERSION := $(shell sdl2-config --version 2> /dev/null)
66 SDL_VERSION := $(shell sdl-config --version 2> /dev/null)
70 $(error SDL/SDL2 library not found)
75 # $(info Using SDL version $(SDL_VERSION) [TARGET == $(TARGET)])
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)
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)
90 # -----------------------------------------------------------------------------
91 # configuring compile-time definitions
92 # -----------------------------------------------------------------------------
94 ifdef RO_GAME_DIR # path to read-only game data specified
95 CONFIG_RO_GAME_DIR = -DRO_GAME_DIR="\"$(RO_GAME_DIR)\""
98 ifdef RW_GAME_DIR # path to writable game data specified
99 CONFIG_RW_GAME_DIR = -DRW_GAME_DIR="\"$(RW_GAME_DIR)\""
102 CONFIG = $(CONFIG_RO_GAME_DIR) $(CONFIG_RW_GAME_DIR) $(JOYSTICK)
106 # PROFILING = $(PROFILING_FLAGS)
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
116 ifdef BUILD_DIST # distribution build
117 SYS_LDFLAGS := $(shell echo $(SYS_LDFLAGS) | \
118 sed -e "s%-rpath,[^ ]*%-rpath,'\$$ORIGIN/lib'%")
122 CFLAGS = $(OPTIONS) $(SYS_CFLAGS) $(EXTRA_CFLAGS) $(CONFIG)
123 LDFLAGS = $(SYS_LDFLAGS) $(EXTRA_LDFLAGS) -lm
180 CNFS_CMD = ../build-scripts/create_element_defs.pl
182 TIMESTAMP_FILE = conftime.h
183 TIMESTAMP_FORMAT = %Y-%m-%d %H:%M
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)
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)")
191 LIBGAME_DIR = libgame
192 LIBGAME = $(LIBGAME_DIR)/libgame.a
194 GAME_EM_DIR = game_em
195 GAME_EM = $(GAME_EM_DIR)/game_em.a
197 GAME_SP_DIR = game_sp
198 GAME_SP = $(GAME_SP_DIR)/game_sp.a
200 GAME_MM_DIR = game_mm
201 GAME_MM = $(GAME_MM_DIR)/game_mm.a
203 RNDLIBS = $(LIBGAME) $(GAME_EM) $(GAME_SP) $(GAME_MM)
204 AUTOCONF = conf_gfx.h conf_snd.h conf_mus.h
206 ICONBASE = windows_icon
207 ICON_BASEPATH = ../Special/Icons/windows_icons
209 ifeq ($(PLATFORM),cross-win32)
210 ICON_PATH = $(ICON_BASEPATH)/$(EDITION)
214 GRAPHICS_DIR = ../graphics
217 # -----------------------------------------------------------------------------
219 # -----------------------------------------------------------------------------
221 all: $(AUTOCONF) libgame_dir game_em_dir game_sp_dir game_mm_dir $(PROGNAME) graphics_dir
223 $(PROGNAME): $(RNDLIBS) $(TIMESTAMP_FILE) $(OBJS) $(ICON)
224 $(CC) $(PROFILING) $(OBJS) $(ICON) $(RNDLIBS) $(LDFLAGS) -o $(PROGNAME)
230 @$(MAKE) -C $(LIBGAME_DIR)
232 @$(MAKE) -C $(LIBGAME_DIR)
235 @$(MAKE) -C $(GAME_EM_DIR)
237 @$(MAKE) -C $(GAME_EM_DIR)
240 @$(MAKE) -C $(GAME_SP_DIR)
242 @$(MAKE) -C $(GAME_SP_DIR)
245 @$(MAKE) -C $(GAME_MM_DIR)
247 @$(MAKE) -C $(GAME_MM_DIR)
250 @for i in $(CNFS); do \
251 echo "$(CNFS_CMD) $$i > $$i"; \
252 $(CNFS_CMD) $$i > $$i; \
256 @for i in $(CNFS); do \
261 conf_gfx.h: conf_gfx.c $(CNFS_CMD)
264 conf_snd.h: conf_snd.c $(CNFS_CMD)
267 conf_mus.h: conf_mus.c $(CNFS_CMD)
270 $(TIMESTAMP_FILE): $(SRCS) $(RNDLIBS)
271 @echo '#define SOURCE_DATE_STRING "$(SOURCE_DATE_STRING)"' \
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)
280 $(CC) $(PROFILING) $(CFLAGS) -c $*.c
283 @test -f $(GRAPHICS_DIR)/Makefile && $(MAKE) -C $(GRAPHICS_DIR) || true
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
294 $(RM) $(ICONBASE).ico
301 clean: clean-obj clean-ico clean-bin
303 clean-git: clean auto-conf-clean
304 @$(MAKE) -C $(GRAPHICS_DIR) clean
306 dist-clean: clean-obj clean-ico
309 # -----------------------------------------------------------------------------
310 # run and test targets
311 # -----------------------------------------------------------------------------
314 cd .. && ./$(PROGBASE) --verbose
317 cd .. && gdb -batch -x GDB_COMMANDS ./$(PROGBASE)
320 cd .. && valgrind -v --leak-check=yes ./$(PROGBASE) 2> valgrind.out
323 # -----------------------------------------------------------------------------
325 # -----------------------------------------------------------------------------
328 $(ETAGS) *.[ch] $(LIBGAME_DIR)/*.[ch] $(GAME_EM_DIR)/*.[ch] $(GAME_SP_DIR)/*.[ch] $(GAME_MM_DIR)/*.[ch]
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
337 ifeq (.depend,$(wildcard .depend))