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