rnd-20030223-1-src
[rocksndiamonds.git] / src / Makefile
1 #=============================================================================#
2 # Makefile for Rocks'n'Diamonds                                               #
3 # (c) 1995-2002 Holger Schemel, info@artsoft.org                              #
4 #=============================================================================#
5
6 .EXPORT_ALL_VARIABLES:
7
8 ifndef PLATFORM                 # platform not specified -- try auto detection
9 ifdef COMSPEC
10 PLATFORM = msdos
11 else
12 PLATFORM = unix
13 endif
14 endif
15
16 ifdef X11_PATH                  # path to X11 specified by top level Makefile
17 XINC_PATH = $(X11_PATH)/include
18 XLIB_PATH = $(X11_PATH)/lib
19 X11_INCL = -I$(XINC_PATH)
20 X11_LIBS = -L$(XLIB_PATH)
21 endif
22
23 AR = ar
24 RANLIB = ranlib
25
26 BMP2ICO = bmp2ico
27 WINDRES = windres
28
29 ifeq ($(PLATFORM),msdos)        # MS-DOS native compiling
30
31 RM = del
32
33 PROGBASE = rocks
34 PROGNAME = ../$(PROGBASE).exe
35
36 SYS_CFLAGS = -DTARGET_X11
37 SYS_LDFLAGS = -s -lalleg
38
39 else                            # Unix or cross-compiling for MS-DOS and Win32
40
41 RM = rm -f
42
43 PROGBASE = rocksndiamonds
44 PROGNAME = ../$(PROGBASE)
45
46 ifeq ($(PLATFORM),solaris)
47 EXTRA_LDFLAGS = -lnsl -lsocket -R$(XLIB_PATH)
48 PLATFORM = unix
49 endif
50
51 ifeq ($(PLATFORM),macosx)
52 PLATFORM = unix
53 TARGET=sdl
54 endif
55
56 ifeq ($(PLATFORM),unix)
57 PROFILING_FLAGS = -pg
58 endif
59
60 ifeq ($(PLATFORM),cross-msdos)
61 PROGBASE = rocks
62 PROGNAME = ../$(PROGBASE).exe
63 TARGET = allegro
64 endif
65
66 ifeq ($(PLATFORM),cross-win32)
67 PROGNAME = ../$(PROGBASE).exe
68 TARGET = sdl
69 endif
70
71 ifeq ($(TARGET),x11)
72 SYS_CFLAGS  = -DTARGET_X11 $(X11_INCL)
73 SYS_LDFLAGS = $(X11_LIBS) -lX11
74 endif
75
76 ifeq ($(TARGET),sdl)
77 SYS_CFLAGS  = -DTARGET_SDL $(shell sdl-config --cflags)
78 SYS_LDFLAGS = -lSDL_image -lSDL_mixer $(shell sdl-config --libs)
79 endif
80
81 ifeq ($(TARGET),allegro)
82 SYS_CFLAGS = -DTARGET_ALLEGRO -I$(CROSS_PATH_MSDOS)/include
83 SYS_LDFLAGS = -lalleg
84 endif
85
86 endif                           # (PLATFORM != msdos)
87
88
89 ifdef RO_GAME_DIR               # path to read-only game data specified
90 CONFIG_RO_GAME_DIR = -DRO_GAME_DIR="\"$(RO_GAME_DIR)\""
91 endif
92
93 ifdef RW_GAME_DIR               # path to writable game data specified
94 CONFIG_RW_GAME_DIR = -DRW_GAME_DIR="\"$(RW_GAME_DIR)\""
95 endif
96
97 ifdef SCORE_ENTRIES             # number of score entries per player specified
98 CONFIG_SCORE_ENTRIES = -D$(SCORE_ENTRIES)
99 endif
100
101 CONFIG_GAME_DIR = $(CONFIG_RO_GAME_DIR) $(CONFIG_RW_GAME_DIR)
102
103
104 CONFIG = $(CONFIG_GAME_DIR) $(CONFIG_SCORE_ENTRIES) $(JOYSTICK)
105 DEBUG = -DDEBUG -g
106 # PROFILING = $(PROFILING_FLAGS)
107
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 -ansi -pedantic      # only for debugging purposes
112 # OPTIONS = -O3 -Wall -ansi -pedantic
113 # OPTIONS = -O3 -Wall
114 # OPTIONS = -O3
115 # OPTIONS = -DSYSV -Ae                          # may be needed for HP-UX
116
117 ifdef BUILD_DIST                                # distribution build
118 OPTIONS = -O3 -Wall
119 endif
120
121 CFLAGS = $(OPTIONS) $(SYS_CFLAGS) $(CONFIG)
122 LDFLAGS = $(SYS_LDFLAGS) $(EXTRA_LDFLAGS) -lm
123
124
125 SRCS =  main.c          \
126         conf_gfx.c      \
127         conf_snd.c      \
128         init.c          \
129         config.c        \
130         events.c        \
131         tools.c         \
132         screens.c       \
133         game.c          \
134         editor.c        \
135         files.c         \
136         tape.c          \
137         cartoons.c      \
138         network.c       \
139         netserv.c
140
141 OBJS =  main.o          \
142         conf_gfx.o      \
143         conf_snd.o      \
144         init.o          \
145         config.o        \
146         events.o        \
147         tools.o         \
148         screens.o       \
149         game.o          \
150         editor.o        \
151         files.o         \
152         tape.o          \
153         cartoons.o      \
154         network.o       \
155         netserv.o
156
157 CNFS =  conf_gfx.h      \
158         conf_snd.h      \
159         conf_chr.c      \
160         conf_chr.h      \
161         conf_cus.c      \
162         conf_cus.h      \
163         conf_e2g.c      \
164         conf_esg.c      \
165         conf_fnt.c
166
167 CNFS_CMD = ../Scripts/create_element_defs.pl
168
169 TIMESTAMP_FILE = conftime.h
170
171 LIBDIR = libgame
172 LIBGAME = $(LIBDIR)/libgame.a
173
174 ICONBASE = windows_icon
175 ifeq ($(PLATFORM),cross-win32)
176 ICON32X32 = ../graphics/$(ICONBASE)_32x32.bmp
177 ICON = $(ICONBASE).o
178 endif
179
180
181 all: libgame_dir $(PROGNAME)
182
183 $(PROGNAME): $(LIBGAME) $(TIMESTAMP_FILE) $(OBJS) $(ICON)
184         $(CC) $(PROFILING) $(OBJS) $(ICON) $(LIBGAME) $(LDFLAGS) -o $(PROGNAME)
185
186 libgame_dir:
187         @$(MAKE) -C $(LIBDIR)
188 $(LIBGAME):
189         @$(MAKE) -C $(LIBDIR)
190
191 auto-conf:
192         @for i in $(CNFS); do                   \
193                 echo "$(CNFS_CMD) $$i > $$i";   \
194                 $(CNFS_CMD) $$i > $$i;          \
195         done
196
197 conf_gfx.h: conf_gfx.c
198         @$(MAKE) auto-conf
199
200 conf_snd.h: conf_snd.c
201         @$(MAKE) auto-conf
202
203 $(TIMESTAMP_FILE): $(SRCS) $(LIBGAME)
204         @date '+"[%Y-%m-%d %H:%M]"' \
205         | sed -e 's/^/#define COMPILE_DATE_STRING /' \
206         > $(TIMESTAMP_FILE)
207
208 $(ICON):
209         $(BMP2ICO) -transparent $(ICONBASE).ico $(ICON32X32)
210         echo "$(ICONBASE) ICON $(ICONBASE).ico" | $(WINDRES) -o $(ICON)
211
212 .c.o:
213         $(CC) $(PROFILING) $(CFLAGS) -c $*.c
214
215 clean-obj:
216         $(MAKE) -C $(LIBDIR) clean
217         $(RM) $(OBJS)
218         $(RM) $(LIBGAME)
219
220 clean-ico:
221         $(RM) $(ICONBASE).ico
222         $(RM) $(ICONBASE).o
223
224 clean-bin:
225         $(RM) $(PROGNAME)
226         $(RM) ../*.exe
227
228 clean: clean-obj clean-ico clean-bin
229
230
231 #-----------------------------------------------------------------------------#
232 # development only stuff                                                      #
233 #-----------------------------------------------------------------------------#
234
235 dist-clean: clean-obj
236
237 depend:
238         $(MAKE) -C $(LIBDIR) depend
239         for i in $(SRCS); do $(CPP) $(CFLAGS) -M $$i; done > .depend
240
241 ifeq (.depend,$(wildcard .depend))
242 include .depend
243 endif