Prevent switching to windowed mode
[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 BALL_OBJS += share/tilt_null.o
324 endif
325 endif
326
327 ifeq ($(PLATFORM),mingw)
328 BALL_OBJS += neverball.ico.o
329 PUTT_OBJS += neverputt.ico.o
330 endif
331
332 BALL_DEPS := $(BALL_OBJS:.o=.d)
333 PUTT_DEPS := $(PUTT_OBJS:.o=.d)
334 MAPC_DEPS := $(MAPC_OBJS:.o=.d)
335
336 MAPS := $(shell find data -name "*.map" \! -name "*.autosave.map")
337 SOLS := $(MAPS:%.map=%.sol)
338
339 DESKTOPS := $(basename $(wildcard dist/*.desktop.in))
340
341 #------------------------------------------------------------------------------
342
343 %.o : %.c
344         $(CC) $(ALL_CFLAGS) $(ALL_CPPFLAGS) -MM -MP -MF $*.d -MT "$@" $<
345         $(CC) $(ALL_CFLAGS) $(ALL_CPPFLAGS) -o $@ -c $<
346
347 %.sol : %.map $(MAPC_TARG)
348         $(MAPC) $< data
349
350 %.desktop : %.desktop.in
351         sh scripts/translate-desktop.sh < $< > $@
352
353 %.ico.o: dist/ico/%.ico
354         echo "1 ICON \"$<\"" | $(WINDRES) -o $@
355
356 #------------------------------------------------------------------------------
357
358 all : $(BALL_TARG) $(PUTT_TARG) $(MAPC_TARG) sols locales desktops
359
360 $(BALL_TARG) : $(BALL_OBJS)
361         $(CC) $(ALL_CFLAGS) -o $(BALL_TARG) $(BALL_OBJS) $(LDFLAGS) $(ALL_LIBS)
362
363 $(PUTT_TARG) : $(PUTT_OBJS)
364         $(CC) $(ALL_CFLAGS) -o $(PUTT_TARG) $(PUTT_OBJS) $(LDFLAGS) $(ALL_LIBS)
365
366 $(MAPC_TARG) : $(MAPC_OBJS)
367         $(CC) $(ALL_CFLAGS) -o $(MAPC_TARG) $(MAPC_OBJS) $(LDFLAGS) $(BASE_LIBS)
368
369 # Work around some extremely helpful sdl-config scripts.
370
371 ifeq ($(PLATFORM),mingw)
372 $(MAPC_TARG) : ALL_CPPFLAGS := $(ALL_CPPFLAGS) -Umain
373 endif
374
375 sols : $(SOLS)
376
377 locales :
378 ifneq ($(ENABLE_NLS),0)
379         $(MAKE) -C po
380 endif
381
382 desktops : $(DESKTOPS)
383
384 clean-src :
385         $(RM) $(BALL_TARG) $(BALL_OBJS) $(BALL_DEPS)
386         $(RM) $(PUTT_TARG) $(PUTT_OBJS) $(PUTT_DEPS)
387         $(RM) $(MAPC_TARG) $(MAPC_OBJS) $(MAPC_DEPS)
388
389 clean : clean-src
390         $(RM) $(SOLS)
391         $(RM) $(DESKTOPS)
392         $(MAKE) -C po clean
393
394 test : all
395         ./neverball
396
397 TAGS :
398         $(RM) $@
399         find . -name '*.[ch]' | xargs etags -a
400
401 #------------------------------------------------------------------------------
402
403 .PHONY : all sols locales clean-src clean test TAGS
404
405 -include $(BALL_DEPS) $(PUTT_DEPS) $(MAPC_DEPS)
406
407 #------------------------------------------------------------------------------
408
409 ifeq ($(PLATFORM),mingw)
410
411 #------------------------------------------------------------------------------
412
413 INSTALLER := ../neverball-$(VERSION)-setup.exe
414
415 MAKENSIS := makensis
416 MAKENSIS_FLAGS := -DVERSION=$(VERSION) -DOUTFILE=$(INSTALLER)
417
418 TODOS   := todos
419 FROMDOS := fromdos
420
421 CP := cp
422
423 TEXT_DOCS := \
424         doc/AUTHORS \
425         doc/MANUAL  \
426         CHANGES     \
427         COPYING     \
428         README
429
430 TXT_DOCS := $(TEXT_DOCS:%=%.txt)
431
432 #------------------------------------------------------------------------------
433
434 .PHONY: setup
435 setup: $(INSTALLER)
436
437 $(INSTALLER): install-dlls convert-text-files all contrib
438         $(MAKENSIS) $(MAKENSIS_FLAGS) -nocd scripts/neverball.nsi
439
440 $(INSTALLER): LDFLAGS := -s $(LDFLAGS)
441
442 .PHONY: clean-setup
443 clean-setup: clean
444         $(RM) install-dlls.sh *.dll $(TXT_DOCS)
445         find data -name "*.txt" -exec $(FROMDOS) {} \;
446         $(MAKE) -C contrib EXT=$(EXT) clean
447
448 #------------------------------------------------------------------------------
449
450 .PHONY: install-dlls
451 install-dlls: install-dlls.sh
452         sh $<
453
454 install-dlls.sh: $(MAPC_TARG) $(BALL_TARG) $(PUTT_TARG)
455         mingw-list-dlls --format=shell $^ > $@
456
457 #------------------------------------------------------------------------------
458
459 .PHONY: convert-text-files
460 convert-text-files: $(TXT_DOCS)
461         find data -name "*.txt" -exec $(TODOS) {} \;
462
463 %.txt: %
464         $(CP) $< $@
465         $(TODOS) $@
466
467 #------------------------------------------------------------------------------
468
469 .PHONY: contrib
470 contrib:
471         $(MAKE) -C contrib EXT=$(EXT)
472
473 #------------------------------------------------------------------------------
474
475 endif
476
477 #------------------------------------------------------------------------------