Reworked mapc+no SDL+no i18n and neverball/neverputt+SDL+i18n distinction.
[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     WINE := wine
83 endif
84
85 #------------------------------------------------------------------------------
86
87 MAPC_TARG := mapc$(EXT)
88 BALL_TARG := neverball$(EXT)
89 PUTT_TARG := neverputt$(EXT)
90
91 #------------------------------------------------------------------------------
92
93 MAPC_OBJS := \
94         share/vec3.o        \
95         share/base_image.o  \
96         share/solid.o       \
97         share/binary.o      \
98         share/base_config.o \
99         share/mapc.o
100 BALL_OBJS := \
101         share/lang.o        \
102         share/st_resol.o    \
103         share/vec3.o        \
104         share/base_image.o  \
105         share/image.o       \
106         share/solid.o       \
107         share/solid_gl.o    \
108         share/part.o        \
109         share/back.o        \
110         share/geom.o        \
111         share/gui.o         \
112         share/base_config.o \
113         share/config.o      \
114         share/binary.o      \
115         share/state.o       \
116         share/audio.o       \
117         share/text.o        \
118         ball/hud.o          \
119         ball/mode.o         \
120         ball/game.o         \
121         ball/score.o        \
122         ball/level.o        \
123         ball/levels.o       \
124         ball/set.o          \
125         ball/demo.o         \
126         ball/util.o         \
127         ball/st_conf.o      \
128         ball/st_demo.o      \
129         ball/st_save.o      \
130         ball/st_goal.o      \
131         ball/st_fall_out.o  \
132         ball/st_time_out.o  \
133         ball/st_done.o      \
134         ball/st_level.o     \
135         ball/st_over.o      \
136         ball/st_play.o      \
137         ball/st_set.o       \
138         ball/st_start.o     \
139         ball/st_title.o     \
140         ball/st_help.o      \
141         ball/st_name.o      \
142         ball/st_shared.o    \
143         ball/st_pause.o     \
144         ball/main.o
145 PUTT_OBJS := \
146         share/lang.o        \
147         share/st_resol.o    \
148         share/vec3.o        \
149         share/base_image.o  \
150         share/image.o       \
151         share/solid.o       \
152         share/solid_gl.o    \
153         share/part.o        \
154         share/geom.o        \
155         share/back.o        \
156         share/base_config.o \
157         share/config.o      \
158         share/binary.o      \
159         share/audio.o       \
160         share/state.o       \
161         share/gui.o         \
162         share/text.o        \
163         putt/hud.o          \
164         putt/game.o         \
165         putt/hole.o         \
166         putt/course.o       \
167         putt/st_all.o       \
168         putt/st_conf.o      \
169         putt/main.o
170
171 BALL_DEPS := $(BALL_OBJS:.o=.d)
172 PUTT_DEPS := $(PUTT_OBJS:.o=.d)
173 MAPC_DEPS := $(MAPC_OBJS:.o=.d)
174
175 MAPS := $(shell find data -name "*.map" \! -name "*.autosave.map")
176 SOLS := $(MAPS:%.map=%.sol)
177
178 #------------------------------------------------------------------------------
179
180 %.o : %.c
181         $(CC) $(ALL_CFLAGS) $(ALL_CPPFLAGS) -MM -MP -MF $*.d -MT "$@" $<
182         $(CC) $(ALL_CFLAGS) $(ALL_CPPFLAGS) -o $@ -c $<
183
184 %.sol : %.map $(MAPC_TARG)
185         $(WINE) ./$(MAPC_TARG) $< data
186
187 #------------------------------------------------------------------------------
188
189 all : $(BALL_TARG) $(PUTT_TARG) $(MAPC_TARG) sols locales
190
191 $(BALL_TARG) : $(BALL_OBJS)
192         $(CC) $(ALL_CFLAGS) -o $(BALL_TARG) $(BALL_OBJS) $(LDFLAGS) $(ALL_LIBS)
193
194 $(PUTT_TARG) : $(PUTT_OBJS)
195         $(CC) $(ALL_CFLAGS) -o $(PUTT_TARG) $(PUTT_OBJS) $(LDFLAGS) $(ALL_LIBS)
196
197 $(MAPC_TARG) : $(MAPC_OBJS)
198         $(CC) $(ALL_CFLAGS) -o $(MAPC_TARG) $(MAPC_OBJS) $(LDFLAGS) $(BASE_LIBS)
199
200 # Work around some extremely helpful sdl-config scripts.
201
202 ifdef MINGW
203 $(MAPC_TARG) : ALL_CPPFLAGS := $(ALL_CPPFLAGS) -Umain
204 endif
205
206 sols : $(SOLS)
207
208 locales :
209 ifneq ($(ENABLE_NLS),0)
210         $(MAKE) -C po
211 endif
212
213 clean-src :
214         $(RM) $(BALL_TARG) $(BALL_OBJS) $(BALL_DEPS)
215         $(RM) $(PUTT_TARG) $(PUTT_OBJS) $(PUTT_DEPS)
216         $(RM) $(MAPC_TARG) $(MAPC_OBJS) $(MAPC_DEPS)
217
218 clean : clean-src
219         $(RM) $(SOLS)
220         $(MAKE) -C po clean
221
222 test : all
223         ./neverball
224
225 #------------------------------------------------------------------------------
226
227 .PHONY : all sols locales clean-src clean test
228
229 -include $(BALL_DEPS) $(PUTT_DEPS) $(MAPC_DEPS)
230
231 #------------------------------------------------------------------------------
232
233 ifdef MINGW
234
235 #------------------------------------------------------------------------------
236
237 INSTALLER := ../neverball-$(VERSION)-setup.exe
238
239 MAKENSIS := makensis
240 MAKENSIS_FLAGS := -DVERSION=$(VERSION) -DOUTFILE=$(INSTALLER)
241
242 TODOS   := todos
243 FROMDOS := fromdos
244
245 CP := cp
246
247 TEXT_DOCS := \
248         doc/AUTHORS \
249         doc/MANUAL  \
250         CHANGES     \
251         COPYING     \
252         README
253
254 TXT_DOCS := $(TEXT_DOCS:%=%.txt)
255
256 #-----------------------------------------------------------------------------
257
258 .PHONY: setup
259 setup: $(INSTALLER)
260
261 $(INSTALLER): install-dlls convert-text-files all tools
262         $(MAKENSIS) $(MAKENSIS_FLAGS) -nocd scripts/neverball.nsi
263
264 $(INSTALLER): LDFLAGS := -s $(LDFLAGS)
265
266 .PHONY: clean-setup
267 clean-setup: clean
268         $(RM) install-dlls.sh *.dll $(TXT_DOCS)
269         find data -name "*.txt" -exec $(FROMDOS) {} \;
270         $(MAKE) -C tools EXT=$(EXT) clean
271
272 #-----------------------------------------------------------------------------
273
274 .PHONY: install-dlls
275 install-dlls: install-dlls.sh
276         sh $<
277
278 install-dlls.sh:
279         if ! sh scripts/gen-install-dlls.sh > $@; then \
280             $(RM) $@; \
281             exit 1; \
282         fi
283         @echo --------------------------------------------------------
284         @echo You can probably ignore any file-not-found errors above.
285         @echo Now edit $@ to your needs before restarting make.
286         @echo --------------------------------------------------------
287         @exit 1
288
289 #-----------------------------------------------------------------------------
290
291 .PHONY: convert-text-files
292 convert-text-files: $(TXT_DOCS)
293         find data -name "*.txt" -exec $(TODOS) {} \;
294
295 %.txt: %
296         $(CP) $< $@
297         $(TODOS) $@
298
299 #-----------------------------------------------------------------------------
300
301 .PHONY: tools
302 tools:
303         $(MAKE) -C tools EXT=$(EXT)
304
305 #------------------------------------------------------------------------------
306
307 endif
308
309 #------------------------------------------------------------------------------