-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathprepare_build.sh
executable file
·430 lines (354 loc) · 10.3 KB
/
prepare_build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
#!/bin/bash
function program_exists() {
$1 $2 1>/dev/null 2>&1
if [ $? -eq 127 ]; then
return 0
fi
upname=$(echo $1 | tr '[a-z]' '[A-Z]' | tr '-' '_')
eval "$upname=$1"
return 1
}
function print_make_file_list() {
FOO=GL_SRC
FOOO=GL_OBJ
( grep -l "^namespace OpenGL" *.cpp ;echo "gl_frustum.cpp";echo "math/obox.cpp math/plane.cpp coldet/math3d.cpp util/physfsrwops.c" ) | sort | xargs echo "$FOO ="
echo "$FOOO = \${$FOO:.cpp=.o}"
FOO=OGTA_SRC
FOOO=OGTA_OBJ
( grep -l "^namespace OpenGTA" *.cpp ; echo "slope_height_func.cpp" )|grep -v viewer.cpp |grep -v sprite_anim_player.cpp| sort | xargs echo "$FOO ="
echo "$FOOO = \${$FOO:.cpp=.o}"
UTIL_SRC=$(ls util/*.cpp | grep -v color.cpp | grep -v sound | xargs echo)
SOUND_SRC=$(ls util/*.cpp | grep sound.* | xargs echo)
LUA_SRC=$(ls lua_addon/*.cpp | xargs echo)
cat <<EOF
# list of used source files
UTIL_SRC = $UTIL_SRC
UTIL_OBJ = \${UTIL_SRC:.cpp=.o}
LUA_SRC = $LUA_SRC
LUA_OBJ = \${LUA_SRC:.cpp=.o}
SOUND_SRC = $SOUND_SRC
SOUND_OBJ = \${SOUND_SRC:.cpp=.o}
OSTEER_SRC = opensteer/src/Clock.cpp
OSTEER_OBJ = \${OSTEER_SRC:.cpp=.o}
SOUND_SRC = util/sound_device.cpp util/sound_fx_cache.cpp util/sound_music_player.cpp \
util/sound_resample2.cpp util/sound_system.cpp
SOUND_OBJ = \$(SOUND_SRC:.cpp=.p)
EOF
}
if [ "$1" == "WIN32" ]; then
EXE_PFIX=.exe
fi
function print_target_list() {
cat <<EOF
# list of make targets (programs)
TARGETS = viewer${EXE_PFIX}
LUA_TARGETS = luaviewer${EXE_PFIX}
all: loki \${TARGETS}
gfxextract${EXE_PFIX}: gfx_extract.cpp read_gry.o read_g24.o read_cmp.o navdata.o dataholder.o \
\$(UTIL_OBJ)
\$(CXX) \$(CATCH_E) \$(GFX_DDUMP) \$(FLAGS) \$(DEFS) \$(LINK_LAZY) \\
\$(INC) \\
-o \$@ \$+ \\
\$(SDL_LIB) \$(SDL_GL_LIB) \$(SDL_IMG_LIB) \$(PHYSFS_LIB) \$(LOKI_LIB)
viewer${EXE_PFIX}: main2.cpp viewer.o \$(OGTA_OBJ) \$(GL_OBJ) \$(UTIL_OBJ) \$(OSTEER_OBJ)
\$(CXX) \$(CATCH_E) \$(FLAGS) \$(DEFS) \\
\$(INC) \\
-o \$@ \$+ \\
\$(SDL_LIB) \$(SDL_GL_LIB) \$(PHYSFS_LIB) \$(LOKI_LIB) \$(COLDET_LIB)
luaviewer${EXE_PFIX}: main2.cpp viewer.o \$(OGTA_OBJ) \$(GL_OBJ) \$(UTIL_OBJ) \$(OSTEER_OBJ) \
\$(LUA_OBJ)
\$(CXX) \$(CATCH_E) \$(FLAGS) \$(DEFS) \\
\$(INC) \\
-o \$@ \$+ \\
\$(SDL_LIB) \$(SDL_GL_LIB) \$(PHYSFS_LIB) \$(LOKI_LIB) \$(COLDET_LIB) \$(LUA_LIB)
spriteplayer${EXE_PFIX}: sprite_anim_player.o \$(OGTA_OBJ) \$(GL_OBJ) \$(UTIL_OBJ) \$(OSTEER_OBJ) main2.cpp
\$(CXX) \$(CATCH_E) \$(FLAGS) \$(DEFS) \\
\$(INC) \\
-o \$@ \$+ \\
\$(SDL_LIB) \$(SDL_GL_LIB) \$(PHYSFS_LIB) \$(LOKI_LIB) \$(COLDET_LIB)
slopeview: main.o tools/display_slopes.o navdata.o read_cmp.o \
\$(UTIL_OBJ) common_sdl_gl.o
\$(CXX) \$(CXXFLAGS) -o \$@ \$+ \$(SDL_LIB) \$(PHYSFS_LIB) -lSDL_image
blockview: main2.o tools/blockview.cpp util/log.o util/m_exceptions.o \
gl_camera.o gl_screen.o read_cmp.o dataholder.o slope_height_func.o navdata.o \
datahelper.o read_gry.o read_g24.o util/set.o util/buffercache.o read_fxt.o blockdata.o
\$(CXX) \$(CXXFLAGS) -o \$@ \$+ \$(SDL_LIB) \$(SDL_GL_LIB) \$(PHYSFS_LIB)
g24: read_g24.cpp read_gry.o \$(UTIL_OBJ)
\$(CXX) -DG24_DUMPER \$(CXXFLAGS) -o \$@ \$+ \$(SDL_LIB) \$(PHYSFS_LIB)
objdump: tools/obj_dump.cpp read_gry.o \$(UTIL_OBJ) main2.o
\$(CXX) \$(CXXFLAGS) -o \$@ \$+ \$(SDL_LIB) \$(PHYSFS_LIB)
objdump_map: tools/obj_dump.cpp read_gry.o \$(UTIL_OBJ) main2.o read_cmp.o navdata.o
\$(CXX) \$(CXXFLAGS) -DDUMP_OBJ_IN_MAP -o \$@ \$+ \$(SDL_LIB) \$(PHYSFS_LIB)
car_dump: tools/car_dump.cpp dataholder.o read_gry.o read_cmp.o read_g24.o navdata.o \
main2.o read_fxt.o util/set.o util/buffercache.o util/log.o util/m_exceptions.o
\$(CXX) \$(CXXFLAGS) -o \$@ \$+ \$(SDL_LIB) \$(PHYSFS_LIB) \$(LOKI_LIB)
plane_test: tests/test_plane.cpp math/line_intersect.o util/log.o \
util/m_exceptions.o util/cell_iterator.o util/set.o util/buffercache.o \
read_cmp.o datahelper.o navdata.o read_fxt.o read_gry.o read_g24.o \
dataholder.o
\$(CXX) \$(CXXFLAGS) -o \$@ \$+ \$(SDL_LIB) \$(PHYSFS_LIB) \$(LOKI_LIB)
lua_map_test: tests/lua_map_test.o util/file_helper.o util/log.o \
util/m_exceptions.o util/buffercache.o util/set.o navdata.o \
dataholder.o read_cmp.o read_gry.o read_g24.o read_fxt.o datahelper.o \
main2.o lua_addon/lua_map.o lua_addon/lua_vm.o lua_addon/lua_stackguard.o
\$(CXX) \$(CXXFLAGS) -o \$@ \$+ \$(SDL_LIB) \$(PHYSFS_LIB) \$(LOKI_LIB) \$(LUA_LIB)
sound_test: read_sdt.o util/m_exceptions.o util/sound_resample2.o \
util/sound_device.o util/sound_system.cpp util/sound_fx_cache.o \
util/sound_music_player.o util/physfsrwops.c util/log.o
\$(CXX) -DSOUND_TEST \$(CXXFLAGS) -o \$@ \$+ \$(SDL_LIB) \$(PHYSFS_LIB) \$(LOKI_LIB) \$(AUDIO_LIB)
EOF
}
#print_make_file_list > src_list.make
#print_target_list >> src_list.make
function pkg_config_haslib () {
$PKG_CONFIG $1 1>/dev/null 2>&1
if [ $? -eq 0 ]; then
return 1
fi
return 0
}
function check_sdl () {
program_exists sdl-config
if [ $? -eq 1 ]; then
SDL_INC=$($SDL_CONFIG --cflags)
SDL_LIB=$($SDL_CONFIG --libs)
else
program_exists pkg-config
if [ $? -eq 1 ]; then
pkg_config_try_multiple SDL SDL sdl
fi
fi
cat <<EOF >_out_$$.cpp
#include <SDL.h>
int main(int argc, char* argv[]) {
SDL_GL_SWAP_CONTROL;
}
EOF
g++ $SDL_INC _out_$$.cpp 2>/dev/null
if [ $? -eq 0 ]; then
SDL_GL_SWAP_CONTROL='#define HAVE_SDL_VSYNC'
else
SDL_GL_SWAP_CONTROL='#undef HAVE_SDL_VSYNC'
fi
rm -f _out_$$.cpp a.out
}
function pkg_config_try_multiple () {
local _prefixName=$1
shift
while [ $# -gt 0 ]; do
pkg_config_haslib $1
if [ $? -eq 1 ]; then
eval "${_prefixName}_INC=\$($PKG_CONFIG --cflags $1)"
eval "${_prefixName}_LIB=\$($PKG_CONFIG --libs $1)"
return
fi
shift
done
}
function check_lua () {
program_exists pkg-config
if [ $? -eq 1 ]; then
pkg_config_try_multiple LUA lua5.1 lua51 lua5 lua
else
program_exists lua-config
if [ $? -eq 1 ]; then
LUA_INC=$($LUA_CONFIG --include)
LUA_LIB=$($LUA_CONFIG --libs)
fi
fi
}
function check_sdl_audio () {
local good=0
cat <<EOF >_out_$$.cpp
#include <SDL_mixer.h>
int main(int argc, char* argv[]) {
}
EOF
g++ $SDL_INC _out_$$.cpp 2>/dev/null
if [ $? -eq 0 ]; then
let good=$good+1
fi
rm -f _out_$$.cpp
cat <<EOF >_out_$$.cpp
#include <SDL_sound.h>
int main(int argc, char* argv[]) {
}
EOF
g++ $SDL_INC _out_$$.cpp 2>/dev/null
if [ $? -eq 0 ]; then
let good=$good+1
fi
rm -f _out_$$.cpp a.out
if [ $good -eq 2 ]; then
AUDIO_LD="-lSDL_mixer -lSDL_sound"
SDL_SOUND_MIXER='#define WITH_SOUND'
else
SDL_SOUND_MIXER='#undef WITH_SOUND'
fi
}
function check_physfs () {
program_exists pkg-config
if [ $? -eq 1 ]; then
pkg_config_try_multiple PHYSFS physfs
fi
}
function check_compiler () {
if [ "$OGTA_PLATFORM" == "WIN32" ]; then
_CXX=i586-mingw32msvc-g++
_CC=i586-mingw32msvc-gcc
else
_CXX=g++
_CC=gcc
fi
$_CXX 1>/dev/null 2>&1
if [ $? -eq 1 ]; then
CXX=$_CXX
else
CXX=
fi
$_CC 1>/dev/null 2>&1
if [ $? -eq 1 ]; then
CC=$_CC
else
CC=
fi
GCC_VERSION=$($CXX --version | head -n 1)
}
# defaults
DEBUG=-ggdb
WARN=-Wall
OPT=-O2
PHYSFS_LIB=-lphysfs
SDL_LIB=-lSDL
LUA_LIB=-llua51
function print_detected() {
cat <<EOF
# using these compilers
CXX = $CXX
CC = $CC
DEBUG = $DEBUG
OPT = $OPT
WARN = $WARN
DEFS = $DEFS
# def only for 'main' programs to let gdb handle the exception
#CATCH_E = -DDONT_CATCH
#GFX_DDUMP = -DDUMP_DELTA_DEBUG
# the external libraries
PHYSFS_INC = $PHYSFS_INC
PHYSFS_LIB = $PHYSFS_LIB
SDL_INC = $SDL_INC
SDL_LIB = $SDL_LIB
SDL_GL_LIB = -lGL -lGLU
SDL_IMG_LIB = -lSDL_image
# this better be lua >= 5.1 (but not 5.0); not detected
LUA_INC = $LUA_INC
LUA_LIB = $LUA_LIB
AUDIO_INC =
AUDIO_LIB = $AUDIO_LD
LINK_LAZY = -Xlinker --unresolved-symbols -Xlinker ignore-all
EOF
}
function print_w32settings() {
cat <<EOF
# using these compilers
CXX = i586-mingw32msvc-g++
CC = i586-mingw32msvc-gcc
#DEBUG = $DEBUG
OPT = $OPT
WARN = $WARN
DEFS = $DEFS
LIB_RT_PATH = libs
# def only for 'main' programs to let gdb handle the exception
#CATCH_E = -DDONT_CATCH
#GFX_DDUMP = -DDUMP_DELTA_DEBUG
# the external libraries
PHYSFS_INC = -Iinc
PHYSFS_LIB = -Llibs -lphysfs-1-1-0 -lzlib1
SDL_INC = -Iinc -D_GNU_SOURCE=1 -D_REENTRANT
SDL_LIB = -Llibs -lSDLmain -lSDL
SDL_GL_LIB = -lopengl32 -lglu32
SDL_IMG_LIB = -lSDL_image
# this better be lua >= 5.1 (but not 5.0); not detected
LUA_INC = $LUA_INC
LUA_LIB = $LUA_LIB
# good idea here?
LINK_LAZY = -Xlinker --unresolved-symbols -Xlinker ignore-all
EOF
}
function print_all() {
check_sdl
check_lua
check_physfs
check_sdl_audio
print_detected
print_make_file_list
print_target_list
cat <<EOF
include depend
EOF
}
function print_config_h() {
if [ -e ogta_version ]; then
LAST_TOUCHED=$(cat ogta_version)
else
LAST_TOUCHED=$(find . -type f -exec ls -tl {} \; | grep -v CVS | tail -1 | awk '{print $6}')
echo $LAST_TOUCHED > ogta_version
fi
cat <<EOF
// WIN32 already defined when cross-compiling...
#ifndef $OGTA_PLATFORM
#define $OGTA_PLATFORM
#endif
// to avoid some errors on prg-exit
#define LOKI_FUNCTOR_IS_NOT_A_SMALLOBJECT
// platform specific switches
#ifdef LINUX
#define OGTA_PLATFORM_INFO "linux"
// for coldet; FIXME: really only for linux?
#define GCC
#elif WIN32
#define OGTA_PLATFORM_INFO "win32"
#else
#error(No platform defined)
#endif
// global compile-time vars
#define OGTA_VERSION_INFO "$LAST_TOUCHED"
#define DEFAULT_SCREEN_WIDTH 640
#define DEFAULT_SCREEN_HEIGHT 480
// 0 - no vsync (default), 1 - try to use SDL_GL_SWAP_CONTROL,
// 2 - try native call (GLX on linux, unsupported on win32)
//#undef DEFAULT_SCREEN_VSYNC
#define DEFAULT_SCREEN_VSYNC 2
// default pathes; env-variables can override
#define OGTA_DEFAULT_DATA_PATH "gtadata.zip"
#define OGTA_DEFAULT_MOD_PATH ""
#define OGTA_DEFAULT_HOME_PATH PHYSFS_getBaseDir()
// just for fun
#define USED_GCC_VERSION "$GCC_VERSION"
// enable features
#define DO_SCALE2X
$SDL_SOUND_MIXER
$SDL_GL_SWAP_CONTROL
// use escape sequences to mark Log::info/warn/error()
#ifdef LINUX
//#define LOG_USE_ANSI_COLORS
#endif
EOF
}
if [[ -n "$1" && "$1" != "LINUX" ]]; then
OGTA_PLATFORM=WIN32
echo "*** WIN32 ***"
DEFS="-include config.h"
check_compiler
print_w32settings > src_list.make
print_make_file_list >> src_list.make
print_target_list >> src_list.make
SDL_GL_SWAP_CONTROL='#define HAVE_SDL_VSYNC'
else
OGTA_PLATFORM="LINUX"
echo "*** LINUX ***"
check_compiler
DEFS="-include config.h"
print_all > src_list.make
fi
print_config_h > config.h