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