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 SDL2
62 SDL_VERSION := $(shell sdl2-config --version 2> /dev/null)
66 $(error SDL2 library not found)
70 # $(info Using SDL version $(SDL_VERSION) [TARGET == $(TARGET)])
72 ifeq ($(TARGET),sdl) # compiling for SDL target
73 $(error SDL library version 1.2 not supported anymore)
76 ifeq ($(TARGET),sdl2) # compiling for SDL2 target
77 SYS_CFLAGS = -DTARGET_SDL2 $(shell sdl2-config --cflags)
78 SDL_LIBS = -lSDL2_image -lSDL2_mixer -lSDL2_net
79 SYS_LDFLAGS = $(SDL_LIBS) $(shell sdl2-config --libs)
83 # -----------------------------------------------------------------------------
84 # configuring compile-time definitions
85 # -----------------------------------------------------------------------------
87 ifdef RO_GAME_DIR # path to read-only game data specified
88 CONFIG_RO_GAME_DIR = -DRO_GAME_DIR="\"$(RO_GAME_DIR)\""
91 ifdef RW_GAME_DIR # path to writable game data specified
92 CONFIG_RW_GAME_DIR = -DRW_GAME_DIR="\"$(RW_GAME_DIR)\""
95 CONFIG = $(CONFIG_RO_GAME_DIR) $(CONFIG_RW_GAME_DIR) $(JOYSTICK)
99 # PROFILING = $(PROFILING_FLAGS)
101 # OPTIONS = $(DEBUG) -Wall # only for debugging purposes
102 # OPTIONS = $(DEBUG) -O3 -Wall # only for debugging purposes
103 # OPTIONS = $(DEBUG) -Wall # only for debugging purposes
104 OPTIONS = $(DEBUG) -Wall -Wstrict-prototypes -Wmissing-prototypes
105 # OPTIONS = $(DEBUG) -Wall -ansi -pedantic # only for debugging purposes
106 # OPTIONS = -O3 -Wall -ansi -pedantic
107 # OPTIONS = -O3 -Wall
110 ifdef BUILD_DIST # distribution build
111 SYS_LDFLAGS := $(shell echo $(SYS_LDFLAGS) | \
112 sed -e "s%-rpath,[^ ]*%-rpath,'\$$ORIGIN/lib'%")
116 CFLAGS = $(OPTIONS) $(SYS_CFLAGS) $(EXTRA_CFLAGS) $(CONFIG)
117 LDFLAGS = $(SYS_LDFLAGS) $(EXTRA_LDFLAGS) -lm -lz
174 CNFS_CMD = ../build-scripts/create_element_defs.pl
176 TIMESTAMP_FILE = conftime.h
177 TIMESTAMP_FORMAT = %Y-%m-%d %H:%M
179 # use SOURCE_DATE_EPOCH, or else last Git commit date, or else current date
180 SOURCE_DATE_EPOCH ?= $(shell test -d ../.git && test `git ls-files -m | wc -l` -eq 0 && git show -s --format=%ct || date +%s)
182 # get source date string from either GNU / Linux or BSD / Mac OS X style "date"
183 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)")
185 LIBGAME_DIR = libgame
186 LIBGAME = $(LIBGAME_DIR)/libgame.a
188 GAME_EM_DIR = game_em
189 GAME_EM = $(GAME_EM_DIR)/game_em.a
191 GAME_SP_DIR = game_sp
192 GAME_SP = $(GAME_SP_DIR)/game_sp.a
194 GAME_MM_DIR = game_mm
195 GAME_MM = $(GAME_MM_DIR)/game_mm.a
197 RNDLIBS = $(LIBGAME) $(GAME_EM) $(GAME_SP) $(GAME_MM)
198 AUTOCONF = conf_gfx.h conf_snd.h conf_mus.h
200 ICONBASE = windows_icon
201 ICON_BASEPATH = ../Special/Icons/windows_icons
203 ifeq ($(PLATFORM),cross-win32)
204 ICON_PATH = $(ICON_BASEPATH)/$(EDITION)
208 GRAPHICS_DIR = ../graphics
211 # -----------------------------------------------------------------------------
213 # -----------------------------------------------------------------------------
215 all: $(AUTOCONF) libgame_dir game_em_dir game_sp_dir game_mm_dir $(PROGNAME) graphics_dir
217 $(PROGNAME): $(RNDLIBS) $(TIMESTAMP_FILE) $(OBJS) $(ICON)
218 $(CC) $(PROFILING) $(OBJS) $(ICON) $(RNDLIBS) $(LDFLAGS) -o $(PROGNAME)
224 @$(MAKE) -C $(LIBGAME_DIR)
226 @$(MAKE) -C $(LIBGAME_DIR)
229 @$(MAKE) -C $(GAME_EM_DIR)
231 @$(MAKE) -C $(GAME_EM_DIR)
234 @$(MAKE) -C $(GAME_SP_DIR)
236 @$(MAKE) -C $(GAME_SP_DIR)
239 @$(MAKE) -C $(GAME_MM_DIR)
241 @$(MAKE) -C $(GAME_MM_DIR)
244 @for i in $(CNFS); do \
245 echo "$(CNFS_CMD) $$i > $$i"; \
246 $(CNFS_CMD) $$i > $$i; \
250 @for i in $(CNFS); do \
255 conf_gfx.h: conf_gfx.c $(CNFS_CMD)
258 conf_snd.h: conf_snd.c $(CNFS_CMD)
261 conf_mus.h: conf_mus.c $(CNFS_CMD)
264 $(TIMESTAMP_FILE): $(SRCS) $(RNDLIBS)
265 @echo '#define SOURCE_DATE_STRING "$(SOURCE_DATE_STRING)"' \
269 # $(CONVERT) $(ICON32X32) $(CONVERT_ICON_ARGS) $(ICONBASE).ico
270 $(CONVERT) $(ICON_PATH)/*.png $(CONVERT_ICON_ARGS) $(ICONBASE).ico
271 echo "$(ICONBASE) ICON $(ICONBASE).ico" | $(WINDRES) -o $(ICON)
274 $(CC) $(PROFILING) $(CFLAGS) -c $*.c
277 @test -f $(GRAPHICS_DIR)/Makefile && $(MAKE) -C $(GRAPHICS_DIR) || true
280 $(MAKE) -C $(LIBGAME_DIR) clean
281 $(MAKE) -C $(GAME_EM_DIR) clean
282 $(MAKE) -C $(GAME_SP_DIR) clean
283 $(MAKE) -C $(GAME_MM_DIR) clean
288 $(RM) $(ICONBASE).ico
295 clean: clean-obj clean-ico clean-bin
297 clean-git: clean auto-conf-clean
298 @$(MAKE) -C $(GRAPHICS_DIR) clean
300 dist-clean: clean-obj clean-ico
303 # -----------------------------------------------------------------------------
304 # run and test targets
305 # -----------------------------------------------------------------------------
308 cd .. && ./$(PROGBASE) --verbose
311 cd .. && gdb -batch -x GDB_COMMANDS ./$(PROGBASE)
314 cd .. && valgrind -v --leak-check=yes ./$(PROGBASE) 2> valgrind.out
317 # -----------------------------------------------------------------------------
319 # -----------------------------------------------------------------------------
322 $(ETAGS) *.[ch] $(LIBGAME_DIR)/*.[ch] $(GAME_EM_DIR)/*.[ch] $(GAME_SP_DIR)/*.[ch] $(GAME_MM_DIR)/*.[ch]
325 $(MAKE) -C $(LIBGAME_DIR) depend
326 $(MAKE) -C $(GAME_EM_DIR) depend
327 $(MAKE) -C $(GAME_SP_DIR) depend
328 $(MAKE) -C $(GAME_MM_DIR) depend
329 for i in $(SRCS); do $(CPP) $(CFLAGS) -M $$i; done > .depend
331 ifeq (.depend,$(wildcard .depend))