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