Set the EWMH _NET_WM_ICON window hint on X11 systems
[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 #------------------------------------------------------------------------------
231
232 %.o : %.c
233         $(CC) $(ALL_CFLAGS) $(ALL_CPPFLAGS) -MM -MP -MF $*.d -MT "$@" $<
234         $(CC) $(ALL_CFLAGS) $(ALL_CPPFLAGS) -o $@ -c $<
235
236 %.sol : %.map $(MAPC_TARG)
237         $(MAPC) $< data
238
239 #------------------------------------------------------------------------------
240
241 all : $(BALL_TARG) $(PUTT_TARG) $(MAPC_TARG) sols locales
242
243 $(BALL_TARG) : $(BALL_OBJS)
244         $(CC) $(ALL_CFLAGS) -o $(BALL_TARG) $(BALL_OBJS) $(LDFLAGS) $(ALL_LIBS)
245
246 $(PUTT_TARG) : $(PUTT_OBJS)
247         $(CC) $(ALL_CFLAGS) -o $(PUTT_TARG) $(PUTT_OBJS) $(LDFLAGS) $(ALL_LIBS)
248
249 $(MAPC_TARG) : $(MAPC_OBJS)
250         $(CC) $(ALL_CFLAGS) -o $(MAPC_TARG) $(MAPC_OBJS) $(LDFLAGS) $(BASE_LIBS)
251
252 # Work around some extremely helpful sdl-config scripts.
253
254 ifdef MINGW
255 $(MAPC_TARG) : ALL_CPPFLAGS := $(ALL_CPPFLAGS) -Umain
256 endif
257
258 sols : $(SOLS)
259
260 locales :
261 ifneq ($(ENABLE_NLS),0)
262         $(MAKE) -C po
263 endif
264
265 clean-src :
266         $(RM) $(BALL_TARG) $(BALL_OBJS) $(BALL_DEPS)
267         $(RM) $(PUTT_TARG) $(PUTT_OBJS) $(PUTT_DEPS)
268         $(RM) $(MAPC_TARG) $(MAPC_OBJS) $(MAPC_DEPS)
269
270 clean : clean-src
271         $(RM) $(SOLS)
272         $(MAKE) -C po clean
273
274 test : all
275         ./neverball
276
277 #------------------------------------------------------------------------------
278
279 .PHONY : all sols locales clean-src clean test
280
281 -include $(BALL_DEPS) $(PUTT_DEPS) $(MAPC_DEPS)
282
283 #------------------------------------------------------------------------------
284
285 ifdef MINGW
286
287 #------------------------------------------------------------------------------
288
289 INSTALLER := ../neverball-$(VERSION)-setup.exe
290
291 MAKENSIS := makensis
292 MAKENSIS_FLAGS := -DVERSION=$(VERSION) -DOUTFILE=$(INSTALLER)
293
294 TODOS   := todos
295 FROMDOS := fromdos
296
297 CP := cp
298
299 TEXT_DOCS := \
300         doc/AUTHORS \
301         doc/MANUAL  \
302         CHANGES     \
303         COPYING     \
304         README
305
306 TXT_DOCS := $(TEXT_DOCS:%=%.txt)
307
308 #------------------------------------------------------------------------------
309
310 .PHONY: setup
311 setup: $(INSTALLER)
312
313 $(INSTALLER): install-dlls convert-text-files all contrib
314         $(MAKENSIS) $(MAKENSIS_FLAGS) -nocd scripts/neverball.nsi
315
316 $(INSTALLER): LDFLAGS := -s $(LDFLAGS)
317
318 .PHONY: clean-setup
319 clean-setup: clean
320         $(RM) install-dlls.sh *.dll $(TXT_DOCS)
321         find data -name "*.txt" -exec $(FROMDOS) {} \;
322         $(MAKE) -C contrib EXT=$(EXT) clean
323
324 #------------------------------------------------------------------------------
325
326 .PHONY: install-dlls
327 install-dlls: install-dlls.sh
328         sh $<
329
330 install-dlls.sh:
331         if ! sh scripts/gen-install-dlls.sh > $@; then \
332             $(RM) $@; \
333             exit 1; \
334         fi
335         @echo --------------------------------------------------------
336         @echo You can probably ignore any file-not-found errors above.
337         @echo Now edit $@ to your needs before restarting make.
338         @echo --------------------------------------------------------
339         @exit 1
340
341 #------------------------------------------------------------------------------
342
343 .PHONY: convert-text-files
344 convert-text-files: $(TXT_DOCS)
345         find data -name "*.txt" -exec $(TODOS) {} \;
346
347 %.txt: %
348         $(CP) $< $@
349         $(TODOS) $@
350
351 #------------------------------------------------------------------------------
352
353 .PHONY: contrib
354 contrib:
355         $(MAKE) -C contrib EXT=$(EXT)
356
357 #------------------------------------------------------------------------------
358
359 endif
360
361 #------------------------------------------------------------------------------