Treat angle values as floating point numbers
[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__
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 ALL_LIBS := $(SDL_LIBS) $(BASE_LIBS) $(TILT_LIBS) $(INTL_LIBS) -lSDL_ttf \
157     -lvorbisfile $(OGL_LIBS)
158
159 #------------------------------------------------------------------------------
160
161 ifeq ($(PLATFORM),mingw)
162     EXT := .exe
163 endif
164
165 MAPC_TARG := mapc$(EXT)
166 BALL_TARG := neverball$(EXT)
167 PUTT_TARG := neverputt$(EXT)
168
169 ifeq ($(PLATFORM),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_base.o  \
182         share/binary.o      \
183         share/base_config.o \
184         share/common.o      \
185         share/fs_common.o   \
186         share/fs_png.o      \
187         share/fs_jpg.o      \
188         share/dir.o         \
189         share/array.o       \
190         share/list.o        \
191         share/mapc.o
192 BALL_OBJS := \
193         share/lang.o        \
194         share/st_resol.o    \
195         share/vec3.o        \
196         share/base_image.o  \
197         share/image.o       \
198         share/solid_base.o  \
199         share/solid_vary.o  \
200         share/solid_draw.o  \
201         share/solid_cmd.o   \
202         share/solid_all.o   \
203         share/part.o        \
204         share/geom.o        \
205         share/item.o        \
206         share/ball.o        \
207         share/gui.o         \
208         share/base_config.o \
209         share/config.o      \
210         share/video.o       \
211         share/glext.o       \
212         share/binary.o      \
213         share/state.o       \
214         share/audio.o       \
215         share/text.o        \
216         share/common.o      \
217         share/keynames.o    \
218         share/syswm.o       \
219         share/list.o        \
220         share/queue.o       \
221         share/cmd.o         \
222         share/array.o       \
223         share/dir.o         \
224         share/fs_common.o   \
225         share/fs_png.o      \
226         share/fs_jpg.o      \
227         share/fs_rwops.o    \
228         share/fs_ov.o       \
229         share/sync.o        \
230         ball/hud.o          \
231         ball/game_common.o  \
232         ball/game_client.o  \
233         ball/game_server.o  \
234         ball/game_proxy.o   \
235         ball/game_draw.o    \
236         ball/score.o        \
237         ball/level.o        \
238         ball/progress.o     \
239         ball/set.o          \
240         ball/demo.o         \
241         ball/demo_dir.o     \
242         ball/util.o         \
243         ball/speed.o        \
244         ball/st_conf.o      \
245         ball/st_demo.o      \
246         ball/st_save.o      \
247         ball/st_goal.o      \
248         ball/st_fail.o      \
249         ball/st_done.o      \
250         ball/st_level.o     \
251         ball/st_over.o      \
252         ball/st_play.o      \
253         ball/st_set.o       \
254         ball/st_start.o     \
255         ball/st_title.o     \
256         ball/st_help.o      \
257         ball/st_name.o      \
258         ball/st_shared.o    \
259         ball/st_pause.o     \
260         ball/st_ball.o      \
261         ball/main.o
262 PUTT_OBJS := \
263         share/lang.o        \
264         share/st_resol.o    \
265         share/vec3.o        \
266         share/base_image.o  \
267         share/image.o       \
268         share/solid_base.o  \
269         share/solid_vary.o  \
270         share/solid_draw.o  \
271         share/solid_cmd.o   \
272         share/solid_all.o   \
273         share/part.o        \
274         share/geom.o        \
275         share/ball.o        \
276         share/base_config.o \
277         share/config.o      \
278         share/video.o       \
279         share/glext.o       \
280         share/binary.o      \
281         share/audio.o       \
282         share/state.o       \
283         share/gui.o         \
284         share/text.o        \
285         share/common.o      \
286         share/syswm.o       \
287         share/list.o        \
288         share/fs_common.o   \
289         share/fs_png.o      \
290         share/fs_jpg.o      \
291         share/fs_rwops.o    \
292         share/fs_ov.o       \
293         share/dir.o         \
294         share/array.o       \
295         share/sync.o        \
296         putt/hud.o          \
297         putt/game.o         \
298         putt/hole.o         \
299         putt/course.o       \
300         putt/st_all.o       \
301         putt/st_conf.o      \
302         putt/main.o
303
304 BALL_OBJS += share/solid_sim_sol.o
305 PUTT_OBJS += share/solid_sim_sol.o
306
307 ifeq ($(ENABLE_FS),stdio)
308 BALL_OBJS += share/fs_stdio.o
309 PUTT_OBJS += share/fs_stdio.o
310 MAPC_OBJS += share/fs_stdio.o
311 else
312 BALL_OBJS += share/fs_physfs.o
313 PUTT_OBJS += share/fs_physfs.o
314 MAPC_OBJS += share/fs_physfs.o
315 endif
316
317 ifeq ($(ENABLE_TILT),wii)
318 BALL_OBJS += share/tilt_wii.o
319 else
320 ifeq ($(ENABLE_TILT),loop)
321 BALL_OBJS += share/tilt_loop.o
322 else
323 ifeq ($(PLATFORM),maemo)
324 BALL_OBJS += share/tilt_maemo.o
325 else
326 BALL_OBJS += share/tilt_null.o
327 endif
328 endif
329 endif
330
331 ifeq ($(PLATFORM),mingw)
332 BALL_OBJS += neverball.ico.o
333 PUTT_OBJS += neverputt.ico.o
334 endif
335
336 BALL_DEPS := $(BALL_OBJS:.o=.d)
337 PUTT_DEPS := $(PUTT_OBJS:.o=.d)
338 MAPC_DEPS := $(MAPC_OBJS:.o=.d)
339
340 MAPS := $(shell find data -name "*.map" \! -name "*.autosave.map")
341 SOLS := $(MAPS:%.map=%.sol)
342
343 DESKTOPS := $(basename $(wildcard dist/*.desktop.in))
344
345 #------------------------------------------------------------------------------
346
347 %.o : %.c
348         $(CC) $(ALL_CFLAGS) $(ALL_CPPFLAGS) -MM -MP -MF $*.d -MT "$@" $<
349         $(CC) $(ALL_CFLAGS) $(ALL_CPPFLAGS) -o $@ -c $<
350
351 %.sol : %.map $(MAPC_TARG)
352         $(MAPC) $< data
353
354 %.desktop : %.desktop.in
355         sh scripts/translate-desktop.sh < $< > $@
356
357 %.ico.o: dist/ico/%.ico
358         echo "1 ICON \"$<\"" | $(WINDRES) -o $@
359
360 #------------------------------------------------------------------------------
361
362 all : $(BALL_TARG) $(PUTT_TARG) $(MAPC_TARG) sols locales desktops
363
364 $(BALL_TARG) : $(BALL_OBJS)
365         $(CC) $(ALL_CFLAGS) -o $(BALL_TARG) $(BALL_OBJS) $(LDFLAGS) $(ALL_LIBS)
366
367 $(PUTT_TARG) : $(PUTT_OBJS)
368         $(CC) $(ALL_CFLAGS) -o $(PUTT_TARG) $(PUTT_OBJS) $(LDFLAGS) $(ALL_LIBS)
369
370 $(MAPC_TARG) : $(MAPC_OBJS)
371         $(CC) $(ALL_CFLAGS) -o $(MAPC_TARG) $(MAPC_OBJS) $(LDFLAGS) $(BASE_LIBS)
372
373 # Work around some extremely helpful sdl-config scripts.
374
375 ifeq ($(PLATFORM),mingw)
376 $(MAPC_TARG) : ALL_CPPFLAGS := $(ALL_CPPFLAGS) -Umain
377 endif
378
379 sols : $(SOLS)
380
381 locales :
382 ifneq ($(ENABLE_NLS),0)
383         $(MAKE) -C po
384 endif
385
386 desktops : $(DESKTOPS)
387
388 clean-src :
389         $(RM) $(BALL_TARG) $(BALL_OBJS) $(BALL_DEPS)
390         $(RM) $(PUTT_TARG) $(PUTT_OBJS) $(PUTT_DEPS)
391         $(RM) $(MAPC_TARG) $(MAPC_OBJS) $(MAPC_DEPS)
392
393 clean : clean-src
394         $(RM) $(SOLS)
395         $(RM) $(DESKTOPS)
396         $(MAKE) -C po clean
397
398 test : all
399         ./neverball
400
401 TAGS :
402         $(RM) $@
403         find . -name '*.[ch]' | xargs etags -a
404
405 #------------------------------------------------------------------------------
406
407 .PHONY : all sols locales clean-src clean test TAGS
408
409 -include $(BALL_DEPS) $(PUTT_DEPS) $(MAPC_DEPS)
410
411 #------------------------------------------------------------------------------
412
413 ifeq ($(PLATFORM),mingw)
414
415 #------------------------------------------------------------------------------
416
417 INSTALLER := ../neverball-$(VERSION)-setup.exe
418
419 MAKENSIS := makensis
420 MAKENSIS_FLAGS := -DVERSION=$(VERSION) -DOUTFILE=$(INSTALLER)
421
422 TODOS   := todos
423 FROMDOS := fromdos
424
425 CP := cp
426
427 TEXT_DOCS := \
428         doc/AUTHORS \
429         doc/MANUAL  \
430         CHANGES     \
431         COPYING     \
432         README
433
434 TXT_DOCS := $(TEXT_DOCS:%=%.txt)
435
436 #------------------------------------------------------------------------------
437
438 .PHONY: setup
439 setup: $(INSTALLER)
440
441 $(INSTALLER): install-dlls convert-text-files all contrib
442         $(MAKENSIS) $(MAKENSIS_FLAGS) -nocd scripts/neverball.nsi
443
444 $(INSTALLER): LDFLAGS := -s $(LDFLAGS)
445
446 .PHONY: clean-setup
447 clean-setup: clean
448         $(RM) install-dlls.sh *.dll $(TXT_DOCS)
449         find data -name "*.txt" -exec $(FROMDOS) {} \;
450         $(MAKE) -C contrib EXT=$(EXT) clean
451
452 #------------------------------------------------------------------------------
453
454 .PHONY: install-dlls
455 install-dlls: install-dlls.sh
456         sh $<
457
458 install-dlls.sh: $(MAPC_TARG) $(BALL_TARG) $(PUTT_TARG)
459         mingw-list-dlls --format=shell $^ > $@
460
461 #------------------------------------------------------------------------------
462
463 .PHONY: convert-text-files
464 convert-text-files: $(TXT_DOCS)
465         find data -name "*.txt" -exec $(TODOS) {} \;
466
467 %.txt: %
468         $(CP) $< $@
469         $(TODOS) $@
470
471 #------------------------------------------------------------------------------
472
473 .PHONY: contrib
474 contrib:
475         $(MAKE) -C contrib EXT=$(EXT)
476
477 #------------------------------------------------------------------------------
478
479 endif
480
481 #------------------------------------------------------------------------------