rnd-20100313-1-src
[rocksndiamonds.git] / src / Makefile
1 # =============================================================================
2 # Rocks'n'Diamonds Makefile (src)
3 # -----------------------------------------------------------------------------
4 # (c) 1995-2006 Holger Schemel <info@artsoft.org>
5 # =============================================================================
6
7 # -----------------------------------------------------------------------------
8 # configuration
9 # -----------------------------------------------------------------------------
10
11 .EXPORT_ALL_VARIABLES:
12
13 ifndef PLATFORM                         # unknown platform -- try auto detection
14 ifdef COMSPEC
15 PLATFORM = msdos
16 else
17 PLATFORM = unix
18 endif
19 endif
20
21 ifdef X11_PATH                          # path to X11 from top level Makefile
22 XINC_PATH = $(X11_PATH)/include
23 XLIB_PATH = $(X11_PATH)/lib
24 X11_INCL = -I$(XINC_PATH)
25 X11_LIBS = -L$(XLIB_PATH) -lX11
26 endif
27
28 AR = ar
29 RANLIB = ranlib
30 ETAGS = etags
31 RM = rm -f
32
33 BMP2ICO = bmp2ico
34 WINDRES = windres
35
36 PROGBASE = rocksndiamonds
37
38 ifdef SPECIAL_EDITION                   # create special edition
39 PROGBASE = $(SPECIAL_EDITION)
40 endif
41
42 PROGNAME = ../$(PROGBASE)
43
44
45 # -----------------------------------------------------------------------------
46 # configuring platform
47 # -----------------------------------------------------------------------------
48
49 ifeq ($(PLATFORM),solaris)              # native compiling to Solaris
50 EXTRA_LDFLAGS = -lnsl -lsocket -R$(XLIB_PATH)
51 PLATFORM = unix
52 endif
53
54 ifeq ($(PLATFORM),macosx)               # native compiling to Mac OS X
55 EXTRA_LDFLAGS = -lstdc++
56 PLATFORM = unix
57 TARGET = sdl
58 endif
59
60 ifeq ($(PLATFORM),os2)                  # native compiling to OS/2
61 RANLIB = echo
62 PROGNAME = ../$(PROGBASE).exe
63 EXTRA_CFLAGS = -Zbin-files -D__ST_MT_ERRNO__ -Zmtd -fomit-frame-pointer
64 EXTRA_LDFLAGS = -lsocket
65 PLATFORM = unix
66 TARGET = x11
67 endif
68
69 ifeq ($(PLATFORM),unix)                 # native compiling to Unix (generic)
70 PROFILING_FLAGS = -pg
71 endif
72
73 ifeq ($(PLATFORM),cross-win32)          # cross-compiling to Windows
74 PROGNAME = ../$(PROGBASE).exe
75 EXTRA_LDFLAGS = -lshfolder -lwsock32
76 TARGET = sdl
77 endif
78
79 ifeq ($(PLATFORM),cross-msdos)          # cross-compiling to MS-DOS
80 PROGBASE = rocks
81 PROGNAME = ../$(PROGBASE).exe
82 TARGET = allegro
83 endif
84
85 ifeq ($(PLATFORM),msdos)                # native compiling to MS-DOS
86 PROGBASE = rocks
87 PROGNAME = ../$(PROGBASE).exe
88 SYS_CFLAGS = -DTARGET_X11
89 SYS_LDFLAGS = -s -lalleg
90 RM = del
91 endif
92
93
94 # -----------------------------------------------------------------------------
95 # configuring target
96 # -----------------------------------------------------------------------------
97
98 ifeq ($(TARGET),x11)                    # compiling for X11 target
99 SYS_CFLAGS  = -DTARGET_X11 $(X11_INCL)
100 SYS_LDFLAGS = $(X11_LIBS)
101 endif
102
103 ifeq ($(TARGET),sdl)                    # compiling for SDL target
104 SYS_CFLAGS  = -DTARGET_SDL $(shell sdl-config --cflags)
105 SDL_LIBS = -lSDL_image -lSDL_mixer -lSDL_net -lsmpeg
106 SYS_LDFLAGS = $(SDL_LIBS) $(shell sdl-config --libs)
107 endif
108
109 ifeq ($(TARGET),sdl-static)             # compiling for SDL target (static)
110 SYS_CFLAGS  = -DTARGET_SDL $(shell sdl-config --cflags)
111 SDL_LIBS = -lSDL_image -lSDL_mixer -lSDL_net -lsmpeg
112 SYS_LDFLAGS = $(SDL_LIBS) $(shell sdl-config --static-libs)
113 endif
114
115 ifeq ($(TARGET),allegro)                # compiling for Allegro target
116 SYS_CFLAGS = -DTARGET_ALLEGRO -I$(CROSS_PATH_MSDOS)/include
117 SYS_LDFLAGS = -lalleg
118 endif
119
120
121 # -----------------------------------------------------------------------------
122 # configuring compile-time definitions
123 # -----------------------------------------------------------------------------
124
125 ifdef RO_GAME_DIR                       # path to read-only game data specified
126 CONFIG_RO_GAME_DIR = -DRO_GAME_DIR="\"$(RO_GAME_DIR)\""
127 endif
128
129 ifdef RW_GAME_DIR                       # path to writable game data specified
130 CONFIG_RW_GAME_DIR = -DRW_GAME_DIR="\"$(RW_GAME_DIR)\""
131 endif
132
133 ifdef SCORE_ENTRIES                     # number of score entries per player
134 CONFIG_SCORE_ENTRIES = -D$(SCORE_ENTRIES)
135 endif
136
137 ifdef SPECIAL_EDITION
138 ifeq ($(SPECIAL_EDITION),rnd_jue)       # create special edition
139 CONFIG_SPECIAL = -DCREATE_SPECIAL_EDITION -DCREATE_SPECIAL_EDITION_RND_JUE
140 endif
141 endif
142
143 CONFIG_GAME_DIR = $(CONFIG_RO_GAME_DIR) $(CONFIG_RW_GAME_DIR)
144 CONFIG_GAME = $(CONFIG_GAME_DIR) $(CONFIG_SCORE_ENTRIES) $(CONFIG_SPECIAL)
145
146 CONFIG = $(CONFIG_GAME) $(JOYSTICK)
147 DEBUG = -DDEBUG -g
148 # PROFILING = $(PROFILING_FLAGS)
149
150 # OPTIONS = $(DEBUG) -Wall                      # only for debugging purposes
151 # OPTIONS = $(DEBUG) -O3 -Wall                  # only for debugging purposes
152 OPTIONS = $(DEBUG) -Wall                        # only for debugging purposes
153 # OPTIONS = $(DEBUG) -Wall -ansi -pedantic      # only for debugging purposes
154 # OPTIONS = -O3 -Wall -ansi -pedantic
155 # OPTIONS = -O3 -Wall
156 # OPTIONS = -O3
157 # OPTIONS = -DSYSV -Ae                  # may be needed for HP-UX
158
159 ifdef BUILD_DIST                        # distribution build
160 OPTIONS = -O3 -Wall
161 endif
162
163 CFLAGS = $(OPTIONS) $(SYS_CFLAGS)  $(EXTRA_CFLAGS) $(CONFIG)
164 LDFLAGS =           $(SYS_LDFLAGS) $(EXTRA_LDFLAGS) -lm
165
166
167 SRCS =  main.c          \
168         conf_gfx.c      \
169         conf_snd.c      \
170         conf_mus.c      \
171         conf_hlp.c      \
172         init.c          \
173         config.c        \
174         events.c        \
175         tools.c         \
176         screens.c       \
177         game.c          \
178         editor.c        \
179         files.c         \
180         tape.c          \
181         cartoons.c      \
182         network.c       \
183         netserv.c
184
185 OBJS =  main.o          \
186         conf_gfx.o      \
187         conf_snd.o      \
188         conf_mus.o      \
189         conf_hlp.o      \
190         init.o          \
191         config.o        \
192         events.o        \
193         tools.o         \
194         screens.o       \
195         game.o          \
196         editor.o        \
197         files.o         \
198         tape.o          \
199         cartoons.o      \
200         network.o       \
201         netserv.o
202
203 CNFS =  conf_gfx.h      \
204         conf_snd.h      \
205         conf_mus.h      \
206         conf_chr.c      \
207         conf_chr.h      \
208         conf_cus.c      \
209         conf_cus.h      \
210         conf_grp.c      \
211         conf_grp.h      \
212         conf_e2g.c      \
213         conf_esg.c      \
214         conf_e2s.c      \
215         conf_fnt.c      \
216         conf_g2s.c      \
217         conf_g2m.c      \
218         conf_var.c      \
219         conf_act.c
220
221 CNFS_CMD = ../Scripts/create_element_defs.pl
222
223 TIMESTAMP_FILE = conftime.h
224
225 LIBGAME_DIR = libgame
226 LIBGAME = $(LIBGAME_DIR)/libgame.a
227
228 GAME_EM_DIR = game_em
229 GAME_EM = $(GAME_EM_DIR)/game_em.a
230
231 GAME_SP_DIR = game_sp
232 GAME_SP = $(GAME_SP_DIR)/game_sp.a
233
234 RNDLIBS = $(LIBGAME) $(GAME_EM) $(GAME_SP)
235
236 ICONBASE = windows_icon
237 ifeq ($(PLATFORM),cross-win32)
238 ifdef SPECIAL_EDITION
239 ICONSUFFIX = 32x32_$(SPECIAL_EDITION)
240 else
241 ICONSUFFIX = 32x32
242 endif
243 ICON32X32 = ../graphics/$(ICONBASE)_$(ICONSUFFIX).bmp
244 ICON = $(ICONBASE).o
245 endif
246
247
248 # -----------------------------------------------------------------------------
249 # build targets
250 # -----------------------------------------------------------------------------
251
252 all: libgame_dir game_em_dir game_sp_dir $(PROGNAME)
253
254 $(PROGNAME): $(RNDLIBS) $(TIMESTAMP_FILE) $(OBJS) $(ICON)
255         $(CC) $(PROFILING) $(OBJS) $(ICON) $(RNDLIBS) $(LDFLAGS) -o $(PROGNAME)
256
257 libgame_dir:
258         @$(MAKE) -C $(LIBGAME_DIR)
259 $(LIBGAME):
260         @$(MAKE) -C $(LIBGAME_DIR)
261
262 game_em_dir:
263         @$(MAKE) -C $(GAME_EM_DIR)
264 $(GAME_EM):
265         @$(MAKE) -C $(GAME_EM_DIR)
266
267 game_sp_dir:
268         @$(MAKE) -C $(GAME_SP_DIR)
269 $(GAME_SP):
270         @$(MAKE) -C $(GAME_SP_DIR)
271
272 auto-conf:
273         @for i in $(CNFS); do                   \
274                 echo "$(CNFS_CMD) $$i > $$i";   \
275                 $(CNFS_CMD) $$i > $$i;          \
276         done
277
278 conf_gfx.h: conf_gfx.c
279         @$(MAKE) auto-conf
280
281 conf_snd.h: conf_snd.c
282         @$(MAKE) auto-conf
283
284 conf_mus.h: conf_mus.c
285         @$(MAKE) auto-conf
286
287 $(TIMESTAMP_FILE): $(SRCS) $(LIBGAME) $(GAME_EM) $(GAME_SP)
288         @date '+"%Y-%m-%d %H:%M"' \
289         | sed -e 's/^/#define COMPILE_DATE_STRING /' \
290         > $(TIMESTAMP_FILE)
291
292 $(ICON):
293         $(BMP2ICO) -transparent $(ICONBASE).ico $(ICON32X32)
294         echo "$(ICONBASE) ICON $(ICONBASE).ico" | $(WINDRES) -o $(ICON)
295
296 .c.o:
297         $(CC) $(PROFILING) $(CFLAGS) -c $*.c
298
299 clean-obj:
300         $(MAKE) -C $(LIBGAME_DIR) clean
301         $(MAKE) -C $(GAME_EM_DIR) clean
302         $(MAKE) -C $(GAME_SP_DIR) clean
303         $(RM) $(OBJS)
304         $(RM) $(LIBGAME)
305         $(RM) $(GAME_EM)
306         $(RM) $(GAME_SP)
307
308 clean-ico:
309         $(RM) $(ICONBASE).ico
310         $(RM) $(ICONBASE).o
311
312 clean-bin:
313         $(RM) $(PROGNAME)
314         $(RM) ../*.exe
315
316 clean: clean-obj clean-ico clean-bin
317
318
319 # -----------------------------------------------------------------------------
320 # run and test targets
321 # -----------------------------------------------------------------------------
322
323 run: all
324         cd .. && ./$(PROGBASE) --verbose
325
326 gdb: all
327         cd .. && gdb -batch -x GDB_COMMANDS ./$(PROGBASE)
328
329 valgrind: all
330         cd .. && valgrind -v --leak-check=yes ./$(PROGBASE) 2> valgrind.out
331
332
333 # -----------------------------------------------------------------------------
334 # development only
335 # -----------------------------------------------------------------------------
336
337 dist-clean: clean-obj
338
339 tags:
340         $(ETAGS) *.[ch] $(LIBGAME_DIR)/*.[ch] $(GAME_EM_DIR)/*.[ch] $(GAME_SP_DIR)/*.[ch]
341
342 depend:
343         $(MAKE) -C $(LIBGAME_DIR) depend
344         $(MAKE) -C $(GAME_EM_DIR) depend
345         $(MAKE) -C $(GAME_SP_DIR) depend
346         for i in $(SRCS); do $(CPP) $(CFLAGS) -M $$i; done > .depend
347
348 ifeq (.depend,$(wildcard .depend))
349 include .depend
350 endif