Don't feed the Makefile nazis.
[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
20     CFLAGS := -O2
21 else
22     #CFLAGS := -Wall -g -ansi -pedantic
23     CFLAGS := -Wall -O2 -ansi -pedantic
24 endif
25
26 #------------------------------------------------------------------------------
27 # Mandatory flags
28
29 # Compiler...
30
31 ALL_CFLAGS := $(CFLAGS)
32
33 # Preprocessor...
34
35 SDL_CPPFLAGS := $(shell sdl-config --cflags)
36 PNG_CPPFLAGS := $(shell libpng-config --cflags)
37
38 ALL_CPPFLAGS := $(SDL_CPPFLAGS) $(PNG_CPPFLAGS) -Ishare \
39     -DVERSION=\"$(VERSION)\"
40
41 ifeq ($(ENABLE_NLS),0)
42     ALL_CPPFLAGS += -DENABLE_NLS=0
43 else
44     ALL_CPPFLAGS += -DENABLE_NLS=1
45 endif
46
47 ifeq ($(ENABLE_WII),1)
48     ALL_CPPFLAGS += -DENABLE_WII=1
49 endif
50
51 ifdef DARWIN
52     ALL_CPPFLAGS += -I/opt/local/include
53 endif
54
55 ALL_CPPFLAGS += $(CPPFLAGS)
56
57 #------------------------------------------------------------------------------
58 # Libraries
59
60 SDL_LIBS := $(shell sdl-config --libs)
61 PNG_LIBS := $(shell libpng-config --libs)
62
63 ifdef MINGW
64     ifneq ($(ENABLE_NLS),0)
65         INTL_LIBS := -lintl -liconv
66     endif
67
68     OGL_LIBS := -lopengl32 -lm
69 else ifdef DARWIN
70     ifneq ($(ENABLE_NLS),0)
71         INTL_LIBS := -lintl -liconv
72     endif
73
74     OGL_LIBS := -framework OpenGL
75 else
76     ifeq ($(ENABLE_WII),1)
77         TILT_LIBS := -lcwiimote -lbluetooth
78     endif
79
80     OGL_LIBS := -lGL -lm
81 endif
82
83 BASE_LIBS := -ljpeg $(PNG_LIBS)
84
85 ifdef DARWIN
86     BASE_LIBS += -L/opt/local/lib
87 endif
88
89 ALL_LIBS := $(SDL_LIBS) $(BASE_LIBS) $(TILT_LIBS) $(INTL_LIBS) -lSDL_ttf \
90     -lvorbisfile $(OGL_LIBS)
91
92 #------------------------------------------------------------------------------
93
94 ifdef MINGW
95     EXT := .exe
96 endif
97
98 MAPC_TARG := mapc$(EXT)
99 BALL_TARG := neverball$(EXT)
100 PUTT_TARG := neverputt$(EXT)
101
102 ifdef MINGW
103     MAPC := wine ./$(MAPC_TARG)
104 else
105     MAPC := ./$(MAPC_TARG)
106 endif
107
108
109 #------------------------------------------------------------------------------
110
111 MAPC_OBJS := \
112         share/vec3.o        \
113         share/base_image.o  \
114         share/solid.o       \
115         share/binary.o      \
116         share/base_config.o \
117         share/mapc.o
118 BALL_OBJS := \
119         share/lang.o        \
120         share/st_resol.o    \
121         share/vec3.o        \
122         share/base_image.o  \
123         share/image.o       \
124         share/solid.o       \
125         share/solid_gl.o    \
126         share/part.o        \
127         share/back.o        \
128         share/geom.o        \
129         share/gui.o         \
130         share/base_config.o \
131         share/config.o      \
132         share/binary.o      \
133         share/state.o       \
134         share/audio.o       \
135         share/text.o        \
136         share/sync.o        \
137         share/tilt.o        \
138         ball/hud.o          \
139         ball/mode.o         \
140         ball/game.o         \
141         ball/score.o        \
142         ball/level.o        \
143         ball/levels.o       \
144         ball/set.o          \
145         ball/demo.o         \
146         ball/util.o         \
147         ball/st_conf.o      \
148         ball/st_demo.o      \
149         ball/st_save.o      \
150         ball/st_goal.o      \
151         ball/st_fall_out.o  \
152         ball/st_time_out.o  \
153         ball/st_done.o      \
154         ball/st_level.o     \
155         ball/st_over.o      \
156         ball/st_play.o      \
157         ball/st_set.o       \
158         ball/st_start.o     \
159         ball/st_title.o     \
160         ball/st_help.o      \
161         ball/st_name.o      \
162         ball/st_shared.o    \
163         ball/st_pause.o     \
164         ball/main.o
165 PUTT_OBJS := \
166         share/lang.o        \
167         share/st_resol.o    \
168         share/vec3.o        \
169         share/base_image.o  \
170         share/image.o       \
171         share/solid.o       \
172         share/solid_gl.o    \
173         share/part.o        \
174         share/geom.o        \
175         share/back.o        \
176         share/base_config.o \
177         share/config.o      \
178         share/binary.o      \
179         share/audio.o       \
180         share/state.o       \
181         share/gui.o         \
182         share/text.o        \
183         share/sync.o        \
184         putt/hud.o          \
185         putt/game.o         \
186         putt/hole.o         \
187         putt/course.o       \
188         putt/st_all.o       \
189         putt/st_conf.o      \
190         putt/main.o
191
192 BALL_DEPS := $(BALL_OBJS:.o=.d)
193 PUTT_DEPS := $(PUTT_OBJS:.o=.d)
194 MAPC_DEPS := $(MAPC_OBJS:.o=.d)
195
196 MAPS := $(shell find data -name "*.map" \! -name "*.autosave.map")
197 SOLS := $(MAPS:%.map=%.sol)
198
199 #------------------------------------------------------------------------------
200
201 %.o : %.c
202         $(CC) $(ALL_CFLAGS) $(ALL_CPPFLAGS) -MM -MP -MF $*.d -MT "$@" $<
203         $(CC) $(ALL_CFLAGS) $(ALL_CPPFLAGS) -o $@ -c $<
204
205 %.sol : %.map $(MAPC_TARG)
206         $(MAPC) $< data
207
208 #------------------------------------------------------------------------------
209
210 all : $(BALL_TARG) $(PUTT_TARG) $(MAPC_TARG) sols locales
211
212 $(BALL_TARG) : $(BALL_OBJS)
213         $(CC) $(ALL_CFLAGS) -o $(BALL_TARG) $(BALL_OBJS) $(LDFLAGS) $(ALL_LIBS)
214
215 $(PUTT_TARG) : $(PUTT_OBJS)
216         $(CC) $(ALL_CFLAGS) -o $(PUTT_TARG) $(PUTT_OBJS) $(LDFLAGS) $(ALL_LIBS)
217
218 $(MAPC_TARG) : $(MAPC_OBJS)
219         $(CC) $(ALL_CFLAGS) -o $(MAPC_TARG) $(MAPC_OBJS) $(LDFLAGS) $(BASE_LIBS)
220
221 # Work around some extremely helpful sdl-config scripts.
222
223 ifdef MINGW
224 $(MAPC_TARG) : ALL_CPPFLAGS := $(ALL_CPPFLAGS) -Umain
225 endif
226
227 sols : $(SOLS)
228
229 locales :
230 ifneq ($(ENABLE_NLS),0)
231         $(MAKE) -C po
232 endif
233
234 clean-src :
235         $(RM) $(BALL_TARG) $(BALL_OBJS) $(BALL_DEPS)
236         $(RM) $(PUTT_TARG) $(PUTT_OBJS) $(PUTT_DEPS)
237         $(RM) $(MAPC_TARG) $(MAPC_OBJS) $(MAPC_DEPS)
238
239 clean : clean-src
240         $(RM) $(SOLS)
241         $(MAKE) -C po clean
242
243 test : all
244         ./neverball
245
246 #------------------------------------------------------------------------------
247
248 .PHONY : all sols locales clean-src clean test
249
250 -include $(BALL_DEPS) $(PUTT_DEPS) $(MAPC_DEPS)
251
252 #------------------------------------------------------------------------------
253
254 ifdef MINGW
255
256 #------------------------------------------------------------------------------
257
258 INSTALLER := ../neverball-$(VERSION)-setup.exe
259
260 MAKENSIS := makensis
261 MAKENSIS_FLAGS := -DVERSION=$(VERSION) -DOUTFILE=$(INSTALLER)
262
263 TODOS   := todos
264 FROMDOS := fromdos
265
266 CP := cp
267
268 TEXT_DOCS := \
269         doc/AUTHORS \
270         doc/MANUAL  \
271         CHANGES     \
272         COPYING     \
273         README
274
275 TXT_DOCS := $(TEXT_DOCS:%=%.txt)
276
277 #-----------------------------------------------------------------------------
278
279 .PHONY: setup
280 setup: $(INSTALLER)
281
282 $(INSTALLER): install-dlls convert-text-files all tools
283         $(MAKENSIS) $(MAKENSIS_FLAGS) -nocd scripts/neverball.nsi
284
285 $(INSTALLER): LDFLAGS := -s $(LDFLAGS)
286
287 .PHONY: clean-setup
288 clean-setup: clean
289         $(RM) install-dlls.sh *.dll $(TXT_DOCS)
290         find data -name "*.txt" -exec $(FROMDOS) {} \;
291         $(MAKE) -C tools EXT=$(EXT) clean
292
293 #-----------------------------------------------------------------------------
294
295 .PHONY: install-dlls
296 install-dlls: install-dlls.sh
297         sh $<
298
299 install-dlls.sh:
300         if ! sh scripts/gen-install-dlls.sh > $@; then \
301             $(RM) $@; \
302             exit 1; \
303         fi
304         @echo --------------------------------------------------------
305         @echo You can probably ignore any file-not-found errors above.
306         @echo Now edit $@ to your needs before restarting make.
307         @echo --------------------------------------------------------
308         @exit 1
309
310 #-----------------------------------------------------------------------------
311
312 .PHONY: convert-text-files
313 convert-text-files: $(TXT_DOCS)
314         find data -name "*.txt" -exec $(TODOS) {} \;
315
316 %.txt: %
317         $(CP) $< $@
318         $(TODOS) $@
319
320 #-----------------------------------------------------------------------------
321
322 .PHONY: tools
323 tools:
324         $(MAKE) -C tools EXT=$(EXT)
325
326 #------------------------------------------------------------------------------
327
328 endif
329
330 #------------------------------------------------------------------------------