Add a basic directory scanner
[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/util.o         \
184         ball/st_conf.o      \
185         ball/st_demo.o      \
186         ball/st_save.o      \
187         ball/st_goal.o      \
188         ball/st_fall_out.o  \
189         ball/st_time_out.o  \
190         ball/st_done.o      \
191         ball/st_level.o     \
192         ball/st_over.o      \
193         ball/st_play.o      \
194         ball/st_set.o       \
195         ball/st_start.o     \
196         ball/st_title.o     \
197         ball/st_help.o      \
198         ball/st_name.o      \
199         ball/st_shared.o    \
200         ball/st_pause.o     \
201         ball/main.o
202 PUTT_OBJS := \
203         share/lang.o        \
204         share/st_resol.o    \
205         share/vec3.o        \
206         share/base_image.o  \
207         share/image.o       \
208         share/solid.o       \
209         share/solid_gl.o    \
210         share/solid_phys.o  \
211         share/part.o        \
212         share/geom.o        \
213         share/ball.o        \
214         share/back.o        \
215         share/base_config.o \
216         share/config.o      \
217         share/video.o       \
218         share/binary.o      \
219         share/audio.o       \
220         share/state.o       \
221         share/gui.o         \
222         share/text.o        \
223         share/sync.o        \
224         share/common.o      \
225         share/syswm.o       \
226         share/list.o        \
227         putt/hud.o          \
228         putt/game.o         \
229         putt/hole.o         \
230         putt/course.o       \
231         putt/st_all.o       \
232         putt/st_conf.o      \
233         putt/main.o
234
235 ifdef MINGW
236 BALL_OBJS += neverball.ico.o
237 PUTT_OBJS += neverputt.ico.o
238 endif
239
240 BALL_DEPS := $(BALL_OBJS:.o=.d)
241 PUTT_DEPS := $(PUTT_OBJS:.o=.d)
242 MAPC_DEPS := $(MAPC_OBJS:.o=.d)
243
244 MAPS := $(shell find data -name "*.map" \! -name "*.autosave.map")
245 SOLS := $(MAPS:%.map=%.sol)
246
247 DESKTOPS := $(basename $(wildcard dist/*.desktop.in))
248
249 #------------------------------------------------------------------------------
250
251 %.o : %.c
252         $(CC) $(ALL_CFLAGS) $(ALL_CPPFLAGS) -MM -MP -MF $*.d -MT "$@" $<
253         $(CC) $(ALL_CFLAGS) $(ALL_CPPFLAGS) -o $@ -c $<
254
255 %.sol : %.map $(MAPC_TARG)
256         $(MAPC) $< data
257
258 %.desktop : %.desktop.in
259         sh scripts/translate-desktop.sh < $< > $@
260
261 %.ico.o: dist/ico/%.ico
262         echo "1 ICON \"$<\"" | $(WINDRES) -o $@
263
264 #------------------------------------------------------------------------------
265
266 all : $(BALL_TARG) $(PUTT_TARG) $(MAPC_TARG) sols locales desktops
267
268 $(BALL_TARG) : $(BALL_OBJS)
269         $(CC) $(ALL_CFLAGS) -o $(BALL_TARG) $(BALL_OBJS) $(LDFLAGS) $(ALL_LIBS)
270
271 $(PUTT_TARG) : $(PUTT_OBJS)
272         $(CC) $(ALL_CFLAGS) -o $(PUTT_TARG) $(PUTT_OBJS) $(LDFLAGS) $(ALL_LIBS)
273
274 $(MAPC_TARG) : $(MAPC_OBJS)
275         $(CC) $(ALL_CFLAGS) -o $(MAPC_TARG) $(MAPC_OBJS) $(LDFLAGS) $(BASE_LIBS)
276
277 # Work around some extremely helpful sdl-config scripts.
278
279 ifdef MINGW
280 $(MAPC_TARG) : ALL_CPPFLAGS := $(ALL_CPPFLAGS) -Umain
281 endif
282
283 sols : $(SOLS)
284
285 locales :
286 ifneq ($(ENABLE_NLS),0)
287         $(MAKE) -C po
288 endif
289
290 desktops : $(DESKTOPS)
291
292 clean-src :
293         $(RM) $(BALL_TARG) $(BALL_OBJS) $(BALL_DEPS)
294         $(RM) $(PUTT_TARG) $(PUTT_OBJS) $(PUTT_DEPS)
295         $(RM) $(MAPC_TARG) $(MAPC_OBJS) $(MAPC_DEPS)
296
297 clean : clean-src
298         $(RM) $(SOLS)
299         $(RM) $(DESKTOPS)
300         $(MAKE) -C po clean
301
302 test : all
303         ./neverball
304
305 TAGS :
306         $(RM) $@
307         find . -name '*.[ch]' | xargs etags -a
308
309 #------------------------------------------------------------------------------
310
311 .PHONY : all sols locales clean-src clean test TAGS
312
313 -include $(BALL_DEPS) $(PUTT_DEPS) $(MAPC_DEPS)
314
315 #------------------------------------------------------------------------------
316
317 ifdef MINGW
318
319 #------------------------------------------------------------------------------
320
321 INSTALLER := ../neverball-$(VERSION)-setup.exe
322
323 MAKENSIS := makensis
324 MAKENSIS_FLAGS := -DVERSION=$(VERSION) -DOUTFILE=$(INSTALLER)
325
326 TODOS   := todos
327 FROMDOS := fromdos
328
329 CP := cp
330
331 TEXT_DOCS := \
332         doc/AUTHORS \
333         doc/MANUAL  \
334         CHANGES     \
335         COPYING     \
336         README
337
338 TXT_DOCS := $(TEXT_DOCS:%=%.txt)
339
340 #------------------------------------------------------------------------------
341
342 .PHONY: setup
343 setup: $(INSTALLER)
344
345 $(INSTALLER): install-dlls convert-text-files all contrib
346         $(MAKENSIS) $(MAKENSIS_FLAGS) -nocd scripts/neverball.nsi
347
348 $(INSTALLER): LDFLAGS := -s $(LDFLAGS)
349
350 .PHONY: clean-setup
351 clean-setup: clean
352         $(RM) install-dlls.sh *.dll $(TXT_DOCS)
353         find data -name "*.txt" -exec $(FROMDOS) {} \;
354         $(MAKE) -C contrib EXT=$(EXT) clean
355
356 #------------------------------------------------------------------------------
357
358 .PHONY: install-dlls
359 install-dlls: install-dlls.sh
360         sh $<
361
362 install-dlls.sh: $(MAPC_TARG) $(BALL_TARG) $(PUTT_TARG)
363         mingw-list-dlls --format=shell $^ > $@
364
365 #------------------------------------------------------------------------------
366
367 .PHONY: convert-text-files
368 convert-text-files: $(TXT_DOCS)
369         find data -name "*.txt" -exec $(TODOS) {} \;
370
371 %.txt: %
372         $(CP) $< $@
373         $(TODOS) $@
374
375 #------------------------------------------------------------------------------
376
377 .PHONY: contrib
378 contrib:
379         $(MAKE) -C contrib EXT=$(EXT)
380
381 #------------------------------------------------------------------------------
382
383 endif
384
385 #------------------------------------------------------------------------------