This repository has been archived by the owner on Nov 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.sh
executable file
·203 lines (168 loc) · 5.96 KB
/
build.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
#!/bin/bash
export PJSIP_VERSION='trunk'
export BASE_DIR=`pwd -P`
export PRODUCT_NAME='libPjsip'
export TARGET_DIR='vendor'
cd `dirname $BASH_SOURCE`
set -o errexit
set -o errtrace
export PRE=" ───── "
function help() {
cat <<EOF
$0 help # shows this help message.
$0 svn_checkout # Get the latest PJSIP sources from SVN
$0 clean # cleans the pjsip source folder.
$0 all # build fat binary that works on all architectures.
$0 armv7 # build armv7 static lib.
$0 armv7s # build armv7s static lib.
$0 arm64 # build arm64 static lib.
$0 i386 # build i386 static lib.
$0 x86_64 # build x86_64 static lib.
$0 info armv7 # show architecture information for armv7 libs.
$0 info armv7s # show architecture information for armv7s libs.
$0 info arm64 # show architecture information for arm64 libs.
$0 info i386 # show architecture information for i386 libs.
$0 info x86_64 # show architecture information for x86_64 libs.
$0 complete # Downloads, builds and copies files.
EOF
}
function complete() {
clean
svn_checkout
mkdir -p "$BASE_DIR"/pjsip/logs/
all
copy_headers
}
function clean() {
echo "$PRE CLEAN"
echo "WARNING: About to clean directory: $BASE_DIR/pjsip"
echo "WARNING: About to clean directory: $BASE_DIR/${TARGET_DIR}"
echo "waiting 5 seconds for sanity check... CTRL-C to abort now"
sleep 1 && echo "4..." && \
sleep 1 && echo "3..." && \
sleep 1 && echo "2..." && \
sleep 1 && echo "1..." && \
sleep 1
rm -rf "$BASE_DIR/pjsip/"
rm -rf "$BASE_DIR/${TARGET_DIR}/"
}
# Checks out the supplied PJSIP version source from SVN. If no version provided latest version is used.
function svn_checkout() {
BASE_URL="http://svn.pjsip.org/repos/pjproject"
echo "Checking out version ${PJSIP_VERSION}"
if [ "$PJSIP_VERSION" = "trunk" ]; then
CHECKOUT_URL="${BASE_URL}/trunk"
else
CHECKOUT_URL="${BASE_URL}/tags/${PJSIP_VERSION}/"
fi
rm -rf "$BASE_DIR/pjsip/src"
svn export "${CHECKOUT_URL}" "${BASE_DIR}/pjsip/src/"
}
# Function Prints info about the created libraries.
function info() {
echo "$PRE ARCH"
find ${TARGET_DIR}/$1/*.a | \
xargs lipo -info 2>/dev/null | grep "rchitecture" | \
sed -El "s/^.+\: .+\/(.+) (are|is architecture)\: (.+)$/\\3 - \\1/g" | \
sort
echo
echo "$PRE INCLUDES"
find src | grep "\\include$" | sort
}
# Shortcut function for building armv7 lib
function armv7() { _build "armv7"; }
# Shortcut function for building armv7s lib
function armv7s() { _build "armv7s"; }
# Shortcut function for building arm64 lib
function arm64() { _build "arm64"; }
# Shortcut function for building i386 lib
function i386() {
export DEVPATH=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer
export CFLAGS="-O2 -m32 -mios-simulator-version-min=9.0"
export LDFLAGS="-O2 -m32 -mios-simulator-version-min=9.0"
_build "i386"
}
# Shortcut function for building x86_64 lib
function x86_64() {
export DEVPATH=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer
export CFLAGS="-O2 -m32 -mios-simulator-version-min=9.0"
export LDFLAGS="-O2 -m32 -mios-simulator-version-min=9.0"
_build "x86_64"
}
# Shortcut function for building all architectures.
function all() {
armv7 && echo && armv7s && echo && arm64 && echo && i386 && echo && x86_64
echo
_merge
}
# Build function doing the actual library building for the specific architecture
function _build() {
echo "$PRE BUILD"
echo "building for $1. this may take a while, tail -f $1.log to see progress."
echo ""
cp "$BASE_DIR"/config_site.h "$BASE_DIR"/pjsip/src/pjlib/include/pj
cd "$BASE_DIR"/pjsip/src
ARCH="-arch $1" ./configure-iphone --with-opus=/tmp/Opus-iOS/dependencies 2>&1 > "$BASE_DIR"/pjsip/logs/$1.log
make dep 2>&1 >> "$BASE_DIR"/pjsip/logs/$1.log
make clean 2>&1 >> "$BASE_DIR"/pjsip/logs/$1.log
make 2>&1 >> "$BASE_DIR"/pjsip/logs/$1.log
echo
_collect $1
}
# The _build function's output is always stored in the same location causing files to be overridden when another architecture is build.
# This function collects the architecture specific build files and stores them in an appropriate directory.
function _collect() {
echo "$PRE COLLECT"
cd "$BASE_DIR"
mkdir -p pjsip/temp/$1
#for x in `find src | grep "\.a$"`; do
for x in `find pjsip/src -name *$1*.a`; do
cp -v ./$x ./pjsip/temp/$1
done | tee "$BASE_DIR"/pjsip/logs/collect.log
}
# Finds all the created architecture specific libraries, stored by the _collect function and merges all libraries in one fat lib suitable for all architectures.
function _merge() {
echo "$PRE MERGE"
cd "$BASE_DIR"
mkdir -p "$BASE_DIR"/${TARGET_DIR}
libtool -o ${TARGET_DIR}/${PRODUCT_NAME}.a `find ./pjsip/temp -name *darwin_ios.a -exec printf '%s ' {} +`
#rm -Rf "$BASE_DIR"/pjsip/temp
}
# Copies header files form the PJSIP src into a temporary directory.
function copy_headers() {
echo "$PRE Copying header files to temporary location"
cd "$BASE_DIR"/pjsip/src
find . -path ./third_party -prune -o -path ./pjsip-apps -prune -o -path ./include -prune -o -type f -wholename '*include/*.h*' -exec bash -c 'copy_to_lib_dir "{}"' ';'
cd "$BASE_DIR"
}
# helper function used by copy_headers
function copy_to_lib_dir() {
echo $1
OLD_PATH=$1
NEW_PATH=()
PATH_PARTS=(`echo $1 | tr '/' '\n'`)
echo $PATH_PARTS
for x in "${PATH_PARTS[@]}"; do
if [ "$x" = "include" ] || [ "${#NEW_PATH[@]}" -ne "0" ]; then
echo $x
NEW_PATH+=("$x")
fi
done
NEW_PATH="${NEW_PATH[@]:1}"
NEW_PATH="${NEW_PATH// //}"
d=$BASE_DIR/${TARGET_DIR}/pjsip-include/$(dirname $NEW_PATH)
mkdir -p $d
cp $OLD_PATH $d
echo $NEW_PATH
exit
}
export -f copy_to_lib_dir
if [ -n "$1" ]; then
CMD=$1
shift
$CMD $*
echo
echo "$PRE DONE"
else
help
fi