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