-
Notifications
You must be signed in to change notification settings - Fork 4
/
build.sh
executable file
·161 lines (137 loc) · 3.71 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
#!/bin/bash -e
# This script builds the Courgette target from Chromium. It works on macOS and
# Linux. Please see the accompanying README.md file.
#
# https://www.chromium.org/developers/how-tos/get-the-code
function status {
printf '\E[33m'
echo "$@"
printf '\E[0m'
}
if [ "$#" -eq 0 ]; then
echo "Usage: $0 workspace-dir [fetch-only|no-update]" >&2
exit 1
fi
# Enter the workspace
mkdir -p "$1"
cd "$1"
# Install depot_tools
if [ ! -d depot_tools ]; then
status "[*] Cloning depot_tools"
git clone --depth 1 \
https://chromium.googlesource.com/chromium/tools/depot_tools.git
elif [ "$2" != "no-update" ]; then
status "[*] Updating depot_tools"
pushd depot_tools
git pull
popd
fi
export PATH="$(pwd)/depot_tools:${PATH}"
# Is this our first build?
if [ ! -f .first-build-finished ]; then
FIRST_BUILD=1
else
FIRST_BUILD=0
fi
# Get the code
if [ ! -d chromium/src ]; then
status "[*] Fetching Chromium sources"
mkdir -p chromium
pushd chromium
git config --global core.precomposeUnicode true
fetch --nohooks --no-history chromium
popd
elif [ "$2" != "no-update" ]; then
status "[*] Updating Chromium sources"
pushd chromium/src
git rebase-update
popd
fi
# Stop here if we just wanted to fetch the code
if [ "$2" = "fetch-only" ]; then
exit 0
fi
# Install additional build dependencies
if [ $FIRST_BUILD -eq 1 ] && [ "$(uname -s)" = "Linux" ]; then
status "[*] Installing build dependencies"
pushd chromium/src
./build/install-build-deps.sh \
--no-arm --no-chromeos-fonts --no-nacl \
--no-prompt
popd
fi
# Run the hooks
pushd chromium/src
if [ $FIRST_BUILD -eq 1 ]; then
status "[*] Running hooks"
gclient runhooks
elif [ "$2" != "no-update" ]; then
status "[*] Running hooks"
gclient sync
fi
popd
# Configure the build
if [ ! -d chromium/src/out/Default ]; then
status "[*] Configuring"
pushd chromium/src
mkdir -p out/Default
(echo "enable_nacl = false"; echo "symbol_level = 0") > out/Default/args.gn
gn gen out/Default
popd
fi
# Build Courgette
status "[*] Building Courgette"
pushd chromium/src
autoninja -C out/Default courgette
popd
touch .first-build-finished
# Create the version string
pushd chromium/src
DATE=$(date +"%Y%m%d")
GITHASH=$(git rev-parse --short HEAD)
VERSION="1.0.0-${DATE}+${GITHASH}"
popd
# Build the Debian package on Linux
if [ "$(uname -s)" = "Linux" ]; then
status "[*] Creating Debian package"
# Copy the packaging template into the workspace
rm -rf courgette
cp -r "$(dirname "$0")"/deb-package courgette
# Copy the Courgette binary into the package
mkdir -p courgette/usr/bin
cp chromium/src/out/Default/courgette courgette/usr/bin
# Copy all built libraries it depends on in as well
mkdir -p courgette/usr/lib
LIBDEPS=$(ldd chromium/src/out/Default/courgette \
| grep 'chromium' \
| awk '{ print $3 }')
cp $LIBDEPS courgette/usr/lib
# Patch up the control file
ARCH=$(dpkg --print-architecture)
sed -i \
-e "s/@VERSION@/$VERSION/g" \
-e "s/@ARCH@/$ARCH/g" \
courgette/DEBIAN/control
# Build the package
dpkg-deb --build courgette
mv courgette.deb "courgette-linux_${VERSION}_${ARCH}.deb"
rm -rf courgette
fi
# Build a zip archive on macOS
if [ "$(uname -s)" = "Darwin" ]; then
status "[*] Creating archive"
# Create the archive directory
rm -rf courgette
mkdir courgette
# Copy the courgette binary into the directory
cp chromium/src/out/Default/courgette courgette
LIBDEPS=$(otool -L chromium/src/out/Default/courgette \
| grep '@rpath' \
| awk '{ print $1 }' \
| sed 's,@rpath/,chromium/src/out/Default/,g')
cp $LIBDEPS courgette
# Make the zip archive
ARCH=$(uname -m)
zip -r "courgette-mac_${VERSION}_${ARCH}.zip" courgette
rm -rf courgette
fi