rocksndiamonds-3.2.0
[rocksndiamonds.git] / src / Makefile
1 # =============================================================================
2 # Rocks'n'Diamonds Makefile (src)
3 # -----------------------------------------------------------------------------
4 # (c) 1995-2005 Holger Schemel <info@artsoft.org>
5 # =============================================================================
6
7 # -----------------------------------------------------------------------------
8 # configuration
9 # -----------------------------------------------------------------------------
10
11 .EXPORT_ALL_VARIABLES:
12
13 ifndef PLATFORM                 # no platform specified -- 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 specified by 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
32 BMP2ICO = bmp2ico
33 WINDRES = windres
34
35 ifeq ($(PLATFORM),msdos)        # MS-DOS native compiling
36
37 RM = del
38
39 PROGBASE = rocks
40 PROGNAME = ../$(PROGBASE).exe
41
42 SYS_CFLAGS = -DTARGET_X11
43 SYS_LDFLAGS = -s -lalleg
44
45 else                            # Unix or cross-compiling for MS-DOS and Win32
46
47 RM = rm -f
48
49 PROGBASE = rocksndiamonds
50 PROGNAME = ../$(PROGBASE)
51
52 ifeq ($(PLATFORM),solaris)
53 EXTRA_LDFLAGS = -lnsl -lsocket -R$(XLIB_PATH)
54 PLATFORM = unix
55 endif
56
57 ifeq ($(PLATFORM),macosx)
58 PLATFORM = unix
59 TARGET = sdl
60 endif
61
62 ifeq ($(PLATFORM),os2)
63 RANLIB = echo
64 PROGNAME = ../$(PROGBASE).exe
65 EXTRA_CFLAGS = -Zbin-files -D__ST_MT_ERRNO__ -Zmtd -fomit-frame-pointer
66 EXTRA_LDFLAGS = -lsocket
67 PLATFORM = unix
68 TARGET = x11
69 endif
70
71 ifeq ($(PLATFORM),unix)
72 PROFILING_FLAGS = -pg
73 endif
74
75 ifeq ($(PLATFORM),cross-msdos)
76 PROGBASE = rocks
77 PROGNAME = ../$(PROGBASE).exe
78 TARGET = allegro
79 endif
80
81 ifeq ($(PLATFORM),cross-win32)
82 EXTRA_LDFLAGS = -lshfolder -lwsock32
83 PROGNAME = ../$(PROGBASE).exe
84 TARGET = sdl
85 endif
86
87 ifeq ($(TARGET),x11)
88 SYS_CFLAGS  = -DTARGET_X11 $(X11_INCL)
89 SYS_LDFLAGS = $(X11_LIBS)
90 endif
91
92 ifeq ($(TARGET),sdl)
93 SYS_CFLAGS  = -DTARGET_SDL $(shell sdl-config --cflags)
94 SDL_LIBS = -lSDL_image -lSDL_mixer -lSDL_net -lsmpeg
95 SYS_LDFLAGS = $(SDL_LIBS) $(shell sdl-config --libs)
96 endif
97
98 ifeq ($(TARGET),sdl-static)
99 SYS_CFLAGS  = -DTARGET_SDL $(shell sdl-config --cflags)
100 SDL_LIBS = -lSDL_image -lSDL_mixer -lSDL_net -lsmpeg
101 SYS_LDFLAGS = $(SDL_LIBS) $(shell sdl-config --static-libs)
102 endif
103
104 ifeq ($(TARGET),allegro)
105 SYS_CFLAGS = -DTARGET_ALLEGRO -I$(CROSS_PATH_MSDOS)/include
106 SYS_LDFLAGS = -lalleg
107 endif
108
109 endif                           # (PLATFORM != msdos)
110
111
112 ifdef RO_GAME_DIR               # path to read-only game data specified
113 CONFIG_RO_GAME_DIR = -DRO_GAME_DIR="\"$(RO_GAME_DIR)\""
114 endif
115
116 ifdef RW_GAME_DIR               # path to writable game data specified
117 CONFIG_RW_GAME_DIR = -DRW_GAME_DIR="\"$(RW_GAME_DIR)\""
118 endif
119
120 ifdef SCORE_ENTRIES             # number of score entries per player specified
121 CONFIG_SCORE_ENTRIES = -D$(SCORE_ENTRIES)
122 endif
123
124 CONFIG_GAME_DIR = $(CONFIG_RO_GAME_DIR) $(CONFIG_RW_GAME_DIR)
125
126
127 CONFIG = $(CONFIG_GAME_DIR) $(CONFIG_SCORE_ENTRIES) $(JOYSTICK)
128 # DEBUG = -DDEBUG -g
129 # PROFILING = $(PROFILING_FLAGS)
130
131 # OPTIONS = $(DEBUG) -Wall                      # only for debugging purposes
132 # OPTIONS = $(DEBUG) -O3 -Wall                  # only for debugging purposes
133 OPTIONS = $(DEBUG) -Wall                        # only for debugging purposes
134 # OPTIONS = $(DEBUG) -Wall -ansi -pedantic      # only for debugging purposes
135 # OPTIONS = -O3 -Wall -ansi -pedantic
136 # OPTIONS = -O3 -Wall
137 # OPTIONS = -O3
138 # OPTIONS = -DSYSV -Ae                          # may be needed for HP-UX
139
140 ifdef BUILD_DIST                                # distribution build
141 OPTIONS = -O3 -Wall
142 endif
143
144 CFLAGS = $(OPTIONS) $(SYS_CFLAGS)  $(EXTRA_CFLAGS) $(CONFIG)
145 LDFLAGS =           $(SYS_LDFLAGS) $(EXTRA_LDFLAGS) -lm
146
147
148 SRCS =  main.c          \
149         conf_gfx.c      \
150         conf_snd.c      \
151         conf_mus.c      \
152         conf_hlp.c      \
153         init.c          \
154         config.c        \
155         events.c        \
156         tools.c         \
157         screens.c       \
158         game.c          \
159         editor.c        \
160         files.c         \
161         tape.c          \
162         cartoons.c      \
163         network.c       \
164         netserv.c
165
166 OBJS =  main.o          \
167         conf_gfx.o      \
168         conf_snd.o      \
169         conf_mus.o      \
170         conf_hlp.o      \
171         init.o          \
172         config.o        \
173         events.o        \
174         tools.o         \
175         screens.o       \
176         game.o          \
177         editor.o        \
178         files.o         \
179         tape.o          \
180         cartoons.o      \
181         network.o       \
182         netserv.o
183
184 CNFS =  conf_gfx.h      \
185         conf_snd.h      \
186         conf_mus.h      \
187         conf_chr.c      \
188         conf_chr.h      \
189         conf_cus.c      \
190         conf_cus.h      \
191         conf_grp.c      \
192         conf_grp.h      \
193         conf_e2g.c      \
194         conf_esg.c      \
195         conf_e2s.c      \
196         conf_fnt.c      \
197         conf_g2s.c      \
198         conf_g2m.c
199
200 CNFS_CMD = ../Scripts/create_element_defs.pl
201
202 TIMESTAMP_FILE = conftime.h
203
204 LIBGAME_DIR = libgame
205 LIBGAME = $(LIBGAME_DIR)/libgame.a
206
207 GAME_EM_DIR = game_em
208 GAME_EM = $(GAME_EM_DIR)/game_em.a
209
210 RNDLIBS = $(LIBGAME) $(GAME_EM)
211
212 ICONBASE = windows_icon
213 ifeq ($(PLATFORM),cross-win32)
214 ICON32X32 = ../graphics/$(ICONBASE)_32x32.bmp
215 ICON = $(ICONBASE).o
216 endif
217
218
219 # -----------------------------------------------------------------------------
220 # build targets
221 # -----------------------------------------------------------------------------
222
223 all: libgame_dir game_em_dir $(PROGNAME)
224
225 $(PROGNAME): $(RNDLIBS) $(TIMESTAMP_FILE) $(OBJS) $(ICON)
226         $(CC) $(PROFILING) $(OBJS) $(ICON) $(RNDLIBS) $(LDFLAGS) -o $(PROGNAME)
227
228 libgame_dir:
229         @$(MAKE) -C $(LIBGAME_DIR)
230 $(LIBGAME):
231         @$(MAKE) -C $(LIBGAME_DIR)
232
233 game_em_dir:
234         @$(MAKE) -C $(GAME_EM_DIR)
235 $(GAME_EM):
236         @$(MAKE) -C $(GAME_EM_DIR)
237
238 auto-conf:
239         @for i in $(CNFS); do                   \
240                 echo "$(CNFS_CMD) $$i > $$i";   \
241                 $(CNFS_CMD) $$i > $$i;          \
242         done
243
244 conf_gfx.h: conf_gfx.c
245         @$(MAKE) auto-conf
246
247 conf_snd.h: conf_snd.c
248         @$(MAKE) auto-conf
249
250 conf_mus.h: conf_mus.c
251         @$(MAKE) auto-conf
252
253 $(TIMESTAMP_FILE): $(SRCS) $(LIBGAME) $(GAME_EM)
254         @date '+"[%Y-%m-%d %H:%M]"' \
255         | sed -e 's/^/#define COMPILE_DATE_STRING /' \
256         > $(TIMESTAMP_FILE)
257
258 $(ICON):
259         $(BMP2ICO) -transparent $(ICONBASE).ico $(ICON32X32)
260         echo "$(ICONBASE) ICON $(ICONBASE).ico" | $(WINDRES) -o $(ICON)
261
262 .c.o:
263         $(CC) $(PROFILING) $(CFLAGS) -c $*.c
264
265 clean-obj:
266         $(MAKE) -C $(LIBGAME_DIR) clean
267         $(MAKE) -C $(GAME_EM_DIR) clean
268         $(RM) $(OBJS)
269         $(RM) $(LIBGAME)
270         $(RM) $(GAME_EM)
271
272 clean-ico:
273         $(RM) $(ICONBASE).ico
274         $(RM) $(ICONBASE).o
275
276 clean-bin:
277         $(RM) $(PROGNAME)
278         $(RM) ../*.exe
279
280 clean: clean-obj clean-ico clean-bin
281
282
283 # -----------------------------------------------------------------------------
284 # development only
285 # -----------------------------------------------------------------------------
286
287 dist-clean: clean-obj
288
289 tags:
290         $(ETAGS) *.[ch] $(LIBGAME_DIR)/*.[ch] $(GAME_EM_DIR)/*.[ch]
291
292 depend:
293         $(MAKE) -C $(LIBGAME_DIR) depend
294         $(MAKE) -C $(GAME_EM_DIR) depend
295         for i in $(SRCS); do $(CPP) $(CFLAGS) -M $$i; done > .depend
296
297 ifeq (.depend,$(wildcard .depend))
298 include .depend
299 endif