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