OLD | NEW |
| (Empty) |
1 #!/bin/bash -e | |
2 | |
3 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
4 # Use of this source code is governed by a BSD-style license that can be | |
5 # found in the LICENSE file. | |
6 | |
7 # Script to install everything needed to build chromium (well, ideally, anyway) | |
8 # See http://code.google.com/p/chromium/wiki/LinuxBuildInstructions | |
9 # and http://code.google.com/p/chromium/wiki/LinuxBuild64Bit | |
10 | |
11 usage() { | |
12 echo "Usage: $0 [--options]" | |
13 echo "Options:" | |
14 echo "--[no-]syms: enable or disable installation of debugging symbols" | |
15 echo "--lib32: enable installation of 32-bit libraries, e.g. for V8 snapshot" | |
16 echo "--[no-]arm: enable or disable installation of arm cross toolchain" | |
17 echo "--[no-]chromeos-fonts: enable or disable installation of Chrome OS"\ | |
18 "fonts" | |
19 echo "--[no-]nacl: enable or disable installation of prerequisites for"\ | |
20 "building standalone NaCl and all its toolchains" | |
21 echo "--no-prompt: silently select standard options/defaults" | |
22 echo "--quick-check: quickly try to determine if dependencies are installed" | |
23 echo " (this avoids interactive prompts and sudo commands," | |
24 echo " so might not be 100% accurate)" | |
25 echo "--unsupported: attempt installation even on unsupported systems" | |
26 echo "Script will prompt interactively if options not given." | |
27 exit 1 | |
28 } | |
29 | |
30 # Checks whether a particular package is available in the repos. | |
31 # USAGE: $ package_exists <package name> | |
32 package_exists() { | |
33 apt-cache pkgnames | grep -x "$1" > /dev/null 2>&1 | |
34 } | |
35 | |
36 # These default to on because (some) bots need them and it keeps things | |
37 # simple for the bot setup if all bots just run the script in its default | |
38 # mode. Developers who don't want stuff they don't need installed on their | |
39 # own workstations can pass --no-arm --no-nacl when running the script. | |
40 do_inst_arm=1 | |
41 do_inst_nacl=1 | |
42 | |
43 while test "$1" != "" | |
44 do | |
45 case "$1" in | |
46 --syms) do_inst_syms=1;; | |
47 --no-syms) do_inst_syms=0;; | |
48 --lib32) do_inst_lib32=1;; | |
49 --arm) do_inst_arm=1;; | |
50 --no-arm) do_inst_arm=0;; | |
51 --chromeos-fonts) do_inst_chromeos_fonts=1;; | |
52 --no-chromeos-fonts) do_inst_chromeos_fonts=0;; | |
53 --nacl) do_inst_nacl=1;; | |
54 --no-nacl) do_inst_nacl=0;; | |
55 --no-prompt) do_default=1 | |
56 do_quietly="-qq --assume-yes" | |
57 ;; | |
58 --quick-check) do_quick_check=1;; | |
59 --unsupported) do_unsupported=1;; | |
60 *) usage;; | |
61 esac | |
62 shift | |
63 done | |
64 | |
65 if test "$do_inst_arm" = "1"; then | |
66 do_inst_lib32=1 | |
67 fi | |
68 | |
69 # Check for lsb_release command in $PATH | |
70 if ! which lsb_release > /dev/null; then | |
71 echo "ERROR: lsb_release not found in \$PATH" >&2 | |
72 exit 1; | |
73 fi | |
74 | |
75 distro=$(lsb_release --id --short) | |
76 codename=$(lsb_release --codename --short) | |
77 ubuntu_codenames="(precise|trusty|utopic|vivid)" | |
78 debian_codenames="(stretch)" | |
79 if [ 0 -eq "${do_unsupported-0}" ] && [ 0 -eq "${do_quick_check-0}" ] ; then | |
80 if [[ ! $codename =~ $ubuntu_codenames && ! $codename =~ $debian_codenames ]];
then | |
81 echo "ERROR: Only Ubuntu 12.04 (precise), 14.04 (trusty), " \ | |
82 "14.10 (utopic) and 15.04 (vivid), and Debian Testing (stretch) are curren
tly supported" >&2 | |
83 exit 1 | |
84 fi | |
85 | |
86 if ! uname -m | egrep -q "i686|x86_64"; then | |
87 echo "Only x86 architectures are currently supported" >&2 | |
88 exit | |
89 fi | |
90 fi | |
91 | |
92 if [ "x$(id -u)" != x0 ] && [ 0 -eq "${do_quick_check-0}" ]; then | |
93 echo "Running as non-root user." | |
94 echo "You might have to enter your password one or more times for 'sudo'." | |
95 echo | |
96 fi | |
97 | |
98 # Packages needed for chromeos only | |
99 chromeos_dev_list="libbluetooth-dev libxkbcommon-dev realpath" | |
100 | |
101 # Packages needed for development | |
102 if [[ $distro = Debian ]] ; then | |
103 # Debian-specific package names | |
104 dev_list="apache2-bin fonts-indic fonts-lyx" | |
105 else | |
106 # Ubuntu-specific package names | |
107 dev_list="apache2.2-bin ttf-indic-fonts xfonts-mathml language-pack-da | |
108 language-pack-fr language-pack-he language-pack-zh-hant" | |
109 fi | |
110 dev_list="$dev_list bison cdbs curl dpkg-dev elfutils devscripts fakeroot | |
111 flex fonts-thai-tlwg g++ git-core git-svn gperf libapache2-mod-php5 | |
112 libasound2-dev libbrlapi-dev libav-tools | |
113 libbz2-dev libcairo2-dev libcap-dev libcups2-dev libcurl4-gnutls-dev | |
114 libdrm-dev libelf-dev libexif-dev libgconf2-dev libglib2.0-dev | |
115 libglu1-mesa-dev libgnome-keyring-dev libgtk2.0-dev libkrb5-dev | |
116 libnspr4-dev libnss3-dev libpam0g-dev libpci-dev libpulse-dev | |
117 libsctp-dev libspeechd-dev libsqlite3-dev libssl-dev libudev-dev | |
118 libwww-perl libxslt1-dev libxss-dev libxt-dev libxtst-dev openbox | |
119 patch perl php5-cgi pkg-config python python-cherrypy3 python-crypto | |
120 python-dev python-numpy python-opencv python-openssl python-psutil | |
121 python-yaml rpm ruby subversion ttf-dejavu-core | |
122 ttf-kochi-gothic ttf-kochi-mincho wdiff zip | |
123 $chromeos_dev_list" | |
124 | |
125 # 64-bit systems need a minimum set of 32-bit compat packages for the pre-built | |
126 # NaCl binaries. | |
127 if file /sbin/init | grep -q 'ELF 64-bit'; then | |
128 dev_list="${dev_list} libc6-i386 lib32gcc1 lib32stdc++6" | |
129 fi | |
130 | |
131 # Run-time libraries required by chromeos only | |
132 chromeos_lib_list="libpulse0 libbz2-1.0" | |
133 | |
134 # Full list of required run-time libraries | |
135 lib_list="libatk1.0-0 libc6 libasound2 libcairo2 libcap2 libcups2 libexpat1 | |
136 libexif12 libfontconfig1 libfreetype6 libglib2.0-0 libgnome-keyring0 | |
137 libgtk2.0-0 libpam0g libpango1.0-0 libpci3 libpcre3 libpixman-1-0 | |
138 libpng12-0 libspeechd2 libstdc++6 libsqlite3-0 libx11-6 | |
139 libxau6 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxdmcp6 | |
140 libxext6 libxfixes3 libxi6 libxinerama1 libxrandr2 libxrender1 | |
141 libxtst6 zlib1g $chromeos_lib_list" | |
142 | |
143 # Debugging symbols for all of the run-time libraries | |
144 dbg_list="libatk1.0-dbg libc6-dbg libcairo2-dbg libfontconfig1-dbg | |
145 libglib2.0-0-dbg libgtk2.0-0-dbg libpango1.0-0-dbg libpcre3-dbg | |
146 libpixman-1-0-dbg libsqlite3-0-dbg libx11-6-dbg libxau6-dbg | |
147 libxcb1-dbg libxcomposite1-dbg libxcursor1-dbg libxdamage1-dbg | |
148 libxdmcp6-dbg libxext6-dbg libxfixes3-dbg libxi6-dbg libxinerama1-dbg | |
149 libxrandr2-dbg libxrender1-dbg libxtst6-dbg zlib1g-dbg" | |
150 | |
151 # Find the proper version of libstdc++6-4.x-dbg. | |
152 if [ "x$codename" = "xprecise" ]; then | |
153 dbg_list="${dbg_list} libstdc++6-4.6-dbg" | |
154 elif [ "x$codename" = "xtrusty" ]; then | |
155 dbg_list="${dbg_list} libstdc++6-4.8-dbg" | |
156 else | |
157 dbg_list="${dbg_list} libstdc++6-4.9-dbg" | |
158 fi | |
159 | |
160 # 32-bit libraries needed e.g. to compile V8 snapshot for Android or armhf | |
161 lib32_list="linux-libc-dev:i386" | |
162 | |
163 # arm cross toolchain packages needed to build chrome on armhf | |
164 arm_list="libc6-dev-armhf-cross | |
165 linux-libc-dev-armhf-cross" | |
166 | |
167 # Work around for dependency issue Debian/Stretch | |
168 if [ "x$codename" = "xstretch" ]; then | |
169 arm_list+=" g++-5-arm-linux-gnueabihf" | |
170 else | |
171 arm_list+=" g++-arm-linux-gnueabihf" | |
172 fi | |
173 | |
174 # Work around for dependency issue Ubuntu/Trusty: http://crbug.com/435056 | |
175 if [ "x$codename" = "xtrusty" ]; then | |
176 arm_list+=" g++-4.8-multilib-arm-linux-gnueabihf | |
177 gcc-4.8-multilib-arm-linux-gnueabihf" | |
178 fi | |
179 | |
180 # Packages to build NaCl, its toolchains, and its ports. | |
181 naclports_list="ant autoconf bison cmake gawk intltool xutils-dev xsltproc" | |
182 nacl_list="g++-mingw-w64-i686 lib32z1-dev | |
183 libasound2:i386 libcap2:i386 libelf-dev:i386 libexif12:i386 | |
184 libfontconfig1:i386 libgconf-2-4:i386 libglib2.0-0:i386 libgpm2:i386 | |
185 libgtk2.0-0:i386 libncurses5:i386 lib32ncurses5-dev | |
186 libnss3:i386 libpango1.0-0:i386 | |
187 libssl1.0.0:i386 libtinfo-dev libtinfo-dev:i386 libtool | |
188 libxcomposite1:i386 libxcursor1:i386 libxdamage1:i386 libxi6:i386 | |
189 libxrandr2:i386 libxss1:i386 libxtst6:i386 texinfo xvfb | |
190 ${naclports_list}" | |
191 | |
192 # Find the proper version of libgbm-dev. We can't just install libgbm-dev as | |
193 # it depends on mesa, and only one version of mesa can exists on the system. | |
194 # Hence we must match the same version or this entire script will fail. | |
195 mesa_variant="" | |
196 for variant in "-lts-trusty" "-lts-utopic"; do | |
197 if $(dpkg-query -Wf'${Status}' libgl1-mesa-glx${variant} 2>/dev/null | \ | |
198 grep -q " ok installed"); then | |
199 mesa_variant="${variant}" | |
200 fi | |
201 done | |
202 dev_list="${dev_list} libgbm-dev${mesa_variant} | |
203 libgles2-mesa-dev${mesa_variant} libgl1-mesa-dev${mesa_variant} | |
204 mesa-common-dev${mesa_variant}" | |
205 nacl_list="${nacl_list} libgl1-mesa-glx${mesa_variant}:i386" | |
206 | |
207 # Some package names have changed over time | |
208 if package_exists ttf-mscorefonts-installer; then | |
209 dev_list="${dev_list} ttf-mscorefonts-installer" | |
210 else | |
211 dev_list="${dev_list} msttcorefonts" | |
212 fi | |
213 if package_exists libnspr4-dbg; then | |
214 dbg_list="${dbg_list} libnspr4-dbg libnss3-dbg" | |
215 lib_list="${lib_list} libnspr4 libnss3" | |
216 else | |
217 dbg_list="${dbg_list} libnspr4-0d-dbg libnss3-1d-dbg" | |
218 lib_list="${lib_list} libnspr4-0d libnss3-1d" | |
219 fi | |
220 if package_exists libjpeg-dev; then | |
221 dev_list="${dev_list} libjpeg-dev" | |
222 else | |
223 dev_list="${dev_list} libjpeg62-dev" | |
224 fi | |
225 if package_exists libudev1; then | |
226 dev_list="${dev_list} libudev1" | |
227 nacl_list="${nacl_list} libudev1:i386" | |
228 else | |
229 dev_list="${dev_list} libudev0" | |
230 nacl_list="${nacl_list} libudev0:i386" | |
231 fi | |
232 if package_exists libbrlapi0.6; then | |
233 dev_list="${dev_list} libbrlapi0.6" | |
234 else | |
235 dev_list="${dev_list} libbrlapi0.5" | |
236 fi | |
237 | |
238 | |
239 # Some packages are only needed if the distribution actually supports | |
240 # installing them. | |
241 if package_exists appmenu-gtk; then | |
242 lib_list="$lib_list appmenu-gtk" | |
243 fi | |
244 | |
245 # When cross building for arm/Android on 64-bit systems the host binaries | |
246 # that are part of v8 need to be compiled with -m32 which means | |
247 # that basic multilib support is needed. | |
248 if file /sbin/init | grep -q 'ELF 64-bit'; then | |
249 # gcc-multilib conflicts with the arm cross compiler (at least in trusty) but | |
250 # g++-X.Y-multilib gives us the 32-bit support that we need. Find out the | |
251 # appropriate value of X and Y by seeing what version the current | |
252 # distribution's g++-multilib package depends on. | |
253 multilib_package=$(apt-cache depends g++-multilib --important | \ | |
254 grep -E --color=never --only-matching '\bg\+\+-[0-9.]+-multilib\b') | |
255 lib32_list="$lib32_list $multilib_package" | |
256 fi | |
257 | |
258 # Waits for the user to press 'Y' or 'N'. Either uppercase of lowercase is | |
259 # accepted. Returns 0 for 'Y' and 1 for 'N'. If an optional parameter has | |
260 # been provided to yes_no(), the function also accepts RETURN as a user input. | |
261 # The parameter specifies the exit code that should be returned in that case. | |
262 # The function will echo the user's selection followed by a newline character. | |
263 # Users can abort the function by pressing CTRL-C. This will call "exit 1". | |
264 yes_no() { | |
265 if [ 0 -ne "${do_default-0}" ] ; then | |
266 [ $1 -eq 0 ] && echo "Y" || echo "N" | |
267 return $1 | |
268 fi | |
269 local c | |
270 while :; do | |
271 c="$(trap 'stty echo -iuclc icanon 2>/dev/null' EXIT INT TERM QUIT | |
272 stty -echo iuclc -icanon 2>/dev/null | |
273 dd count=1 bs=1 2>/dev/null | od -An -tx1)" | |
274 case "$c" in | |
275 " 0a") if [ -n "$1" ]; then | |
276 [ $1 -eq 0 ] && echo "Y" || echo "N" | |
277 return $1 | |
278 fi | |
279 ;; | |
280 " 79") echo "Y" | |
281 return 0 | |
282 ;; | |
283 " 6e") echo "N" | |
284 return 1 | |
285 ;; | |
286 "") echo "Aborted" >&2 | |
287 exit 1 | |
288 ;; | |
289 *) # The user pressed an unrecognized key. As we are not echoing | |
290 # any incorrect user input, alert the user by ringing the bell. | |
291 (tput bel) 2>/dev/null | |
292 ;; | |
293 esac | |
294 done | |
295 } | |
296 | |
297 if test "$do_inst_syms" = "" && test 0 -eq ${do_quick_check-0} | |
298 then | |
299 echo "This script installs all tools and libraries needed to build Chromium." | |
300 echo "" | |
301 echo "For most of the libraries, it can also install debugging symbols, which" | |
302 echo "will allow you to debug code in the system libraries. Most developers" | |
303 echo "won't need these symbols." | |
304 echo -n "Do you want me to install them for you (y/N) " | |
305 if yes_no 1; then | |
306 do_inst_syms=1 | |
307 fi | |
308 fi | |
309 if test "$do_inst_syms" = "1"; then | |
310 echo "Including debugging symbols." | |
311 else | |
312 echo "Skipping debugging symbols." | |
313 dbg_list= | |
314 fi | |
315 | |
316 if test "$do_inst_lib32" = "1" ; then | |
317 echo "Including 32-bit libraries for ARM/Android." | |
318 else | |
319 echo "Skipping 32-bit libraries for ARM/Android." | |
320 lib32_list= | |
321 fi | |
322 | |
323 if test "$do_inst_arm" = "1" ; then | |
324 echo "Including ARM cross toolchain." | |
325 else | |
326 echo "Skipping ARM cross toolchain." | |
327 arm_list= | |
328 fi | |
329 | |
330 if test "$do_inst_nacl" = "1"; then | |
331 echo "Including NaCl, NaCl toolchain, NaCl ports dependencies." | |
332 else | |
333 echo "Skipping NaCl, NaCl toolchain, NaCl ports dependencies." | |
334 nacl_list= | |
335 fi | |
336 | |
337 # The `sort -r -s -t: -k2` sorts all the :i386 packages to the front, to avoid | |
338 # confusing dpkg-query (crbug.com/446172). | |
339 packages="$( | |
340 echo "${dev_list} ${lib_list} ${dbg_list} ${lib32_list} ${arm_list}"\ | |
341 "${nacl_list}" | tr " " "\n" | sort -u | sort -r -s -t: -k2 | tr "\n" " " | |
342 )" | |
343 | |
344 if [ 1 -eq "${do_quick_check-0}" ] ; then | |
345 failed_check="$(dpkg-query -W -f '${PackageSpec}:${Status}\n' \ | |
346 ${packages} 2>&1 | grep -v "ok installed" || :)" | |
347 if [ -n "${failed_check}" ]; then | |
348 echo | |
349 nomatch="$(echo "${failed_check}" | \ | |
350 sed -e "s/^No packages found matching \(.*\).$/\1/;t;d")" | |
351 missing="$(echo "${failed_check}" | \ | |
352 sed -e "/^No packages found matching/d;s/^\(.*\):.*$/\1/")" | |
353 if [ "$nomatch" ]; then | |
354 # Distinguish between packages that actually aren't available to the | |
355 # system (i.e. not in any repo) and packages that just aren't known to | |
356 # dpkg (i.e. managed by apt). | |
357 unknown="" | |
358 for p in ${nomatch}; do | |
359 if apt-cache show ${p} > /dev/null 2>&1; then | |
360 missing="${p}\n${missing}" | |
361 else | |
362 unknown="${p}\n${unknown}" | |
363 fi | |
364 done | |
365 if [ -n "${unknown}" ]; then | |
366 echo "WARNING: The following packages are unknown to your system" | |
367 echo "(maybe missing a repo or need to 'sudo apt-get update'):" | |
368 echo -e "${unknown}" | sed -e "s/^/ /" | |
369 fi | |
370 fi | |
371 if [ -n "${missing}" ]; then | |
372 echo "WARNING: The following packages are not installed:" | |
373 echo -e "${missing}" | sed -e "s/^/ /" | |
374 fi | |
375 exit 1 | |
376 fi | |
377 exit 0 | |
378 fi | |
379 | |
380 if test "$do_inst_lib32" = "1" || test "$do_inst_nacl" = "1"; then | |
381 if [[ ! $codename =~ (precise) ]]; then | |
382 sudo dpkg --add-architecture i386 | |
383 fi | |
384 fi | |
385 sudo apt-get update | |
386 | |
387 # We initially run "apt-get" with the --reinstall option and parse its output. | |
388 # This way, we can find all the packages that need to be newly installed | |
389 # without accidentally promoting any packages from "auto" to "manual". | |
390 # We then re-run "apt-get" with just the list of missing packages. | |
391 echo "Finding missing packages..." | |
392 # Intentionally leaving $packages unquoted so it's more readable. | |
393 echo "Packages required: " $packages | |
394 echo | |
395 new_list_cmd="sudo apt-get install --reinstall $(echo $packages)" | |
396 if new_list="$(yes n | LANGUAGE=en LANG=C $new_list_cmd)"; then | |
397 # We probably never hit this following line. | |
398 echo "No missing packages, and the packages are up-to-date." | |
399 elif [ $? -eq 1 ]; then | |
400 # We expect apt-get to have exit status of 1. | |
401 # This indicates that we cancelled the install with "yes n|". | |
402 new_list=$(echo "$new_list" | | |
403 sed -e '1,/The following NEW packages will be installed:/d;s/^ //;t;d') | |
404 new_list=$(echo "$new_list" | sed 's/ *$//') | |
405 if [ -z "$new_list" ] ; then | |
406 echo "No missing packages, and the packages are up-to-date." | |
407 else | |
408 echo "Installing missing packages: $new_list." | |
409 sudo apt-get install ${do_quietly-} ${new_list} | |
410 fi | |
411 echo | |
412 else | |
413 # An apt-get exit status of 100 indicates that a real error has occurred. | |
414 | |
415 # I am intentionally leaving out the '"'s around new_list_cmd, | |
416 # as this makes it easier to cut and paste the output | |
417 echo "The following command failed: " ${new_list_cmd} | |
418 echo | |
419 echo "It produces the following output:" | |
420 yes n | $new_list_cmd || true | |
421 echo | |
422 echo "You will have to install the above packages yourself." | |
423 echo | |
424 exit 100 | |
425 fi | |
426 | |
427 # Install the Chrome OS default fonts. This must go after running | |
428 # apt-get, since install-chromeos-fonts depends on curl. | |
429 if test "$do_inst_chromeos_fonts" != "0"; then | |
430 echo | |
431 echo "Installing Chrome OS fonts." | |
432 dir=`echo $0 | sed -r -e 's/\/[^/]+$//'` | |
433 if ! sudo $dir/linux/install-chromeos-fonts.py; then | |
434 echo "ERROR: The installation of the Chrome OS default fonts failed." | |
435 if [ `stat -f -c %T $dir` == "nfs" ]; then | |
436 echo "The reason is that your repo is installed on a remote file system." | |
437 else | |
438 echo "This is expected if your repo is installed on a remote file system." | |
439 fi | |
440 echo "It is recommended to install your repo on a local file system." | |
441 echo "You can skip the installation of the Chrome OS default founts with" | |
442 echo "the command line option: --no-chromeos-fonts." | |
443 exit 1 | |
444 fi | |
445 else | |
446 echo "Skipping installation of Chrome OS fonts." | |
447 fi | |
448 | |
449 # $1 - target name | |
450 # $2 - link name | |
451 create_library_symlink() { | |
452 target=$1 | |
453 linkname=$2 | |
454 if [ -L $linkname ]; then | |
455 if [ "$(basename $(readlink $linkname))" != "$(basename $target)" ]; then | |
456 sudo rm $linkname | |
457 fi | |
458 fi | |
459 if [ ! -r $linkname ]; then | |
460 echo "Creating link: $linkname" | |
461 sudo ln -fs $target $linkname | |
462 fi | |
463 } | |
464 | |
465 if test "$do_inst_nacl" = "1"; then | |
466 echo "Installing symbolic links for NaCl." | |
467 # naclports needs to cross build python for i386, but libssl1.0.0:i386 | |
468 # only contains libcrypto.so.1.0.0 and not the symlink needed for | |
469 # linking (libcrypto.so). | |
470 create_library_symlink /lib/i386-linux-gnu/libcrypto.so.1.0.0 \ | |
471 /usr/lib/i386-linux-gnu/libcrypto.so | |
472 | |
473 create_library_symlink /lib/i386-linux-gnu/libssl.so.1.0.0 \ | |
474 /usr/lib/i386-linux-gnu/libssl.so | |
475 else | |
476 echo "Skipping symbolic links for NaCl." | |
477 fi | |
OLD | NEW |