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