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