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