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