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