Makefile: enable debug mode
[neverball] / Makefile
1
2 #------------------------------------------------------------------------------
3
4 VERSION := $(shell sh scripts/version.sh)
5 ifeq ($(VERSION),unknown)
6     $(warning Failed to obtain sane version for this build.)
7 endif
8
9 DEBUG := 1
10
11 # Provide a target system hint for the Makefile.
12
13 ifeq ($(shell uname), Darwin)
14     DARWIN := 1
15 endif
16
17 #------------------------------------------------------------------------------
18 # Optional flags (CFLAGS, CPPFLAGS, ...)
19
20 ifeq ($(ENABLE_WII),1)
21     # libwiimote is NOT ANSI compliant (TODO, check if this is necessary.  GCC
22     # is supposed to suppress warnings from system headers.)
23
24     ifneq ($(DEBUG),1)
25         CFLAGS   := -g
26         CPPFLAGS :=
27     else
28         CFLAGS   := -O2
29         CPPFLAGS := -DNDEBUG
30     endif
31 else
32     ifeq ($(DEBUG),1)
33         CFLAGS   := -Wall -g -ansi -pedantic
34         CPPFLAGS :=
35     else
36         CFLAGS   := -Wall -O2 -ansi -pedantic
37         CPPFLAGS := -DNDEBUG
38     endif
39 endif
40
41 #------------------------------------------------------------------------------
42 # Mandatory flags
43
44 # Compiler...
45
46 ALL_CFLAGS := $(CFLAGS)
47
48 # Preprocessor...
49
50 SDL_CPPFLAGS := $(shell sdl-config --cflags)
51 PNG_CPPFLAGS := $(shell libpng-config --cflags)
52
53 ALL_CPPFLAGS := $(SDL_CPPFLAGS) $(PNG_CPPFLAGS) -Ishare \
54     -DVERSION=\"$(VERSION)\"
55
56 ifeq ($(ENABLE_NLS),0)
57     ALL_CPPFLAGS += -DENABLE_NLS=0
58 else
59     ALL_CPPFLAGS += -DENABLE_NLS=1
60 endif
61
62 ifeq ($(ENABLE_WII),1)
63     ALL_CPPFLAGS += -DENABLE_WII=1
64 endif
65
66 ifdef DARWIN
67     ALL_CPPFLAGS += -I/opt/local/include
68 endif
69
70 ALL_CPPFLAGS += $(CPPFLAGS)
71
72 #------------------------------------------------------------------------------
73 # Libraries
74
75 SDL_LIBS := $(shell sdl-config --libs)
76 PNG_LIBS := $(shell libpng-config --libs)
77
78 # The  non-conditionalised values  below  are specific  to the  native
79 # system. The native system of this Makefile is Linux (or GNU+Linux if
80 # you prefer). Please be sure to  override ALL of them for each target
81 # system in the conditional parts below.
82
83 INTL_LIBS :=
84
85 ifeq ($(ENABLE_WII),1)
86     TILT_LIBS := -lcwiimote -lbluetooth
87 endif
88
89 OGL_LIBS := -lGL -lm
90
91 ifdef MINGW
92     ifneq ($(ENABLE_NLS),0)
93         INTL_LIBS := -lintl -liconv
94     endif
95
96     TILT_LIBS :=
97     OGL_LIBS  := -lopengl32 -lm
98 endif
99
100 ifdef DARWIN
101     ifneq ($(ENABLE_NLS),0)
102         INTL_LIBS := -lintl -liconv
103     endif
104
105     TILT_LIBS :=
106     OGL_LIBS  := -framework OpenGL
107 endif
108
109 BASE_LIBS := -ljpeg $(PNG_LIBS)
110
111 ifdef DARWIN
112     BASE_LIBS += -L/opt/local/lib
113 endif
114
115 ALL_LIBS := $(SDL_LIBS) $(BASE_LIBS) $(TILT_LIBS) $(INTL_LIBS) -lSDL_ttf \
116     -lvorbisfile $(OGL_LIBS)
117
118 #------------------------------------------------------------------------------
119
120 ifdef MINGW
121     EXT := .exe
122 endif
123
124 MAPC_TARG := mapc$(EXT)
125 BALL_TARG := neverball$(EXT)
126 PUTT_TARG := neverputt$(EXT)
127
128 ifdef MINGW
129     MAPC := $(WINE) ./$(MAPC_TARG)
130 else
131     MAPC := ./$(MAPC_TARG)
132 endif
133
134
135 #------------------------------------------------------------------------------
136
137 MAPC_OBJS := \
138         share/vec3.o        \
139         share/base_image.o  \
140         share/solid.o       \
141         share/binary.o      \
142         share/base_config.o \
143         share/mapc.o
144 BALL_OBJS := \
145         share/lang.o        \
146         share/st_resol.o    \
147         share/vec3.o        \
148         share/base_image.o  \
149         share/image.o       \
150         share/solid.o       \
151         share/solid_gl.o    \
152         share/part.o        \
153         share/back.o        \
154         share/geom.o        \
155         share/item.o        \
156         share/ball.o        \
157         share/gui.o         \
158         share/base_config.o \
159         share/config.o      \
160         share/binary.o      \
161         share/state.o       \
162         share/audio.o       \
163         share/text.o        \
164         share/sync.o        \
165         share/tilt.o        \
166         share/common.o      \
167         share/keynames.o    \
168         share/syswm.o       \
169         ball/hud.o          \
170         ball/game.o         \
171         ball/score.o        \
172         ball/level.o        \
173         ball/progress.o     \
174         ball/set.o          \
175         ball/demo.o         \
176         ball/util.o         \
177         ball/st_conf.o      \
178         ball/st_demo.o      \
179         ball/st_save.o      \
180         ball/st_goal.o      \
181         ball/st_fall_out.o  \
182         ball/st_time_out.o  \
183         ball/st_done.o      \
184         ball/st_level.o     \
185         ball/st_over.o      \
186         ball/st_play.o      \
187         ball/st_set.o       \
188         ball/st_start.o     \
189         ball/st_title.o     \
190         ball/st_help.o      \
191         ball/st_name.o      \
192         ball/st_shared.o    \
193         ball/st_pause.o     \
194         ball/main.o
195 PUTT_OBJS := \
196         share/lang.o        \
197         share/st_resol.o    \
198         share/vec3.o        \
199         share/base_image.o  \
200         share/image.o       \
201         share/solid.o       \
202         share/solid_gl.o    \
203         share/part.o        \
204         share/geom.o        \
205         share/ball.o        \
206         share/back.o        \
207         share/base_config.o \
208         share/config.o      \
209         share/binary.o      \
210         share/audio.o       \
211         share/state.o       \
212         share/gui.o         \
213         share/text.o        \
214         share/sync.o        \
215         share/common.o      \
216         share/syswm.o       \
217         putt/hud.o          \
218         putt/game.o         \
219         putt/hole.o         \
220         putt/course.o       \
221         putt/st_all.o       \
222         putt/st_conf.o      \
223         putt/main.o
224
225 BALL_DEPS := $(BALL_OBJS:.o=.d)
226 PUTT_DEPS := $(PUTT_OBJS:.o=.d)
227 MAPC_DEPS := $(MAPC_OBJS:.o=.d)
228
229 MAPS := $(shell find data -name "*.map" \! -name "*.autosave.map")
230 SOLS := $(MAPS:%.map=%.sol)
231
232 #------------------------------------------------------------------------------
233
234 %.o : %.c
235         $(CC) $(ALL_CFLAGS) $(ALL_CPPFLAGS) -MM -MP -MF $*.d -MT "$@" $<
236         $(CC) $(ALL_CFLAGS) $(ALL_CPPFLAGS) -o $@ -c $<
237
238 %.sol : %.map $(MAPC_TARG)
239         $(MAPC) $< data
240
241 #------------------------------------------------------------------------------
242
243 all : $(BALL_TARG) $(PUTT_TARG) $(MAPC_TARG) sols locales
244
245 $(BALL_TARG) : $(BALL_OBJS)
246         $(CC) $(ALL_CFLAGS) -o $(BALL_TARG) $(BALL_OBJS) $(LDFLAGS) $(ALL_LIBS)
247
248 $(PUTT_TARG) : $(PUTT_OBJS)
249         $(CC) $(ALL_CFLAGS) -o $(PUTT_TARG) $(PUTT_OBJS) $(LDFLAGS) $(ALL_LIBS)
250
251 $(MAPC_TARG) : $(MAPC_OBJS)
252         $(CC) $(ALL_CFLAGS) -o $(MAPC_TARG) $(MAPC_OBJS) $(LDFLAGS) $(BASE_LIBS)
253
254 # Work around some extremely helpful sdl-config scripts.
255
256 ifdef MINGW
257 $(MAPC_TARG) : ALL_CPPFLAGS := $(ALL_CPPFLAGS) -Umain
258 endif
259
260 sols : $(SOLS)
261
262 locales :
263 ifneq ($(ENABLE_NLS),0)
264         $(MAKE) -C po
265 endif
266
267 clean-src :
268         $(RM) $(BALL_TARG) $(BALL_OBJS) $(BALL_DEPS)
269         $(RM) $(PUTT_TARG) $(PUTT_OBJS) $(PUTT_DEPS)
270         $(RM) $(MAPC_TARG) $(MAPC_OBJS) $(MAPC_DEPS)
271
272 clean : clean-src
273         $(RM) $(SOLS)
274         $(MAKE) -C po clean
275
276 test : all
277         ./neverball
278
279 #------------------------------------------------------------------------------
280
281 .PHONY : all sols locales clean-src clean test
282
283 -include $(BALL_DEPS) $(PUTT_DEPS) $(MAPC_DEPS)
284
285 #------------------------------------------------------------------------------
286
287 ifdef MINGW
288
289 #------------------------------------------------------------------------------
290
291 INSTALLER := ../neverball-$(VERSION)-setup.exe
292
293 MAKENSIS := makensis
294 MAKENSIS_FLAGS := -DVERSION=$(VERSION) -DOUTFILE=$(INSTALLER)
295
296 TODOS   := todos
297 FROMDOS := fromdos
298
299 CP := cp
300
301 TEXT_DOCS := \
302         doc/AUTHORS \
303         doc/MANUAL  \
304         CHANGES     \
305         COPYING     \
306         README
307
308 TXT_DOCS := $(TEXT_DOCS:%=%.txt)
309
310 #------------------------------------------------------------------------------
311
312 .PHONY: setup
313 setup: $(INSTALLER)
314
315 $(INSTALLER): install-dlls convert-text-files all contrib
316         $(MAKENSIS) $(MAKENSIS_FLAGS) -nocd scripts/neverball.nsi
317
318 $(INSTALLER): LDFLAGS := -s $(LDFLAGS)
319
320 .PHONY: clean-setup
321 clean-setup: clean
322         $(RM) install-dlls.sh *.dll $(TXT_DOCS)
323         find data -name "*.txt" -exec $(FROMDOS) {} \;
324         $(MAKE) -C contrib EXT=$(EXT) clean
325
326 #------------------------------------------------------------------------------
327
328 .PHONY: install-dlls
329 install-dlls: install-dlls.sh
330         sh $<
331
332 install-dlls.sh:
333         if ! sh scripts/gen-install-dlls.sh > $@; then \
334             $(RM) $@; \
335             exit 1; \
336         fi
337         @echo --------------------------------------------------------
338         @echo You can probably ignore any file-not-found errors above.
339         @echo Now edit $@ to your needs before restarting make.
340         @echo --------------------------------------------------------
341         @exit 1
342
343 #------------------------------------------------------------------------------
344
345 .PHONY: convert-text-files
346 convert-text-files: $(TXT_DOCS)
347         find data -name "*.txt" -exec $(TODOS) {} \;
348
349 %.txt: %
350         $(CP) $< $@
351         $(TODOS) $@
352
353 #------------------------------------------------------------------------------
354
355 .PHONY: contrib
356 contrib:
357         $(MAKE) -C contrib EXT=$(EXT)
358
359 #------------------------------------------------------------------------------
360
361 endif
362
363 #------------------------------------------------------------------------------