[email protected] | e041ed1 | 2009-03-10 16:43:01 | [diff] [blame] | 1 | #!/bin/bash -e |
| 2 | |
[email protected] | e46cdae | 2009-08-25 20:59:27 | [diff] [blame] | 3 | # Copyright (c) 2009 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 | |
[email protected] | cf1df40 | 2008-10-31 21:45:30 | [diff] [blame] | 7 | # Script to install everything needed to build chromium (well, ideally, anyway) |
[email protected] | 592ea8ca | 2008-11-03 19:47:36 | [diff] [blame] | 8 | # See http://code.google.com/p/chromium/wiki/LinuxBuildInstructions |
| 9 | # and http://code.google.com/p/chromium/wiki/LinuxBuild64Bit |
[email protected] | cf1df40 | 2008-10-31 21:45:30 | [diff] [blame] | 10 | |
[email protected] | 1eae2bfb | 2010-01-26 18:17:53 | [diff] [blame] | 11 | usage() { |
| 12 | echo "Usage: $0 [--options]" |
| 13 | echo "Options:" |
| 14 | echo "--[no-]syms: enable or disable installation of debugging symbols" |
| 15 | echo "--[no-]gold: enable or disable installation of gold linker" |
| 16 | echo "--[no-]lib32: enable or disable installation of 32 bit libraries" |
| 17 | echo "Script will prompt interactively if options not given." |
| 18 | exit 1 |
| 19 | } |
| 20 | |
| 21 | while test "$1" != "" |
| 22 | do |
| 23 | case "$1" in |
| 24 | --syms) do_inst_syms=1;; |
| 25 | --no-syms) do_inst_syms=0;; |
| 26 | --gold) do_inst_gold=1;; |
| 27 | --no-gold) do_inst_gold=0;; |
| 28 | --lib32) do_inst_lib32=1;; |
| 29 | --no-lib32) do_inst_lib32=0;; |
| 30 | *) usage;; |
| 31 | esac |
| 32 | shift |
| 33 | done |
| 34 | |
[email protected] | c87aa98 | 2009-06-11 17:44:04 | [diff] [blame] | 35 | install_gold() { |
| 36 | # Gold is optional; it's a faster replacement for ld, |
| 37 | # and makes life on 2GB machines much more pleasant. |
| 38 | |
[email protected] | b62f11e7 | 2010-05-03 17:20:45 | [diff] [blame] | 39 | # First make sure root can access this directory, as that's tripped |
| 40 | # up some folks. |
[email protected] | 1bf2ac97 | 2009-06-30 23:57:48 | [diff] [blame] | 41 | if sudo touch xyz.$$ |
| 42 | then |
| 43 | sudo rm xyz.$$ |
| 44 | else |
| 45 | echo root cannot write to the current directory, not installing gold |
| 46 | return |
| 47 | fi |
| 48 | |
[email protected] | ae0637b | 2010-06-30 17:07:56 | [diff] [blame] | 49 | BINUTILS=binutils-2.20.1 |
[email protected] | c87aa98 | 2009-06-11 17:44:04 | [diff] [blame] | 50 | BINUTILS_URL=http://ftp.gnu.org/gnu/binutils/$BINUTILS.tar.bz2 |
[email protected] | ae0637b | 2010-06-30 17:07:56 | [diff] [blame] | 51 | BINUTILS_SHA1=fd2ba806e6f3a55cee453cb25c86991b26a75dee |
[email protected] | c87aa98 | 2009-06-11 17:44:04 | [diff] [blame] | 52 | |
| 53 | test -f $BINUTILS.tar.bz2 || wget $BINUTILS_URL |
[email protected] | d42915d4 | 2009-11-18 10:36:46 | [diff] [blame] | 54 | if test "`sha1sum $BINUTILS.tar.bz2|cut -d' ' -f1`" != "$BINUTILS_SHA1" |
[email protected] | c87aa98 | 2009-06-11 17:44:04 | [diff] [blame] | 55 | then |
| 56 | echo Bad sha1sum for $BINUTILS.tar.bz2 |
| 57 | exit 1 |
| 58 | fi |
[email protected] | 0b53eb0 | 2009-09-23 22:22:47 | [diff] [blame] | 59 | |
[email protected] | c87aa98 | 2009-06-11 17:44:04 | [diff] [blame] | 60 | tar -xjvf $BINUTILS.tar.bz2 |
| 61 | cd $BINUTILS |
[email protected] | c87aa98 | 2009-06-11 17:44:04 | [diff] [blame] | 62 | ./configure --prefix=/usr/local/gold --enable-gold |
[email protected] | 80e0c630 | 2011-02-11 22:11:31 | [diff] [blame] | 63 | make maybe-all-binutils maybe-all-gold -j4 |
| 64 | if sudo make maybe-install-binutils maybe-install-gold |
[email protected] | 1bf2ac97 | 2009-06-30 23:57:48 | [diff] [blame] | 65 | then |
| 66 | # Still need to figure out graceful way of pointing gyp to use |
| 67 | # /usr/local/gold/bin/ld without requiring him to set environment |
| 68 | # variables. That will go into bootstrap-linux.sh when it's ready. |
| 69 | echo "Installing gold as /usr/bin/ld." |
| 70 | echo "To uninstall, do 'cd /usr/bin; sudo rm ld; sudo mv ld.orig ld'" |
[email protected] | 803c45c5 | 2009-11-18 10:58:00 | [diff] [blame] | 71 | test -f /usr/bin/ld && test ! -f /usr/bin/ld.orig && \ |
| 72 | sudo mv /usr/bin/ld /usr/bin/ld.orig |
[email protected] | b2e24bd | 2009-09-10 17:45:39 | [diff] [blame] | 73 | sudo strip /usr/local/gold/bin/ld |
[email protected] | 1bf2ac97 | 2009-06-30 23:57:48 | [diff] [blame] | 74 | sudo ln -fs /usr/local/gold/bin/ld /usr/bin/ld.gold |
| 75 | sudo ln -fs /usr/bin/ld.gold /usr/bin/ld |
| 76 | else |
| 77 | echo "make install failed, not installing gold" |
| 78 | fi |
[email protected] | c87aa98 | 2009-06-11 17:44:04 | [diff] [blame] | 79 | } |
| 80 | |
[email protected] | a51551d | 2010-07-15 22:59:48 | [diff] [blame] | 81 | if ! egrep -q \ |
| 82 | 'Ubuntu (8\.04|8\.10|9\.04|9\.10|10\.04|10\.10|karmic|lucid|maverick)' \ |
| 83 | /etc/issue; then |
| 84 | echo "Only Ubuntu 8.04 (hardy) through 10.10 (maverick) are currently" \ |
| 85 | "supported" >&2 |
[email protected] | cf1df40 | 2008-10-31 21:45:30 | [diff] [blame] | 86 | exit 1 |
| 87 | fi |
[email protected] | cf1df40 | 2008-10-31 21:45:30 | [diff] [blame] | 88 | |
[email protected] | e041ed1 | 2009-03-10 16:43:01 | [diff] [blame] | 89 | if ! uname -m | egrep -q "i686|x86_64"; then |
| 90 | echo "Only x86 architectures are currently supported" >&2 |
| 91 | exit |
| 92 | fi |
| 93 | |
| 94 | if [ "x$(id -u)" != x0 ]; then |
| 95 | echo "Running as non-root user." |
| 96 | echo "You might have to enter your password one or more times for 'sudo'." |
[email protected] | 8ada8c5 | 2009-03-10 21:53:08 | [diff] [blame] | 97 | echo |
[email protected] | e041ed1 | 2009-03-10 16:43:01 | [diff] [blame] | 98 | fi |
| 99 | |
[email protected] | fdc6bf5 | 2010-06-07 22:01:57 | [diff] [blame] | 100 | # Packages needed for chromeos only |
| 101 | chromeos_dev_list="libpulse-dev" |
| 102 | |
[email protected] | e041ed1 | 2009-03-10 16:43:01 | [diff] [blame] | 103 | # Packages need for development |
[email protected] | b62f11e7 | 2010-05-03 17:20:45 | [diff] [blame] | 104 | dev_list="apache2 bison fakeroot flex g++ gperf libapache2-mod-php5 |
[email protected] | cd03d82 | 2010-05-13 21:11:20 | [diff] [blame] | 105 | libasound2-dev libbz2-dev libcairo2-dev libdbus-glib-1-dev |
| 106 | libgconf2-dev libgl1-mesa-dev libglu1-mesa-dev libglib2.0-dev |
[email protected] | ce940f0 | 2010-06-07 22:34:40 | [diff] [blame] | 107 | libgnome-keyring-dev libgtk2.0-dev libjpeg62-dev libnspr4-dev |
| 108 | libnss3-dev libpam0g-dev libsqlite3-dev libxslt1-dev libxss-dev |
[email protected] | 9dc4bed | 2010-11-04 19:23:30 | [diff] [blame] | 109 | libxtst-dev lighttpd mesa-common-dev msttcorefonts patch perl |
| 110 | php5-cgi pkg-config python python-dev rpm subversion ttf-dejavu-core |
| 111 | ttf-kochi-gothic ttf-kochi-mincho wdiff libcurl4-gnutls-dev |
| 112 | $chromeos_dev_list" |
[email protected] | fdc6bf5 | 2010-06-07 22:01:57 | [diff] [blame] | 113 | |
| 114 | # Run-time libraries required by chromeos only |
[email protected] | 34799f9d | 2010-07-08 17:51:33 | [diff] [blame] | 115 | chromeos_lib_list="libpulse0 libbz2-1.0 libcurl4-gnutls-dev" |
[email protected] | e041ed1 | 2009-03-10 16:43:01 | [diff] [blame] | 116 | |
| 117 | # Full list of required run-time libraries |
[email protected] | e3212ba | 2010-03-11 15:27:24 | [diff] [blame] | 118 | lib_list="libatk1.0-0 libc6 libasound2 libcairo2 libdbus-glib-1-2 libexpat1 |
[email protected] | ce940f0 | 2010-06-07 22:34:40 | [diff] [blame] | 119 | libfontconfig1 libfreetype6 libglib2.0-0 libgnome-keyring0 libgtk2.0-0 |
[email protected] | fd11101b | 2011-02-16 04:46:46 | [diff] [blame] | 120 | libnspr4-0d libnss3-1d libpam0g libpango1.0-0 libpcre3 libpixman-1-0 |
| 121 | libpng12-0 libstdc++6 libsqlite3-0 libx11-6 libxau6 libxcb1 |
| 122 | libxcomposite1 libxcursor1 libxdamage1 libxdmcp6 libxext6 libxfixes3 |
| 123 | libxi6 libxinerama1 libxrandr2 libxrender1 libxtst6 zlib1g |
[email protected] | 9dc4bed | 2010-11-04 19:23:30 | [diff] [blame] | 124 | $chromeos_lib_list" |
[email protected] | e041ed1 | 2009-03-10 16:43:01 | [diff] [blame] | 125 | |
| 126 | # Debugging symbols for all of the run-time libraries |
[email protected] | 8442146 | 2010-03-11 17:20:25 | [diff] [blame] | 127 | dbg_list="libatk1.0-dbg libc6-dbg libcairo2-dbg |
[email protected] | e759c4b | 2010-03-10 19:04:58 | [diff] [blame] | 128 | libfontconfig1-dbg libglib2.0-0-dbg libgtk2.0-0-dbg libnspr4-0d-dbg |
| 129 | libnss3-1d-dbg libpango1.0-0-dbg libpcre3-dbg libpixman-1-0-dbg |
| 130 | libx11-6-dbg libxau6-dbg libxcb1-dbg libxcomposite1-dbg |
[email protected] | e041ed1 | 2009-03-10 16:43:01 | [diff] [blame] | 131 | libxcursor1-dbg libxdamage1-dbg libxdmcp6-dbg libxext6-dbg |
| 132 | libxfixes3-dbg libxi6-dbg libxinerama1-dbg libxrandr2-dbg |
[email protected] | 9dc4bed | 2010-11-04 19:23:30 | [diff] [blame] | 133 | libxrender1-dbg libxtst6-dbg zlib1g-dbg" |
[email protected] | e041ed1 | 2009-03-10 16:43:01 | [diff] [blame] | 134 | |
[email protected] | ce940f0 | 2010-06-07 22:34:40 | [diff] [blame] | 135 | # CUPS package changed its name from hardy to the next version. Include |
[email protected] | cd03d82 | 2010-05-13 21:11:20 | [diff] [blame] | 136 | # proper package here depending on the system. |
[email protected] | 1437d24 | 2010-05-14 03:10:46 | [diff] [blame] | 137 | if egrep -q 'Ubuntu (8\.04|8\.10)' /etc/issue; then |
[email protected] | cd03d82 | 2010-05-13 21:11:20 | [diff] [blame] | 138 | dev_list="${dev_list} libcupsys2-dev" |
| 139 | else |
| 140 | dev_list="${dev_list} libcups2-dev" |
| 141 | fi |
| 142 | |
[email protected] | 8ada8c5 | 2009-03-10 21:53:08 | [diff] [blame] | 143 | # Waits for the user to press 'Y' or 'N'. Either uppercase of lowercase is |
| 144 | # accepted. Returns 0 for 'Y' and 1 for 'N'. If an optional parameter has |
| 145 | # been provided to yes_no(), the function also accepts RETURN as a user input. |
| 146 | # The parameter specifies the exit code that should be returned in that case. |
| 147 | # The function will echo the user's selection followed by a newline character. |
| 148 | # Users can abort the function by pressing CTRL-C. This will call "exit 1". |
| 149 | yes_no() { |
| 150 | local c |
| 151 | while :; do |
| 152 | c="$(trap 'stty echo -iuclc icanon 2>/dev/null' EXIT INT TERM QUIT |
| 153 | stty -echo iuclc -icanon 2>/dev/null |
| 154 | dd count=1 bs=1 2>/dev/null | od -An -tx1)" |
| 155 | case "$c" in |
| 156 | " 0a") if [ -n "$1" ]; then |
| 157 | [ $1 -eq 0 ] && echo "Y" || echo "N" |
| 158 | return $1 |
| 159 | fi |
| 160 | ;; |
| 161 | " 79") echo "Y" |
| 162 | return 0 |
| 163 | ;; |
| 164 | " 6e") echo "N" |
| 165 | return 1 |
| 166 | ;; |
| 167 | "") echo "Aborted" >&2 |
| 168 | exit 1 |
| 169 | ;; |
| 170 | *) # The user pressed an unrecognized key. As we are not echoing |
| 171 | # any incorrect user input, alert the user by ringing the bell. |
| 172 | (tput bel) 2>/dev/null |
| 173 | ;; |
| 174 | esac |
| 175 | done |
| 176 | } |
| 177 | |
[email protected] | 1eae2bfb | 2010-01-26 18:17:53 | [diff] [blame] | 178 | if test "$do_inst_syms" = "" |
| 179 | then |
| 180 | echo "This script installs all tools and libraries needed to build Chromium." |
| 181 | echo "" |
| 182 | echo "For most of the libraries, it can also install debugging symbols, which" |
| 183 | echo "will allow you to debug code in the system libraries. Most developers" |
| 184 | echo "won't need these symbols." |
| 185 | echo -n "Do you want me to install them for you (y/N) " |
| 186 | if yes_no 1; then |
| 187 | do_inst_syms=1 |
| 188 | fi |
| 189 | fi |
| 190 | if test "$do_inst_syms" = "1"; then |
[email protected] | 8ada8c5 | 2009-03-10 21:53:08 | [diff] [blame] | 191 | echo "Installing debugging symbols." |
| 192 | else |
| 193 | echo "Skipping installation of debugging symbols." |
| 194 | dbg_list= |
| 195 | fi |
| 196 | |
[email protected] | e041ed1 | 2009-03-10 16:43:01 | [diff] [blame] | 197 | sudo apt-get update |
| 198 | |
| 199 | # We initially run "apt-get" with the --reinstall option and parse its output. |
| 200 | # This way, we can find all the packages that need to be newly installed |
| 201 | # without accidentally promoting any packages from "auto" to "manual". |
| 202 | # We then re-run "apt-get" with just the list of missing packages. |
| 203 | echo "Finding missing packages..." |
[email protected] | 12de04f | 2009-08-11 17:30:48 | [diff] [blame] | 204 | packages="${dev_list} ${lib_list} ${dbg_list}" |
[email protected] | b6e06452 | 2009-08-10 18:47:51 | [diff] [blame] | 205 | # Intentially leaving $packages unquoted so it's more readable. |
| 206 | echo "Packages required: " $packages |
| 207 | echo |
[email protected] | 79a9d296 | 2009-08-06 21:10:58 | [diff] [blame] | 208 | new_list_cmd="sudo apt-get install --reinstall $(echo $packages)" |
[email protected] | b62f11e7 | 2010-05-03 17:20:45 | [diff] [blame] | 209 | if new_list="$(yes n | LANG=C $new_list_cmd)"; then |
[email protected] | b6e06452 | 2009-08-10 18:47:51 | [diff] [blame] | 210 | # We probably never hit this following line. |
[email protected] | 79a9d296 | 2009-08-06 21:10:58 | [diff] [blame] | 211 | echo "No missing packages, and the packages are up-to-date." |
[email protected] | b62f11e7 | 2010-05-03 17:20:45 | [diff] [blame] | 212 | elif [ $? -eq 1 ]; then |
[email protected] | 79a9d296 | 2009-08-06 21:10:58 | [diff] [blame] | 213 | # We expect apt-get to have exit status of 1. |
| 214 | # This indicates that we canceled the install with "yes n|". |
[email protected] | b6e06452 | 2009-08-10 18:47:51 | [diff] [blame] | 215 | new_list=$(echo "$new_list" | |
[email protected] | 79a9d296 | 2009-08-06 21:10:58 | [diff] [blame] | 216 | sed -e '1,/The following NEW packages will be installed:/d;s/^ //;t;d') |
[email protected] | b6e06452 | 2009-08-10 18:47:51 | [diff] [blame] | 217 | new_list=$(echo "$new_list" | sed 's/ *$//') |
| 218 | if [ -z "$new_list" ] ; then |
| 219 | echo "No missing packages, and the packages are up-to-date." |
| 220 | else |
| 221 | echo "Installing missing packages: $new_list." |
| 222 | sudo apt-get install ${new_list} |
| 223 | fi |
| 224 | echo |
[email protected] | 79a9d296 | 2009-08-06 21:10:58 | [diff] [blame] | 225 | else |
| 226 | # An apt-get exit status of 100 indicates that a real error has occurred. |
[email protected] | e041ed1 | 2009-03-10 16:43:01 | [diff] [blame] | 227 | |
[email protected] | 79a9d296 | 2009-08-06 21:10:58 | [diff] [blame] | 228 | # I am intentionally leaving out the '"'s around new_list_cmd, |
| 229 | # as this makes it easier to cut and paste the output |
[email protected] | 79a9d296 | 2009-08-06 21:10:58 | [diff] [blame] | 230 | echo "The following command failed: " ${new_list_cmd} |
| 231 | echo |
| 232 | echo "It produces the following output:" |
| 233 | yes n | $new_list_cmd || true |
| 234 | echo |
| 235 | echo "You will have to install the above packages yourself." |
| 236 | echo |
| 237 | exit 100 |
| 238 | fi |
[email protected] | e041ed1 | 2009-03-10 16:43:01 | [diff] [blame] | 239 | |
[email protected] | b62f11e7 | 2010-05-03 17:20:45 | [diff] [blame] | 240 | # Some operating systems already ship gold (on recent Debian and |
| 241 | # Ubuntu you can do "apt-get install binutils-gold" to get it), but |
[email protected] | ae0637b | 2010-06-30 17:07:56 | [diff] [blame] | 242 | # older releases didn't. Additionally, gold 2.20 (included in Ubuntu |
| 243 | # Lucid) makes binaries that just segfault. |
| 244 | # So install from source if we don't have a good version. |
[email protected] | c87aa98 | 2009-06-11 17:44:04 | [diff] [blame] | 245 | |
| 246 | case `ld --version` in |
[email protected] | ae0637b | 2010-06-30 17:07:56 | [diff] [blame] | 247 | *gold*2.20.1*) ;; |
| 248 | *gold*2.2[1-9]*) ;; |
[email protected] | c87aa98 | 2009-06-11 17:44:04 | [diff] [blame] | 249 | * ) |
[email protected] | 1eae2bfb | 2010-01-26 18:17:53 | [diff] [blame] | 250 | if test "$do_inst_gold" = "" |
| 251 | then |
| 252 | echo "Gold is a new linker that links Chrome 5x faster than ld." |
| 253 | echo "Don't use it if you need to link other apps (e.g. valgrind, wine)" |
| 254 | echo -n "REPLACE SYSTEM LINKER ld with gold and back up ld? (y/N) " |
| 255 | if yes_no 1; then |
| 256 | do_inst_gold=1 |
| 257 | fi |
| 258 | fi |
| 259 | if test "$do_inst_gold" = "1" |
| 260 | then |
[email protected] | ae0637b | 2010-06-30 17:07:56 | [diff] [blame] | 261 | # If the system provides a good version of gold, just install it. |
| 262 | if apt-cache show binutils-gold | grep -Eq 'Version: 2.2(0.1|[1-9]*)'; then |
[email protected] | f9569168 | 2009-11-17 05:19:56 | [diff] [blame] | 263 | echo "Installing binutils-gold. Backing up ld as ld.single." |
| 264 | sudo apt-get install binutils-gold |
| 265 | else |
| 266 | # FIXME: avoid installing as /usr/bin/ld |
| 267 | echo "Building binutils. Backing up ld as ld.orig." |
| 268 | install_gold || exit 99 |
| 269 | fi |
[email protected] | c87aa98 | 2009-06-11 17:44:04 | [diff] [blame] | 270 | else |
| 271 | echo "Not installing gold." |
| 272 | fi |
| 273 | esac |
| 274 | |
[email protected] | e041ed1 | 2009-03-10 16:43:01 | [diff] [blame] | 275 | # Install 32bit backwards compatibility support for 64bit systems |
[email protected] | b6e06452 | 2009-08-10 18:47:51 | [diff] [blame] | 276 | if [ "$(uname -m)" = "x86_64" ]; then |
[email protected] | 1eae2bfb | 2010-01-26 18:17:53 | [diff] [blame] | 277 | if test "$do_inst_lib32" = "" |
| 278 | then |
| 279 | echo "Installing 32bit libraries not already provided by the system" |
| 280 | echo |
[email protected] | b62f11e7 | 2010-05-03 17:20:45 | [diff] [blame] | 281 | echo "This is only needed to build a 32-bit Chrome on your 64-bit system." |
| 282 | echo |
[email protected] | 1eae2bfb | 2010-01-26 18:17:53 | [diff] [blame] | 283 | echo "While we only need to install a relatively small number of library" |
| 284 | echo "files, we temporarily need to download a lot of large *.deb packages" |
| 285 | echo "that contain these files. We will create new *.deb packages that" |
| 286 | echo "include just the 32bit libraries. These files will then be found on" |
| 287 | echo "your system in places like /lib32, /usr/lib32, /usr/lib/debug/lib32," |
| 288 | echo "/usr/lib/debug/usr/lib32. If you ever need to uninstall these files," |
| 289 | echo "look for packages named *-ia32.deb." |
| 290 | echo "Do you want me to download all packages needed to build new 32bit" |
| 291 | echo -n "package files (Y/n) " |
[email protected] | 628b7ca | 2010-01-28 02:44:26 | [diff] [blame] | 292 | if yes_no 0; then |
[email protected] | 1eae2bfb | 2010-01-26 18:17:53 | [diff] [blame] | 293 | do_inst_lib32=1 |
| 294 | fi |
| 295 | fi |
| 296 | if test "$do_inst_lib32" != "1" |
| 297 | then |
[email protected] | 8ada8c5 | 2009-03-10 21:53:08 | [diff] [blame] | 298 | echo "Exiting without installing any 32bit libraries." |
| 299 | exit 0 |
| 300 | fi |
[email protected] | b62f11e7 | 2010-05-03 17:20:45 | [diff] [blame] | 301 | |
| 302 | # Standard 32bit compatibility libraries |
| 303 | echo "First, installing the limited existing 32-bit support..." |
| 304 | cmp_list="ia32-libs lib32asound2-dev lib32readline5-dev lib32stdc++6 lib32z1 |
| 305 | lib32z1-dev libc6-dev-i386 libc6-i386 g++-multilib" |
[email protected] | a81e44e1 | 2010-05-17 21:16:53 | [diff] [blame] | 306 | sudo apt-get install $cmp_list |
[email protected] | b62f11e7 | 2010-05-03 17:20:45 | [diff] [blame] | 307 | |
[email protected] | e041ed1 | 2009-03-10 16:43:01 | [diff] [blame] | 308 | tmp=/tmp/install-32bit.$$ |
| 309 | trap 'rm -rf "${tmp}"' EXIT INT TERM QUIT |
| 310 | mkdir -p "${tmp}/apt/lists/partial" "${tmp}/cache" "${tmp}/partial" |
| 311 | touch "${tmp}/status" |
| 312 | |
| 313 | [ -r /etc/apt/apt.conf ] && cp /etc/apt/apt.conf "${tmp}/apt/" |
[email protected] | b6e06452 | 2009-08-10 18:47:51 | [diff] [blame] | 314 | cat >>"${tmp}/apt/apt.conf" <<EOF |
[email protected] | 79a9d296 | 2009-08-06 21:10:58 | [diff] [blame] | 315 | Apt::Architecture "i386"; |
| 316 | Dir::Cache "${tmp}/cache"; |
| 317 | Dir::Cache::Archives "${tmp}/"; |
| 318 | Dir::State::Lists "${tmp}/apt/lists/"; |
| 319 | Dir::State::status "${tmp}/status"; |
[email protected] | b6e06452 | 2009-08-10 18:47:51 | [diff] [blame] | 320 | EOF |
[email protected] | 1bf2ac97 | 2009-06-30 23:57:48 | [diff] [blame] | 321 | |
[email protected] | e041ed1 | 2009-03-10 16:43:01 | [diff] [blame] | 322 | # Download 32bit packages |
| 323 | echo "Computing list of available 32bit packages..." |
[email protected] | a81e44e1 | 2010-05-17 21:16:53 | [diff] [blame] | 324 | sudo apt-get -c="${tmp}/apt/apt.conf" update |
[email protected] | e041ed1 | 2009-03-10 16:43:01 | [diff] [blame] | 325 | |
| 326 | echo "Downloading available 32bit packages..." |
[email protected] | a81e44e1 | 2010-05-17 21:16:53 | [diff] [blame] | 327 | sudo apt-get -c="${tmp}/apt/apt.conf" \ |
| 328 | --yes --download-only --force-yes --reinstall install \ |
[email protected] | e041ed1 | 2009-03-10 16:43:01 | [diff] [blame] | 329 | ${lib_list} ${dbg_list} |
| 330 | |
| 331 | # Open packages, remove everything that is not a library, move the |
| 332 | # library to a lib32 directory and package everything as a *.deb file. |
| 333 | echo "Repackaging and installing 32bit packages for use on 64bit systems..." |
| 334 | for i in ${lib_list} ${dbg_list}; do |
| 335 | orig="$(echo "${tmp}/${i}"_*_i386.deb)" |
| 336 | compat="$(echo "${orig}" | |
| 337 | sed -e 's,\(_[^_/]*_\)i386\(.deb\),-ia32\1amd64\2,')" |
| 338 | rm -rf "${tmp}/staging" |
| 339 | msg="$(fakeroot -u sh -exc ' |
| 340 | # Unpack 32bit Debian archive |
| 341 | umask 022 |
| 342 | mkdir -p "'"${tmp}"'/staging/dpkg/DEBIAN" |
| 343 | cd "'"${tmp}"'/staging" |
| 344 | ar x "'${orig}'" |
| 345 | tar zCfx dpkg data.tar.gz |
| 346 | tar zCfx dpkg/DEBIAN control.tar.gz |
| 347 | |
[email protected] | 34799f9d | 2010-07-08 17:51:33 | [diff] [blame] | 348 | # Create a posix extended regular expression fragment that will |
| 349 | # recognize the includes which have changed. Should be rare, |
| 350 | # will almost always be empty. |
| 351 | includes=`sed -n -e "s/^[0-9a-z]* //g" \ |
| 352 | -e "\,usr/include/,p" dpkg/DEBIAN/md5sums | |
| 353 | xargs -n 1 -I FILE /bin/sh -c \ |
| 354 | "cmp -s dpkg/FILE /FILE || echo FILE" | |
| 355 | tr "\n" "|" | |
| 356 | sed -e "s,|$,,"` |
[email protected] | e041ed1 | 2009-03-10 16:43:01 | [diff] [blame] | 357 | |
[email protected] | 34799f9d | 2010-07-08 17:51:33 | [diff] [blame] | 358 | # If empty, set it to not match anything. |
| 359 | test -z "$includes" && includes="^//" |
| 360 | |
| 361 | # Turn the conflicts into an extended RE for removal from the |
| 362 | # Provides line. |
| 363 | conflicts=`sed -n -e "/Conflicts/s/Conflicts: *//;T;s/, */|/g;p" \ |
| 364 | dpkg/DEBIAN/control` |
| 365 | |
| 366 | # Rename package, change architecture, remove conflicts and dependencies |
| 367 | sed -r -i \ |
| 368 | -e "/Package/s/$/-ia32/" \ |
| 369 | -e "/Architecture/s/:.*$/: amd64/" \ |
| 370 | -e "/Depends/s/:.*/: ia32-libs/" \ |
| 371 | -e "/Provides/s/($conflicts)(, *)?//g;T1;s/, *$//;:1" \ |
| 372 | -e "/Recommends/d" \ |
| 373 | -e "/Conflicts/d" \ |
| 374 | dpkg/DEBIAN/control |
| 375 | |
| 376 | # Only keep files that live in "lib" directories or the includes |
| 377 | # that have changed. |
| 378 | sed -r -i \ |
| 379 | -e "/\/lib64\//d" -e "/\/.?bin\//d" \ |
| 380 | -e "\,$includes,s,[ /]include/,&32/,g;s,include/32/,include32/,g" \ |
| 381 | -e "s, lib/, lib32/,g" \ |
| 382 | -e "s,/lib/,/lib32/,g" \ |
| 383 | -e "t;d" \ |
| 384 | -e "\,^/usr/lib32/debug\(.*/lib32\),s,^/usr/lib32/debug,/usr/lib/debug," \ |
| 385 | dpkg/DEBIAN/md5sums |
[email protected] | e041ed1 | 2009-03-10 16:43:01 | [diff] [blame] | 386 | |
| 387 | # Re-run ldconfig after installation/removal |
| 388 | { echo "#!/bin/sh"; echo "[ \"x\$1\" = xconfigure ]&&ldconfig||:"; } \ |
| 389 | >dpkg/DEBIAN/postinst |
| 390 | { echo "#!/bin/sh"; echo "[ \"x\$1\" = xremove ]&&ldconfig||:"; } \ |
| 391 | >dpkg/DEBIAN/postrm |
| 392 | chmod 755 dpkg/DEBIAN/postinst dpkg/DEBIAN/postrm |
| 393 | |
| 394 | # Remove any other control files |
| 395 | find dpkg/DEBIAN -mindepth 1 "(" -name control -o -name md5sums -o \ |
| 396 | -name postinst -o -name postrm ")" -o -print | |
| 397 | xargs -r rm -rf |
| 398 | |
[email protected] | 34799f9d | 2010-07-08 17:51:33 | [diff] [blame] | 399 | # Remove any files/dirs that live outside of "lib" directories, |
| 400 | # or are not in our list of changed includes. |
| 401 | find dpkg -mindepth 1 -regextype posix-extended \ |
| 402 | "(" -name DEBIAN -o -name lib -o -regex "dpkg/($includes)" ")" \ |
| 403 | -prune -o -print | tac | |
| 404 | xargs -r -n 1 sh -c "rm \$0 2>/dev/null || rmdir \$0 2>/dev/null || : " |
[email protected] | e041ed1 | 2009-03-10 16:43:01 | [diff] [blame] | 405 | find dpkg -name lib64 -o -name bin -o -name "?bin" | |
| 406 | tac | xargs -r rm -rf |
| 407 | |
[email protected] | 34799f9d | 2010-07-08 17:51:33 | [diff] [blame] | 408 | # Remove any symbolic links that were broken by the above steps. |
| 409 | find -L dpkg -type l -print | tac | xargs -r rm -rf |
| 410 | |
[email protected] | e041ed1 | 2009-03-10 16:43:01 | [diff] [blame] | 411 | # Rename lib to lib32, but keep debug symbols in /usr/lib/debug/usr/lib32 |
| 412 | # That is where gdb looks for them. |
| 413 | find dpkg -type d -o -path "*/lib/*" -print | |
| 414 | xargs -r -n 1 sh -c " |
| 415 | i=\$(echo \"\${0}\" | |
| 416 | sed -e s,/lib/,/lib32/,g \ |
| 417 | -e s,/usr/lib32/debug\\\\\(.*/lib32\\\\\),/usr/lib/debug\\\\1,); |
| 418 | mkdir -p \"\${i%/*}\"; |
| 419 | mv \"\${0}\" \"\${i}\"" |
| 420 | |
[email protected] | 34799f9d | 2010-07-08 17:51:33 | [diff] [blame] | 421 | # Rename include to include32. |
| 422 | [ -d "dpkg/usr/include" ] && mv "dpkg/usr/include" "dpkg/usr/include32" |
| 423 | |
[email protected] | e041ed1 | 2009-03-10 16:43:01 | [diff] [blame] | 424 | # Prune any empty directories |
| 425 | find dpkg -type d | tac | xargs -r -n 1 rmdir 2>/dev/null || : |
| 426 | |
| 427 | # Create our own Debian package |
| 428 | cd .. |
| 429 | dpkg --build staging/dpkg .' 2>&1)" |
| 430 | compat="$(eval echo $(echo "${compat}" | |
| 431 | sed -e 's,_[^_/]*_amd64.deb,_*_amd64.deb,'))" |
| 432 | [ -r "${compat}" ] || { |
| 433 | echo "${msg}" >&2 |
| 434 | echo "Failed to build new Debian archive!" >&2 |
| 435 | exit 1 |
| 436 | } |
| 437 | |
| 438 | msg="$(sudo dpkg -i "${compat}" 2>&1)" && { |
| 439 | echo "Installed ${compat##*/}" |
| 440 | } || { |
| 441 | # echo "${msg}" >&2 |
| 442 | echo "Skipped ${compat##*/}" |
| 443 | } |
| 444 | done |
| 445 | |
| 446 | # Add symbolic links for developing 32bit code |
| 447 | echo "Adding missing symbolic links, enabling 32bit code development..." |
| 448 | for i in $(find /lib32 /usr/lib32 -maxdepth 1 -name \*.so.\* | |
| 449 | sed -e 's/[.]so[.][0-9].*/.so/' | |
| 450 | sort -u); do |
| 451 | [ "x${i##*/}" = "xld-linux.so" ] && continue |
| 452 | [ -r "$i" ] && continue |
| 453 | j="$(ls "$i."* | sed -e 's/.*[.]so[.]\([^.]*\)$/\1/;t;d' | |
| 454 | sort -n | tail -n 1)" |
| 455 | [ -r "$i.$j" ] || continue |
| 456 | sudo ln -s "${i##*/}.$j" "$i" |
| 457 | done |
| 458 | fi |