Request SSE floating-point math from GCC for x86 systems
[neverball] / Makefile
1
2 #------------------------------------------------------------------------------
3
4 VERSION := $(shell sh scripts/version.sh)
5 ifeq ($(VERSION),unknown)
6     $(warning Failed to obtain sane version for this build.)
7 endif
8
9 # Provide a target system hint for the Makefile.
10
11 ifeq ($(shell uname), Darwin)
12     DARWIN := 1
13 endif
14
15 #------------------------------------------------------------------------------
16 # Optional flags (CFLAGS, CPPFLAGS, ...)
17
18 ifeq ($(ENABLE_WII),1)
19     # libwiimote is NOT ANSI compliant (TODO, check if this is necessary.  GCC
20     # is supposed to suppress warnings from system headers.)
21
22     ifneq ($(DEBUG),1)
23         CFLAGS   := -g
24         CPPFLAGS :=
25     else
26         CFLAGS   := -O2
27         CPPFLAGS := -DNDEBUG
28     endif
29 else
30     ifeq ($(DEBUG),1)
31         CFLAGS   := -Wall -g -ansi -pedantic
32         CPPFLAGS :=
33     else
34         CFLAGS   := -Wall -O2 -ansi -pedantic
35         CPPFLAGS := -DNDEBUG
36     endif
37 endif
38
39 #------------------------------------------------------------------------------
40 # Mandatory flags
41
42 # Compiler...
43
44 SSE_CFLAGS := $(shell env CC="$(CC)" sh scripts/get-sse-cflags.sh)
45
46 ALL_CFLAGS := $(SSE_CFLAGS) $(CFLAGS)
47
48 # Preprocessor...
49
50 SDL_CPPFLAGS := $(shell sdl-config --cflags)
51 PNG_CPPFLAGS := $(shell libpng-config --cflags)
52
53 ALL_CPPFLAGS := $(SDL_CPPFLAGS) $(PNG_CPPFLAGS) -Ishare \
54     -DVERSION=\"$(VERSION)\"
55
56 ifeq ($(ENABLE_NLS),0)
57     ALL_CPPFLAGS += -DENABLE_NLS=0
58 else
59     ALL_CPPFLAGS += -DENABLE_NLS=1
60 endif
61
62 ifeq ($(ENABLE_WII),1)
63     ALL_CPPFLAGS += -DENABLE_WII=1
64 endif
65
66 ifdef DARWIN
67     ALL_CPPFLAGS += -I/opt/local/include
68 endif
69
70 ALL_CPPFLAGS += $(CPPFLAGS)
71
72 #------------------------------------------------------------------------------
73 # Libraries
74
75 SDL_LIBS := $(shell sdl-config --libs)
76 PNG_LIBS := $(shell libpng-config --libs)
77
78 # The  non-conditionalised values  below  are specific  to the  native
79 # system. The native system of this Makefile is Linux (or GNU+Linux if
80 # you prefer). Please be sure to  override ALL of them for each target
81 # system in the conditional parts below.
82
83 INTL_LIBS :=
84
85 ifeq ($(ENABLE_WII),1)
86     TILT_LIBS := -lcwiimote -lbluetooth
87 endif
88
89 OGL_LIBS := -lGL -lm
90
91 ifdef MINGW
92     ifneq ($(ENABLE_NLS),0)
93         INTL_LIBS := -lintl -liconv
94     endif
95
96     TILT_LIBS :=
97     OGL_LIBS  := -lopengl32 -lm
98 endif
99
100 ifdef DARWIN
101     ifneq ($(ENABLE_NLS),0)
102         INTL_LIBS := -lintl -liconv
103     endif
104
105     TILT_LIBS :=
106     OGL_LIBS  := -framework OpenGL
107 endif
108
109 BASE_LIBS := -ljpeg $(PNG_LIBS)
110
111 ifdef DARWIN
112     BASE_LIBS += -L/opt/local/lib
113 endif
114
115 ALL_LIBS := $(SDL_LIBS) $(BASE_LIBS) $(TILT_LIBS) $(INTL_LIBS) -lSDL_ttf \
116     -lvorbisfile $(OGL_LIBS)
117
118 #------------------------------------------------------------------------------
119
120 ifdef MINGW
121     EXT := .exe
122 endif
123
124 MAPC_TARG := mapc$(EXT)
125 BALL_TARG := neverball$(EXT)
126 PUTT_TARG := neverputt$(EXT)
127
128 ifdef MINGW
129     MAPC := $(WINE) ./$(MAPC_TARG)
130 else
131     MAPC := ./$(MAPC_TARG)
132 endif
133
134
135 #------------------------------------------------------------------------------
136
137 MAPC_OBJS := \
138         share/vec3.o        \
139         share/base_image.o  \
140         share/solid.o       \
141         share/binary.o      \
142         share/base_config.o \
143         share/mapc.o
144 BALL_OBJS := \
145         share/lang.o        \
146         share/st_resol.o    \
147         share/vec3.o        \
148         share/base_image.o  \
149         share/image.o       \
150         share/solid.o       \
151         share/solid_gl.o    \
152         share/part.o        \
153         share/back.o        \
154         share/geom.o        \
155         share/item.o        \
156         share/ball.o        \
157         share/gui.o         \
158         share/base_config.o \
159         share/config.o      \
160         share/binary.o      \
161         share/state.o       \
162         share/audio.o       \
163         share/text.o        \
164         share/sync.o        \
165         share/tilt.o        \
166         share/common.o      \
167         share/keynames.o    \
168         share/syswm.o       \
169         ball/hud.o          \
170         ball/game.o         \
171         ball/score.o        \
172         ball/level.o        \
173         ball/progress.o     \
174         ball/set.o          \
175         ball/demo.o         \
176         ball/util.o         \
177         ball/st_conf.o      \
178         ball/st_demo.o      \
179         ball/st_save.o      \
180         ball/st_goal.o      \
181         ball/st_fall_out.o  \
182         ball/st_time_out.o  \
183         ball/st_done.o      \
184         ball/st_level.o     \
185         ball/st_over.o      \
186         ball/st_play.o      \
187         ball/st_set.o       \
188         ball/st_start.o     \
189         ball/st_title.o     \
190         ball/st_help.o      \
191         ball/st_name.o      \
192         ball/st_shared.o    \
193         ball/st_pause.o     \
194         ball/main.o
195 PUTT_OBJS := \
196         share/lang.o        \
197         share/st_resol.o    \
198         share/vec3.o        \
199         share/base_image.o  \
200         share/image.o       \
201         share/solid.o       \
202         share/solid_gl.o    \
203         share/part.o        \
204         share/geom.o        \
205         share/ball.o        \
206         share/back.o        \
207         share/base_config.o \
208         share/config.o      \
209         share/binary.o      \
210         share/audio.o       \
211         share/state.o       \
212         share/gui.o         \
213         share/text.o        \
214         share/sync.o        \
215         share/common.o      \
216         share/syswm.o       \
217         putt/hud.o          \
218         putt/game.o         \
219         putt/hole.o         \
220         putt/course.o       \
221         putt/st_all.o       \
222         putt/st_conf.o      \
223         putt/main.o
224
225 BALL_DEPS := $(BALL_OBJS:.o=.d)
226 PUTT_DEPS := $(PUTT_OBJS:.o=.d)
227 MAPC_DEPS := $(MAPC_OBJS:.o=.d)
228
229 MAPS := $(shell find data -name "*.map" \! -name "*.autosave.map")
230 SOLS := $(MAPS:%.map=%.sol)
231
232 DESKTOPS := $(basename $(wildcard dist/*.desktop.in))
233
234 #------------------------------------------------------------------------------
235
236 %.o : %.c
237         $(CC) $(ALL_CFLAGS) $(ALL_CPPFLAGS) -MM -MP -MF $*.d -MT "$@" $<
238         $(CC) $(ALL_CFLAGS) $(ALL_CPPFLAGS) -o $@ -c $<
239
240 %.sol : %.map $(MAPC_TARG)
241         $(MAPC) $< data
242
243 %.desktop : %.desktop.in
244         sh scripts/translate-desktop.sh < $< > $@
245
246 #------------------------------------------------------------------------------
247
248 all : $(BALL_TARG) $(PUTT_TARG) $(MAPC_TARG) sols locales desktops
249
250 $(BALL_TARG) : $(BALL_OBJS)
251         $(CC) $(ALL_CFLAGS) -o $(BALL_TARG) $(BALL_OBJS) $(LDFLAGS) $(ALL_LIBS)
252
253 $(PUTT_TARG) : $(PUTT_OBJS)
254         $(CC) $(ALL_CFLAGS) -o $(PUTT_TARG) $(PUTT_OBJS) $(LDFLAGS) $(ALL_LIBS)
255
256 $(MAPC_TARG) : $(MAPC_OBJS)
257         $(CC) $(ALL_CFLAGS) -o $(MAPC_TARG) $(MAPC_OBJS) $(LDFLAGS) $(BASE_LIBS)
258
259 # Work around some extremely helpful sdl-config scripts.
260
261 ifdef MINGW
262 $(MAPC_TARG) : ALL_CPPFLAGS := $(ALL_CPPFLAGS) -Umain
263 endif
264
265 sols : $(SOLS)
266
267 locales :
268 ifneq ($(ENABLE_NLS),0)
269         $(MAKE) -C po
270 endif
271
272 desktops : $(DESKTOPS)
273
274 clean-src :
275         $(RM) $(BALL_TARG) $(BALL_OBJS) $(BALL_DEPS)
276         $(RM) $(PUTT_TARG) $(PUTT_OBJS) $(PUTT_DEPS)
277         $(RM) $(MAPC_TARG) $(MAPC_OBJS) $(MAPC_DEPS)
278
279 clean : clean-src
280         $(RM) $(SOLS)
281         $(RM) $(DESKTOPS)
282         $(MAKE) -C po clean
283
284 test : all
285         ./neverball
286
287 #------------------------------------------------------------------------------
288
289 .PHONY : all sols locales clean-src clean test
290
291 -include $(BALL_DEPS) $(PUTT_DEPS) $(MAPC_DEPS)
292
293 #------------------------------------------------------------------------------
294
295 ifdef MINGW
296
297 #------------------------------------------------------------------------------
298
299 INSTALLER := ../neverball-$(VERSION)-setup.exe
300
301 MAKENSIS := makensis
302 MAKENSIS_FLAGS := -DVERSION=$(VERSION) -DOUTFILE=$(INSTALLER)
303
304 TODOS   := todos
305 FROMDOS := fromdos
306
307 CP := cp
308
309 TEXT_DOCS := \
310         doc/AUTHORS \
311         doc/MANUAL  \
312         CHANGES     \
313         COPYING     \
314         README
315
316 TXT_DOCS := $(TEXT_DOCS:%=%.txt)
317
318 #------------------------------------------------------------------------------
319
320 .PHONY: setup
321 setup: $(INSTALLER)
322
323 $(INSTALLER): install-dlls convert-text-files all contrib
324         $(MAKENSIS) $(MAKENSIS_FLAGS) -nocd scripts/neverball.nsi
325
326 $(INSTALLER): LDFLAGS := -s $(LDFLAGS)
327
328 .PHONY: clean-setup
329 clean-setup: clean
330         $(RM) install-dlls.sh *.dll $(TXT_DOCS)
331         find data -name "*.txt" -exec $(FROMDOS) {} \;
332         $(MAKE) -C contrib EXT=$(EXT) clean
333
334 #------------------------------------------------------------------------------
335
336 .PHONY: install-dlls
337 install-dlls: install-dlls.sh
338         sh $<
339
340 install-dlls.sh:
341         mingw-list-dlls --sh > $@
342         @echo --------------------------------------------------------
343         @echo Now edit $@ to your needs before restarting make.
344         @echo --------------------------------------------------------
345         @exit 1
346
347 #------------------------------------------------------------------------------
348
349 .PHONY: convert-text-files
350 convert-text-files: $(TXT_DOCS)
351         find data -name "*.txt" -exec $(TODOS) {} \;
352
353 %.txt: %
354         $(CP) $< $@
355         $(TODOS) $@
356
357 #------------------------------------------------------------------------------
358
359 .PHONY: contrib
360 contrib:
361         $(MAKE) -C contrib EXT=$(EXT)
362
363 #------------------------------------------------------------------------------
364
365 endif
366
367 #------------------------------------------------------------------------------