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