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