forked from keroserene/go-webrtc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
·134 lines (115 loc) · 3.56 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
#!/usr/bin/env bash
# For a native compile (using current values of GOOS and GOARCH):
# ./build.sh
# For a cross compile:
# GOOS=linux GOARCH=amd64 ./build.sh
# GOOS=linux GOARCH=arm ./build.sh
# (For a cross-compile from linux-amd64 to linux-arm, you may need to install the binutils-arm-linux-gnueabihf package.)
# For macOS (GOOS=darwin GOARCH=amd64), you can currently only do a native compile.
PROJECT_DIR=$(pwd)
THIRD_PARTY_DIR="$PROJECT_DIR/third_party"
WEBRTC_REPO="https://chromium.googlesource.com/external/webrtc"
WEBRTC_DIR="$THIRD_PARTY_DIR/webrtc"
WEBRTC_SRC="$WEBRTC_DIR/src"
DEPOT_TOOLS_DIR="$THIRD_PARTY_DIR/depot_tools"
OS=$(go env GOOS)
ARCH=$(go env GOARCH)
CONFIG="Release"
COMMIT="88f5d9180eae78a6162cccd78850ff416eb82483" # branch-heads/64
# Values are from,
# https://github.com/golang/go/blob/master/src/go/build/syslist.go
# https://chromium.googlesource.com/chromium/src/+/master/tools/gn/docs/reference.md
oses=",linux:linux,darwin:mac,windows:win,android:android,"
cpus=",386:x86,amd64:x64,arm:arm,"
get() {
echo "$(expr "$1" : ".*,$2:\([^,]*\),.*")"
}
TARGET_OS=$(get $oses $OS)
TARGET_CPU=$(get $cpus $ARCH)
INCLUDE_DIR="$PROJECT_DIR/include"
LIB_DIR="$PROJECT_DIR/lib"
PATH="$PATH:$DEPOT_TOOLS_DIR"
mkdir -p $THIRD_PARTY_DIR
mkdir -p $INCLUDE_DIR
mkdir -p $LIB_DIR
if [[ -d $DEPOT_TOOLS_DIR ]]; then
echo "Syncing depot_tools ..."
pushd $DEPOT_TOOLS_DIR
git pull --rebase || exit 1
popd
else
echo "Getting depot_tools ..."
mkdir -p $DEPOT_TOOLS_DIR
git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git $DEPOT_TOOLS_DIR || exit 1
fi
if [[ -d $WEBRTC_DIR ]]; then
echo "Syncing webrtc ..."
pushd $WEBRTC_SRC || exit 1
if ! git diff-index --quiet HEAD --; then
echo -en "\nOpen files present in $WEBRTC_SRC\nReset them? (y/N): "
read ANSWER
if [ "$ANSWER" != "y" ]; then
echo "*** Cancelled ***"
exit 1
fi
git reset --hard HEAD || exit 1
fi
popd
pushd $WEBRTC_DIR
gclient sync --with_branch_heads -r $COMMIT || exit 1
popd
else
echo "Getting webrtc ..."
mkdir -p $WEBRTC_DIR
pushd $WEBRTC_DIR
gclient config --name src $WEBRTC_REPO || exit 1
gclient sync --with_branch_heads -r $COMMIT || exit 1
popd
fi
if [ "$ARCH" = "arm" ]; then
echo "Manually fetching arm sysroot"
pushd $WEBRTC_SRC || exit 1
./build/linux/sysroot_scripts/install-sysroot.py --arch=arm || exit 1
popd
fi
echo "Checking out latest tested / compatible version of webrtc ..."
pushd $WEBRTC_SRC
git checkout $COMMIT
popd
echo "Cleaning webrtc ..."
pushd $WEBRTC_SRC || exit 1
rm -rf out/$CONFIG
popd
echo "Building webrtc ..."
pushd $WEBRTC_SRC
gn gen out/$CONFIG --args="target_os=\"$TARGET_OS\" target_cpu=\"$TARGET_CPU\" is_debug=false use_custom_libcxx=false" || exit 1
ninja -C out/$CONFIG webrtc field_trial metrics_default pc_test_utils || exit 1
popd
echo "Copying headers ..."
pushd $WEBRTC_SRC || exit 1
rm -rf "$INCLUDE_DIR"
for h in $(find . -type f -name '*.h')
do
mkdir -p "$INCLUDE_DIR/$(dirname $h)"
cp $h "$INCLUDE_DIR/$h"
done
popd
pushd $PROJECT_DIR || exit 1
git clean -fd "$INCLUDE_DIR"
popd
echo "Concatenating libraries ..."
pushd $WEBRTC_SRC/out/$CONFIG
if [ "$OS" = "darwin" ]; then
find obj -name '*.o' > filelist
libtool -static -o libwebrtc-magic.a -filelist filelist
strip -S -x -o libwebrtc-magic.a libwebrtc-magic.a
elif [ "$ARCH" = "arm" ]; then
arm-linux-gnueabihf-ar crs libwebrtc-magic.a $(find obj -name '*.o')
else
ar crs libwebrtc-magic.a $(find obj -name '*.o')
fi
OUT_LIBRARY=$LIB_DIR/libwebrtc-$OS-$ARCH-magic.a
mv libwebrtc-magic.a ${OUT_LIBRARY}
echo "Built ${OUT_LIBRARY}"
popd
echo "Build complete."