-
Notifications
You must be signed in to change notification settings - Fork 30
/
doit.sh
executable file
·240 lines (190 loc) · 8.4 KB
/
doit.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
#
# help:
# -O1 = removes references to unused strings for printf_hide -> anti reversing | found "-O3 -s" but dunno the advantage
#
# ./doit.sh tar
# ./doit.sh cod1_1_5
# ./doit.sh cod2_1_2
# ./doit.sh cod2_1_3
# ./doit.sh cod4_1_7
# ./doit.sh wrapper
#
mkdir -p bin
mkdir -p objects_normal
# clang warns about everything
cc="gcc"
#options="-I. -m32 -fPIC -fvisibility=hidden -O1"
options="-I. -m32 -fPIC -Wno-write-strings"
no_warning_spam="-Wall -Wno-write-strings -Wno-pointer-arith -Wno-format -Wno-parentheses -Wno-unused-variable -Wno-unused-function -Wno-unused-but-set-variable -Wno-return-type -Wno-sign-compare"
options="$options $no_warning_spam"
#objects_tcc="build/gsc_tcc.opp /home/kung/tcc/tcc-0.9.25/libtcc.a"
tmp="/root/q3rally/q3rallysa/build";
objects_car="$tmp/q_shared.o $tmp/q_math.o $tmp/com_printf.o $tmp/bg_wheel_forces.o $tmp/bg_pmove.o $tmp/bg_physics.o $tmp/bg_misc.o"
mysql_config="`mysql_config --cflags --libs`"
mysql_link=""
if [ -d "./vendors/lib" ]; then
mysql_config=""
mysql_link="-lmysqlclient -L./vendors/lib"
fi
# if dir $java_jdk exists: add java support to libcod
# download url: https://jdk8.java.net/download.html
java_jdk="/root/helper/openjdk8"
java_lib=""
java_header=""
java_enable="false"
# when the JDK is not found, force it to be off
if [ ! -d $java_jdk ]; then
java_enable="false"
fi
if [ "$java_enable" == "true" ]; then
java_lib="-ljvm -L$java_jdk/jre/lib/i386/server/"
java_header="-I$java_jdk/include/ -I$java_jdk/include/linux/"
options="$options -DIS_JAVA_ENABLED"
fi
if [ "$1" == "" ] || [ "$1" == "tar" ]; then
echo "##### TAR LIBCOD #####"
rm libcod.tar
#tar -cf libcod.tar json
#tar -rf libcod.tar jsonrpc
tar -cf libcod.tar plugins
#tar -rf libcod.tar vendors
tar -rf libcod.tar *.c
tar -rf libcod.tar *.cpp
tar -rf libcod.tar *.hpp
tar -rf libcod.tar doit.sh
echo "libcod.tar created: $?"
fi
if [ "$1" == "" ] || [ "$1" == "base" ]; then
echo "##### COMPILE GSC_ASTAR.CPP #####"
$cc $options -c gsc_astar.cpp -o objects_normal/gsc_astar.opp
echo "##### COMPILE GSC_MYSQL.CPP #####"
$cc $options -c gsc_mysql.cpp -o objects_normal/gsc_mysql.opp -lmysqlclient -L/usr/lib/mysql
echo "##### COMPILE SERVER.C #####"
$cc $options -c server.c -o objects_normal/server.opp -D SERVER_PORT=8000
echo "##### COMPILE GSC_MEMORY.CPP #####"
$cc $options -c gsc_memory.cpp -o objects_normal/gsc_memory.opp
echo "##### COMPILE cracking.CPP #####"
$cc $options -c cracking.cpp -o objects_normal/cracking.opp
echo "##### COMPILE GSC_MATH.CPP #####"
$cc $options -o objects_normal/gsc_math.opp -c gsc_math.cpp
echo "##### COMPILE JAVA_EMBED.C #####"
if [ "$java_enable" == "true" ]; then
$cc $options -o objects_normal/java_embed.opp -c java_embed.c $java_header
else
echo "Ignore java_embed.c, because java_enable==false (e.g. because the dir \$java_jdk=$java_jdk does not exist)"
fi
fi
if [ "$1" == "" ] || [ "$1" == "clean" ]; then
echo "##### CLEAN OBJECTS #####"
rm objects_* -r
rm bin -r
rm libcod.tar
fi
if [ "$1" == "" ] || [ "$1" == "tcc" ]; then
mkdir -p objects_tcc
echo "##### COMPILE gsc_tcc.cpp #####"
$cc $options -c gsc_tcc.cpp -o objects_tcc/gsc_tcc.opp
fi
if [ "$1" == "" ] || [ "$1" == "car" ]; then
mkdir -p objects_car
echo "##### COMPILE GSC_CAR.CPP #####"
$cc $options -c gsc_car.cpp -o objects_car/gsc_car.opp -I/root/q3rally/q3rallysa/
fi
if [ "$1" == "" ] || [ "$1" == "cod2_1_3" ]; then
constants="-D COD2_VERSION=COD2_VERSION_1_3 -D COD_VERSION=COD2_1_3"
mkdir -p objects_$1
echo "##### COMPILE $1 LIBCOD.CPP #####"
$cc $options $constants -o objects_$1/libcod.opp -c libcod.cpp
echo "##### COMPILE $1 GSC.CPP #####"
$cc $options $constants -o objects_$1/gsc.opp -c gsc.cpp
echo "##### COMPILE $1 GSC_PLAYER.CPP #####"
$cc $options $constants -o objects_$1/gsc_player.opp -c gsc_player.cpp
echo "##### COMPILE $1 GSC_UTILS.CPP #####"
$cc $options $constants -o objects_$1/gsc_utils.opp -c gsc_utils.cpp
echo "##### LINK lib$1.so #####"
objects="$(ls objects_normal/*.opp) $(ls objects_$1/*.opp)"
$cc -m32 -shared -L/lib32 $mysql_link -o bin/lib$1.so $objects $objects_tcc -Os -s -ldl -Wall $java_lib $mysql_config
fi
# -Xlinker --defsym -Xlinker stackStart=0x08297500
if [ "$1" == "" ] || [ "$1" == "cod2_1_2" ]; then
constants="-D COD2_VERSION=COD2_VERSION_1_2 -D COD_VERSION=COD2_1_2"
mkdir -p objects_$1
echo "##### COMPILE $1 LIBCOD.CPP #####"
$cc $options $constants -o objects_$1/libcod.opp -c libcod.cpp
echo "##### COMPILE $1 GSC.CPP #####"
$cc $options $constants -o objects_$1/gsc.opp -c gsc.cpp
echo "##### COMPILE $1 GSC_PLAYER.CPP #####"
$cc $options $constants -o objects_$1/gsc_player.opp -c gsc_player.cpp
echo "##### COMPILE $1 GSC_UTILS.CPP #####"
$cc $options $constants -o objects_$1/gsc_utils.opp -c gsc_utils.cpp
echo "##### LINK lib$1.so #####"
objects="$(ls objects_normal/*.opp) $(ls objects_$1/*.opp)"
$cc -m32 -shared -L/lib32 $mysql_link -o bin/lib$1.so $objects $objects_tcc -Os -s -ldl -Wall $java_lib $mysql_config
fi
if [ "$1" == "" ] || [ "$1" == "cod2_1_0" ]; then
constants="-D COD2_VERSION=COD2_VERSION_1_0 -D COD_VERSION=COD2_1_0"
mkdir -p objects_$1
echo "##### COMPILE $1 LIBCOD.CPP #####"
$cc $options $constants -o objects_$1/libcod.opp -c libcod.cpp
echo "##### COMPILE $1 GSC.CPP #####"
$cc $options $constants -o objects_$1/gsc.opp -c gsc.cpp
echo "##### COMPILE $1 GSC_PLAYER.CPP #####"
$cc $options $constants -o objects_$1/gsc_player.opp -c gsc_player.cpp
echo "##### COMPILE $1 GSC_UTILS.CPP #####"
$cc $options $constants -o objects_$1/gsc_utils.opp -c gsc_utils.cpp
echo "##### LINK lib$1.so #####"
objects="$(ls objects_normal/*.opp) $(ls objects_$1/*.opp)"
$cc -m32 -shared -L/lib32 $mysql_link -o bin/lib$1.so $objects $objects_tcc -Os -s -ldl -Wall $java_lib $mysql_config
fi
if [ "$1" == "" ] || [ "$1" == "cod1_1_5" ]; then
constants="-D COD_VERSION=COD1_1_5"
#echo "##### COMPILE CoD1 1.5 LIBCOD2.CPP #####"
#$cc $options $constants -c libcod2.cpp -o libcod2.opp
echo "##### COMPILE CoD1 1.5 GSC.CPP #####"
$cc $options $constants -c gsc.cpp -o gsc.opp
#echo "##### COMPILE CoD1 1.5 GSC_PLAYER.CPP #####"
#$cc $options $constants -c gsc_player.cpp -o gsc_player.opp
echo "##### LINK libcod1_1_5.so #####"
$cc -m32 -shared -L/lib32 $mysql_link -o bin/libcod1_1_5.so libcod2.opp gsc.opp gsc_player.opp gsc_astar.opp gsc_mysql.opp server.opp gsc_memory.opp cracking.opp $objects_tcc -Os -s -ldl -Wall $mysql_config
fi
if [ "$1" == "" ] || [ "$1" == "cod4_1_7" ]; then
constants="-D COD_VERSION=COD4_1_7"
mkdir -p objects_$1
echo "##### COMPILE $1 LIBCOD.CPP #####"
$cc $options $constants -o objects_$1/libcod.opp -c libcod.cpp
echo "##### COMPILE $1 GSC.CPP #####"
$cc $options $constants -o objects_$1/gsc.opp -c gsc.cpp
echo "##### COMPILE $1 GSC_PLAYER.CPP #####"
$cc $options $constants -o objects_$1/gsc_player.opp -c gsc_player.cpp
echo "##### COMPILE $1 GSC_UTILS.CPP #####"
$cc $options $constants -o objects_$1/gsc_utils.opp -c gsc_utils.cpp
echo "##### LINK lib$1.so #####"
objects="$(ls objects_normal/*.opp) $(ls objects_$1/*.opp)"
$cc -m32 -shared -L/lib32 $mysql_link -o bin/lib$1.so $objects $objects_tcc -Os -s -ldl -Wall $java_lib $mysql_config
fi
if [ "$1" == "" ] || [ "$1" == "cod4_1_7_l" ]; then
constants="-D COD_VERSION=COD4_1_7_L"
mkdir -p objects_$1
echo "##### COMPILE $1 LIBCOD.CPP #####"
$cc $options $constants -o objects_$1/libcod.opp -c libcod.cpp
echo "##### COMPILE $1 GSC.CPP #####"
$cc $options $constants -o objects_$1/gsc.opp -c gsc.cpp
echo "##### COMPILE $1 GSC_PLAYER.CPP #####"
$cc $options $constants -o objects_$1/gsc_player.opp -c gsc_player.cpp
echo "##### COMPILE $1 GSC_UTILS.CPP #####"
$cc $options $constants -o objects_$1/gsc_utils.opp -c gsc_utils.cpp
echo "##### LINK lib$1.so #####"
objects="$(ls objects_normal/*.opp) $(ls objects_$1/*.opp)"
$cc -m32 -shared -L/lib32 $mysql_link -o bin/lib$1.so $objects $objects_tcc -Os -s -ldl -Wall $java_lib $mysql_config
fi
if [ "$1" == "wrapper" ]; then
echo "##### WRAPPER: COMPILE wrapper_libcod2.cpp #####"
cp wrapper_libcod2.cpp a.cpp # just for name hiding in the .opp/.so -.-
$cc -m32 -fPIC -c a.cpp -o wrapper_libcod2.opp
#strip wrapper_libcod2.opp
# make the shared lib for the wrapper
echo "##### WRAPPER: LINK wrapper_libcod2.so #####"
$cc -m32 -shared -L/lib32 -o wrapper_libcod2.so wrapper_libcod2.opp
cp wrapper_libcod2.so bin/libcod2.so
#cp wrapper_libcod2.so /root/helper/game_cod2/libs/libcod2.so # other then "mv", "ld" can use it so (not just from game-libs-folder)
fi