-
Notifications
You must be signed in to change notification settings - Fork 0
/
cookbook
169 lines (148 loc) · 3.56 KB
/
cookbook
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
if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then
echo "This script is not meant to be executed directly"
exit 1
fi
if [[ -z "$OS" ]]; then
echo "Please set OS to the platform you wish to build"
exit 1
fi
if [[ $OS = android ]]; then
if [[ -z "$ANDROID_SDK_PATH" && -z "$CI" ]]; then
ANDROID_SDK_PATH="$HOME/usr/android-sdk"
fi
ANDROID_NDK_HOME="$ANDROID_SDK_PATH/ndk-bundle"
TOOLCHAIN_PATH="$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin"
CMAKE_TOOLCHAIN_FILE="$ANDROID_NDK_HOME/build/cmake/android.toolchain.cmake"
export PATH="$ANDROID_NDK_HOME:$TOOLCHAIN_PATH:$PATH"
fi
KITCHEN="$(readlink -f "$(dirname "${BASH_SOURCE[0]}")")"
RECIPE="$(basename "$0")"
PATCHES="$KITCHEN/patches"
SOURCES="$KITCHEN/sources"
LOGS="$KITCHEN/logs"
mkdir -p "$SOURCES" "$LOGS"
fire() {
set -ex
($@)
set +ex
}
cook() {
PLATFORM=${1%-*}
ARCH=${1#*-}
echo -n "Cooking $RECIPE for $PLATFORM-$ARCH..."
if [[ $PLATFORM = android ]]; then
HOST=$ARCH-linux-$PLATFORM
ANDROID_PLATFORM=android-21
if [[ $ARCH = aarch64 ]]; then
ANDROID_ABI=arm64-v8a
RPATH="$ANDROID_NDK_HOME/platforms/$ANDROID_PLATFORM/arch-arm64"
elif [[ $ARCH = x86_64 ]]; then
ANDROID_ABI=x86_64
RPATH="$ANDROID_NDK_HOME/platforms/$ANDROID_PLATFORM/arch-x86_64"
fi
fi
BLD="$KITCHEN/build/$PLATFORM-$ARCH/$RECIPE"
PREFIX="$KITCHEN/libs/$PLATFORM-$ARCH"
mkdir -p "$BLD" "$PREFIX"
cd "$BLD"
export PKG_CONFIG_PATH="$PREFIX/lib/pkgconfig"
RECIPE_LOG_FILE="$LOGS/$RECIPE-$PLATFORM-$ARCH-build.log"
trap recipe_exit INT
trap recipe_exit DEBUG
RECIPE_LOG=$(fire recipe $PLATFORM-$ARCH 2>&1)
trap - DEBUG
trap - INT
echo "done"
}
recipe_exit() {
local rc=$?
echo "$RECIPE_LOG" > "$RECIPE_LOG_FILE"
if [ $rc -ne 0 ]; then
echo "failed"
echo "$RECIPE_LOG"
exit $rc
fi
}
prep_tarball() {
if [[ ! -d "$SRC" ]]; then
local type="${1##*.}"
local tarball="$RECIPE-$VERSION.tar.$type"
cd "$SOURCES"
echo -n "Fetching $RECIPE tarball..."
wget -qO $tarball "$1"
echo "done"
mkdir -p "$SRC"
echo -n "Extracting tarball..."
case $type in
gz)
tar zxf $tarball --strip=1 -C "$SRC"
;;
bz2)
tar jxf $tarball --strip=1 -C "$SRC"
;;
xz)
tar Jxf $tarball --strip=1 -C "$SRC"
;;
esac
echo "done"
rm -f $tarball
fi
}
prep_git() {
if [[ ! -d "$SRC" ]]; then
local url="$1"
echo -n "Cloning $RECIPE..."
git -C "$SOURCES" clone -q --branch $VERSION "$1" "$RECIPE-$VERSION"
echo "done"
fi
}
prep_patch() {
for name in "$@"; do
if [[ ! -f "$SRC/.$name" ]]; then
patch -sd "$SRC" -p1 < "$PATCHES/$RECIPE/$name.patch"
touch "$SRC/.$name"
fi
done
}
prep_bootstrap() {
if [[ $OS != windows && ! -x "$SRC/configure" ]]; then
BOOTSTRAP_LOG_FILE="$LOGS/$RECIPE-bootstrap.log"
echo -n "Running bootstrap..."
cd "$SRC"
chmod 755 .bootstrap
trap bootstrap_exit INT
trap bootstrap_exit DEBUG
BOOTSTRAP_LOG=$("./$1" 2>&1)
trap - DEBUG
trap - INT
echo "done"
fi
}
bootstrap_exit() {
local rc=$?
echo "$BOOTSTRAP_LOG" > "$BOOTSTRAP_LOG_FILE"
if [ $rc -ne 0 ]; then
echo "failed"
echo "$BOOTSTRAP_LOG"
exit $rc
fi
}
begin() {
if [[ -z "$VERSION" ]]; then
echo "VERSION not defined"
exit 1
fi
if [[ -z "$PLATFORMS" ]]; then
echo "PLATFORMS not defined"
exit 1
fi
if [[ -z "$SRC" ]]; then
SRC="$SOURCES/$RECIPE-$VERSION"
fi
prep
for platform in $PLATFORMS; do
if [[ ${platform%-*} = $OS ]]; then
cook $platform
fi
done
}