blob: 9b61d8b2ca6ac183fe2ea99ab564a1724f69636d [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
11 BINUTILS=binutils-2.19.1
12 BINUTILS_URL=http://ftp.gnu.org/gnu/binutils/$BINUTILS.tar.bz2
13 BINUTILS_SHA1=88c91e36cde93433e4c4c2b2e3417777aad84526
14
15 test -f $BINUTILS.tar.bz2 || wget $BINUTILS_URL
16 if `sha1sum $BINUTILS.tar.bz2` != $BINUTILS_SHA1
17 then
18 echo Bad sha1sum for $BINUTILS.tar.bz2
19 exit 1
20 fi
21 cat > binutils-fix.patch <<__EOF__
22--- binutils-2.19.1/gold/reduced_debug_output.h.orig 2009-05-10 14:44:52.000000000 -0700
23+++ binutils-2.19.1/gold/reduced_debug_output.h 2009-05-10 14:46:51.000000000 -0700
24@@ -64,7 +64,7 @@
25 void
26 failed(std::string reason)
27 {
28- gold_warning(reason.c_str());
29+ gold_warning("%s", reason.c_str());
30 failed_ = true;
31 }
32
33@@ -110,7 +110,7 @@
34 void
35 failed(std::string reason)
36 {
37- gold_warning(reason.c_str());
38+ gold_warning("%s", reason.c_str());
39 this->failed_ = true;
40 }
41
42__EOF__
43
44 tar -xjvf $BINUTILS.tar.bz2
45 cd $BINUTILS
46 patch -p1 < ../binutils-fix.patch
47 ./configure --prefix=/usr/local/gold --enable-gold
48 make -j3
49 sudo make install
50
51 # Still need to figure out graceful way of pointing gyp to use
52 # /usr/local/gold/bin/ld without requiring him to set environment
53 # variables. That will go into bootstrap-linux.sh when it's ready.
54 echo "Installing gold as /usr/bin/ld."
55 echo "To uninstall, do 'cd /usr/bin; sudo rm ld; sudo mv ld.orig ld'"
56 test -f /usr/bin/ld && sudo mv /usr/bin/ld /usr/bin/ld.orig
57 sudo ln -fs /usr/local/gold/bin/ld /usr/bin/ld.gold
58 sudo ln -fs /usr/bin/ld.gold /usr/bin/ld
59}
60
[email protected]a79d5122009-04-27 21:01:1361if ! egrep -q "Ubuntu 8.04|Ubuntu 8.10|Ubuntu 9.04" /etc/issue; then
62 echo "Only Ubuntu 8.04, 8.10, and 9.04 are currently supported" >&2
[email protected]cf1df402008-10-31 21:45:3063 exit 1
64fi
[email protected]cf1df402008-10-31 21:45:3065
[email protected]e041ed12009-03-10 16:43:0166if ! uname -m | egrep -q "i686|x86_64"; then
67 echo "Only x86 architectures are currently supported" >&2
68 exit
69fi
70
71if [ "x$(id -u)" != x0 ]; then
72 echo "Running as non-root user."
73 echo "You might have to enter your password one or more times for 'sudo'."
[email protected]8ada8c52009-03-10 21:53:0874 echo
[email protected]e041ed12009-03-10 16:43:0175fi
76
77# Packages need for development
[email protected]c8975ad2009-05-13 00:33:2978dev_list="bison fakeroot flex g++ g++-multilib gperf libasound2-dev
79 libcairo2-dev libgconf2-dev libglib2.0-dev libgtk2.0-dev libnspr4-dev
80 libnss3-dev libsqlite3-dev lighttpd msttcorefonts perl php5-cgi
[email protected]c87aa982009-06-11 17:44:0481 pkg-config python subversion wdiff"
[email protected]e041ed12009-03-10 16:43:0182
83# Full list of required run-time libraries
[email protected]c8975ad2009-05-13 00:33:2984lib_list="libatk1.0-0 libc6 libasound2 libcairo2 libexpat1 libfontconfig1
85 libfreetype6 libglib2.0-0 libgtk2.0-0 libnspr4-0d libnss3-1d
86 libpango1.0-0 libpcre3 libpixman-1-0 libpng12-0 libstdc++6
[email protected]c87aa982009-06-11 17:44:0487 libsqlite3-0 libx11-6 libxau6 libxcb1 libxcomposite1
[email protected]c8975ad2009-05-13 00:33:2988 libxcursor1 libxdamage1 libxdmcp6 libxext6 libxfixes3 libxi6
89 libxinerama1 libxrandr2 libxrender1 zlib1g"
[email protected]e041ed12009-03-10 16:43:0190
91# Debugging symbols for all of the run-time libraries
92dbg_list="libatk1.0-dbg libc6-dbg libcairo2-dbg libfontconfig1-dbg
93 libglib2.0-0-dbg libgtk2.0-0-dbg libnspr4-0d-dbg libnss3-1d-dbg
94 libpango1.0-0-dbg libpcre3-dbg libpixman-1-0-dbg libx11-6-dbg
[email protected]c87aa982009-06-11 17:44:0495 libxau6-dbg libxcb1-dbg libxcomposite1-dbg
[email protected]e041ed12009-03-10 16:43:0196 libxcursor1-dbg libxdamage1-dbg libxdmcp6-dbg libxext6-dbg
97 libxfixes3-dbg libxi6-dbg libxinerama1-dbg libxrandr2-dbg
98 libxrender1-dbg zlib1g-dbg"
99
100# Standard 32bit compatibility libraries
[email protected]7670df02009-06-09 19:55:06101cmp_list="ia32-libs lib32asound2-dev lib32readline-dev lib32stdc++6 lib32z1
102 lib32z1-dev libc6-dev-i386 libc6-i386"
[email protected]e041ed12009-03-10 16:43:01103
[email protected]8ada8c52009-03-10 21:53:08104# Waits for the user to press 'Y' or 'N'. Either uppercase of lowercase is
105# accepted. Returns 0 for 'Y' and 1 for 'N'. If an optional parameter has
106# been provided to yes_no(), the function also accepts RETURN as a user input.
107# The parameter specifies the exit code that should be returned in that case.
108# The function will echo the user's selection followed by a newline character.
109# Users can abort the function by pressing CTRL-C. This will call "exit 1".
110yes_no() {
111 local c
112 while :; do
113 c="$(trap 'stty echo -iuclc icanon 2>/dev/null' EXIT INT TERM QUIT
114 stty -echo iuclc -icanon 2>/dev/null
115 dd count=1 bs=1 2>/dev/null | od -An -tx1)"
116 case "$c" in
117 " 0a") if [ -n "$1" ]; then
118 [ $1 -eq 0 ] && echo "Y" || echo "N"
119 return $1
120 fi
121 ;;
122 " 79") echo "Y"
123 return 0
124 ;;
125 " 6e") echo "N"
126 return 1
127 ;;
128 "") echo "Aborted" >&2
129 exit 1
130 ;;
131 *) # The user pressed an unrecognized key. As we are not echoing
132 # any incorrect user input, alert the user by ringing the bell.
133 (tput bel) 2>/dev/null
134 ;;
135 esac
136 done
137}
138
[email protected]c87aa982009-06-11 17:44:04139echo "This script installs all tools and libraries needed to build Chromium."
140echo ""
[email protected]8ada8c52009-03-10 21:53:08141echo "For most of the libraries, it can also install debugging symbols, which"
142echo "will allow you to debug code in the system libraries. Most developers"
143echo "won't need these symbols."
144echo -n "Do you want me to install them for you (y/N) "
145if yes_no 1; then
146 echo "Installing debugging symbols."
147else
148 echo "Skipping installation of debugging symbols."
149 dbg_list=
150fi
151
[email protected]e041ed12009-03-10 16:43:01152sudo apt-get update
153
154# We initially run "apt-get" with the --reinstall option and parse its output.
155# This way, we can find all the packages that need to be newly installed
156# without accidentally promoting any packages from "auto" to "manual".
157# We then re-run "apt-get" with just the list of missing packages.
158echo "Finding missing packages..."
159new_list="$(yes n |
[email protected]74a34ad62009-04-22 18:04:33160 LANG=C sudo apt-get install --reinstall \
[email protected]343b7212009-04-03 01:58:48161 ${dev_list} ${lib_list} ${dbg_list} \
[email protected]e041ed12009-03-10 16:43:01162 $([ "$(uname -m)" = x86_64 ] && echo ${cmp_list}) \
[email protected]c87aa982009-06-11 17:44:04163 |
[email protected]74a34ad62009-04-22 18:04:33164 sed -e '1,/The following NEW packages will be installed:/d;s/^ //;t;d')"
[email protected]e041ed12009-03-10 16:43:01165
166echo "Installing missing packages..."
167sudo apt-get install ${new_list}
168
[email protected]c87aa982009-06-11 17:44:04169# Some operating systems already ship gold
170# (on Debian, you can probably do "apt-get install binutils-gold" to get it),
171# but though Ubuntu toyed with shipping it, they haven't yet.
172# So just install from source if it isn't the default linker.
173
174case `ld --version` in
175*gold*) ;;
176* )
177 # FIXME: avoid installing as /usr/bin/ld
178 echo "Gold is a new linker that links Chrome 5x faster than ld."
179 echo "Don't use it if you need to link other apps (e.g. valgrind, wine)"
180 echo -n "REPLACE SYSTEM LINKER ld with gold and back up ld as ld.orig? (y/N) "
181 if yes_no 1; then
182 echo "Building binutils."
183 install_gold || exit 99
184 else
185 echo "Not installing gold."
186 fi
187esac
188
[email protected]e041ed12009-03-10 16:43:01189# Install 32bit backwards compatibility support for 64bit systems
190if [ "$(uname -m)" = x86_64 ]; then
191 echo "Installing 32bit libraries that are not already provided by the system"
[email protected]8ada8c52009-03-10 21:53:08192 echo
193 echo "While we only need to install a relatively small number of library"
194 echo "files, we temporarily need to download a lot of large *.deb packages"
195 echo "that contain these files. We will create new *.deb packages that"
196 echo "include just the 32bit libraries. These files will then be found on"
197 echo "your system in places like /lib32, /usr/lib32, /usr/lib/debug/lib32,"
198 echo "/usr/lib/debug/usr/lib32. If you ever need to uninstall these files,"
199 echo "look for packages named *-ia32.deb."
200 echo "Do you want me to download all packages needed to build new 32bit"
201 echo -n "package files (Y/n) "
202 if ! yes_no 0; then
203 echo "Exiting without installing any 32bit libraries."
204 exit 0
205 fi
[email protected]e041ed12009-03-10 16:43:01206 tmp=/tmp/install-32bit.$$
207 trap 'rm -rf "${tmp}"' EXIT INT TERM QUIT
208 mkdir -p "${tmp}/apt/lists/partial" "${tmp}/cache" "${tmp}/partial"
209 touch "${tmp}/status"
210
211 [ -r /etc/apt/apt.conf ] && cp /etc/apt/apt.conf "${tmp}/apt/"
212 cat >>"${tmp}/apt/apt.conf" <<-EOF
213 Apt::Architecture "i386";
214 Dir::Cache "${tmp}/cache";
215 Dir::Cache::Archives "${tmp}/";
216 Dir::State::Lists "${tmp}/apt/lists/";
217 Dir::State::status "${tmp}/status";
218 EOF
219
220 # Download 32bit packages
221 echo "Computing list of available 32bit packages..."
222 apt-get -c="${tmp}/apt/apt.conf" update
223
224 echo "Downloading available 32bit packages..."
225 apt-get -c="${tmp}/apt/apt.conf" \
226 --yes --download-only --force-yes --reinstall install \
227 ${lib_list} ${dbg_list}
228
229 # Open packages, remove everything that is not a library, move the
230 # library to a lib32 directory and package everything as a *.deb file.
231 echo "Repackaging and installing 32bit packages for use on 64bit systems..."
232 for i in ${lib_list} ${dbg_list}; do
233 orig="$(echo "${tmp}/${i}"_*_i386.deb)"
234 compat="$(echo "${orig}" |
235 sed -e 's,\(_[^_/]*_\)i386\(.deb\),-ia32\1amd64\2,')"
236 rm -rf "${tmp}/staging"
237 msg="$(fakeroot -u sh -exc '
238 # Unpack 32bit Debian archive
239 umask 022
240 mkdir -p "'"${tmp}"'/staging/dpkg/DEBIAN"
241 cd "'"${tmp}"'/staging"
242 ar x "'${orig}'"
243 tar zCfx dpkg data.tar.gz
244 tar zCfx dpkg/DEBIAN control.tar.gz
245
246 # Rename package, change architecture, remove dependencies
247 sed -i -e "s/\(Package:.*\)/\1-ia32/" \
248 -e "s/\(Architecture:\).*/\1 amd64/" \
249 -e "s/\(Depends:\).*/\1 ia32-libs/" \
250 -e "/Recommends/d" \
251 -e "/Conflicts/d" \
252 dpkg/DEBIAN/control
253
254 # Only keep files that live in "lib" directories
255 sed -i -e "/\/lib64\//d" -e "/\/.?bin\//d" \
256 -e "s,\([ /]lib\)/,\132/g,;t1;d;:1" \
257 -e "s,^/usr/lib32/debug\(.*/lib32\),/usr/lib/debug\1," \
258 dpkg/DEBIAN/md5sums
259
260 # Re-run ldconfig after installation/removal
261 { echo "#!/bin/sh"; echo "[ \"x\$1\" = xconfigure ]&&ldconfig||:"; } \
262 >dpkg/DEBIAN/postinst
263 { echo "#!/bin/sh"; echo "[ \"x\$1\" = xremove ]&&ldconfig||:"; } \
264 >dpkg/DEBIAN/postrm
265 chmod 755 dpkg/DEBIAN/postinst dpkg/DEBIAN/postrm
266
267 # Remove any other control files
268 find dpkg/DEBIAN -mindepth 1 "(" -name control -o -name md5sums -o \
269 -name postinst -o -name postrm ")" -o -print |
270 xargs -r rm -rf
271
272 # Remove any files/dirs that live outside of "lib" directories
273 find dpkg -mindepth 1 "(" -name DEBIAN -o -name lib ")" -prune -o \
274 -print | tac | xargs -r -n 1 sh -c \
275 "rm \$0 2>/dev/null || rmdir \$0 2>/dev/null || : "
276 find dpkg -name lib64 -o -name bin -o -name "?bin" |
277 tac | xargs -r rm -rf
278
279 # Rename lib to lib32, but keep debug symbols in /usr/lib/debug/usr/lib32
280 # That is where gdb looks for them.
281 find dpkg -type d -o -path "*/lib/*" -print |
282 xargs -r -n 1 sh -c "
283 i=\$(echo \"\${0}\" |
284 sed -e s,/lib/,/lib32/,g \
285 -e s,/usr/lib32/debug\\\\\(.*/lib32\\\\\),/usr/lib/debug\\\\1,);
286 mkdir -p \"\${i%/*}\";
287 mv \"\${0}\" \"\${i}\""
288
289 # Prune any empty directories
290 find dpkg -type d | tac | xargs -r -n 1 rmdir 2>/dev/null || :
291
292 # Create our own Debian package
293 cd ..
294 dpkg --build staging/dpkg .' 2>&1)"
295 compat="$(eval echo $(echo "${compat}" |
296 sed -e 's,_[^_/]*_amd64.deb,_*_amd64.deb,'))"
297 [ -r "${compat}" ] || {
298 echo "${msg}" >&2
299 echo "Failed to build new Debian archive!" >&2
300 exit 1
301 }
302
303 msg="$(sudo dpkg -i "${compat}" 2>&1)" && {
304 echo "Installed ${compat##*/}"
305 } || {
306 # echo "${msg}" >&2
307 echo "Skipped ${compat##*/}"
308 }
309 done
310
311 # Add symbolic links for developing 32bit code
312 echo "Adding missing symbolic links, enabling 32bit code development..."
313 for i in $(find /lib32 /usr/lib32 -maxdepth 1 -name \*.so.\* |
314 sed -e 's/[.]so[.][0-9].*/.so/' |
315 sort -u); do
316 [ "x${i##*/}" = "xld-linux.so" ] && continue
317 [ -r "$i" ] && continue
318 j="$(ls "$i."* | sed -e 's/.*[.]so[.]\([^.]*\)$/\1/;t;d' |
319 sort -n | tail -n 1)"
320 [ -r "$i.$j" ] || continue
321 sudo ln -s "${i##*/}.$j" "$i"
322 done
323fi