blob: c681cad422f1fe2cac59b94777e412eba3795431 [file] [log] [blame]
[email protected]e041ed12009-03-10 16:43:011#!/bin/bash -e
2
[email protected]4da8fad2011-04-11 18:42:423# Copyright (c) 2011 The Chromium Authors. All rights reserved.
[email protected]e46cdae2009-08-25 20:59:274# Use of this source code is governed by a BSD-style license that can be
5# found in the LICENSE file.
6
[email protected]cf1df402008-10-31 21:45:307# Script to install everything needed to build chromium (well, ideally, anyway)
[email protected]592ea8ca2008-11-03 19:47:368# See http://code.google.com/p/chromium/wiki/LinuxBuildInstructions
9# and http://code.google.com/p/chromium/wiki/LinuxBuild64Bit
[email protected]cf1df402008-10-31 21:45:3010
[email protected]1eae2bfb2010-01-26 18:17:5311usage() {
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"
[email protected]ce774642011-09-12 23:21:3917 echo "--[no-]restore-usr-bin-ld: enable or disable restoring /usr/bin/ld to"
18 echo " ld.bfd if it is currently gold"
[email protected]1eae2bfb2010-01-26 18:17:5319 echo "Script will prompt interactively if options not given."
20 exit 1
21}
22
23while test "$1" != ""
24do
25 case "$1" in
[email protected]ce774642011-09-12 23:21:3926 --syms) do_inst_syms=1;;
27 --no-syms) do_inst_syms=0;;
28 --gold) do_inst_gold=1;;
29 --no-gold) do_inst_gold=0;;
30 --lib32) do_inst_lib32=1;;
31 --no-lib32) do_inst_lib32=0;;
32 --restore-usr-bin-ld) do_restore_usr_bin_ld=1;;
33 --no-restore-usr-bin-ld) do_restore_usr_bin_ld=0;;
[email protected]1eae2bfb2010-01-26 18:17:5334 *) usage;;
35 esac
36 shift
37done
38
[email protected]c87aa982009-06-11 17:44:0439install_gold() {
40 # Gold is optional; it's a faster replacement for ld,
41 # and makes life on 2GB machines much more pleasant.
42
[email protected]b62f11e72010-05-03 17:20:4543 # First make sure root can access this directory, as that's tripped
44 # up some folks.
[email protected]1bf2ac972009-06-30 23:57:4845 if sudo touch xyz.$$
46 then
47 sudo rm xyz.$$
48 else
49 echo root cannot write to the current directory, not installing gold
50 return
51 fi
52
[email protected]42276a972011-07-08 20:31:5753 BINUTILS=binutils-2.21.1
[email protected]c87aa982009-06-11 17:44:0454 BINUTILS_URL=http://ftp.gnu.org/gnu/binutils/$BINUTILS.tar.bz2
[email protected]fdfe9afd2011-09-06 19:05:5655 BINUTILS_SHA1=525255ca6874b872540c9967a1d26acfbc7c8230
[email protected]c87aa982009-06-11 17:44:0456
57 test -f $BINUTILS.tar.bz2 || wget $BINUTILS_URL
[email protected]d42915d42009-11-18 10:36:4658 if test "`sha1sum $BINUTILS.tar.bz2|cut -d' ' -f1`" != "$BINUTILS_SHA1"
[email protected]c87aa982009-06-11 17:44:0459 then
60 echo Bad sha1sum for $BINUTILS.tar.bz2
61 exit 1
62 fi
[email protected]0b53eb02009-09-23 22:22:4763
[email protected]c87aa982009-06-11 17:44:0464 tar -xjvf $BINUTILS.tar.bz2
65 cd $BINUTILS
[email protected]ce774642011-09-12 23:21:3966 ./configure --prefix=/usr/local/gold --enable-gold=default --enable-threads \
67 --enable-bfd=yes
68 NCPU=`cat /proc/cpuinfo |grep ^processor|wc -l`
69 make maybe-all-binutils maybe-all-gold maybe-all-ld -j${NCPU}
70 if sudo make maybe-install-binutils maybe-install-gold maybe-install-ld
[email protected]1bf2ac972009-06-30 23:57:4871 then
72 # Still need to figure out graceful way of pointing gyp to use
73 # /usr/local/gold/bin/ld without requiring him to set environment
[email protected]ce774642011-09-12 23:21:3974 # variables.
75 sudo strip /usr/local/gold/bin/ld.gold
76 sudo strip /usr/local/gold/bin/ld.bfd
[email protected]1bf2ac972009-06-30 23:57:4877 else
78 echo "make install failed, not installing gold"
79 fi
[email protected]c87aa982009-06-11 17:44:0480}
81
[email protected]a51551d2010-07-15 22:59:4882if ! egrep -q \
[email protected]e345f66f2011-10-17 20:52:1683 'Ubuntu (10\.04|10\.10|11\.04|11\.10|lucid|maverick|natty|oneiric)' \
[email protected]a51551d2010-07-15 22:59:4884 /etc/issue; then
[email protected]e345f66f2011-10-17 20:52:1685 echo "Only Ubuntu 10.04 (lucid) through 11.10 (oneiric) are currently" \
[email protected]a51551d2010-07-15 22:59:4886 "supported" >&2
[email protected]cf1df402008-10-31 21:45:3087 exit 1
88fi
[email protected]cf1df402008-10-31 21:45:3089
[email protected]e041ed12009-03-10 16:43:0190if ! uname -m | egrep -q "i686|x86_64"; then
91 echo "Only x86 architectures are currently supported" >&2
92 exit
93fi
94
95if [ "x$(id -u)" != x0 ]; then
96 echo "Running as non-root user."
97 echo "You might have to enter your password one or more times for 'sudo'."
[email protected]8ada8c52009-03-10 21:53:0898 echo
[email protected]e041ed12009-03-10 16:43:0199fi
100
[email protected]fdc6bf52010-06-07 22:01:57101# Packages needed for chromeos only
102chromeos_dev_list="libpulse-dev"
103
[email protected]e041ed12009-03-10 16:43:01104# Packages need for development
[email protected]b3c46f42011-09-30 23:54:55105dev_list="apache2.2-bin bison curl elfutils
106 fakeroot flex g++ gperf language-pack-fr
[email protected]12440af82011-06-16 19:54:19107 libapache2-mod-php5 libasound2-dev libbz2-dev libcairo2-dev
[email protected]867a46422011-09-01 00:55:05108 libcups2-dev libdbus-glib-1-dev libelf-dev libgconf2-dev
[email protected]4da8fad2011-04-11 18:42:42109 libgl1-mesa-dev libglu1-mesa-dev libglib2.0-dev libgnome-keyring-dev
[email protected]6acbd8dd2011-08-24 21:19:20110 libgtk2.0-dev libjpeg62-dev libkrb5-dev libnspr4-dev libnss3-dev
[email protected]c44a75492011-09-21 23:14:26111 libpam0g-dev libsctp-dev libsqlite3-dev libssl-dev libxslt1-dev
[email protected]e345f66f2011-10-17 20:52:16112 libxss-dev libxt-dev libxtst-dev mesa-common-dev msttcorefonts patch
113 perl libwww-perl php5-cgi pkg-config python python-dev rpm subversion
[email protected]c44a75492011-09-21 23:14:26114 ttf-dejavu-core ttf-kochi-gothic ttf-kochi-mincho wdiff ruby
115 libcurl4-gnutls-dev ttf-indic-fonts ttf-thai-tlwg
[email protected]9dc4bed2010-11-04 19:23:30116 $chromeos_dev_list"
[email protected]fdc6bf52010-06-07 22:01:57117
118# Run-time libraries required by chromeos only
[email protected]34799f9d2010-07-08 17:51:33119chromeos_lib_list="libpulse0 libbz2-1.0 libcurl4-gnutls-dev"
[email protected]e041ed12009-03-10 16:43:01120
121# Full list of required run-time libraries
[email protected]a9259a52011-05-21 01:05:22122lib_list="libatk1.0-0 libc6 libasound2 libcairo2 libcups2 libdbus-glib-1-2
123 libexpat1 libfontconfig1 libfreetype6 libglib2.0-0 libgnome-keyring0
124 libgtk2.0-0 libpam0g libpango1.0-0 libpcre3 libpixman-1-0
[email protected]fd11101b2011-02-16 04:46:46125 libpng12-0 libstdc++6 libsqlite3-0 libx11-6 libxau6 libxcb1
126 libxcomposite1 libxcursor1 libxdamage1 libxdmcp6 libxext6 libxfixes3
127 libxi6 libxinerama1 libxrandr2 libxrender1 libxtst6 zlib1g
[email protected]9dc4bed2010-11-04 19:23:30128 $chromeos_lib_list"
[email protected]e041ed12009-03-10 16:43:01129
130# Debugging symbols for all of the run-time libraries
[email protected]f3307aa2011-10-21 22:52:38131dbg_list="libatk1.0-dbg libc6-dbg libcairo2-dbg libdbus-glib-1-2-dbg
[email protected]1a0f64a2011-05-20 17:53:55132 libfontconfig1-dbg libglib2.0-0-dbg libgtk2.0-0-dbg
133 libpango1.0-0-dbg libpcre3-dbg libpixman-1-0-dbg
[email protected]b944e322011-05-18 20:01:35134 libsqlite3-0-dbg
[email protected]e759c4b2010-03-10 19:04:58135 libx11-6-dbg libxau6-dbg libxcb1-dbg libxcomposite1-dbg
[email protected]e041ed12009-03-10 16:43:01136 libxcursor1-dbg libxdamage1-dbg libxdmcp6-dbg libxext6-dbg
137 libxfixes3-dbg libxi6-dbg libxinerama1-dbg libxrandr2-dbg
[email protected]9dc4bed2010-11-04 19:23:30138 libxrender1-dbg libxtst6-dbg zlib1g-dbg"
[email protected]e041ed12009-03-10 16:43:01139
[email protected]31a605532011-08-23 22:27:35140# Plugin lists needed for tests.
141plugin_list="flashplugin-installer"
142
[email protected]1a0f64a2011-05-20 17:53:55143# Some NSS packages were renamed in Natty.
144if egrep -q 'Ubuntu (10\.04|10\.10)' /etc/issue; then
145 dbg_list="${dbg_list} libnspr4-0d-dbg libnss3-1d-dbg"
146 lib_list="${lib_list} libnspr4-0d libnss3-1d"
[email protected]cd03d822010-05-13 21:11:20147else
[email protected]1a0f64a2011-05-20 17:53:55148 dbg_list="${dbg_list} libnspr4-dbg libnss3-dbg"
149 lib_list="${lib_list} libnspr4 libnss3"
[email protected]4da8fad2011-04-11 18:42:42150fi
151
[email protected]8ada8c52009-03-10 21:53:08152# Waits for the user to press 'Y' or 'N'. Either uppercase of lowercase is
153# accepted. Returns 0 for 'Y' and 1 for 'N'. If an optional parameter has
154# been provided to yes_no(), the function also accepts RETURN as a user input.
155# The parameter specifies the exit code that should be returned in that case.
156# The function will echo the user's selection followed by a newline character.
157# Users can abort the function by pressing CTRL-C. This will call "exit 1".
158yes_no() {
159 local c
160 while :; do
161 c="$(trap 'stty echo -iuclc icanon 2>/dev/null' EXIT INT TERM QUIT
162 stty -echo iuclc -icanon 2>/dev/null
163 dd count=1 bs=1 2>/dev/null | od -An -tx1)"
164 case "$c" in
165 " 0a") if [ -n "$1" ]; then
166 [ $1 -eq 0 ] && echo "Y" || echo "N"
167 return $1
168 fi
169 ;;
170 " 79") echo "Y"
171 return 0
172 ;;
173 " 6e") echo "N"
174 return 1
175 ;;
176 "") echo "Aborted" >&2
177 exit 1
178 ;;
179 *) # The user pressed an unrecognized key. As we are not echoing
180 # any incorrect user input, alert the user by ringing the bell.
181 (tput bel) 2>/dev/null
182 ;;
183 esac
184 done
185}
186
[email protected]1eae2bfb2010-01-26 18:17:53187if test "$do_inst_syms" = ""
188then
189 echo "This script installs all tools and libraries needed to build Chromium."
190 echo ""
191 echo "For most of the libraries, it can also install debugging symbols, which"
192 echo "will allow you to debug code in the system libraries. Most developers"
193 echo "won't need these symbols."
194 echo -n "Do you want me to install them for you (y/N) "
195 if yes_no 1; then
196 do_inst_syms=1
197 fi
198fi
199if test "$do_inst_syms" = "1"; then
[email protected]8ada8c52009-03-10 21:53:08200 echo "Installing debugging symbols."
201else
202 echo "Skipping installation of debugging symbols."
203 dbg_list=
204fi
205
[email protected]e041ed12009-03-10 16:43:01206sudo apt-get update
207
208# We initially run "apt-get" with the --reinstall option and parse its output.
209# This way, we can find all the packages that need to be newly installed
210# without accidentally promoting any packages from "auto" to "manual".
211# We then re-run "apt-get" with just the list of missing packages.
212echo "Finding missing packages..."
[email protected]31a605532011-08-23 22:27:35213packages="${dev_list} ${lib_list} ${dbg_list} ${plugin_list}"
[email protected]b6e064522009-08-10 18:47:51214# Intentially leaving $packages unquoted so it's more readable.
215echo "Packages required: " $packages
216echo
[email protected]79a9d2962009-08-06 21:10:58217new_list_cmd="sudo apt-get install --reinstall $(echo $packages)"
[email protected]b62f11e72010-05-03 17:20:45218if new_list="$(yes n | LANG=C $new_list_cmd)"; then
[email protected]b6e064522009-08-10 18:47:51219 # We probably never hit this following line.
[email protected]79a9d2962009-08-06 21:10:58220 echo "No missing packages, and the packages are up-to-date."
[email protected]b62f11e72010-05-03 17:20:45221elif [ $? -eq 1 ]; then
[email protected]79a9d2962009-08-06 21:10:58222 # We expect apt-get to have exit status of 1.
223 # This indicates that we canceled the install with "yes n|".
[email protected]b6e064522009-08-10 18:47:51224 new_list=$(echo "$new_list" |
[email protected]79a9d2962009-08-06 21:10:58225 sed -e '1,/The following NEW packages will be installed:/d;s/^ //;t;d')
[email protected]b6e064522009-08-10 18:47:51226 new_list=$(echo "$new_list" | sed 's/ *$//')
227 if [ -z "$new_list" ] ; then
228 echo "No missing packages, and the packages are up-to-date."
229 else
230 echo "Installing missing packages: $new_list."
231 sudo apt-get install ${new_list}
232 fi
233 echo
[email protected]79a9d2962009-08-06 21:10:58234else
235 # An apt-get exit status of 100 indicates that a real error has occurred.
[email protected]e041ed12009-03-10 16:43:01236
[email protected]79a9d2962009-08-06 21:10:58237 # I am intentionally leaving out the '"'s around new_list_cmd,
238 # as this makes it easier to cut and paste the output
[email protected]79a9d2962009-08-06 21:10:58239 echo "The following command failed: " ${new_list_cmd}
240 echo
241 echo "It produces the following output:"
242 yes n | $new_list_cmd || true
243 echo
244 echo "You will have to install the above packages yourself."
245 echo
246 exit 100
247fi
[email protected]e041ed12009-03-10 16:43:01248
[email protected]b62f11e72010-05-03 17:20:45249# Some operating systems already ship gold (on recent Debian and
250# Ubuntu you can do "apt-get install binutils-gold" to get it), but
[email protected]ae0637b2010-06-30 17:07:56251# older releases didn't. Additionally, gold 2.20 (included in Ubuntu
[email protected]b4ce3c22d2011-02-23 21:30:17252# Lucid) makes binaries that just segfault, and 2.20.1 does not support
253# --map-whole-files.
[email protected]ae0637b2010-06-30 17:07:56254# So install from source if we don't have a good version.
[email protected]c87aa982009-06-11 17:44:04255
256case `ld --version` in
[email protected]ce774642011-09-12 23:21:39257*gold*2.2[1-9].*)
258 echo "*** Warning ***"
259 echo "If the default linker is gold, linking may fail for:"
260 echo "the Linux kernel, kernel modules, Valgrind, and Wine."
261 echo "If you previously installed gold as the default linker,"
262 echo "you can restore the original linker by running:"
263 echo "'cd /usr/bin; sudo rm ld; sudo mv ld.orig ld'"
264 echo
265 if [ "$do_restore_usr_bin_ld" = "" ]
266 then
267 echo -n "Restore /usr/bin/ld to the original linker? (Y/n) "
268 if yes_no 0
269 then
270 do_restore_usr_bin_ld=1
271 fi
272 echo
273 fi
274 if [ "$do_restore_usr_bin_ld" = "1" ]
275 then
276 if sudo mv /usr/bin/ld.orig /usr/bin/ld
277 then
278 echo "Restored /usr/bin/ld.orig as /usr/bin/ld"
279 else
280 echo "Failed to restore /usr/bin/ld.orig as /usr/bin/ld"
281 fi
282 echo
283 fi
284 ;;
285esac
286
287# Check the gold version first.
288gold_up_to_date="1"
[email protected]dfce800042011-09-27 01:57:09289if [ -x "/usr/local/gold/bin/ld" ]
290then
291 case `/usr/local/gold/bin/ld --version` in
292 *gold*2.2[1-9].*) ;;
293 * )
294 gold_up_to_date="0"
295 esac
296fi
[email protected]ce774642011-09-12 23:21:39297
298# Then check and make sure ld.bfd exists.
299if [ "$gold_up_to_date" = "1" ] && [ ! -x "/usr/local/gold/bin/ld.bfd" ]
300then
301 gold_up_to_date="0"
302fi
303
304if [ "$gold_up_to_date" = "0" ]
305then
[email protected]1eae2bfb2010-01-26 18:17:53306 if test "$do_inst_gold" = ""
307 then
[email protected]ce774642011-09-12 23:21:39308 echo "Gold is a new linker that links Chrome 5x faster than GNU ld."
309 echo -n "*** To use the gold linker, "
310 echo "you must pass -B/usr/local/gold/bin/ to g++ ***"
311 echo -n "Install the gold linker? (y/N) "
[email protected]1eae2bfb2010-01-26 18:17:53312 if yes_no 1; then
313 do_inst_gold=1
314 fi
315 fi
316 if test "$do_inst_gold" = "1"
317 then
[email protected]4f4bb6f2011-09-28 19:27:52318 echo "Building binutils with gold..."
319 install_gold || exit 99
[email protected]c87aa982009-06-11 17:44:04320 else
321 echo "Not installing gold."
322 fi
[email protected]ce774642011-09-12 23:21:39323fi
[email protected]c87aa982009-06-11 17:44:04324
[email protected]e041ed12009-03-10 16:43:01325# Install 32bit backwards compatibility support for 64bit systems
[email protected]b6e064522009-08-10 18:47:51326if [ "$(uname -m)" = "x86_64" ]; then
[email protected]1eae2bfb2010-01-26 18:17:53327 if test "$do_inst_lib32" = ""
328 then
329 echo "Installing 32bit libraries not already provided by the system"
330 echo
[email protected]b62f11e72010-05-03 17:20:45331 echo "This is only needed to build a 32-bit Chrome on your 64-bit system."
332 echo
[email protected]1eae2bfb2010-01-26 18:17:53333 echo "While we only need to install a relatively small number of library"
334 echo "files, we temporarily need to download a lot of large *.deb packages"
335 echo "that contain these files. We will create new *.deb packages that"
336 echo "include just the 32bit libraries. These files will then be found on"
337 echo "your system in places like /lib32, /usr/lib32, /usr/lib/debug/lib32,"
338 echo "/usr/lib/debug/usr/lib32. If you ever need to uninstall these files,"
339 echo "look for packages named *-ia32.deb."
340 echo "Do you want me to download all packages needed to build new 32bit"
[email protected]08137542011-09-23 21:35:18341 echo -n "package files (y/N) "
342 if yes_no 1; then
[email protected]1eae2bfb2010-01-26 18:17:53343 do_inst_lib32=1
344 fi
345 fi
346 if test "$do_inst_lib32" != "1"
347 then
[email protected]8ada8c52009-03-10 21:53:08348 echo "Exiting without installing any 32bit libraries."
349 exit 0
350 fi
[email protected]b62f11e72010-05-03 17:20:45351
352 # Standard 32bit compatibility libraries
353 echo "First, installing the limited existing 32-bit support..."
[email protected]7cf14b372011-12-08 18:32:52354 cmp_list="ia32-libs lib32asound2-dev lib32stdc++6 lib32z1
[email protected]b62f11e72010-05-03 17:20:45355 lib32z1-dev libc6-dev-i386 libc6-i386 g++-multilib"
[email protected]7cf14b372011-12-08 18:32:52356 if [ -n "`apt-cache search lib32readline-gplv2-dev 2>/dev/null`" ]; then
357 cmp_list="${cmp_list} lib32readline-gplv2-dev"
358 else
359 cmp_list="${cmp_list} lib32readline5-dev"
360 fi
[email protected]a81e44e12010-05-17 21:16:53361 sudo apt-get install $cmp_list
[email protected]b62f11e72010-05-03 17:20:45362
[email protected]e041ed12009-03-10 16:43:01363 tmp=/tmp/install-32bit.$$
364 trap 'rm -rf "${tmp}"' EXIT INT TERM QUIT
365 mkdir -p "${tmp}/apt/lists/partial" "${tmp}/cache" "${tmp}/partial"
366 touch "${tmp}/status"
367
368 [ -r /etc/apt/apt.conf ] && cp /etc/apt/apt.conf "${tmp}/apt/"
[email protected]b6e064522009-08-10 18:47:51369 cat >>"${tmp}/apt/apt.conf" <<EOF
[email protected]79a9d2962009-08-06 21:10:58370 Apt::Architecture "i386";
371 Dir::Cache "${tmp}/cache";
372 Dir::Cache::Archives "${tmp}/";
373 Dir::State::Lists "${tmp}/apt/lists/";
374 Dir::State::status "${tmp}/status";
[email protected]b6e064522009-08-10 18:47:51375EOF
[email protected]1bf2ac972009-06-30 23:57:48376
[email protected]e041ed12009-03-10 16:43:01377 # Download 32bit packages
378 echo "Computing list of available 32bit packages..."
[email protected]a81e44e12010-05-17 21:16:53379 sudo apt-get -c="${tmp}/apt/apt.conf" update
[email protected]e041ed12009-03-10 16:43:01380
381 echo "Downloading available 32bit packages..."
[email protected]a81e44e12010-05-17 21:16:53382 sudo apt-get -c="${tmp}/apt/apt.conf" \
383 --yes --download-only --force-yes --reinstall install \
[email protected]e041ed12009-03-10 16:43:01384 ${lib_list} ${dbg_list}
385
386 # Open packages, remove everything that is not a library, move the
387 # library to a lib32 directory and package everything as a *.deb file.
388 echo "Repackaging and installing 32bit packages for use on 64bit systems..."
389 for i in ${lib_list} ${dbg_list}; do
390 orig="$(echo "${tmp}/${i}"_*_i386.deb)"
391 compat="$(echo "${orig}" |
392 sed -e 's,\(_[^_/]*_\)i386\(.deb\),-ia32\1amd64\2,')"
393 rm -rf "${tmp}/staging"
394 msg="$(fakeroot -u sh -exc '
395 # Unpack 32bit Debian archive
396 umask 022
397 mkdir -p "'"${tmp}"'/staging/dpkg/DEBIAN"
398 cd "'"${tmp}"'/staging"
399 ar x "'${orig}'"
400 tar zCfx dpkg data.tar.gz
401 tar zCfx dpkg/DEBIAN control.tar.gz
402
[email protected]34799f9d2010-07-08 17:51:33403 # Create a posix extended regular expression fragment that will
404 # recognize the includes which have changed. Should be rare,
405 # will almost always be empty.
406 includes=`sed -n -e "s/^[0-9a-z]* //g" \
407 -e "\,usr/include/,p" dpkg/DEBIAN/md5sums |
408 xargs -n 1 -I FILE /bin/sh -c \
409 "cmp -s dpkg/FILE /FILE || echo FILE" |
410 tr "\n" "|" |
411 sed -e "s,|$,,"`
[email protected]e041ed12009-03-10 16:43:01412
[email protected]34799f9d2010-07-08 17:51:33413 # If empty, set it to not match anything.
414 test -z "$includes" && includes="^//"
415
416 # Turn the conflicts into an extended RE for removal from the
417 # Provides line.
418 conflicts=`sed -n -e "/Conflicts/s/Conflicts: *//;T;s/, */|/g;p" \
419 dpkg/DEBIAN/control`
420
421 # Rename package, change architecture, remove conflicts and dependencies
422 sed -r -i \
423 -e "/Package/s/$/-ia32/" \
424 -e "/Architecture/s/:.*$/: amd64/" \
425 -e "/Depends/s/:.*/: ia32-libs/" \
426 -e "/Provides/s/($conflicts)(, *)?//g;T1;s/, *$//;:1" \
427 -e "/Recommends/d" \
428 -e "/Conflicts/d" \
429 dpkg/DEBIAN/control
430
431 # Only keep files that live in "lib" directories or the includes
432 # that have changed.
433 sed -r -i \
434 -e "/\/lib64\//d" -e "/\/.?bin\//d" \
435 -e "\,$includes,s,[ /]include/,&32/,g;s,include/32/,include32/,g" \
436 -e "s, lib/, lib32/,g" \
437 -e "s,/lib/,/lib32/,g" \
438 -e "t;d" \
439 -e "\,^/usr/lib32/debug\(.*/lib32\),s,^/usr/lib32/debug,/usr/lib/debug," \
440 dpkg/DEBIAN/md5sums
[email protected]e041ed12009-03-10 16:43:01441
442 # Re-run ldconfig after installation/removal
443 { echo "#!/bin/sh"; echo "[ \"x\$1\" = xconfigure ]&&ldconfig||:"; } \
444 >dpkg/DEBIAN/postinst
445 { echo "#!/bin/sh"; echo "[ \"x\$1\" = xremove ]&&ldconfig||:"; } \
446 >dpkg/DEBIAN/postrm
447 chmod 755 dpkg/DEBIAN/postinst dpkg/DEBIAN/postrm
448
449 # Remove any other control files
450 find dpkg/DEBIAN -mindepth 1 "(" -name control -o -name md5sums -o \
451 -name postinst -o -name postrm ")" -o -print |
452 xargs -r rm -rf
453
[email protected]34799f9d2010-07-08 17:51:33454 # Remove any files/dirs that live outside of "lib" directories,
455 # or are not in our list of changed includes.
456 find dpkg -mindepth 1 -regextype posix-extended \
457 "(" -name DEBIAN -o -name lib -o -regex "dpkg/($includes)" ")" \
458 -prune -o -print | tac |
459 xargs -r -n 1 sh -c "rm \$0 2>/dev/null || rmdir \$0 2>/dev/null || : "
[email protected]e041ed12009-03-10 16:43:01460 find dpkg -name lib64 -o -name bin -o -name "?bin" |
461 tac | xargs -r rm -rf
462
[email protected]34799f9d2010-07-08 17:51:33463 # Remove any symbolic links that were broken by the above steps.
464 find -L dpkg -type l -print | tac | xargs -r rm -rf
465
[email protected]e041ed12009-03-10 16:43:01466 # Rename lib to lib32, but keep debug symbols in /usr/lib/debug/usr/lib32
467 # That is where gdb looks for them.
468 find dpkg -type d -o -path "*/lib/*" -print |
469 xargs -r -n 1 sh -c "
470 i=\$(echo \"\${0}\" |
471 sed -e s,/lib/,/lib32/,g \
472 -e s,/usr/lib32/debug\\\\\(.*/lib32\\\\\),/usr/lib/debug\\\\1,);
473 mkdir -p \"\${i%/*}\";
474 mv \"\${0}\" \"\${i}\""
475
[email protected]34799f9d2010-07-08 17:51:33476 # Rename include to include32.
477 [ -d "dpkg/usr/include" ] && mv "dpkg/usr/include" "dpkg/usr/include32"
478
[email protected]e041ed12009-03-10 16:43:01479 # Prune any empty directories
480 find dpkg -type d | tac | xargs -r -n 1 rmdir 2>/dev/null || :
481
482 # Create our own Debian package
483 cd ..
484 dpkg --build staging/dpkg .' 2>&1)"
485 compat="$(eval echo $(echo "${compat}" |
486 sed -e 's,_[^_/]*_amd64.deb,_*_amd64.deb,'))"
487 [ -r "${compat}" ] || {
488 echo "${msg}" >&2
489 echo "Failed to build new Debian archive!" >&2
490 exit 1
491 }
492
493 msg="$(sudo dpkg -i "${compat}" 2>&1)" && {
494 echo "Installed ${compat##*/}"
495 } || {
496 # echo "${msg}" >&2
497 echo "Skipped ${compat##*/}"
498 }
499 done
500
501 # Add symbolic links for developing 32bit code
502 echo "Adding missing symbolic links, enabling 32bit code development..."
503 for i in $(find /lib32 /usr/lib32 -maxdepth 1 -name \*.so.\* |
504 sed -e 's/[.]so[.][0-9].*/.so/' |
505 sort -u); do
506 [ "x${i##*/}" = "xld-linux.so" ] && continue
507 [ -r "$i" ] && continue
508 j="$(ls "$i."* | sed -e 's/.*[.]so[.]\([^.]*\)$/\1/;t;d' |
509 sort -n | tail -n 1)"
510 [ -r "$i.$j" ] || continue
511 sudo ln -s "${i##*/}.$j" "$i"
512 done
513fi