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