forked from Piasy/WebRTC-Docker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·328 lines (277 loc) · 9.82 KB
/
Copy pathbuild.sh
File metadata and controls
executable file
·328 lines (277 loc) · 9.82 KB
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
# !/bin/bash
# Copyright Pristine Inc
# Author: Rahul Behera <rahul@pristine.io>
# Author: Aaron Alaniz <aaron@pristine.io>
# Author: Arik Yaacob <arik@pristine.io>
#
# Builds the android peer connection library
# Get location of the script itself .. thanks SO ! http://stackoverflow.com/a/246128
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
PROJECT_ROOT="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
# Utility method for creating a directory
create_directory_if_not_found() {
# if we cannot find the directory
if [ ! -d "$1" ];
then
echo "$1 directory not found, creating..."
mkdir -p "$1"
echo "directory created at $1"
fi
}
DEFAULT_WEBRTC_URL="https://webrtc.googlesource.com/src.git"
WEBRTC_ROOT="$PROJECT_ROOT/webrtc"
DEPOT_TOOLS="$WEBRTC_ROOT/depot_tools"
create_directory_if_not_found "$WEBRTC_ROOT"
BUILD="$WEBRTC_ROOT/libjingle_peerconnection_builds"
WEBRTC_TARGET="AppRTCMobile"
ANDROID_TOOLCHAINS="$WEBRTC_ROOT/src/third_party/android_tools/ndk/toolchains"
exec_ninja() {
echo "Running ninja"
ninja -C $1 $WEBRTC_TARGET
}
# Installs the required dependencies on the machine
install_dependencies() {
sudo apt-get -y install wget git gnupg flex bison gperf build-essential zip curl subversion pkg-config libglib2.0-dev libgtk2.0-dev libxtst-dev libxss-dev libpci-dev libdbus-1-dev libgconf2-dev libgnome-keyring-dev libnss3-dev
#Download the latest script to install the android dependencies for ubuntu
curl https://chromium.googlesource.com/chromium/src/+/master/build/install-build-deps-android.sh?format=TEXT | base64 -d > install-build-deps-android.sh
curl https://chromium.googlesource.com/chromium/src/+/master/build/install-build-deps.sh?format=TEXT | base64 -d > install-build-deps.sh
chmod u+x ./install-build-deps.sh
#use bash (not dash which is default) to run the script
sudo /bin/bash ./install-build-deps-android.sh
#delete the file we just downloaded... not needed anymore
#rm install-build-deps-android.sh
}
# Update/Get/Ensure the Gclient Depot Tools
# Also will add to your environment
pull_depot_tools() {
WORKING_DIR=`pwd`
# Either clone or get latest depot tools
if [ ! -d "$DEPOT_TOOLS" ]
then
echo Make directory for gclient called Depot Tools
mkdir -p "$DEPOT_TOOLS"
echo Pull the depo tools project from chromium source into the depot tools directory
git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git $DEPOT_TOOLS
else
echo Change directory into the depot tools
cd "$DEPOT_TOOLS"
echo Pull the depot tools down to the latest
git pull
fi
PATH="$PATH:$DEPOT_TOOLS"
# Navigate back
cd "$WORKING_DIR"
}
# Update/Get the webrtc code base
pull_webrtc() {
WORKING_DIR=`pwd`
# If no directory where webrtc root should be...
create_directory_if_not_found "$WEBRTC_ROOT"
cd "$WEBRTC_ROOT"
# Fetch
yes | fetch --nohooks webrtc_android
# Get latest webrtc source
echo Pull down the latest from the webrtc repo
echo this can take a while
if [ -z $1 ]
then
echo "gclient sync with newest"
yes | gclient sync
else
echo "gclient sync with $1"
cd /webrtc/src/
git checkout -b $1 branch-heads/$1
yes | gclient sync --force
fi
# Navigate back
cd "$WORKING_DIR"
}
# Prepare our build
function wrbase() {
export GYP_DEFINES="host_os=linux libjingle_java=1 build_with_libjingle=1 build_with_chromium=0 enable_tracing=1 enable_android_opensl=0 use_sysroot=0 include_tests=0"
if [ "$WEBRTC_DEBUG" != "true" ] ;
then
export GYP_DEFINES="$GYP_DEFINES fastbuild=2"
fi
export GYP_GENERATORS="ninja"
}
# Arm V7 with Neon
function wrarmv7() {
wrbase
export GYP_DEFINES="$GYP_DEFINES OS=android"
export GYP_GENERATOR_FLAGS="$GYP_GENERATOR_FLAGS output_dir=out/android_armeabi-v7a"
export GYP_CROSSCOMPILE=1
echo "ARMv7 with Neon Build"
}
# Arm 64
function wrarmv8() {
wrbase
export GYP_DEFINES="$GYP_DEFINES OS=android target_arch=arm64 target_subarch=arm64"
export GYP_GENERATOR_FLAGS="output_dir=out/android_arm64-v8a"
export GYP_CROSSCOMPILE=1
echo "ARMv8 with Neon Build"
}
# x86
function wrX86() {
wrbase
export GYP_DEFINES="$GYP_DEFINES OS=android target_arch=ia32"
export GYP_GENERATOR_FLAGS="output_dir=out/android_x86"
echo "x86 Build"
}
# x86_64
function wrX86_64() {
wrbase
export GYP_DEFINES="$GYP_DEFINES OS=android target_arch=x64"
export GYP_GENERATOR_FLAGS="output_dir=out/android_x86_64"
echo "x86_64 Build"
}
# Setup our defines for the build
prepare_gyp_defines() {
# Configure environment for Android
echo Setting up build environment for Android
source "$WEBRTC_ROOT/src/build/android/envsetup.sh"
# Check to see if the user wants to set their own gyp defines
echo Export the base settings of GYP_DEFINES so we can define how we want to build
if [ -z $USER_GYP_DEFINES ]
then
echo "User has not specified any gyp defines so we proceed with default"
if [ "$WEBRTC_ARCH" = "x86" ] ;
then
wrX86
elif [ "$WEBRTC_ARCH" = "x86_64" ] ;
then
wrX86_64
elif [ "$WEBRTC_ARCH" = "armv7" ] ;
then
wrarmv7
elif [ "$WEBRTC_ARCH" = "armv8" ] ;
then
wrarmv8
fi
else
echo "User has specified their own gyp defines"
export GYP_DEFINES="$USER_GYP_DEFINES"
fi
echo "GYP_DEFINES=$GYP_DEFINES"
}
# Builds the apprtc demo
execute_build() {
WORKING_DIR=`pwd`
cd "$WEBRTC_ROOT/src"
if [ "$WEBRTC_ARCH" = "x86" ] ;
then
ARCH="x86"
STRIP="$ANDROID_TOOLCHAINS/x86-4.9/prebuilt/linux-x86_64/bin/i686-linux-android-strip"
elif [ "$WEBRTC_ARCH" = "x86_64" ] ;
then
ARCH="x64"
STRIP="$ANDROID_TOOLCHAINS/x86_64-4.9/prebuilt/linux-x86_64/bin/x86_64-linux-android-strip"
elif [ "$WEBRTC_ARCH" = "armv7" ] ;
then
ARCH="arm"
STRIP="$ANDROID_TOOLCHAINS/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-strip"
elif [ "$WEBRTC_ARCH" = "armv8" ] ;
then
ARCH="arm64"
STRIP="$ANDROID_TOOLCHAINS/aarch64-linux-android-4.9/prebuilt/linux-x86_64/bin/aarch64-linux-android-strip"
fi
if [ "$WEBRTC_DEBUG" = "true" ] ;
then
BUILD_TYPE="Debug"
DEBUG_ARG='is_debug=true'
else
BUILD_TYPE="Release"
DEBUG_ARG='is_debug=false dcheck_always_on=true'
fi
ARCH_OUT="out/android_${ARCH}"
echo Generate projects using GN
gn gen "$ARCH_OUT/$BUILD_TYPE" --args="$DEBUG_ARG symbol_level=1 target_os=\"android\" target_cpu=\"${ARCH}\""
#gclient runhooks
REVISION_NUM=`get_webrtc_revision`
echo "Build ${WEBRTC_TARGET} in $BUILD_TYPE (arch: ${WEBRTC_ARCH})"
exec_ninja "$ARCH_OUT/$BUILD_TYPE"
# Verify the build actually worked
if [ $? -eq 0 ]; then
SOURCE_DIR="$WEBRTC_ROOT/src/$ARCH_OUT/$BUILD_TYPE"
TARGET_DIR="$BUILD/$BUILD_TYPE"
create_directory_if_not_found "$TARGET_DIR"
echo "Copy JAR File"
create_directory_if_not_found "$TARGET_DIR/libs/"
create_directory_if_not_found "$TARGET_DIR/jni/"
if [ "$WEBRTC_ARCH" = "x86" ] ;
then
ARCH_JNI="$TARGET_DIR/jni/x86"
elif [ "$WEBRTC_ARCH" = "x86_64" ] ;
then
ARCH_JNI="$TARGET_DIR/jni/x86_64"
elif [ "$WEBRTC_ARCH" = "armv7" ] ;
then
ARCH_JNI="$TARGET_DIR/jni/armeabi-v7a"
elif [ "$WEBRTC_ARCH" = "armv8" ] ;
then
ARCH_JNI="$TARGET_DIR/jni/arm64-v8a"
fi
create_directory_if_not_found "$ARCH_JNI"
# Copy the jars
cp -p "$SOURCE_DIR/lib.java/webrtc/sdk/android/libjingle_peerconnection_java.jar" "$TARGET_DIR/libs/libjingle_peerconnection.jar"
cp -p "$SOURCE_DIR/lib.java/webrtc/rtc_base/base_java.jar" "$TARGET_DIR/libs/base_java.jar"
cp -p "$SOURCE_DIR/lib.java/webrtc/modules/audio_device/audio_device_java.jar" "$TARGET_DIR/libs/audio_device_java.jar"
# Strip the build only if its release
if [ "$WEBRTC_DEBUG" = "true" ] ;
then
cp -p "$WEBRTC_ROOT/src/$ARCH_OUT/$BUILD_TYPE/libjingle_peerconnection_so.so" "$ARCH_JNI/libjingle_peerconnection_so.so"
else
"$STRIP" -o "$ARCH_JNI/libjingle_peerconnection_so.so" "$WEBRTC_ROOT/src/$ARCH_OUT/$BUILD_TYPE/libjingle_peerconnection_so.so" -s
fi
cd "$TARGET_DIR"
mkdir -p aidl
mkdir -p assets
mkdir -p res
cd "$WORKING_DIR"
echo "$BUILD_TYPE build for apprtc complete for revision $REVISION_NUM"
else
echo "$BUILD_TYPE build for apprtc failed for revision $REVISION_NUM"
#exit 1
fi
}
# Gets the webrtc revision
get_webrtc_revision() {
DIR=`pwd`
cd "$WEBRTC_ROOT/src"
REVISION_NUMBER=`git log -1 | grep 'Cr-Commit-Position: refs/heads/master@{#' | egrep -o "[0-9]+}" | tr -d '}'`
if [ -z "$REVISION_NUMBER" ]
then
REVISION_NUMBER=`git describe --tags | sed 's/\([0-9]*\)-.*/\1/'`
fi
if [ -z "$REVISION_NUMBER" ]
then
echo "Error grabbing revision number"
exit 1
fi
echo $REVISION_NUMBER
cd "$DIR"
}
get_webrtc() {
pull_depot_tools &&
pull_webrtc $1
}
# Updates webrtc and builds apprtc
build_apprtc() {
export WEBRTC_ARCH=armv7
prepare_gyp_defines &&
execute_build
export WEBRTC_ARCH=armv8
prepare_gyp_defines &&
execute_build
export WEBRTC_ARCH=x86
prepare_gyp_defines &&
execute_build
export WEBRTC_ARCH=x86_64
prepare_gyp_defines &&
execute_build
}