Makefile: bump version
[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.3
8 else
9     VERSION := $(shell sh scripts/version.sh)
10     ifeq ($(VERSION),unknown)
11         VERSION := 1.5.3-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 ifdef DARWIN
91     ALL_CPPFLAGS += -I/opt/local/include
92 endif
93
94 ALL_CPPFLAGS += $(CPPFLAGS)
95
96 #------------------------------------------------------------------------------
97 # Libraries
98
99 SDL_LIBS := $(shell sdl-config --libs)
100 PNG_LIBS := $(shell libpng-config --libs)
101 FS_LIBS := -lphysfs
102
103 # The  non-conditionalised values  below  are specific  to the  native
104 # system. The native system of this Makefile is Linux (or GNU+Linux if
105 # you prefer). Please be sure to  override ALL of them for each target
106 # system in the conditional parts below.
107
108 INTL_LIBS :=
109
110 ifeq ($(ENABLE_WII),1)
111     TILT_LIBS := -lcwiimote -lbluetooth
112 endif
113
114 OGL_LIBS := -lGL -lm
115
116 ifdef MINGW
117     ifneq ($(ENABLE_NLS),0)
118         INTL_LIBS := -lintl
119     endif
120
121     TILT_LIBS :=
122     OGL_LIBS  := -lopengl32 -lm
123 endif
124
125 ifdef DARWIN
126     ifneq ($(ENABLE_NLS),0)
127         INTL_LIBS := -lintl
128     endif
129
130     TILT_LIBS :=
131     OGL_LIBS  := -framework OpenGL
132 endif
133
134 BASE_LIBS := -ljpeg $(PNG_LIBS) $(FS_LIBS)
135
136 ifdef DARWIN
137     BASE_LIBS += -L/opt/local/lib
138 endif
139
140 ALL_LIBS := $(SDL_LIBS) $(BASE_LIBS) $(TILT_LIBS) $(INTL_LIBS) -lSDL_ttf \
141     -lvorbisfile $(OGL_LIBS)
142
143 #------------------------------------------------------------------------------
144
145 ifdef MINGW
146     EXT := .exe
147 endif
148
149 MAPC_TARG := mapc$(EXT)
150 BALL_TARG := neverball$(EXT)
151 PUTT_TARG := neverputt$(EXT)
152
153 ifdef MINGW
154     MAPC := $(WINE) ./$(MAPC_TARG)
155 else
156     MAPC := ./$(MAPC_TARG)
157 endif
158
159
160 #------------------------------------------------------------------------------
161
162 MAPC_OBJS := \
163         share/vec3.o        \
164         share/base_image.o  \
165         share/solid.o       \
166         share/binary.o      \
167         share/base_config.o \
168         share/common.o      \
169         share/fs.o          \
170         share/fs_png.o      \
171         share/fs_jpg.o      \
172         share/dir.o         \
173         share/array.o       \
174         share/mapc.o
175 BALL_OBJS := \
176         share/lang.o        \
177         share/st_resol.o    \
178         share/vec3.o        \
179         share/base_image.o  \
180         share/image.o       \
181         share/solid.o       \
182         share/solid_gl.o    \
183         share/solid_phys.o  \
184         share/part.o        \
185         share/back.o        \
186         share/geom.o        \
187         share/item.o        \
188         share/ball.o        \
189         share/gui.o         \
190         share/base_config.o \
191         share/config.o      \
192         share/video.o       \
193         share/binary.o      \
194         share/state.o       \
195         share/audio.o       \
196         share/text.o        \
197         share/tilt.o        \
198         share/common.o      \
199         share/keynames.o    \
200         share/syswm.o       \
201         share/list.o        \
202         share/queue.o       \
203         share/cmd.o         \
204         share/array.o       \
205         share/dir.o         \
206         share/fs.o          \
207         share/fs_png.o      \
208         share/fs_jpg.o      \
209         share/fs_rwops.o    \
210         share/fs_ov.o       \
211         ball/hud.o          \
212         ball/game_common.o  \
213         ball/game_client.o  \
214         ball/game_server.o  \
215         ball/game_proxy.o   \
216         ball/score.o        \
217         ball/level.o        \
218         ball/progress.o     \
219         ball/set.o          \
220         ball/demo.o         \
221         ball/demo_dir.o     \
222         ball/util.o         \
223         ball/st_conf.o      \
224         ball/st_demo.o      \
225         ball/st_save.o      \
226         ball/st_goal.o      \
227         ball/st_fall_out.o  \
228         ball/st_time_out.o  \
229         ball/st_done.o      \
230         ball/st_level.o     \
231         ball/st_over.o      \
232         ball/st_play.o      \
233         ball/st_set.o       \
234         ball/st_start.o     \
235         ball/st_title.o     \
236         ball/st_help.o      \
237         ball/st_name.o      \
238         ball/st_shared.o    \
239         ball/st_pause.o     \
240         ball/st_ball.o      \
241         ball/main.o
242 PUTT_OBJS := \
243         share/lang.o        \
244         share/st_resol.o    \
245         share/vec3.o        \
246         share/base_image.o  \
247         share/image.o       \
248         share/solid.o       \
249         share/solid_gl.o    \
250         share/solid_phys.o  \
251         share/part.o        \
252         share/geom.o        \
253         share/ball.o        \
254         share/back.o        \
255         share/base_config.o \
256         share/config.o      \
257         share/video.o       \
258         share/binary.o      \
259         share/audio.o       \
260         share/state.o       \
261         share/gui.o         \
262         share/text.o        \
263         share/common.o      \
264         share/syswm.o       \
265         share/list.o        \
266         share/fs.o          \
267         share/fs_png.o      \
268         share/fs_jpg.o      \
269         share/fs_rwops.o    \
270         share/fs_ov.o       \
271         share/dir.o         \
272         share/array.o       \
273         putt/hud.o          \
274         putt/game.o         \
275         putt/hole.o         \
276         putt/course.o       \
277         putt/st_all.o       \
278         putt/st_conf.o      \
279         putt/main.o
280
281 ifdef MINGW
282 BALL_OBJS += neverball.ico.o
283 PUTT_OBJS += neverputt.ico.o
284 endif
285
286 BALL_DEPS := $(BALL_OBJS:.o=.d)
287 PUTT_DEPS := $(PUTT_OBJS:.o=.d)
288 MAPC_DEPS := $(MAPC_OBJS:.o=.d)
289
290 MAPS := $(shell find data -name "*.map" \! -name "*.autosave.map")
291 SOLS := $(MAPS:%.map=%.sol)
292
293 DESKTOPS := $(basename $(wildcard dist/*.desktop.in))
294
295 #------------------------------------------------------------------------------
296
297 %.o : %.c
298         $(CC) $(ALL_CFLAGS) $(ALL_CPPFLAGS) -MM -MP -MF $*.d -MT "$@" $<
299         $(CC) $(ALL_CFLAGS) $(ALL_CPPFLAGS) -o $@ -c $<
300
301 %.sol : %.map $(MAPC_TARG)
302         $(MAPC) $< data
303
304 %.desktop : %.desktop.in
305         sh scripts/translate-desktop.sh < $< > $@
306
307 %.ico.o: dist/ico/%.ico
308         echo "1 ICON \"$<\"" | $(WINDRES) -o $@
309
310 #------------------------------------------------------------------------------
311
312 all : $(BALL_TARG) $(PUTT_TARG) $(MAPC_TARG) sols locales desktops
313
314 $(BALL_TARG) : $(BALL_OBJS)
315         $(CC) $(ALL_CFLAGS) -o $(BALL_TARG) $(BALL_OBJS) $(LDFLAGS) $(ALL_LIBS)
316
317 $(PUTT_TARG) : $(PUTT_OBJS)
318         $(CC) $(ALL_CFLAGS) -o $(PUTT_TARG) $(PUTT_OBJS) $(LDFLAGS) $(ALL_LIBS)
319
320 $(MAPC_TARG) : $(MAPC_OBJS)
321         $(CC) $(ALL_CFLAGS) -o $(MAPC_TARG) $(MAPC_OBJS) $(LDFLAGS) $(BASE_LIBS)
322
323 # Work around some extremely helpful sdl-config scripts.
324
325 ifdef MINGW
326 $(MAPC_TARG) : ALL_CPPFLAGS := $(ALL_CPPFLAGS) -Umain
327 endif
328
329 sols : $(SOLS)
330
331 locales :
332 ifneq ($(ENABLE_NLS),0)
333         $(MAKE) -C po
334 endif
335
336 desktops : $(DESKTOPS)
337
338 clean-src :
339         $(RM) $(BALL_TARG) $(BALL_OBJS) $(BALL_DEPS)
340         $(RM) $(PUTT_TARG) $(PUTT_OBJS) $(PUTT_DEPS)
341         $(RM) $(MAPC_TARG) $(MAPC_OBJS) $(MAPC_DEPS)
342
343 clean : clean-src
344         $(RM) $(SOLS)
345         $(RM) $(DESKTOPS)
346         $(MAKE) -C po clean
347
348 test : all
349         ./neverball
350
351 TAGS :
352         $(RM) $@
353         find . -name '*.[ch]' | xargs etags -a
354
355 #------------------------------------------------------------------------------
356
357 .PHONY : all sols locales clean-src clean test TAGS
358
359 -include $(BALL_DEPS) $(PUTT_DEPS) $(MAPC_DEPS)
360
361 #------------------------------------------------------------------------------
362
363 ifdef MINGW
364
365 #------------------------------------------------------------------------------
366
367 INSTALLER := ../neverball-$(VERSION)-setup.exe
368
369 MAKENSIS := makensis
370 MAKENSIS_FLAGS := -DVERSION=$(VERSION) -DOUTFILE=$(INSTALLER)
371
372 TODOS   := todos
373 FROMDOS := fromdos
374
375 CP := cp
376
377 TEXT_DOCS := \
378         doc/AUTHORS \
379         doc/MANUAL  \
380         CHANGES     \
381         COPYING     \
382         README
383
384 TXT_DOCS := $(TEXT_DOCS:%=%.txt)
385
386 #------------------------------------------------------------------------------
387
388 .PHONY: setup
389 setup: $(INSTALLER)
390
391 $(INSTALLER): install-dlls convert-text-files all contrib
392         $(MAKENSIS) $(MAKENSIS_FLAGS) -nocd scripts/neverball.nsi
393
394 $(INSTALLER): LDFLAGS := -s $(LDFLAGS)
395
396 .PHONY: clean-setup
397 clean-setup: clean
398         $(RM) install-dlls.sh *.dll $(TXT_DOCS)
399         find data -name "*.txt" -exec $(FROMDOS) {} \;
400         $(MAKE) -C contrib EXT=$(EXT) clean
401
402 #------------------------------------------------------------------------------
403
404 .PHONY: install-dlls
405 install-dlls: install-dlls.sh
406         sh $<
407
408 install-dlls.sh: $(MAPC_TARG) $(BALL_TARG) $(PUTT_TARG)
409         mingw-list-dlls --format=shell $^ > $@
410
411 #------------------------------------------------------------------------------
412
413 .PHONY: convert-text-files
414 convert-text-files: $(TXT_DOCS)
415         find data -name "*.txt" -exec $(TODOS) {} \;
416
417 %.txt: %
418         $(CP) $< $@
419         $(TODOS) $@
420
421 #------------------------------------------------------------------------------
422
423 .PHONY: contrib
424 contrib:
425         $(MAKE) -C contrib EXT=$(EXT)
426
427 #------------------------------------------------------------------------------
428
429 endif
430
431 #------------------------------------------------------------------------------