-
Notifications
You must be signed in to change notification settings - Fork 3
/
make.sh
executable file
·383 lines (330 loc) · 10.5 KB
/
make.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
#!/bin/bash
set -e
# set -o xtrace
if [ "$VERSION" = "" -a "$GITHUB_REF" != "" ];
then
export VERSION="`if [[ $GITHUB_REF == refs\/tags* ]]; then echo ${GITHUB_REF//refs\/tags\//}; fi`"
if [ "$VERSION" = "" ];
then
branch="${GITHUB_REF//refs\/heads\//}"
export VERSION="$branch-SNAPSHOT"
fi
else
VERSION="1.1"
fi
DEPLOY="false"
mkdir -p build
mkdir -p build/tests
rm -Rf build/tests/resources
cp -Rf resources build/tests/
if [ ! -f "build/bash_colors.sh" ];
then
wget -q https://raw.githubusercontent.com/maxtsepkov/bash_colors/738f82882672babfaa21a2c5e78097d9d8118f91/bash_colors.sh -O build/bash_colors.sh
fi
source build/bash_colors.sh
function cleanTMP {
rm -Rf build/tmp
mkdir -p build/tmp
}
function clean {
rm -R build
mkdir build
}
function downloadIfRequired {
if [ ! -d "build/vhacd" ];
then
download
fi
}
function download {
clr_green "Download VHACD"
rm -f build/tmp/vhacd.zip
wget -q https://github.com/kmammou/v-hacd/archive/ded1fe468c3b9db82d7747cbb114751f29b73d84.zip -O build/tmp/vhacd.zip
mkdir build/tmp/ext
unzip -q build/tmp/vhacd.zip -d build/tmp/ext
mv build/tmp/ext/* build/vhacd
}
function setPlatformArch {
PLATFORM=$1
ARCH=$2
if [ "$ARCH" = "" ]; then
OUT_PATH="$PWD/build/lib/$PLATFORM"
else
OUT_PATH="$PWD/build/lib/$PLATFORM-$ARCH"
fi
mkdir -p $OUT_PATH
}
function buildLinux64 {
buildLinux "x86-64"
}
function buildLinux32 {
buildLinux "x86"
}
function buildLinux {
downloadIfRequired
setPlatformArch "linux" $1
clr_green "Compile for $PLATFORM $ARCH..."
arch_flag="-m64"
if [ "$1" = "x86" ];
then
arch_flag="-m32"
fi
build_script="
g++ -mtune=generic -fpermissive -U_FORTIFY_SOURCE -fPIC -O3 $arch_flag -shared
-Ibuild/vhacd/src/VHACD_Lib/inc
-Ibuild/vhacd/src/VHACD_Lib/public
-Inative/src -pthread
build/vhacd/src/VHACD_Lib/src/*.cpp
native/src/*.cpp
-Wl,-soname,vhacd.so -o $OUT_PATH/libvhacd.so -lrt"
clr_escape "$(echo $build_script)" $CLR_BOLD $CLR_BLUE
$build_script
if [ $? -ne 0 ]; then exit 1; fi
clr_green "Compile Tests for $PLATFORM $ARCH..."
tests=($(ls -d native/tests/*))
for i in "${tests[@]}"
do
name=`basename $i`
ex_name="$name.$PLATFORM.$ARCH"
clr_brown "+ $ex_name"
build_script="g++ $arch_flag -fpermissive
-Ibuild/vhacd/src/VHACD_Lib/inc
-Ibuild/vhacd/src/VHACD_Lib/public
-Inative/src -pthread -fPIC
-Inative/tests/commons/
-I$i -Wl,--as-needed
build/vhacd/src/VHACD_Lib/src/*.cpp
native/src/*.cpp
$i/*.cpp
-o build/tests/$ex_name -lrt "
clr_escape "$(echo $build_script)" $CLR_BOLD $CLR_BLUE
$build_script
if [ $? -ne 0 ]; then exit 1; fi
done
}
function buildWindows {
downloadIfRequired
setPlatformArch "win32" $1
clr_green "Compile for $PLATFORM $ARCH..."
compiler="x86_64-w64-mingw32-g++"
if [ "$1" = "x86" ];
then
compiler="i686-w64-mingw32-g++"
fi
build_script="
$compiler -mtune=generic -fpermissive -fPIC -U_FORTIFY_SOURCE -O3 -DWIN32 -shared
-Ibuild/vhacd/src/VHACD_Lib/inc
-Ibuild/vhacd/src/VHACD_Lib/public
-Inative/ -static
build/vhacd/src/VHACD_Lib/src/*.cpp
native/src/*.cpp -Wp,-w
-Wl,-soname,vhacd.dll -o $OUT_PATH/vhacd.dll"
clr_escape "$(echo $build_script)" $CLR_BOLD $CLR_BLUE
$build_script
if [ $? -ne 0 ]; then exit 1; fi
clr_green "Compile Tests for $PLATFORM $ARCH..."
tests=($(ls -d native/tests/*))
for i in "${tests[@]}"
do
name=`basename $i`
ex_name="$name.$PLATFORM.$ARCH.exe"
clr_brown "+ $ex_name"
build_script="$compiler -fpermissive -DWIN32
-Ibuild/vhacd/src/VHACD_Lib/inc
-Ibuild/vhacd/src/VHACD_Lib/public
-Inative/src
-Inative/tests/commons/
-I$i -static -Wp,-w -Wl,--as-needed
build/vhacd/src/VHACD_Lib/src/*.cpp
native/src/*.cpp
$i/*.cpp
-o build/tests/$ex_name"
clr_escape "$(echo $build_script)" $CLR_BOLD $CLR_BLUE
$build_script
if [ $? -ne 0 ]; then exit 1; fi
done
}
function buildWindows32 {
buildWindows "x86"
}
function buildWindows64 {
buildWindows "x86-64"
}
function buildJavaBindings {
if [ "$JAVA_HOME" = "" ];
then
export JAVA_HOME=$(dirname $(dirname $(readlink -f $(which javac))))
fi
echo "Use JAVA_HOME $JAVA_HOME"
if [ ! -f build/jnaerator.jar ];
then
clr_green "Download jnaerator..."
wget -q https://github.com/riccardobl/JNAerator/archive/refs/heads/master.zip -O build/tmp/jnaerator.zip
mkdir -p build/tmp/jnaerator-ext
unzip -q build/tmp/jnaerator.zip -d build/tmp/jnaerator-ext/
cd build/tmp/jnaerator-ext/*/
clr_green "Build jnaerator..."
mvn -DskipTests -q clean install -Dmaven.javadoc.skip=true -Dmaven.compiler.source=1.7 -Dmaven.compiler.target=1.7
cp jnaerator/target/jnaerator-*-shaded.jar ../../../jnaerator.jar
cd ../../../../
fi
clr_green "Build java bindings..."
mkdir -p build/release
rm -Rf build/tmp/libvhacd
mkdir -p build/tmp/libvhacd
cp -Rf build/lib/* build/tmp/libvhacd/
cmd="`which java`
-jar build/jnaerator.jar
-mode Directory
-runtime JNA
-sizeAsLong
-noComments
-noRawBindings
-preferJavac
-package 'vhacd.vhacd_native'
-f
-DBINDINGS=1
-library vhacd
native/src/VHACDNative.h
-o build/tmp/libvhacd"
clr_escape "$(echo $cmd)" $CLR_BOLD $CLR_BLUE
$cmd
if [ $? -ne 0 ]; then exit 1; fi
rm -f build/release/vhacd-native.jar
mkdir -p build/tmp/bin
mkdir -p build/tmp/j
if [ ! -f build/jna-platform.jar ];
then
clr_green "Download JNA Platform..."
wget -q https://repo1.maven.org/maven2/net/java/dev/jna/jna-platform/4.2.2/jna-platform-4.2.2.jar -O build/jna-platform.jar
fi
if [ ! -f build/jna.jar ];
then
clr_green "Download JNA..."
wget -q https://repo1.maven.org/maven2/net/java/dev/jna/jna/4.2.2/jna-4.2.2.jar -O build/jna.jar
fi
unzip -q build/jna.jar -d build/tmp/j/
rm -Rf build/tmp/j/META-INF
unzip -q build/jna-platform.jar -d build/tmp/j/
rm -Rf build/tmp/j/META-INF
clr_green "Build vhacd-native-$VERSION-sources.jar..."
cp -Rf build/tmp/libvhacd/* build/tmp/j/
cp -Rf java/src/* build/tmp/j/
cp -Rf build/tmp/j/* build/tmp/bin/
find build/tmp/j -type f ! -name '*.java' -delete
cmd="`which jar`
cf
build/release/vhacd-native-$VERSION-sources.jar
-C build/tmp/j .
"
clr_escape "$(echo $cmd)" $CLR_BOLD $CLR_BLUE
$cmd
if [ $? -ne 0 ]; then exit 1; fi
clr_green "Build vhacd-native-$VERSION.jar..."
find build/tmp/bin -type f -name '*.java' > build/tmp/java-src.txt
cmd="`which javac` -source 1.7 -target 1.7 -Xlint:none -cp build/tmp/bin @build/tmp/java-src.txt"
clr_escape "$(echo $cmd)" $CLR_BOLD $CLR_BLUE
$cmd
if [ $? -ne 0 ]; then exit 1; fi
find build/tmp/bin -type f -name '*.java' -delete
cmd="`which jar`
cf
build/release/vhacd-native-$VERSION.jar
-C build/tmp/bin .
"
clr_escape "$(echo $cmd)" $CLR_BOLD $CLR_BLUE
$cmd
if [ $? -ne 0 ]; then exit 1; fi
clr_green "Compile Tests for java..."
tests=($(ls -d java/tests/*))
for i in "${tests[@]}"
do
name=`basename $i`
ex_name="$name.jar"
clr_brown "+ $ex_name"
rm -Rf build/tmp/jt
mkdir -p build/tmp/jt
cp -Rf $i/* build/tmp/jt
cp -Rf build/tmp/bin/* build/tmp/jt
find build/tmp/jt -type f -name '*.java' > build/tmp/java-src.txt
cmd="`which javac` -source 1.7 -target 1.7 -Xlint:none -cp build/tmp/jt @build/tmp/java-src.txt"
clr_escape "$(echo $cmd)" $CLR_BOLD $CLR_BLUE
$cmd
if [ $? -ne 0 ]; then exit 1; fi
cmd="`which jar`
cf
build/tests/$ex_name
-C build/tmp/jt .
"
clr_escape "$(echo $cmd)" $CLR_BOLD $CLR_BLUE
$cmd
if [ $? -ne 0 ]; then exit 1; fi
done
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<project
xmlns=\"http://maven.apache.org/POM/4.0.0\"
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd\">
<modelVersion>4.0.0</modelVersion>
<groupId>vhacd</groupId>
<artifactId>vhacd-native</artifactId>
<version>$VERSION</version>
<name>vhacd-native</name>
<description>Native bindings for vhacd</description>
<url></url>
</project> " > build/release/vhacd-native-$VERSION.pom
}
function buildMac {
downloadIfRequired
setPlatformArch "darwin" ""
clr_green "Compile for $PLATFORM..."
build_script="
g++ -mtune=generic -fpermissive -U_FORTIFY_SOURCE -fPIC -O3 -shared
-Ibuild/vhacd/src/VHACD_Lib/inc
-Ibuild/vhacd/src/VHACD_Lib/public
-Inative/src
build/vhacd/src/VHACD_Lib/src/*.cpp
native/src/*.cpp
-o $OUT_PATH/libvhacd.dylib"
clr_escape "$(echo $build_script)" $CLR_BOLD $CLR_BLUE
$build_script
if [ $? -ne 0 ]; then exit 1; fi
clr_green "Compile Tests for $PLATFORM $ARCH..."
tests=($(ls -d native/tests/*))
for i in "${tests[@]}"
do
name=`basename $i`
ex_name="$name.$PLATFORM"
clr_brown "+ $ex_name"
build_script="g++ -fpermissive
-Ibuild/vhacd/src/VHACD_Lib/inc
-Ibuild/vhacd/src/VHACD_Lib/public
-Inative/src -fPIC
-Inative/tests/commons/
-I$i
build/vhacd/src/VHACD_Lib/src/*.cpp
native/src/*.cpp
$i/*.cpp
-o build/tests/$ex_name"
clr_escape "$(echo $build_script)" $CLR_BOLD $CLR_BLUE
$build_script
if [ $? -ne 0 ]; then exit 1; fi
done
}
function buildAll {
buildLinux32
buildLinux64
buildWindows32
buildWindows64
buildJavaBindings
}
cleanTMP
if [ "$1" = "" ];
then
echo "Usage: make.sh target"
echo " - Targets: buildAll,buildWindows32,buildWindows64,buildLinux32,buildLinux64,buildJavaBindings,clean"
else
clr_magenta "Run $@..."
$@
clr_magenta "Build complete, results are stored in $PWD/build/"
fi