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