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