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