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.
7 # Script to install everything needed to build chromium (well, ideally, anyway)
8 # See https://chromium.googlesource.com/chromium/src/+/master/docs/linux_build_instructions.md
11 echo "Usage: $0 [--options]"
13 echo "--[no-]syms: enable or disable installation of debugging symbols"
14 echo "--lib32: enable installation of 32-bit libraries, e.g. for V8 snapshot"
15 echo "--[no-]arm: enable or disable installation of arm cross toolchain"
16 echo "--[no-]chromeos-fonts: enable or disable installation of Chrome OS"\
18 echo "--[no-]nacl: enable or disable installation of prerequisites for"\
19 "building standalone NaCl and all its toolchains"
20 echo "--[no-]backwards-compatible: enable or disable installation of packages
21 that are no longer currently needed and have been removed from this
22 script. Useful for bisection."
23 echo "--no-prompt: silently select standard options/defaults"
24 echo "--quick-check: quickly try to determine if dependencies are installed"
25 echo " (this avoids interactive prompts and sudo commands,"
26 echo " so might not be 100% accurate)"
27 echo "--unsupported: attempt installation even on unsupported systems"
28 echo "Script will prompt interactively if options not given."
32 # Checks whether a particular package is available in the repos.
33 # USAGE: $ package_exists <package name>
35 # 'apt-cache search' takes a regex string, so eg. the +'s in packages like
36 # "libstdc++" need to be escaped.
37 local escaped="$(echo $1 | sed 's/[\~\+\.\:-]/\\&/g')"
38 [ ! -z "$(apt-cache search --names-only "${escaped}" | \
39 awk '$1 == "'$1'" { print $1; }')" ]
42 # These default to on because (some) bots need them and it keeps things
43 # simple for the bot setup if all bots just run the script in its default
44 # mode. Developers who don't want stuff they don't need installed on their
45 # own workstations can pass --no-arm --no-nacl when running the script.
52 --syms) do_inst_syms=1;;
53 --no-syms) do_inst_syms=0;;
54 --lib32) do_inst_lib32=1;;
55 --arm) do_inst_arm=1;;
56 --no-arm) do_inst_arm=0;;
57 --chromeos-fonts) do_inst_chromeos_fonts=1;;
58 --no-chromeos-fonts) do_inst_chromeos_fonts=0;;
59 --nacl) do_inst_nacl=1;;
60 --no-nacl) do_inst_nacl=0;;
61 --backwards-compatible) do_inst_backwards_compatible=1;;
62 --no-backwards-compatible) do_inst_backwards_compatible=0;;
63 --add-cross-tool-repo) add_cross_tool_repo=1;;
64 --no-prompt) do_default=1
65 do_quietly="-qq --assume-yes"
67 --quick-check) do_quick_check=1;;
68 --unsupported) do_unsupported=1;;
74 if [ "$do_inst_arm" = "1" ]; then
78 # Check for lsb_release command in $PATH
79 if ! which lsb_release > /dev/null; then
80 echo "ERROR: lsb_release not found in \$PATH" >&2
84 distro_codename=$(lsb_release --codename --short)
85 distro_id=$(lsb_release --id --short)
86 supported_codenames="(trusty|xenial|artful|bionic)"
87 supported_ids="(Debian)"
88 if [ 0 -eq "${do_unsupported-0}" ] && [ 0 -eq "${do_quick_check-0}" ] ; then
89 if [[ ! $distro_codename =~ $supported_codenames &&
90 ! $distro_id =~ $supported_ids ]]; then
91 echo -e "ERROR: The only supported distros are\n" \
92 "\tUbuntu 14.04 LTS (trusty)\n" \
93 "\tUbuntu 16.04 LTS (xenial)\n" \
94 "\tUbuntu 17.10 (artful)\n" \
95 "\tUbuntu 18.04 LTS (bionic)\n" \
96 "\tDebian 8 (jessie) or later" >&2
100 if ! uname -m | egrep -q "i686|x86_64"; then
101 echo "Only x86 architectures are currently supported" >&2
106 if [ "x$(id -u)" != x0 ] && [ 0 -eq "${do_quick_check-0}" ]; then
107 echo "Running as non-root user."
108 echo "You might have to enter your password one or more times for 'sudo'."
112 # Packages needed for chromeos only
113 chromeos_dev_list="libbluetooth-dev libxkbcommon-dev"
115 if package_exists realpath; then
116 chromeos_dev_list="${chromeos_dev_list} realpath"
119 # Packages needed for development
196 # 64-bit systems need a minimum set of 32-bit compat packages for the pre-built
198 if file -L /sbin/init | grep -q 'ELF 64-bit'; then
199 dev_list="${dev_list} libc6-i386 lib32gcc1 lib32stdc++6"
202 # Run-time libraries required by chromeos only
203 chromeos_lib_list="libpulse0 libbz2-1.0"
205 # List of required run-time libraries
250 # Full list of required run-time libraries
256 # 32-bit libraries needed e.g. to compile V8 snapshot for Android or armhf
257 lib32_list="linux-libc-dev:i386 libpci3:i386"
259 # 32-bit libraries needed for a 32-bit build
260 lib32_list="$lib32_list libx11-xcb1:i386"
262 # Packages that have been removed from this script. Regardless of configuration
263 # or options passed to this script, whenever a package is removed, it should be
265 backwards_compatible_list="\
275 language-pack-zh-hant
278 libappindicator3-1:i386
302 ttf-mscorefonts-installer
305 case $distro_codename in
307 backwards_compatible_list+=" \
308 libgbm-dev-lts-trusty
309 libgl1-mesa-dev-lts-trusty
310 libgl1-mesa-glx-lts-trusty:i386
311 libgles2-mesa-dev-lts-trusty
312 mesa-common-dev-lts-trusty"
315 backwards_compatible_list+=" \
316 libgbm-dev-lts-xenial
317 libgl1-mesa-dev-lts-xenial
318 libgl1-mesa-glx-lts-xenial:i386
319 libgles2-mesa-dev-lts-xenial
320 mesa-common-dev-lts-xenial"
324 # arm cross toolchain packages needed to build chrome on armhf
325 EM_REPO="deb http://emdebian.org/tools/debian/ jessie main"
326 EM_SOURCE=$(cat <<EOF
327 # Repo added by Chromium $0
329 # deb-src http://emdebian.org/tools/debian/ jessie main
332 EM_ARCHIVE_KEY_FINGER="084C6C6F39159EDB67969AA87DE089671804772E"
333 GPP_ARM_PACKAGE="g++-arm-linux-gnueabihf"
334 case $distro_codename in
336 eval $(apt-config shell APT_SOURCESDIR 'Dir::Etc::sourceparts/d')
337 CROSSTOOLS_LIST="${APT_SOURCESDIR}/crosstools.list"
338 arm_list="libc6-dev:armhf
339 linux-libc-dev:armhf"
340 if [ "$do_inst_arm" = "1" ]; then
341 if $(dpkg-query -W ${GPP_ARM_PACKAGE} &>/dev/null); then
342 arm_list+=" ${GPP_ARM_PACKAGE}"
344 if [ "${add_cross_tool_repo}" = "1" ]; then
345 gpg --keyserver pgp.mit.edu --recv-keys ${EM_ARCHIVE_KEY_FINGER}
346 gpg -a --export ${EM_ARCHIVE_KEY_FINGER} | sudo apt-key add -
347 if ! grep "^${EM_REPO}" "${CROSSTOOLS_LIST}" &>/dev/null; then
348 echo "${EM_SOURCE}" | sudo tee -a "${CROSSTOOLS_LIST}" >/dev/null
350 arm_list+=" ${GPP_ARM_PACKAGE}"
352 echo "The Debian Cross-toolchains repository is necessary to"
353 echo "cross-compile Chromium for arm."
354 echo "Rerun with --add-deb-cross-tool-repo to have it added for you."
359 # All necessary ARM packages are available on the default repos on
360 # Debian 9 and later.
362 arm_list="libc6-dev-armhf-cross
363 linux-libc-dev-armhf-cross
368 # Work around for dependency issue Ubuntu/Trusty: http://crbug.com/435056
369 case $distro_codename in
371 arm_list+=" g++-4.8-multilib-arm-linux-gnueabihf
372 gcc-4.8-multilib-arm-linux-gnueabihf"
374 xenial|artful|bionic)
375 arm_list+=" g++-5-multilib-arm-linux-gnueabihf
376 gcc-5-multilib-arm-linux-gnueabihf
377 gcc-arm-linux-gnueabihf"
381 # Packages to build NaCl, its toolchains, and its ports.
382 naclports_list="ant autoconf bison cmake gawk intltool xutils-dev xsltproc"
413 if package_exists libssl1.1; then
414 nacl_list="${nacl_list} libssl1.1:i386"
415 elif package_exists libssl1.0.2; then
416 nacl_list="${nacl_list} libssl1.0.2:i386"
418 nacl_list="${nacl_list} libssl1.0.0:i386"
421 # Some package names have changed over time
422 if package_exists libpng16-16; then
423 lib_list="${lib_list} libpng16-16"
425 lib_list="${lib_list} libpng12-0"
427 if package_exists libnspr4; then
428 lib_list="${lib_list} libnspr4 libnss3"
430 lib_list="${lib_list} libnspr4-0d libnss3-1d"
432 if package_exists libjpeg-dev; then
433 dev_list="${dev_list} libjpeg-dev"
435 dev_list="${dev_list} libjpeg62-dev"
437 if package_exists libudev1; then
438 dev_list="${dev_list} libudev1"
439 nacl_list="${nacl_list} libudev1:i386"
441 dev_list="${dev_list} libudev0"
442 nacl_list="${nacl_list} libudev0:i386"
444 if package_exists libbrlapi0.6; then
445 dev_list="${dev_list} libbrlapi0.6"
447 dev_list="${dev_list} libbrlapi0.5"
449 if package_exists apache2.2-bin; then
450 dev_list="${dev_list} apache2.2-bin"
452 dev_list="${dev_list} apache2-bin"
454 if package_exists libav-tools; then
455 dev_list="${dev_list} libav-tools"
457 if package_exists php7.2-cgi; then
458 dev_list="${dev_list} php7.2-cgi libapache2-mod-php7.2"
459 elif package_exists php7.1-cgi; then
460 dev_list="${dev_list} php7.1-cgi libapache2-mod-php7.1"
461 elif package_exists php7.0-cgi; then
462 dev_list="${dev_list} php7.0-cgi libapache2-mod-php7.0"
464 dev_list="${dev_list} php5-cgi libapache2-mod-php5"
467 # Some packages are only needed if the distribution actually supports
469 if package_exists appmenu-gtk; then
470 lib_list="$lib_list appmenu-gtk"
473 # Cross-toolchain strip is needed for building the sysroots.
474 if package_exists binutils-arm-linux-gnueabihf; then
475 dev_list="${dev_list} binutils-arm-linux-gnueabihf"
477 if package_exists binutils-aarch64-linux-gnu; then
478 dev_list="${dev_list} binutils-aarch64-linux-gnu"
480 if package_exists binutils-mipsel-linux-gnu; then
481 dev_list="${dev_list} binutils-mipsel-linux-gnu"
483 if package_exists binutils-mips64el-linux-gnuabi64; then
484 dev_list="${dev_list} binutils-mips64el-linux-gnuabi64"
487 # When cross building for arm/Android on 64-bit systems the host binaries
488 # that are part of v8 need to be compiled with -m32 which means
489 # that basic multilib support is needed.
490 if file -L /sbin/init | grep -q 'ELF 64-bit'; then
491 # gcc-multilib conflicts with the arm cross compiler (at least in trusty) but
492 # g++-X.Y-multilib gives us the 32-bit support that we need. Find out the
493 # appropriate value of X and Y by seeing what version the current
494 # distribution's g++-multilib package depends on.
495 multilib_package=$(apt-cache depends g++-multilib --important | \
496 grep -E --color=never --only-matching '\bg\+\+-[0-9.]+-multilib\b')
497 lib32_list="$lib32_list $multilib_package"
500 if [ "$do_inst_syms" = "1" ]; then
501 echo "Including debugging symbols."
503 # Debian is in the process of transitioning to automatic debug packages, which
504 # have the -dbgsym suffix (https://wiki.debian.org/AutomaticDebugPackages).
505 # Untransitioned packages have the -dbg suffix. And on some systems, neither
506 # will be available, so exclude the ones that are missing.
508 if package_exists "$1-dbgsym"; then
510 elif package_exists "$1-dbg"; then
515 for package in "${common_lib_list}"; do
516 dbg_list="$dbg_list $(dbg_package_name ${package})"
519 # Debugging symbols packages not following common naming scheme
520 if [ "$(dbg_package_name libstdc++6)" == "" ]; then
521 if package_exists libstdc++6-8-dbg; then
522 dbg_list="${dbg_list} libstdc++6-8-dbg"
523 elif package_exists libstdc++6-7-dbg; then
524 dbg_list="${dbg_list} libstdc++6-7-dbg"
525 elif package_exists libstdc++6-6-dbg; then
526 dbg_list="${dbg_list} libstdc++6-6-dbg"
527 elif package_exists libstdc++6-5-dbg; then
528 dbg_list="${dbg_list} libstdc++6-5-dbg"
529 elif package_exists libstdc++6-4.9-dbg; then
530 dbg_list="${dbg_list} libstdc++6-4.9-dbg"
531 elif package_exists libstdc++6-4.8-dbg; then
532 dbg_list="${dbg_list} libstdc++6-4.8-dbg"
533 elif package_exists libstdc++6-4.7-dbg; then
534 dbg_list="${dbg_list} libstdc++6-4.7-dbg"
535 elif package_exists libstdc++6-4.6-dbg; then
536 dbg_list="${dbg_list} libstdc++6-4.6-dbg"
539 if [ "$(dbg_package_name libatk1.0-0)" == "" ]; then
540 dbg_list="$dbg_list $(dbg_package_name libatk1.0)"
542 if [ "$(dbg_package_name libpango1.0-0)" == "" ]; then
543 dbg_list="$dbg_list $(dbg_package_name libpango1.0-dev)"
546 echo "Skipping debugging symbols."
550 if [ "$do_inst_lib32" = "1" ]; then
551 echo "Including 32-bit libraries."
553 echo "Skipping 32-bit libraries."
557 if [ "$do_inst_arm" = "1" ]; then
558 echo "Including ARM cross toolchain."
560 echo "Skipping ARM cross toolchain."
564 if [ "$do_inst_nacl" = "1" ]; then
565 echo "Including NaCl, NaCl toolchain, NaCl ports dependencies."
567 echo "Skipping NaCl, NaCl toolchain, NaCl ports dependencies."
571 filtered_backwards_compatible_list=
572 if [ "$do_inst_backwards_compatible" = "1" ]; then
573 echo "Including backwards compatible packages."
574 for package in ${backwards_compatible_list}; do
575 if package_exists ${package}; then
576 filtered_backwards_compatible_list+=" ${package}"
581 # The `sort -r -s -t: -k2` sorts all the :i386 packages to the front, to avoid
582 # confusing dpkg-query (crbug.com/446172).
584 echo "${dev_list} ${lib_list} ${dbg_list} ${lib32_list} ${arm_list}" \
585 "${nacl_list}" ${filtered_backwards_compatible_list} | tr " " "\n" | \
586 sort -u | sort -r -s -t: -k2 | tr "\n" " "
589 if [ 1 -eq "${do_quick_check-0}" ] ; then
590 if ! missing_packages="$(dpkg-query -W -f ' ' ${packages} 2>&1)"; then
591 # Distinguish between packages that actually aren't available to the
592 # system (i.e. not in any repo) and packages that just aren't known to
593 # dpkg (i.e. managed by apt).
594 missing_packages="$(echo "${missing_packages}" | awk '{print $NF}')"
597 for p in ${missing_packages}; do
598 if apt-cache show ${p} > /dev/null 2>&1; then
599 not_installed="${p}\n${not_installed}"
601 unknown="${p}\n${unknown}"
604 if [ -n "${not_installed}" ]; then
605 echo "WARNING: The following packages are not installed:"
606 echo -e "${not_installed}" | sed -e "s/^/ /"
608 if [ -n "${unknown}" ]; then
609 echo "WARNING: The following packages are unknown to your system"
610 echo "(maybe missing a repo or need to 'sudo apt-get update'):"
611 echo -e "${unknown}" | sed -e "s/^/ /"
618 if [ "$do_inst_lib32" = "1" ] || [ "$do_inst_nacl" = "1" ]; then
619 sudo dpkg --add-architecture i386
623 # We initially run "apt-get" with the --reinstall option and parse its output.
624 # This way, we can find all the packages that need to be newly installed
625 # without accidentally promoting any packages from "auto" to "manual".
626 # We then re-run "apt-get" with just the list of missing packages.
627 echo "Finding missing packages..."
628 # Intentionally leaving $packages unquoted so it's more readable.
629 echo "Packages required: " $packages
631 new_list_cmd="sudo apt-get install --reinstall $(echo $packages)"
632 if new_list="$(yes n | LANGUAGE=en LANG=C $new_list_cmd)"; then
633 # We probably never hit this following line.
634 echo "No missing packages, and the packages are up to date."
635 elif [ $? -eq 1 ]; then
636 # We expect apt-get to have exit status of 1.
637 # This indicates that we cancelled the install with "yes n|".
638 new_list=$(echo "$new_list" |
639 sed -e '1,/The following NEW packages will be installed:/d;s/^ //;t;d')
640 new_list=$(echo "$new_list" | sed 's/ *$//')
641 if [ -z "$new_list" ] ; then
642 echo "No missing packages, and the packages are up to date."
644 echo "Installing missing packages: $new_list."
645 sudo apt-get install ${do_quietly-} ${new_list}
649 # An apt-get exit status of 100 indicates that a real error has occurred.
651 # I am intentionally leaving out the '"'s around new_list_cmd,
652 # as this makes it easier to cut and paste the output
653 echo "The following command failed: " ${new_list_cmd}
655 echo "It produces the following output:"
656 yes n | $new_list_cmd || true
658 echo "You will have to install the above packages yourself."
663 # Install the Chrome OS default fonts. This must go after running
664 # apt-get, since install-chromeos-fonts depends on curl.
665 if [ "$do_inst_chromeos_fonts" != "0" ]; then
667 echo "Installing Chrome OS fonts."
668 dir=`echo $0 | sed -r -e 's/\/[^/]+$//'`
669 if ! sudo $dir/linux/install-chromeos-fonts.py; then
670 echo "ERROR: The installation of the Chrome OS default fonts failed."
671 if [ `stat -f -c %T $dir` == "nfs" ]; then
672 echo "The reason is that your repo is installed on a remote file system."
674 echo "This is expected if your repo is installed on a remote file system."
676 echo "It is recommended to install your repo on a local file system."
677 echo "You can skip the installation of the Chrome OS default founts with"
678 echo "the command line option: --no-chromeos-fonts."
682 echo "Skipping installation of Chrome OS fonts."
685 echo "Installing locales."
686 CHROMIUM_LOCALES="da_DK.UTF-8 fr_FR.UTF-8 he_IL.UTF-8 zh_TW.UTF-8"
687 LOCALE_GEN=/etc/locale.gen
688 if [ -e ${LOCALE_GEN} ]; then
689 OLD_LOCALE_GEN="$(cat /etc/locale.gen)"
690 for CHROMIUM_LOCALE in ${CHROMIUM_LOCALES}; do
691 sudo sed -i "s/^# ${CHROMIUM_LOCALE}/${CHROMIUM_LOCALE}/" ${LOCALE_GEN}
693 # Regenerating locales can take a while, so only do it if we need to.
694 if (echo "${OLD_LOCALE_GEN}" | cmp -s ${LOCALE_GEN}); then
695 echo "Locales already up-to-date."
700 for CHROMIUM_LOCALE in ${CHROMIUM_LOCALES}; do
701 sudo locale-gen ${CHROMIUM_LOCALE}