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