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 -Wstrict-prototypes -Wmissing-prototypes
112 # OPTIONS = $(DEBUG) -Wall -ansi -pedantic # only for debugging purposes
113 # OPTIONS = -O3 -Wall -ansi -pedantic
114 # OPTIONS = -O3 -Wall
117 ifdef BUILD_DIST # distribution build
118 SYS_LDFLAGS := $(shell echo $(SYS_LDFLAGS) | \
119 sed -e "s%-rpath,[^ ]*%-rpath,'\$$ORIGIN/lib'%")
123 CFLAGS = $(OPTIONS) $(SYS_CFLAGS) $(EXTRA_CFLAGS) $(CONFIG)
124 LDFLAGS = $(SYS_LDFLAGS) $(EXTRA_LDFLAGS) -lm
181 CNFS_CMD = ../build-scripts/create_element_defs.pl
183 TIMESTAMP_FILE = conftime.h
184 TIMESTAMP_FORMAT = %Y-%m-%d %H:%M
186 # use SOURCE_DATE_EPOCH, or else last Git commit date, or else current date
187 SOURCE_DATE_EPOCH ?= $(shell test -d ../.git && test `git ls-files -m | wc -l` -eq 0 && git show -s --format=%ct || date +%s)
189 # get source date string from either GNU / Linux or BSD / Mac OS X style "date"
190 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)")
192 LIBGAME_DIR = libgame
193 LIBGAME = $(LIBGAME_DIR)/libgame.a
195 GAME_EM_DIR = game_em
196 GAME_EM = $(GAME_EM_DIR)/game_em.a
198 GAME_SP_DIR = game_sp
199 GAME_SP = $(GAME_SP_DIR)/game_sp.a
201 GAME_MM_DIR = game_mm
202 GAME_MM = $(GAME_MM_DIR)/game_mm.a
204 RNDLIBS = $(LIBGAME) $(GAME_EM) $(GAME_SP) $(GAME_MM)
205 AUTOCONF = conf_gfx.h conf_snd.h conf_mus.h
207 ICONBASE = windows_icon
208 ICON_BASEPATH = ../Special/Icons/windows_icons
210 ifeq ($(PLATFORM),cross-win32)
211 ICON_PATH = $(ICON_BASEPATH)/$(EDITION)
215 GRAPHICS_DIR = ../graphics
218 # -----------------------------------------------------------------------------
220 # -----------------------------------------------------------------------------
222 all: $(AUTOCONF) libgame_dir game_em_dir game_sp_dir game_mm_dir $(PROGNAME) graphics_dir
224 $(PROGNAME): $(RNDLIBS) $(TIMESTAMP_FILE) $(OBJS) $(ICON)
225 $(CC) $(PROFILING) $(OBJS) $(ICON) $(RNDLIBS) $(LDFLAGS) -o $(PROGNAME)
231 @$(MAKE) -C $(LIBGAME_DIR)
233 @$(MAKE) -C $(LIBGAME_DIR)
236 @$(MAKE) -C $(GAME_EM_DIR)
238 @$(MAKE) -C $(GAME_EM_DIR)
241 @$(MAKE) -C $(GAME_SP_DIR)
243 @$(MAKE) -C $(GAME_SP_DIR)
246 @$(MAKE) -C $(GAME_MM_DIR)
248 @$(MAKE) -C $(GAME_MM_DIR)
251 @for i in $(CNFS); do \
252 echo "$(CNFS_CMD) $$i > $$i"; \
253 $(CNFS_CMD) $$i > $$i; \
257 @for i in $(CNFS); do \
262 conf_gfx.h: conf_gfx.c $(CNFS_CMD)
265 conf_snd.h: conf_snd.c $(CNFS_CMD)
268 conf_mus.h: conf_mus.c $(CNFS_CMD)
271 $(TIMESTAMP_FILE): $(SRCS) $(RNDLIBS)
272 @echo '#define SOURCE_DATE_STRING "$(SOURCE_DATE_STRING)"' \
276 # $(CONVERT) $(ICON32X32) $(CONVERT_ICON_ARGS) $(ICONBASE).ico
277 $(CONVERT) $(ICON_PATH)/*.png $(CONVERT_ICON_ARGS) $(ICONBASE).ico
278 echo "$(ICONBASE) ICON $(ICONBASE).ico" | $(WINDRES) -o $(ICON)
281 $(CC) $(PROFILING) $(CFLAGS) -c $*.c
284 @test -f $(GRAPHICS_DIR)/Makefile && $(MAKE) -C $(GRAPHICS_DIR) || true
287 $(MAKE) -C $(LIBGAME_DIR) clean
288 $(MAKE) -C $(GAME_EM_DIR) clean
289 $(MAKE) -C $(GAME_SP_DIR) clean
290 $(MAKE) -C $(GAME_MM_DIR) clean
295 $(RM) $(ICONBASE).ico
302 clean: clean-obj clean-ico clean-bin
304 clean-git: clean auto-conf-clean
305 @$(MAKE) -C $(GRAPHICS_DIR) clean
307 dist-clean: clean-obj clean-ico
310 # -----------------------------------------------------------------------------
311 # run and test targets
312 # -----------------------------------------------------------------------------
315 cd .. && ./$(PROGBASE) --verbose
318 cd .. && gdb -batch -x GDB_COMMANDS ./$(PROGBASE)
321 cd .. && valgrind -v --leak-check=yes ./$(PROGBASE) 2> valgrind.out
324 # -----------------------------------------------------------------------------
326 # -----------------------------------------------------------------------------
329 $(ETAGS) *.[ch] $(LIBGAME_DIR)/*.[ch] $(GAME_EM_DIR)/*.[ch] $(GAME_SP_DIR)/*.[ch] $(GAME_MM_DIR)/*.[ch]
332 $(MAKE) -C $(LIBGAME_DIR) depend
333 $(MAKE) -C $(GAME_EM_DIR) depend
334 $(MAKE) -C $(GAME_SP_DIR) depend
335 $(MAKE) -C $(GAME_MM_DIR) depend
336 for i in $(SRCS); do $(CPP) $(CFLAGS) -M $$i; done > .depend
338 ifeq (.depend,$(wildcard .depend))