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