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