Move item-related functions into a separate module
[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/item.o        \
154         share/ball.o        \
155         share/gui.o         \
156         share/base_config.o \
157         share/config.o      \
158         share/binary.o      \
159         share/state.o       \
160         share/audio.o       \
161         share/text.o        \
162         share/sync.o        \
163         share/tilt.o        \
164         share/common.o      \
165         share/keynames.o    \
166         ball/hud.o          \
167         ball/game.o         \
168         ball/score.o        \
169         ball/level.o        \
170         ball/progress.o     \
171         ball/set.o          \
172         ball/demo.o         \
173         ball/util.o         \
174         ball/st_conf.o      \
175         ball/st_demo.o      \
176         ball/st_save.o      \
177         ball/st_goal.o      \
178         ball/st_fall_out.o  \
179         ball/st_time_out.o  \
180         ball/st_done.o      \
181         ball/st_level.o     \
182         ball/st_over.o      \
183         ball/st_play.o      \
184         ball/st_set.o       \
185         ball/st_start.o     \
186         ball/st_title.o     \
187         ball/st_help.o      \
188         ball/st_name.o      \
189         ball/st_shared.o    \
190         ball/st_pause.o     \
191         ball/main.o
192 PUTT_OBJS := \
193         share/lang.o        \
194         share/st_resol.o    \
195         share/vec3.o        \
196         share/base_image.o  \
197         share/image.o       \
198         share/solid.o       \
199         share/solid_gl.o    \
200         share/part.o        \
201         share/geom.o        \
202         share/ball.o        \
203         share/back.o        \
204         share/base_config.o \
205         share/config.o      \
206         share/binary.o      \
207         share/audio.o       \
208         share/state.o       \
209         share/gui.o         \
210         share/text.o        \
211         share/sync.o        \
212         share/common.o      \
213         putt/hud.o          \
214         putt/game.o         \
215         putt/hole.o         \
216         putt/course.o       \
217         putt/st_all.o       \
218         putt/st_conf.o      \
219         putt/main.o
220
221 BALL_DEPS := $(BALL_OBJS:.o=.d)
222 PUTT_DEPS := $(PUTT_OBJS:.o=.d)
223 MAPC_DEPS := $(MAPC_OBJS:.o=.d)
224
225 MAPS := $(shell find data -name "*.map" \! -name "*.autosave.map")
226 SOLS := $(MAPS:%.map=%.sol)
227
228 #------------------------------------------------------------------------------
229
230 %.o : %.c
231         $(CC) $(ALL_CFLAGS) $(ALL_CPPFLAGS) -MM -MP -MF $*.d -MT "$@" $<
232         $(CC) $(ALL_CFLAGS) $(ALL_CPPFLAGS) -o $@ -c $<
233
234 %.sol : %.map $(MAPC_TARG)
235         $(MAPC) $< data
236
237 #------------------------------------------------------------------------------
238
239 all : $(BALL_TARG) $(PUTT_TARG) $(MAPC_TARG) sols locales
240
241 $(BALL_TARG) : $(BALL_OBJS)
242         $(CC) $(ALL_CFLAGS) -o $(BALL_TARG) $(BALL_OBJS) $(LDFLAGS) $(ALL_LIBS)
243
244 $(PUTT_TARG) : $(PUTT_OBJS)
245         $(CC) $(ALL_CFLAGS) -o $(PUTT_TARG) $(PUTT_OBJS) $(LDFLAGS) $(ALL_LIBS)
246
247 $(MAPC_TARG) : $(MAPC_OBJS)
248         $(CC) $(ALL_CFLAGS) -o $(MAPC_TARG) $(MAPC_OBJS) $(LDFLAGS) $(BASE_LIBS)
249
250 # Work around some extremely helpful sdl-config scripts.
251
252 ifdef MINGW
253 $(MAPC_TARG) : ALL_CPPFLAGS := $(ALL_CPPFLAGS) -Umain
254 endif
255
256 sols : $(SOLS)
257
258 locales :
259 ifneq ($(ENABLE_NLS),0)
260         $(MAKE) -C po
261 endif
262
263 clean-src :
264         $(RM) $(BALL_TARG) $(BALL_OBJS) $(BALL_DEPS)
265         $(RM) $(PUTT_TARG) $(PUTT_OBJS) $(PUTT_DEPS)
266         $(RM) $(MAPC_TARG) $(MAPC_OBJS) $(MAPC_DEPS)
267
268 clean : clean-src
269         $(RM) $(SOLS)
270         $(MAKE) -C po clean
271
272 test : all
273         ./neverball
274
275 #------------------------------------------------------------------------------
276
277 .PHONY : all sols locales clean-src clean test
278
279 -include $(BALL_DEPS) $(PUTT_DEPS) $(MAPC_DEPS)
280
281 #------------------------------------------------------------------------------
282
283 ifdef MINGW
284
285 #------------------------------------------------------------------------------
286
287 INSTALLER := ../neverball-$(VERSION)-setup.exe
288
289 MAKENSIS := makensis
290 MAKENSIS_FLAGS := -DVERSION=$(VERSION) -DOUTFILE=$(INSTALLER)
291
292 TODOS   := todos
293 FROMDOS := fromdos
294
295 CP := cp
296
297 TEXT_DOCS := \
298         doc/AUTHORS \
299         doc/MANUAL  \
300         CHANGES     \
301         COPYING     \
302         README
303
304 TXT_DOCS := $(TEXT_DOCS:%=%.txt)
305
306 #------------------------------------------------------------------------------
307
308 .PHONY: setup
309 setup: $(INSTALLER)
310
311 $(INSTALLER): install-dlls convert-text-files all contrib
312         $(MAKENSIS) $(MAKENSIS_FLAGS) -nocd scripts/neverball.nsi
313
314 $(INSTALLER): LDFLAGS := -s $(LDFLAGS)
315
316 .PHONY: clean-setup
317 clean-setup: clean
318         $(RM) install-dlls.sh *.dll $(TXT_DOCS)
319         find data -name "*.txt" -exec $(FROMDOS) {} \;
320         $(MAKE) -C contrib EXT=$(EXT) clean
321
322 #------------------------------------------------------------------------------
323
324 .PHONY: install-dlls
325 install-dlls: install-dlls.sh
326         sh $<
327
328 install-dlls.sh:
329         if ! sh scripts/gen-install-dlls.sh > $@; then \
330             $(RM) $@; \
331             exit 1; \
332         fi
333         @echo --------------------------------------------------------
334         @echo You can probably ignore any file-not-found errors above.
335         @echo Now edit $@ to your needs before restarting make.
336         @echo --------------------------------------------------------
337         @exit 1
338
339 #------------------------------------------------------------------------------
340
341 .PHONY: convert-text-files
342 convert-text-files: $(TXT_DOCS)
343         find data -name "*.txt" -exec $(TODOS) {} \;
344
345 %.txt: %
346         $(CP) $< $@
347         $(TODOS) $@
348
349 #------------------------------------------------------------------------------
350
351 .PHONY: contrib
352 contrib:
353         $(MAKE) -C contrib EXT=$(EXT)
354
355 #------------------------------------------------------------------------------
356
357 endif
358
359 #------------------------------------------------------------------------------