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