blob: 917c7b6b8293f72c1bcb9e25290e049b944088da [file] [log] [blame]
[email protected]e041ed12009-03-10 16:43:011#!/bin/bash -e
2
[email protected]aac39c92012-02-08 18:39:533# Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]e46cdae2009-08-25 20:59:274# Use of this source code is governed by a BSD-style license that can be
5# found in the LICENSE file.
6
[email protected]cf1df402008-10-31 21:45:307# Script to install everything needed to build chromium (well, ideally, anyway)
[email protected]592ea8ca2008-11-03 19:47:368# See http://code.google.com/p/chromium/wiki/LinuxBuildInstructions
9# and http://code.google.com/p/chromium/wiki/LinuxBuild64Bit
[email protected]cf1df402008-10-31 21:45:3010
[email protected]1eae2bfb2010-01-26 18:17:5311usage() {
12 echo "Usage: $0 [--options]"
13 echo "Options:"
14 echo "--[no-]syms: enable or disable installation of debugging symbols"
[email protected]1eae2bfb2010-01-26 18:17:5315 echo "--[no-]lib32: enable or disable installation of 32 bit libraries"
16 echo "Script will prompt interactively if options not given."
17 exit 1
18}
19
20while test "$1" != ""
21do
22 case "$1" in
[email protected]ce774642011-09-12 23:21:3923 --syms) do_inst_syms=1;;
24 --no-syms) do_inst_syms=0;;
[email protected]ce774642011-09-12 23:21:3925 --lib32) do_inst_lib32=1;;
26 --no-lib32) do_inst_lib32=0;;
[email protected]1eae2bfb2010-01-26 18:17:5327 *) usage;;
28 esac
29 shift
30done
31
[email protected]a51551d2010-07-15 22:59:4832if ! egrep -q \
[email protected]757c2962012-03-15 19:05:1833 'Ubuntu (10\.04|10\.10|11\.04|11\.10|12\.04|lucid|maverick|natty|oneiric|precise)' \
[email protected]a51551d2010-07-15 22:59:4834 /etc/issue; then
[email protected]757c2962012-03-15 19:05:1835 echo "Only Ubuntu 10.04 (lucid) through 12.04 (precise) are currently" \
[email protected]a51551d2010-07-15 22:59:4836 "supported" >&2
[email protected]cf1df402008-10-31 21:45:3037 exit 1
38fi
[email protected]cf1df402008-10-31 21:45:3039
[email protected]e041ed12009-03-10 16:43:0140if ! uname -m | egrep -q "i686|x86_64"; then
41 echo "Only x86 architectures are currently supported" >&2
42 exit
43fi
44
45if [ "x$(id -u)" != x0 ]; then
46 echo "Running as non-root user."
47 echo "You might have to enter your password one or more times for 'sudo'."
[email protected]8ada8c52009-03-10 21:53:0848 echo
[email protected]e041ed12009-03-10 16:43:0149fi
50
[email protected]fdc6bf52010-06-07 22:01:5751# Packages needed for chromeos only
52chromeos_dev_list="libpulse-dev"
53
[email protected]e041ed12009-03-10 16:43:0154# Packages need for development
[email protected]041d14a2011-12-13 01:42:4855dev_list="apache2.2-bin bison curl elfutils fakeroot flex g++ gperf
56 language-pack-fr libapache2-mod-php5 libasound2-dev libbz2-dev
57 libcairo2-dev libcups2-dev libcurl4-gnutls-dev libdbus-glib-1-dev
58 libelf-dev libgconf2-dev libgl1-mesa-dev libglib2.0-dev
[email protected]b11411c2012-03-21 22:09:4159 libglu1-mesa-dev libgnome-keyring-dev libgtk2.0-dev
[email protected]041d14a2011-12-13 01:42:4860 libkrb5-dev libnspr4-dev libnss3-dev libpam0g-dev libsctp-dev
[email protected]6de217b72011-12-17 03:36:3261 libsqlite3-dev libssl-dev libudev-dev libwww-perl libxslt1-dev
[email protected]757c2962012-03-15 19:05:1862 libxss-dev libxt-dev libxtst-dev mesa-common-dev patch
[email protected]6de217b72011-12-17 03:36:3263 perl php5-cgi pkg-config python python-cherrypy3 python-dev
64 python-psutil rpm ruby subversion ttf-dejavu-core ttf-indic-fonts
[email protected]52de18db2012-02-15 23:38:0765 ttf-kochi-gothic ttf-kochi-mincho ttf-thai-tlwg wdiff git-core
[email protected]9dc4bed2010-11-04 19:23:3066 $chromeos_dev_list"
[email protected]fdc6bf52010-06-07 22:01:5767
68# Run-time libraries required by chromeos only
[email protected]34799f9d2010-07-08 17:51:3369chromeos_lib_list="libpulse0 libbz2-1.0 libcurl4-gnutls-dev"
[email protected]e041ed12009-03-10 16:43:0170
71# Full list of required run-time libraries
[email protected]a9259a52011-05-21 01:05:2272lib_list="libatk1.0-0 libc6 libasound2 libcairo2 libcups2 libdbus-glib-1-2
73 libexpat1 libfontconfig1 libfreetype6 libglib2.0-0 libgnome-keyring0
74 libgtk2.0-0 libpam0g libpango1.0-0 libpcre3 libpixman-1-0
[email protected]6de217b72011-12-17 03:36:3275 libpng12-0 libstdc++6 libsqlite3-0 libudev0 libx11-6 libxau6 libxcb1
[email protected]fd11101b2011-02-16 04:46:4676 libxcomposite1 libxcursor1 libxdamage1 libxdmcp6 libxext6 libxfixes3
77 libxi6 libxinerama1 libxrandr2 libxrender1 libxtst6 zlib1g
[email protected]9dc4bed2010-11-04 19:23:3078 $chromeos_lib_list"
[email protected]e041ed12009-03-10 16:43:0179
80# Debugging symbols for all of the run-time libraries
[email protected]f3307aa2011-10-21 22:52:3881dbg_list="libatk1.0-dbg libc6-dbg libcairo2-dbg libdbus-glib-1-2-dbg
[email protected]1a0f64a2011-05-20 17:53:5582 libfontconfig1-dbg libglib2.0-0-dbg libgtk2.0-0-dbg
83 libpango1.0-0-dbg libpcre3-dbg libpixman-1-0-dbg
[email protected]b944e322011-05-18 20:01:3584 libsqlite3-0-dbg
[email protected]e759c4b2010-03-10 19:04:5885 libx11-6-dbg libxau6-dbg libxcb1-dbg libxcomposite1-dbg
[email protected]e041ed12009-03-10 16:43:0186 libxcursor1-dbg libxdamage1-dbg libxdmcp6-dbg libxext6-dbg
87 libxfixes3-dbg libxi6-dbg libxinerama1-dbg libxrandr2-dbg
[email protected]9dc4bed2010-11-04 19:23:3088 libxrender1-dbg libxtst6-dbg zlib1g-dbg"
[email protected]e041ed12009-03-10 16:43:0189
[email protected]31a605532011-08-23 22:27:3590# Plugin lists needed for tests.
91plugin_list="flashplugin-installer"
92
[email protected]757c2962012-03-15 19:05:1893# Some package names have changed over time
[email protected]b11411c2012-03-21 22:09:4194if apt-cache show ttf-mscorefonts-installer >/dev/null 2>&1; then
[email protected]757c2962012-03-15 19:05:1895 dev_list="${dev_list} ttf-mscorefonts-installer"
[email protected]b11411c2012-03-21 22:09:4196else
97 dev_list="${dev_list} msttcorefonts"
[email protected]757c2962012-03-15 19:05:1898fi
[email protected]b11411c2012-03-21 22:09:4199if apt-cache show libnspr4-dbg >/dev/null 2>&1; then
[email protected]1a0f64a2011-05-20 17:53:55100 dbg_list="${dbg_list} libnspr4-dbg libnss3-dbg"
101 lib_list="${lib_list} libnspr4 libnss3"
[email protected]757c2962012-03-15 19:05:18102else
103 dbg_list="${dbg_list} libnspr4-0d-dbg libnss3-1d-dbg"
104 lib_list="${lib_list} libnspr4-0d libnss3-1d"
105fi
[email protected]b11411c2012-03-21 22:09:41106if apt-cache show libjpeg-dev >/dev/null 2>&1; then
107 dev_list="${dev_list} libjpeg-dev"
108else
109 dev_list="${dev_list} libjpeg62-dev"
110fi
[email protected]757c2962012-03-15 19:05:18111
112# Some packages are only needed, if the distribution actually supports
113# installing them.
[email protected]b11411c2012-03-21 22:09:41114if apt-cache show appmenu-gtk >/dev/null 2>&1; then
[email protected]757c2962012-03-15 19:05:18115 lib_list="$lib_list appmenu-gtk"
[email protected]4da8fad2011-04-11 18:42:42116fi
117
[email protected]8ada8c52009-03-10 21:53:08118# Waits for the user to press 'Y' or 'N'. Either uppercase of lowercase is
119# accepted. Returns 0 for 'Y' and 1 for 'N'. If an optional parameter has
120# been provided to yes_no(), the function also accepts RETURN as a user input.
121# The parameter specifies the exit code that should be returned in that case.
122# The function will echo the user's selection followed by a newline character.
123# Users can abort the function by pressing CTRL-C. This will call "exit 1".
124yes_no() {
125 local c
126 while :; do
127 c="$(trap 'stty echo -iuclc icanon 2>/dev/null' EXIT INT TERM QUIT
128 stty -echo iuclc -icanon 2>/dev/null
129 dd count=1 bs=1 2>/dev/null | od -An -tx1)"
130 case "$c" in
131 " 0a") if [ -n "$1" ]; then
132 [ $1 -eq 0 ] && echo "Y" || echo "N"
133 return $1
134 fi
135 ;;
136 " 79") echo "Y"
137 return 0
138 ;;
139 " 6e") echo "N"
140 return 1
141 ;;
142 "") echo "Aborted" >&2
143 exit 1
144 ;;
145 *) # The user pressed an unrecognized key. As we are not echoing
146 # any incorrect user input, alert the user by ringing the bell.
147 (tput bel) 2>/dev/null
148 ;;
149 esac
150 done
151}
152
[email protected]1eae2bfb2010-01-26 18:17:53153if test "$do_inst_syms" = ""
154then
155 echo "This script installs all tools and libraries needed to build Chromium."
156 echo ""
157 echo "For most of the libraries, it can also install debugging symbols, which"
158 echo "will allow you to debug code in the system libraries. Most developers"
159 echo "won't need these symbols."
160 echo -n "Do you want me to install them for you (y/N) "
161 if yes_no 1; then
162 do_inst_syms=1
163 fi
164fi
165if test "$do_inst_syms" = "1"; then
[email protected]8ada8c52009-03-10 21:53:08166 echo "Installing debugging symbols."
167else
168 echo "Skipping installation of debugging symbols."
169 dbg_list=
170fi
171
[email protected]e041ed12009-03-10 16:43:01172sudo apt-get update
173
174# We initially run "apt-get" with the --reinstall option and parse its output.
175# This way, we can find all the packages that need to be newly installed
176# without accidentally promoting any packages from "auto" to "manual".
177# We then re-run "apt-get" with just the list of missing packages.
178echo "Finding missing packages..."
[email protected]31a605532011-08-23 22:27:35179packages="${dev_list} ${lib_list} ${dbg_list} ${plugin_list}"
[email protected]757c2962012-03-15 19:05:18180# Intentionally leaving $packages unquoted so it's more readable.
[email protected]b6e064522009-08-10 18:47:51181echo "Packages required: " $packages
182echo
[email protected]79a9d2962009-08-06 21:10:58183new_list_cmd="sudo apt-get install --reinstall $(echo $packages)"
[email protected]b62f11e72010-05-03 17:20:45184if new_list="$(yes n | LANG=C $new_list_cmd)"; then
[email protected]b6e064522009-08-10 18:47:51185 # We probably never hit this following line.
[email protected]79a9d2962009-08-06 21:10:58186 echo "No missing packages, and the packages are up-to-date."
[email protected]b62f11e72010-05-03 17:20:45187elif [ $? -eq 1 ]; then
[email protected]79a9d2962009-08-06 21:10:58188 # We expect apt-get to have exit status of 1.
[email protected]757c2962012-03-15 19:05:18189 # This indicates that we cancelled the install with "yes n|".
[email protected]b6e064522009-08-10 18:47:51190 new_list=$(echo "$new_list" |
[email protected]79a9d2962009-08-06 21:10:58191 sed -e '1,/The following NEW packages will be installed:/d;s/^ //;t;d')
[email protected]b6e064522009-08-10 18:47:51192 new_list=$(echo "$new_list" | sed 's/ *$//')
193 if [ -z "$new_list" ] ; then
194 echo "No missing packages, and the packages are up-to-date."
195 else
196 echo "Installing missing packages: $new_list."
197 sudo apt-get install ${new_list}
198 fi
199 echo
[email protected]79a9d2962009-08-06 21:10:58200else
201 # An apt-get exit status of 100 indicates that a real error has occurred.
[email protected]e041ed12009-03-10 16:43:01202
[email protected]79a9d2962009-08-06 21:10:58203 # I am intentionally leaving out the '"'s around new_list_cmd,
204 # as this makes it easier to cut and paste the output
[email protected]79a9d2962009-08-06 21:10:58205 echo "The following command failed: " ${new_list_cmd}
206 echo
207 echo "It produces the following output:"
208 yes n | $new_list_cmd || true
209 echo
210 echo "You will have to install the above packages yourself."
211 echo
212 exit 100
213fi
[email protected]e041ed12009-03-10 16:43:01214
215# Install 32bit backwards compatibility support for 64bit systems
[email protected]b6e064522009-08-10 18:47:51216if [ "$(uname -m)" = "x86_64" ]; then
[email protected]1eae2bfb2010-01-26 18:17:53217 if test "$do_inst_lib32" = ""
218 then
[email protected]e76a3632012-03-15 20:56:27219 echo "We no longer recommend that you use this script to install"
220 echo "32bit libraries on a 64bit system. Instead, consider using"
221 echo "the install-chroot.sh script to help you set up a 32bit"
222 echo "environment for building and testing 32bit versions of Chrome."
[email protected]1eae2bfb2010-01-26 18:17:53223 echo
[email protected]e76a3632012-03-15 20:56:27224 echo "If you nonetheless want to try installing 32bit libraries"
225 echo "directly, you can do so by explicitly passing the --lib32"
[email protected]472f5e192012-03-16 00:02:20226 echo "option to install-build-deps.sh."
[email protected]1eae2bfb2010-01-26 18:17:53227 fi
228 if test "$do_inst_lib32" != "1"
229 then
[email protected]8ada8c52009-03-10 21:53:08230 echo "Exiting without installing any 32bit libraries."
231 exit 0
232 fi
[email protected]b62f11e72010-05-03 17:20:45233
[email protected]e76a3632012-03-15 20:56:27234 echo "N.B. the code for installing 32bit libraries on a 64bit"
235 echo " system is no longer actively maintained and might"
236 echo " not work with modern versions of Ubuntu or Debian."
237 echo
238
[email protected]b62f11e72010-05-03 17:20:45239 # Standard 32bit compatibility libraries
240 echo "First, installing the limited existing 32-bit support..."
[email protected]7cf14b372011-12-08 18:32:52241 cmp_list="ia32-libs lib32asound2-dev lib32stdc++6 lib32z1
[email protected]b62f11e72010-05-03 17:20:45242 lib32z1-dev libc6-dev-i386 libc6-i386 g++-multilib"
[email protected]7cf14b372011-12-08 18:32:52243 if [ -n "`apt-cache search lib32readline-gplv2-dev 2>/dev/null`" ]; then
244 cmp_list="${cmp_list} lib32readline-gplv2-dev"
245 else
246 cmp_list="${cmp_list} lib32readline5-dev"
247 fi
[email protected]a81e44e12010-05-17 21:16:53248 sudo apt-get install $cmp_list
[email protected]b62f11e72010-05-03 17:20:45249
[email protected]e041ed12009-03-10 16:43:01250 tmp=/tmp/install-32bit.$$
251 trap 'rm -rf "${tmp}"' EXIT INT TERM QUIT
252 mkdir -p "${tmp}/apt/lists/partial" "${tmp}/cache" "${tmp}/partial"
253 touch "${tmp}/status"
254
255 [ -r /etc/apt/apt.conf ] && cp /etc/apt/apt.conf "${tmp}/apt/"
[email protected]b6e064522009-08-10 18:47:51256 cat >>"${tmp}/apt/apt.conf" <<EOF
[email protected]79a9d2962009-08-06 21:10:58257 Apt::Architecture "i386";
258 Dir::Cache "${tmp}/cache";
259 Dir::Cache::Archives "${tmp}/";
260 Dir::State::Lists "${tmp}/apt/lists/";
261 Dir::State::status "${tmp}/status";
[email protected]b6e064522009-08-10 18:47:51262EOF
[email protected]1bf2ac972009-06-30 23:57:48263
[email protected]e041ed12009-03-10 16:43:01264 # Download 32bit packages
265 echo "Computing list of available 32bit packages..."
[email protected]a81e44e12010-05-17 21:16:53266 sudo apt-get -c="${tmp}/apt/apt.conf" update
[email protected]e041ed12009-03-10 16:43:01267
268 echo "Downloading available 32bit packages..."
[email protected]a81e44e12010-05-17 21:16:53269 sudo apt-get -c="${tmp}/apt/apt.conf" \
270 --yes --download-only --force-yes --reinstall install \
[email protected]e041ed12009-03-10 16:43:01271 ${lib_list} ${dbg_list}
272
273 # Open packages, remove everything that is not a library, move the
274 # library to a lib32 directory and package everything as a *.deb file.
275 echo "Repackaging and installing 32bit packages for use on 64bit systems..."
276 for i in ${lib_list} ${dbg_list}; do
277 orig="$(echo "${tmp}/${i}"_*_i386.deb)"
278 compat="$(echo "${orig}" |
279 sed -e 's,\(_[^_/]*_\)i386\(.deb\),-ia32\1amd64\2,')"
280 rm -rf "${tmp}/staging"
281 msg="$(fakeroot -u sh -exc '
282 # Unpack 32bit Debian archive
283 umask 022
284 mkdir -p "'"${tmp}"'/staging/dpkg/DEBIAN"
285 cd "'"${tmp}"'/staging"
286 ar x "'${orig}'"
287 tar zCfx dpkg data.tar.gz
288 tar zCfx dpkg/DEBIAN control.tar.gz
289
[email protected]34799f9d2010-07-08 17:51:33290 # Create a posix extended regular expression fragment that will
291 # recognize the includes which have changed. Should be rare,
292 # will almost always be empty.
293 includes=`sed -n -e "s/^[0-9a-z]* //g" \
294 -e "\,usr/include/,p" dpkg/DEBIAN/md5sums |
295 xargs -n 1 -I FILE /bin/sh -c \
296 "cmp -s dpkg/FILE /FILE || echo FILE" |
297 tr "\n" "|" |
298 sed -e "s,|$,,"`
[email protected]e041ed12009-03-10 16:43:01299
[email protected]34799f9d2010-07-08 17:51:33300 # If empty, set it to not match anything.
301 test -z "$includes" && includes="^//"
302
303 # Turn the conflicts into an extended RE for removal from the
304 # Provides line.
305 conflicts=`sed -n -e "/Conflicts/s/Conflicts: *//;T;s/, */|/g;p" \
306 dpkg/DEBIAN/control`
307
308 # Rename package, change architecture, remove conflicts and dependencies
309 sed -r -i \
310 -e "/Package/s/$/-ia32/" \
311 -e "/Architecture/s/:.*$/: amd64/" \
312 -e "/Depends/s/:.*/: ia32-libs/" \
313 -e "/Provides/s/($conflicts)(, *)?//g;T1;s/, *$//;:1" \
314 -e "/Recommends/d" \
315 -e "/Conflicts/d" \
316 dpkg/DEBIAN/control
317
318 # Only keep files that live in "lib" directories or the includes
319 # that have changed.
320 sed -r -i \
321 -e "/\/lib64\//d" -e "/\/.?bin\//d" \
322 -e "\,$includes,s,[ /]include/,&32/,g;s,include/32/,include32/,g" \
323 -e "s, lib/, lib32/,g" \
324 -e "s,/lib/,/lib32/,g" \
325 -e "t;d" \
326 -e "\,^/usr/lib32/debug\(.*/lib32\),s,^/usr/lib32/debug,/usr/lib/debug," \
327 dpkg/DEBIAN/md5sums
[email protected]e041ed12009-03-10 16:43:01328
329 # Re-run ldconfig after installation/removal
330 { echo "#!/bin/sh"; echo "[ \"x\$1\" = xconfigure ]&&ldconfig||:"; } \
331 >dpkg/DEBIAN/postinst
332 { echo "#!/bin/sh"; echo "[ \"x\$1\" = xremove ]&&ldconfig||:"; } \
333 >dpkg/DEBIAN/postrm
334 chmod 755 dpkg/DEBIAN/postinst dpkg/DEBIAN/postrm
335
336 # Remove any other control files
337 find dpkg/DEBIAN -mindepth 1 "(" -name control -o -name md5sums -o \
338 -name postinst -o -name postrm ")" -o -print |
339 xargs -r rm -rf
340
[email protected]34799f9d2010-07-08 17:51:33341 # Remove any files/dirs that live outside of "lib" directories,
342 # or are not in our list of changed includes.
343 find dpkg -mindepth 1 -regextype posix-extended \
344 "(" -name DEBIAN -o -name lib -o -regex "dpkg/($includes)" ")" \
345 -prune -o -print | tac |
346 xargs -r -n 1 sh -c "rm \$0 2>/dev/null || rmdir \$0 2>/dev/null || : "
[email protected]e041ed12009-03-10 16:43:01347 find dpkg -name lib64 -o -name bin -o -name "?bin" |
348 tac | xargs -r rm -rf
349
[email protected]34799f9d2010-07-08 17:51:33350 # Remove any symbolic links that were broken by the above steps.
351 find -L dpkg -type l -print | tac | xargs -r rm -rf
352
[email protected]e041ed12009-03-10 16:43:01353 # Rename lib to lib32, but keep debug symbols in /usr/lib/debug/usr/lib32
354 # That is where gdb looks for them.
355 find dpkg -type d -o -path "*/lib/*" -print |
356 xargs -r -n 1 sh -c "
357 i=\$(echo \"\${0}\" |
358 sed -e s,/lib/,/lib32/,g \
359 -e s,/usr/lib32/debug\\\\\(.*/lib32\\\\\),/usr/lib/debug\\\\1,);
360 mkdir -p \"\${i%/*}\";
361 mv \"\${0}\" \"\${i}\""
362
[email protected]34799f9d2010-07-08 17:51:33363 # Rename include to include32.
364 [ -d "dpkg/usr/include" ] && mv "dpkg/usr/include" "dpkg/usr/include32"
365
[email protected]e041ed12009-03-10 16:43:01366 # Prune any empty directories
367 find dpkg -type d | tac | xargs -r -n 1 rmdir 2>/dev/null || :
368
369 # Create our own Debian package
370 cd ..
371 dpkg --build staging/dpkg .' 2>&1)"
372 compat="$(eval echo $(echo "${compat}" |
373 sed -e 's,_[^_/]*_amd64.deb,_*_amd64.deb,'))"
374 [ -r "${compat}" ] || {
375 echo "${msg}" >&2
376 echo "Failed to build new Debian archive!" >&2
377 exit 1
378 }
379
380 msg="$(sudo dpkg -i "${compat}" 2>&1)" && {
381 echo "Installed ${compat##*/}"
382 } || {
383 # echo "${msg}" >&2
384 echo "Skipped ${compat##*/}"
385 }
386 done
387
388 # Add symbolic links for developing 32bit code
389 echo "Adding missing symbolic links, enabling 32bit code development..."
390 for i in $(find /lib32 /usr/lib32 -maxdepth 1 -name \*.so.\* |
391 sed -e 's/[.]so[.][0-9].*/.so/' |
392 sort -u); do
393 [ "x${i##*/}" = "xld-linux.so" ] && continue
394 [ -r "$i" ] && continue
395 j="$(ls "$i."* | sed -e 's/.*[.]so[.]\([^.]*\)$/\1/;t;d' |
396 sort -n | tail -n 1)"
397 [ -r "$i.$j" ] || continue
398 sudo ln -s "${i##*/}.$j" "$i"
399 done
400fi