forked from lordhoto/ios-toolchain
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-library.sh
executable file
·129 lines (110 loc) · 3.12 KB
/
build-library.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
#!/bin/bash
#
# Copyright (c) 2016 Johannes Schickel <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# NLS nuisances.
LC_ALL=C
export LC_ALL
LANGUAGE=C
export LANGUAGE
function verbose_cmd {
echo "$@"
eval "$@"
}
if [ "X$1" = "X--no-shadow-build" ]; then
shift 1
SHADOW_BUILD_SUFFIX=""
else
SHADOW_BUILD_SUFFIX="-build"
fi
BUILD_DIR=build/
if [ -z "$PARALLELISM" ]; then
PARALLELISM=2
fi
if [ -z "$PACKAGE" ]; then
echo "ERROR: \$PACKAGE not set."
exit 1
fi
if [ -z "$PACKAGE_FILE" ]; then
echo "ERROR: \$PACKAGE_FILE not set."
exit 1
fi
if [ -z "$PATCH_DIR" ]; then
echo "ERROR: \$PATCH_DIR not set."
exit 1
fi
if [ -z "$CACHE_DIR" ]; then
echo "ERROR: \$CACHE_DIR not set."
exit 1
fi
if [ -z "$IOS_TOOLCHAIN_BASE" ]; then
echo "ERROR: \$IOS_TOOLCHAIN_BASE needs to be set to toolchain's base directory."
exit 1
fi
IOS_TOOLCHAIN_BASE=`realpath $IOS_TOOLCHAIN_BASE`
if [ -z "$TARGET" ]; then
echo "ERROR: $TARGET needs to be set to the target triple."
exit 1
fi
TARGET_BASE="$IOS_TOOLCHAIN_BASE/$TARGET"
export PATH="$IOS_TOOLCHAIN_BASE/bin:$TARGET_BASE/bin:$TARGET_BASE/usr/bin:$PATH"
export CC="$TARGET-clang"
export CXX="$TARGET-clang++"
export CPPFLAGS="-I$TARGET_BASE/usr/include"
export LDFLAGS="-L$TARGET_BASE/usr/lib"
export PKG_CONFIG="$TARGET-pkg-config"
mkdir -p "$BUILD_DIR"
pushd "$BUILD_DIR" &>/dev/null
echo "Preparing sources for $PACKAGE..."
case "$PACKAGE_FILE" in
*.tar.*)
tar xf "$PACKAGE_FILE"
;;
*)
echo "ERROR: Unsupported package type."
exit 1
;;
esac
pushd "$PACKAGE" &>/dev/null
for i in `ls "$PATCH_DIR/$PACKAGE/" 2>/dev/null`; do
echo "Apply patch $i..."
patch -p1 < "$PATCH_DIR/$PACKAGE/$i" || exit 1
done
popd &>/dev/null
mkdir -p "$PACKAGE$SHADOW_BUILD_SUFFIX"
pushd "$PACKAGE$SHADOW_BUILD_SUFFIX" &>/dev/null
CACHE_OPT=""
if [ -f "$CACHE_DIR/$PACKAGE/$TARGET.cache" ]; then
echo "Copying cache file..."
CACHE_OPT="--cache-file=cache.cache"
cp "$CACHE_DIR/$PACKAGE/$TARGET.cache" cache.cache
fi
popd &>/dev/null
echo "Building $PACKAGE for $TARGET..."
if [ -n "$PACKAGE_SUB" ]; then
CONFIGURE="\"../$PACKAGE/$PACKAGE_SUB/configure\""
else
CONFIGURE="\"../$PACKAGE/configure\""
fi
pushd "$PACKAGE$SHADOW_BUILD_SUFFIX" &>/dev/null
verbose_cmd "$CONFIGURE" "--host=$TARGET" "\"--prefix=$TARGET_BASE/usr\"" --disable-shared --enable-static $CACHE_OPT "$@" "&>build.log" || exit 1
verbose_cmd "make -j$PARALLELISM &>build.log" || exit 1
verbose_cmd "make install &>build.log" || exit 1
popd &>/dev/null
popd &>/dev/null
echo "Successfull library build."
chmod -R u+w "$BUILD_DIR"
rm -r "$BUILD_DIR"