blob: 4ea4c1a7dcd5b0d162d41aa7d22579ab36fc95af [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..."
354 cmp_list="ia32-libs lib32asound2-dev lib32readline5-dev lib32stdc++6 lib32z1
355 lib32z1-dev libc6-dev-i386 libc6-i386 g++-multilib"
[email protected]a81e44e12010-05-17 21:16:53356 sudo apt-get install $cmp_list
[email protected]b62f11e72010-05-03 17:20:45357
[email protected]e041ed12009-03-10 16:43:01358 tmp=/tmp/install-32bit.$$
359 trap 'rm -rf "${tmp}"' EXIT INT TERM QUIT
360 mkdir -p "${tmp}/apt/lists/partial" "${tmp}/cache" "${tmp}/partial"
361 touch "${tmp}/status"
362
363 [ -r /etc/apt/apt.conf ] && cp /etc/apt/apt.conf "${tmp}/apt/"
[email protected]b6e064522009-08-10 18:47:51364 cat >>"${tmp}/apt/apt.conf" <<EOF
[email protected]79a9d2962009-08-06 21:10:58365 Apt::Architecture "i386";
366 Dir::Cache "${tmp}/cache";
367 Dir::Cache::Archives "${tmp}/";
368 Dir::State::Lists "${tmp}/apt/lists/";
369 Dir::State::status "${tmp}/status";
[email protected]b6e064522009-08-10 18:47:51370EOF
[email protected]1bf2ac972009-06-30 23:57:48371
[email protected]e041ed12009-03-10 16:43:01372 # Download 32bit packages
373 echo "Computing list of available 32bit packages..."
[email protected]a81e44e12010-05-17 21:16:53374 sudo apt-get -c="${tmp}/apt/apt.conf" update
[email protected]e041ed12009-03-10 16:43:01375
376 echo "Downloading available 32bit packages..."
[email protected]a81e44e12010-05-17 21:16:53377 sudo apt-get -c="${tmp}/apt/apt.conf" \
378 --yes --download-only --force-yes --reinstall install \
[email protected]e041ed12009-03-10 16:43:01379 ${lib_list} ${dbg_list}
380
381 # Open packages, remove everything that is not a library, move the
382 # library to a lib32 directory and package everything as a *.deb file.
383 echo "Repackaging and installing 32bit packages for use on 64bit systems..."
384 for i in ${lib_list} ${dbg_list}; do
385 orig="$(echo "${tmp}/${i}"_*_i386.deb)"
386 compat="$(echo "${orig}" |
387 sed -e 's,\(_[^_/]*_\)i386\(.deb\),-ia32\1amd64\2,')"
388 rm -rf "${tmp}/staging"
389 msg="$(fakeroot -u sh -exc '
390 # Unpack 32bit Debian archive
391 umask 022
392 mkdir -p "'"${tmp}"'/staging/dpkg/DEBIAN"
393 cd "'"${tmp}"'/staging"
394 ar x "'${orig}'"
395 tar zCfx dpkg data.tar.gz
396 tar zCfx dpkg/DEBIAN control.tar.gz
397
[email protected]34799f9d2010-07-08 17:51:33398 # Create a posix extended regular expression fragment that will
399 # recognize the includes which have changed. Should be rare,
400 # will almost always be empty.
401 includes=`sed -n -e "s/^[0-9a-z]* //g" \
402 -e "\,usr/include/,p" dpkg/DEBIAN/md5sums |
403 xargs -n 1 -I FILE /bin/sh -c \
404 "cmp -s dpkg/FILE /FILE || echo FILE" |
405 tr "\n" "|" |
406 sed -e "s,|$,,"`
[email protected]e041ed12009-03-10 16:43:01407
[email protected]34799f9d2010-07-08 17:51:33408 # If empty, set it to not match anything.
409 test -z "$includes" && includes="^//"
410
411 # Turn the conflicts into an extended RE for removal from the
412 # Provides line.
413 conflicts=`sed -n -e "/Conflicts/s/Conflicts: *//;T;s/, */|/g;p" \
414 dpkg/DEBIAN/control`
415
416 # Rename package, change architecture, remove conflicts and dependencies
417 sed -r -i \
418 -e "/Package/s/$/-ia32/" \
419 -e "/Architecture/s/:.*$/: amd64/" \
420 -e "/Depends/s/:.*/: ia32-libs/" \
421 -e "/Provides/s/($conflicts)(, *)?//g;T1;s/, *$//;:1" \
422 -e "/Recommends/d" \
423 -e "/Conflicts/d" \
424 dpkg/DEBIAN/control
425
426 # Only keep files that live in "lib" directories or the includes
427 # that have changed.
428 sed -r -i \
429 -e "/\/lib64\//d" -e "/\/.?bin\//d" \
430 -e "\,$includes,s,[ /]include/,&32/,g;s,include/32/,include32/,g" \
431 -e "s, lib/, lib32/,g" \
432 -e "s,/lib/,/lib32/,g" \
433 -e "t;d" \
434 -e "\,^/usr/lib32/debug\(.*/lib32\),s,^/usr/lib32/debug,/usr/lib/debug," \
435 dpkg/DEBIAN/md5sums
[email protected]e041ed12009-03-10 16:43:01436
437 # Re-run ldconfig after installation/removal
438 { echo "#!/bin/sh"; echo "[ \"x\$1\" = xconfigure ]&&ldconfig||:"; } \
439 >dpkg/DEBIAN/postinst
440 { echo "#!/bin/sh"; echo "[ \"x\$1\" = xremove ]&&ldconfig||:"; } \
441 >dpkg/DEBIAN/postrm
442 chmod 755 dpkg/DEBIAN/postinst dpkg/DEBIAN/postrm
443
444 # Remove any other control files
445 find dpkg/DEBIAN -mindepth 1 "(" -name control -o -name md5sums -o \
446 -name postinst -o -name postrm ")" -o -print |
447 xargs -r rm -rf
448
[email protected]34799f9d2010-07-08 17:51:33449 # Remove any files/dirs that live outside of "lib" directories,
450 # or are not in our list of changed includes.
451 find dpkg -mindepth 1 -regextype posix-extended \
452 "(" -name DEBIAN -o -name lib -o -regex "dpkg/($includes)" ")" \
453 -prune -o -print | tac |
454 xargs -r -n 1 sh -c "rm \$0 2>/dev/null || rmdir \$0 2>/dev/null || : "
[email protected]e041ed12009-03-10 16:43:01455 find dpkg -name lib64 -o -name bin -o -name "?bin" |
456 tac | xargs -r rm -rf
457
[email protected]34799f9d2010-07-08 17:51:33458 # Remove any symbolic links that were broken by the above steps.
459 find -L dpkg -type l -print | tac | xargs -r rm -rf
460
[email protected]e041ed12009-03-10 16:43:01461 # Rename lib to lib32, but keep debug symbols in /usr/lib/debug/usr/lib32
462 # That is where gdb looks for them.
463 find dpkg -type d -o -path "*/lib/*" -print |
464 xargs -r -n 1 sh -c "
465 i=\$(echo \"\${0}\" |
466 sed -e s,/lib/,/lib32/,g \
467 -e s,/usr/lib32/debug\\\\\(.*/lib32\\\\\),/usr/lib/debug\\\\1,);
468 mkdir -p \"\${i%/*}\";
469 mv \"\${0}\" \"\${i}\""
470
[email protected]34799f9d2010-07-08 17:51:33471 # Rename include to include32.
472 [ -d "dpkg/usr/include" ] && mv "dpkg/usr/include" "dpkg/usr/include32"
473
[email protected]e041ed12009-03-10 16:43:01474 # Prune any empty directories
475 find dpkg -type d | tac | xargs -r -n 1 rmdir 2>/dev/null || :
476
477 # Create our own Debian package
478 cd ..
479 dpkg --build staging/dpkg .' 2>&1)"
480 compat="$(eval echo $(echo "${compat}" |
481 sed -e 's,_[^_/]*_amd64.deb,_*_amd64.deb,'))"
482 [ -r "${compat}" ] || {
483 echo "${msg}" >&2
484 echo "Failed to build new Debian archive!" >&2
485 exit 1
486 }
487
488 msg="$(sudo dpkg -i "${compat}" 2>&1)" && {
489 echo "Installed ${compat##*/}"
490 } || {
491 # echo "${msg}" >&2
492 echo "Skipped ${compat##*/}"
493 }
494 done
495
496 # Add symbolic links for developing 32bit code
497 echo "Adding missing symbolic links, enabling 32bit code development..."
498 for i in $(find /lib32 /usr/lib32 -maxdepth 1 -name \*.so.\* |
499 sed -e 's/[.]so[.][0-9].*/.so/' |
500 sort -u); do
501 [ "x${i##*/}" = "xld-linux.so" ] && continue
502 [ -r "$i" ] && continue
503 j="$(ls "$i."* | sed -e 's/.*[.]so[.]\([^.]*\)$/\1/;t;d' |
504 sort -n | tail -n 1)"
505 [ -r "$i.$j" ] || continue
506 sudo ln -s "${i##*/}.$j" "$i"
507 done
508fi