forked from bytedeco/javacpp-presets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cppbuild.sh
executable file
·188 lines (177 loc) · 8.51 KB
/
cppbuild.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
#!/bin/bash
# Scripts to build and install native C++ libraries
set -eu
which cmake3 &> /dev/null && CMAKE3="cmake3" || CMAKE3="cmake"
[[ -z ${CMAKE:-} ]] && CMAKE=$CMAKE3
[[ -z ${MAKEJ:-} ]] && MAKEJ=4
[[ -z ${OLDCC:-} ]] && OLDCC="gcc"
[[ -z ${OLDCXX:-} ]] && OLDCXX="g++"
[[ -z ${OLDFC:-} ]] && OLDFC="gfortran"
KERNEL=(`uname -s | tr [A-Z] [a-z]`)
ARCH=(`uname -m | tr [A-Z] [a-z]`)
case $KERNEL in
darwin)
OS=macosx
;;
mingw32*)
OS=windows
KERNEL=windows
ARCH=x86
;;
mingw64*)
OS=windows
KERNEL=windows
ARCH=x86_64
;;
*)
OS=$KERNEL
;;
esac
case $ARCH in
arm*)
ARCH=arm
;;
aarch64*)
ARCH=arm64
;;
i386|i486|i586|i686)
ARCH=x86
;;
amd64|x86-64)
ARCH=x86_64
;;
esac
PLATFORM=$OS-$ARCH
EXTENSION=
echo "Detected platform \"$PLATFORM\""
while [[ $# > 0 ]]; do
case "$1" in
-platform=*)
PLATFORM="${1#-platform=}"
;;
-platform)
shift
PLATFORM="$1"
;;
-extension=*)
EXTENSION="${1#-extension=}"
;;
-extension)
shift
EXTENSION="$1"
;;
install)
OPERATION=install
;;
clean)
OPERATION=clean
;;
*)
PROJECTS+=("$1")
;;
esac
shift
done
echo -n "Building for platform \"$PLATFORM\""
if [[ -n "$EXTENSION" ]]; then
echo -n " with extension \"$EXTENSION\""
fi
echo
if [[ -z ${OPERATION:-} ]]; then
echo "Usage: ANDROID_NDK=/path/to/android-ndk/ bash cppbuild.sh [-platform <name>] [-extension <name>] <install | clean> [projects]"
echo "where possible platform names are: android-arm, android-x86, linux-x86, linux-x86_64, macosx-x86_64, windows-x86, windows-x86_64, etc."
exit 1
fi
if [[ -z ${ANDROID_NDK:-} ]]; then
ANDROID_NDK=~/Android/android-ndk/
fi
export ANDROID_NDK
export ANDROID_CC="$ANDROID_NDK/toolchains/llvm/prebuilt/$KERNEL-$ARCH/bin/clang"
export ANDROID_CPP="$ANDROID_NDK/sources/cxx-stl/llvm-libc++/"
case $PLATFORM in
android-arm)
export ANDROID_BIN="$ANDROID_NDK/toolchains/arm-linux-androideabi-4.9/prebuilt/$KERNEL-$ARCH/"
export ANDROID_ROOT="$ANDROID_NDK/platforms/android-21/arch-arm/"
export ANDROID_FLAGS="--gcc-toolchain=$ANDROID_BIN --sysroot=$ANDROID_ROOT -isystem $ANDROID_CPP/include/ -isystem $ANDROID_CPP/../llvm-libc++abi/include/ -isystem $ANDROID_NDK/sources/android/support/include/ -isystem $ANDROID_CPP/libs/armeabi-v7a/include/ -isystem $ANDROID_NDK/sysroot/usr/include/ -isystem $ANDROID_NDK/sysroot/usr/include/arm-linux-androideabi/ -isystem $ANDROID_ROOT/usr/include/ -isystem $ANDROID_NDK/sources/android/cpufeatures/ -D__ANDROID_API__=21 -DANDROID -fPIC -ffunction-sections -funwind-tables -fstack-protector-strong -target armv7-none-linux-androideabi -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16 -z text -Wno-unused-command-line-argument -Wno-unknown-warning-option -Wno-ignored-optimization-argument -Wl,--fix-cortex-a8 -L$ANDROID_CPP/libs/armeabi-v7a/ -L$ANDROID_ROOT/usr/lib/ -Wl,--no-undefined -static-libstdc++"
export ANDROID_PREFIX="$ANDROID_BIN/bin/arm-linux-androideabi"
export ANDROID_LIBS="-lc++_static -lc++abi -landroid_support -ldl -lm -lc"
;;
android-arm64)
export ANDROID_BIN="$ANDROID_NDK/toolchains/aarch64-linux-android-4.9/prebuilt/$KERNEL-$ARCH/"
export ANDROID_ROOT="$ANDROID_NDK/platforms/android-21/arch-arm64/"
export ANDROID_FLAGS="--gcc-toolchain=$ANDROID_BIN --sysroot=$ANDROID_ROOT -isystem $ANDROID_CPP/include/ -isystem $ANDROID_CPP/../llvm-libc++abi/include/ -isystem $ANDROID_NDK/sources/android/support/include/ -isystem $ANDROID_CPP/libs/arm64-v8a/include/ -isystem $ANDROID_NDK/sysroot/usr/include/ -isystem $ANDROID_NDK/sysroot/usr/include/aarch64-linux-android/ -isystem $ANDROID_ROOT/usr/include/ -isystem $ANDROID_NDK/sources/android/cpufeatures/ -D__ANDROID_API__=21 -DANDROID -fPIC -ffunction-sections -funwind-tables -fstack-protector-strong -target aarch64-none-linux-android -march=armv8-a -z text -Wno-unused-command-line-argument -Wno-unknown-warning-option -Wno-ignored-optimization-argument -L$ANDROID_CPP/libs/arm64-v8a/ -L$ANDROID_ROOT/usr/lib/ -Wl,--no-undefined -static-libstdc++"
export ANDROID_PREFIX="$ANDROID_BIN/bin/aarch64-linux-android"
export ANDROID_LIBS="-lc++_static -lc++abi -ldl -lm -lc"
;;
android-x86)
export ANDROID_BIN="$ANDROID_NDK/toolchains/x86-4.9/prebuilt/$KERNEL-$ARCH/"
export ANDROID_ROOT="$ANDROID_NDK/platforms/android-21/arch-x86/"
export ANDROID_FLAGS="--gcc-toolchain=$ANDROID_BIN --sysroot=$ANDROID_ROOT -isystem $ANDROID_CPP/include/ -isystem $ANDROID_CPP/../llvm-libc++abi/include/ -isystem $ANDROID_NDK/sources/android/support/include/ -isystem $ANDROID_CPP/libs/x86/include/ -isystem $ANDROID_NDK/sysroot/usr/include/ -isystem $ANDROID_NDK/sysroot/usr/include/i686-linux-android/ -isystem $ANDROID_ROOT/usr/include/ -isystem $ANDROID_NDK/sources/android/cpufeatures/ -D__ANDROID_API__=21 -DANDROID -fPIC -ffunction-sections -funwind-tables -fstack-protector-strong -target i686-none-linux-android -march=i686 -mtune=atom -mssse3 -mfpmath=sse -z text -Wno-unused-command-line-argument -Wno-unknown-warning-option -Wno-ignored-optimization-argument -L$ANDROID_CPP/libs/x86/ -L$ANDROID_ROOT/usr/lib/ -Wl,--no-undefined -static-libstdc++"
export ANDROID_PREFIX="$ANDROID_BIN/bin/i686-linux-android"
export ANDROID_LIBS="-lc++_static -lc++abi -landroid_support -ldl -lm -lc"
;;
android-x86_64)
export ANDROID_BIN="$ANDROID_NDK/toolchains/x86_64-4.9/prebuilt/$KERNEL-$ARCH/"
export ANDROID_ROOT="$ANDROID_NDK/platforms/android-21/arch-x86_64/"
export ANDROID_FLAGS="--gcc-toolchain=$ANDROID_BIN --sysroot=$ANDROID_ROOT -isystem $ANDROID_CPP/include/ -isystem $ANDROID_CPP/../llvm-libc++abi/include/ -isystem $ANDROID_NDK/sources/android/support/include/ -isystem $ANDROID_CPP/libs/x86_64/include/ -isystem $ANDROID_NDK/sysroot/usr/include/ -isystem $ANDROID_NDK/sysroot/usr/include/x86_64-linux-android/ -isystem $ANDROID_ROOT/usr/include/ -isystem $ANDROID_NDK/sources/android/cpufeatures/ -D__ANDROID_API__=21 -DANDROID -fPIC -ffunction-sections -funwind-tables -fstack-protector-strong -target x86_64-none-linux-android -march=x86-64 -mtune=atom -z text -Wno-unused-command-line-argument -Wno-unknown-warning-option -Wno-ignored-optimization-argument -L$ANDROID_CPP/libs/x86_64/ -L$ANDROID_ROOT/usr/lib64/ -Wl,--no-undefined -static-libstdc++"
export ANDROID_PREFIX="$ANDROID_BIN/bin/x86_64-linux-android"
export ANDROID_LIBS="-lc++_static -lc++abi -ldl -lm -lc"
;;
esac
TOP_PATH=`pwd`
function download {
mkdir -p "$TOP_PATH/downloads"
if [[ ! -e "$TOP_PATH/downloads/$2" ]]; then
echo "Downloading $1"
curl -L "$1" -o "$TOP_PATH/downloads/$2" --fail
DOWNLOADSTATUS=$?
if [ "$DOWNLOADSTATUS" -eq 28 ]
then
echo "Download timed out, waiting 5 minutes then trying again"
rm "$TOP_PATH/downloads/$2"
sleep 600
curl -L "$1" -o "$TOP_PATH/downloads/$2" --fail
if [ $? -ne 0 ]
then
echo "File still could not be downloaded!"
rm "$TOP_PATH/downloads/$2"
exit 1
fi
elif [ "$DOWNLOADSTATUS" -ne 0 ]
then
echo "File could not be downloaded!"
rm "$TOP_PATH/downloads/$2"
exit 1
fi
fi
ln -sf "$TOP_PATH/downloads/$2" "$2"
}
function sedinplace {
if ! sed --version 2>&1 | grep -i gnu > /dev/null; then
sed -i '' "$@"
else
sed -i "$@"
fi
}
if [[ -z ${PROJECTS:-} ]]; then
PROJECTS=(opencv ffmpeg flycapture spinnaker libdc1394 libfreenect libfreenect2 librealsense videoinput artoolkitplus chilitags flandmark hdf5 mkl mkl-dnn openblas arpack-ng cminpack fftw gsl cpython numpy llvm libpostal leptonica tesseract caffe cuda mxnet tensorflow tensorrt ale onnx ngraph liquidfun qt skia cpu_features systems)
fi
for PROJECT in ${PROJECTS[@]}; do
case $OPERATION in
install)
if [[ ! -d $PROJECT ]]; then
echo "Warning: Project \"$PROJECT\" not found"
else
echo "Installing \"$PROJECT\""
mkdir -p $PROJECT/cppbuild
pushd $PROJECT/cppbuild
source ../cppbuild.sh
popd
fi
;;
clean)
echo "Cleaning \"$PROJECT\""
rm -Rf $PROJECT/cppbuild
;;
esac
done