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