blob: a7d5198162c8220c75329cdd1b6f5ad03630ff8d [file] [log] [blame]
[email protected]e041ed12009-03-10 16:43:011#!/bin/bash -e
2
[email protected]cf1df402008-10-31 21:45:303# Script to install everything needed to build chromium (well, ideally, anyway)
[email protected]592ea8ca2008-11-03 19:47:364# See http://code.google.com/p/chromium/wiki/LinuxBuildInstructions
5# and http://code.google.com/p/chromium/wiki/LinuxBuild64Bit
[email protected]cf1df402008-10-31 21:45:306
[email protected]c87aa982009-06-11 17:44:047install_gold() {
8 # Gold is optional; it's a faster replacement for ld,
9 # and makes life on 2GB machines much more pleasant.
10
[email protected]1bf2ac972009-06-30 23:57:4811 # First make sure root can access this directory, as that's tripped up some folks.
12 if sudo touch xyz.$$
13 then
14 sudo rm xyz.$$
15 else
16 echo root cannot write to the current directory, not installing gold
17 return
18 fi
19
[email protected]c87aa982009-06-11 17:44:0420 BINUTILS=binutils-2.19.1
21 BINUTILS_URL=http://ftp.gnu.org/gnu/binutils/$BINUTILS.tar.bz2
22 BINUTILS_SHA1=88c91e36cde93433e4c4c2b2e3417777aad84526
23
24 test -f $BINUTILS.tar.bz2 || wget $BINUTILS_URL
25 if `sha1sum $BINUTILS.tar.bz2` != $BINUTILS_SHA1
26 then
27 echo Bad sha1sum for $BINUTILS.tar.bz2
28 exit 1
29 fi
30 cat > binutils-fix.patch <<__EOF__
31--- binutils-2.19.1/gold/reduced_debug_output.h.orig 2009-05-10 14:44:52.000000000 -0700
32+++ binutils-2.19.1/gold/reduced_debug_output.h 2009-05-10 14:46:51.000000000 -0700
33@@ -64,7 +64,7 @@
34 void
35 failed(std::string reason)
36 {
37- gold_warning(reason.c_str());
38+ gold_warning("%s", reason.c_str());
39 failed_ = true;
40 }
41
42@@ -110,7 +110,7 @@
43 void
44 failed(std::string reason)
45 {
46- gold_warning(reason.c_str());
47+ gold_warning("%s", reason.c_str());
48 this->failed_ = true;
49 }
50
51__EOF__
52
53 tar -xjvf $BINUTILS.tar.bz2
54 cd $BINUTILS
55 patch -p1 < ../binutils-fix.patch
56 ./configure --prefix=/usr/local/gold --enable-gold
57 make -j3
[email protected]1bf2ac972009-06-30 23:57:4858 if sudo make install
59 then
60 # Still need to figure out graceful way of pointing gyp to use
61 # /usr/local/gold/bin/ld without requiring him to set environment
62 # variables. That will go into bootstrap-linux.sh when it's ready.
63 echo "Installing gold as /usr/bin/ld."
64 echo "To uninstall, do 'cd /usr/bin; sudo rm ld; sudo mv ld.orig ld'"
65 test -f /usr/bin/ld && sudo mv /usr/bin/ld /usr/bin/ld.orig
66 sudo ln -fs /usr/local/gold/bin/ld /usr/bin/ld.gold
67 sudo ln -fs /usr/bin/ld.gold /usr/bin/ld
68 else
69 echo "make install failed, not installing gold"
70 fi
[email protected]c87aa982009-06-11 17:44:0471}
72
[email protected]a79d5122009-04-27 21:01:1373if ! egrep -q "Ubuntu 8.04|Ubuntu 8.10|Ubuntu 9.04" /etc/issue; then
74 echo "Only Ubuntu 8.04, 8.10, and 9.04 are currently supported" >&2
[email protected]cf1df402008-10-31 21:45:3075 exit 1
76fi
[email protected]cf1df402008-10-31 21:45:3077
[email protected]e041ed12009-03-10 16:43:0178if ! uname -m | egrep -q "i686|x86_64"; then
79 echo "Only x86 architectures are currently supported" >&2
80 exit
81fi
82
83if [ "x$(id -u)" != x0 ]; then
84 echo "Running as non-root user."
85 echo "You might have to enter your password one or more times for 'sudo'."
[email protected]8ada8c52009-03-10 21:53:0886 echo
[email protected]e041ed12009-03-10 16:43:0187fi
88
89# Packages need for development
[email protected]c8975ad2009-05-13 00:33:2990dev_list="bison fakeroot flex g++ g++-multilib gperf libasound2-dev
91 libcairo2-dev libgconf2-dev libglib2.0-dev libgtk2.0-dev libnspr4-dev
92 libnss3-dev libsqlite3-dev lighttpd msttcorefonts perl php5-cgi
[email protected]c87aa982009-06-11 17:44:0493 pkg-config python subversion wdiff"
[email protected]e041ed12009-03-10 16:43:0194
95# Full list of required run-time libraries
[email protected]c8975ad2009-05-13 00:33:2996lib_list="libatk1.0-0 libc6 libasound2 libcairo2 libexpat1 libfontconfig1
97 libfreetype6 libglib2.0-0 libgtk2.0-0 libnspr4-0d libnss3-1d
98 libpango1.0-0 libpcre3 libpixman-1-0 libpng12-0 libstdc++6
[email protected]c87aa982009-06-11 17:44:0499 libsqlite3-0 libx11-6 libxau6 libxcb1 libxcomposite1
[email protected]c8975ad2009-05-13 00:33:29100 libxcursor1 libxdamage1 libxdmcp6 libxext6 libxfixes3 libxi6
101 libxinerama1 libxrandr2 libxrender1 zlib1g"
[email protected]e041ed12009-03-10 16:43:01102
103# Debugging symbols for all of the run-time libraries
104dbg_list="libatk1.0-dbg libc6-dbg libcairo2-dbg libfontconfig1-dbg
105 libglib2.0-0-dbg libgtk2.0-0-dbg libnspr4-0d-dbg libnss3-1d-dbg
106 libpango1.0-0-dbg libpcre3-dbg libpixman-1-0-dbg libx11-6-dbg
[email protected]c87aa982009-06-11 17:44:04107 libxau6-dbg libxcb1-dbg libxcomposite1-dbg
[email protected]e041ed12009-03-10 16:43:01108 libxcursor1-dbg libxdamage1-dbg libxdmcp6-dbg libxext6-dbg
109 libxfixes3-dbg libxi6-dbg libxinerama1-dbg libxrandr2-dbg
110 libxrender1-dbg zlib1g-dbg"
111
112# Standard 32bit compatibility libraries
[email protected]7670df02009-06-09 19:55:06113cmp_list="ia32-libs lib32asound2-dev lib32readline-dev lib32stdc++6 lib32z1
114 lib32z1-dev libc6-dev-i386 libc6-i386"
[email protected]e041ed12009-03-10 16:43:01115
[email protected]8ada8c52009-03-10 21:53:08116# Waits for the user to press 'Y' or 'N'. Either uppercase of lowercase is
117# accepted. Returns 0 for 'Y' and 1 for 'N'. If an optional parameter has
118# been provided to yes_no(), the function also accepts RETURN as a user input.
119# The parameter specifies the exit code that should be returned in that case.
120# The function will echo the user's selection followed by a newline character.
121# Users can abort the function by pressing CTRL-C. This will call "exit 1".
122yes_no() {
123 local c
124 while :; do
125 c="$(trap 'stty echo -iuclc icanon 2>/dev/null' EXIT INT TERM QUIT
126 stty -echo iuclc -icanon 2>/dev/null
127 dd count=1 bs=1 2>/dev/null | od -An -tx1)"
128 case "$c" in
129 " 0a") if [ -n "$1" ]; then
130 [ $1 -eq 0 ] && echo "Y" || echo "N"
131 return $1
132 fi
133 ;;
134 " 79") echo "Y"
135 return 0
136 ;;
137 " 6e") echo "N"
138 return 1
139 ;;
140 "") echo "Aborted" >&2
141 exit 1
142 ;;
143 *) # The user pressed an unrecognized key. As we are not echoing
144 # any incorrect user input, alert the user by ringing the bell.
145 (tput bel) 2>/dev/null
146 ;;
147 esac
148 done
149}
150
[email protected]c87aa982009-06-11 17:44:04151echo "This script installs all tools and libraries needed to build Chromium."
152echo ""
[email protected]8ada8c52009-03-10 21:53:08153echo "For most of the libraries, it can also install debugging symbols, which"
154echo "will allow you to debug code in the system libraries. Most developers"
155echo "won't need these symbols."
156echo -n "Do you want me to install them for you (y/N) "
157if yes_no 1; then
158 echo "Installing debugging symbols."
159else
160 echo "Skipping installation of debugging symbols."
161 dbg_list=
162fi
163
[email protected]e041ed12009-03-10 16:43:01164sudo apt-get update
165
166# We initially run "apt-get" with the --reinstall option and parse its output.
167# This way, we can find all the packages that need to be newly installed
168# without accidentally promoting any packages from "auto" to "manual".
169# We then re-run "apt-get" with just the list of missing packages.
170echo "Finding missing packages..."
[email protected]79a9d2962009-08-06 21:10:58171packages="${dev_list} ${lib_list} ${dbg_list}
172 $([ "$(uname -m)" = x86_64 ] && echo ${cmp_list})"
173echo "Packages required: $packages"
174new_list_cmd="sudo apt-get install --reinstall $(echo $packages)"
175if new_list="$(yes n | LANG=C $new_list_cmd)"
176then
177 echo "No missing packages, and the packages are up-to-date."
178elif [ $? -eq 1 ]
179then
180 # We expect apt-get to have exit status of 1.
181 # This indicates that we canceled the install with "yes n|".
182 new_list=$(echo $new_list |
183 sed -e '1,/The following NEW packages will be installed:/d;s/^ //;t;d')
184 echo "Installing missing packages: $new_list."
185 sudo apt-get install ${new_list}
186else
187 # An apt-get exit status of 100 indicates that a real error has occurred.
[email protected]e041ed12009-03-10 16:43:01188
[email protected]79a9d2962009-08-06 21:10:58189 # I am intentionally leaving out the '"'s around new_list_cmd,
190 # as this makes it easier to cut and paste the output
191 echo
192 echo "The following command failed: " ${new_list_cmd}
193 echo
194 echo "It produces the following output:"
195 yes n | $new_list_cmd || true
196 echo
197 echo "You will have to install the above packages yourself."
198 echo
199 exit 100
200fi
[email protected]e041ed12009-03-10 16:43:01201
[email protected]c87aa982009-06-11 17:44:04202# Some operating systems already ship gold
203# (on Debian, you can probably do "apt-get install binutils-gold" to get it),
204# but though Ubuntu toyed with shipping it, they haven't yet.
205# So just install from source if it isn't the default linker.
206
207case `ld --version` in
208*gold*) ;;
209* )
210 # FIXME: avoid installing as /usr/bin/ld
211 echo "Gold is a new linker that links Chrome 5x faster than ld."
212 echo "Don't use it if you need to link other apps (e.g. valgrind, wine)"
213 echo -n "REPLACE SYSTEM LINKER ld with gold and back up ld as ld.orig? (y/N) "
214 if yes_no 1; then
215 echo "Building binutils."
216 install_gold || exit 99
217 else
218 echo "Not installing gold."
219 fi
220esac
221
[email protected]e041ed12009-03-10 16:43:01222# Install 32bit backwards compatibility support for 64bit systems
223if [ "$(uname -m)" = x86_64 ]; then
224 echo "Installing 32bit libraries that are not already provided by the system"
[email protected]8ada8c52009-03-10 21:53:08225 echo
226 echo "While we only need to install a relatively small number of library"
227 echo "files, we temporarily need to download a lot of large *.deb packages"
228 echo "that contain these files. We will create new *.deb packages that"
229 echo "include just the 32bit libraries. These files will then be found on"
230 echo "your system in places like /lib32, /usr/lib32, /usr/lib/debug/lib32,"
231 echo "/usr/lib/debug/usr/lib32. If you ever need to uninstall these files,"
232 echo "look for packages named *-ia32.deb."
233 echo "Do you want me to download all packages needed to build new 32bit"
234 echo -n "package files (Y/n) "
235 if ! yes_no 0; then
236 echo "Exiting without installing any 32bit libraries."
237 exit 0
238 fi
[email protected]e041ed12009-03-10 16:43:01239 tmp=/tmp/install-32bit.$$
240 trap 'rm -rf "${tmp}"' EXIT INT TERM QUIT
241 mkdir -p "${tmp}/apt/lists/partial" "${tmp}/cache" "${tmp}/partial"
242 touch "${tmp}/status"
243
244 [ -r /etc/apt/apt.conf ] && cp /etc/apt/apt.conf "${tmp}/apt/"
245 cat >>"${tmp}/apt/apt.conf" <<-EOF
[email protected]79a9d2962009-08-06 21:10:58246 Apt::Architecture "i386";
247 Dir::Cache "${tmp}/cache";
248 Dir::Cache::Archives "${tmp}/";
249 Dir::State::Lists "${tmp}/apt/lists/";
250 Dir::State::status "${tmp}/status";
251 EOF
[email protected]1bf2ac972009-06-30 23:57:48252
[email protected]e041ed12009-03-10 16:43:01253 # Download 32bit packages
254 echo "Computing list of available 32bit packages..."
255 apt-get -c="${tmp}/apt/apt.conf" update
256
257 echo "Downloading available 32bit packages..."
258 apt-get -c="${tmp}/apt/apt.conf" \
259 --yes --download-only --force-yes --reinstall install \
260 ${lib_list} ${dbg_list}
261
262 # Open packages, remove everything that is not a library, move the
263 # library to a lib32 directory and package everything as a *.deb file.
264 echo "Repackaging and installing 32bit packages for use on 64bit systems..."
265 for i in ${lib_list} ${dbg_list}; do
266 orig="$(echo "${tmp}/${i}"_*_i386.deb)"
267 compat="$(echo "${orig}" |
268 sed -e 's,\(_[^_/]*_\)i386\(.deb\),-ia32\1amd64\2,')"
269 rm -rf "${tmp}/staging"
270 msg="$(fakeroot -u sh -exc '
271 # Unpack 32bit Debian archive
272 umask 022
273 mkdir -p "'"${tmp}"'/staging/dpkg/DEBIAN"
274 cd "'"${tmp}"'/staging"
275 ar x "'${orig}'"
276 tar zCfx dpkg data.tar.gz
277 tar zCfx dpkg/DEBIAN control.tar.gz
278
279 # Rename package, change architecture, remove dependencies
280 sed -i -e "s/\(Package:.*\)/\1-ia32/" \
281 -e "s/\(Architecture:\).*/\1 amd64/" \
282 -e "s/\(Depends:\).*/\1 ia32-libs/" \
283 -e "/Recommends/d" \
284 -e "/Conflicts/d" \
285 dpkg/DEBIAN/control
286
287 # Only keep files that live in "lib" directories
288 sed -i -e "/\/lib64\//d" -e "/\/.?bin\//d" \
289 -e "s,\([ /]lib\)/,\132/g,;t1;d;:1" \
290 -e "s,^/usr/lib32/debug\(.*/lib32\),/usr/lib/debug\1," \
291 dpkg/DEBIAN/md5sums
292
293 # Re-run ldconfig after installation/removal
294 { echo "#!/bin/sh"; echo "[ \"x\$1\" = xconfigure ]&&ldconfig||:"; } \
295 >dpkg/DEBIAN/postinst
296 { echo "#!/bin/sh"; echo "[ \"x\$1\" = xremove ]&&ldconfig||:"; } \
297 >dpkg/DEBIAN/postrm
298 chmod 755 dpkg/DEBIAN/postinst dpkg/DEBIAN/postrm
299
300 # Remove any other control files
301 find dpkg/DEBIAN -mindepth 1 "(" -name control -o -name md5sums -o \
302 -name postinst -o -name postrm ")" -o -print |
303 xargs -r rm -rf
304
305 # Remove any files/dirs that live outside of "lib" directories
306 find dpkg -mindepth 1 "(" -name DEBIAN -o -name lib ")" -prune -o \
307 -print | tac | xargs -r -n 1 sh -c \
308 "rm \$0 2>/dev/null || rmdir \$0 2>/dev/null || : "
309 find dpkg -name lib64 -o -name bin -o -name "?bin" |
310 tac | xargs -r rm -rf
311
312 # Rename lib to lib32, but keep debug symbols in /usr/lib/debug/usr/lib32
313 # That is where gdb looks for them.
314 find dpkg -type d -o -path "*/lib/*" -print |
315 xargs -r -n 1 sh -c "
316 i=\$(echo \"\${0}\" |
317 sed -e s,/lib/,/lib32/,g \
318 -e s,/usr/lib32/debug\\\\\(.*/lib32\\\\\),/usr/lib/debug\\\\1,);
319 mkdir -p \"\${i%/*}\";
320 mv \"\${0}\" \"\${i}\""
321
322 # Prune any empty directories
323 find dpkg -type d | tac | xargs -r -n 1 rmdir 2>/dev/null || :
324
325 # Create our own Debian package
326 cd ..
327 dpkg --build staging/dpkg .' 2>&1)"
328 compat="$(eval echo $(echo "${compat}" |
329 sed -e 's,_[^_/]*_amd64.deb,_*_amd64.deb,'))"
330 [ -r "${compat}" ] || {
331 echo "${msg}" >&2
332 echo "Failed to build new Debian archive!" >&2
333 exit 1
334 }
335
336 msg="$(sudo dpkg -i "${compat}" 2>&1)" && {
337 echo "Installed ${compat##*/}"
338 } || {
339 # echo "${msg}" >&2
340 echo "Skipped ${compat##*/}"
341 }
342 done
343
344 # Add symbolic links for developing 32bit code
345 echo "Adding missing symbolic links, enabling 32bit code development..."
346 for i in $(find /lib32 /usr/lib32 -maxdepth 1 -name \*.so.\* |
347 sed -e 's/[.]so[.][0-9].*/.so/' |
348 sort -u); do
349 [ "x${i##*/}" = "xld-linux.so" ] && continue
350 [ -r "$i" ] && continue
351 j="$(ls "$i."* | sed -e 's/.*[.]so[.]\([^.]*\)$/\1/;t;d' |
352 sort -n | tail -n 1)"
353 [ -r "$i.$j" ] || continue
354 sudo ln -s "${i##*/}.$j" "$i"
355 done
356fi