blob: 34802dfd931bb1cb7ab12b7642fbb076e5f30b1d [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]1a0f64a2011-05-20 17:53:5583 'Ubuntu (10\.04|10\.10|11\.04|lucid|maverick|natty)' \
[email protected]a51551d2010-07-15 22:59:4884 /etc/issue; then
[email protected]1a0f64a2011-05-20 17:53:5585 echo "Only Ubuntu 10.04 (lucid) through 11.04 (natty) 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]12440af82011-06-16 19:54:19105dev_list="apache2.2-bin bison fakeroot flex g++ gperf language-pack-fr
106 libapache2-mod-php5 libasound2-dev libbz2-dev libcairo2-dev
[email protected]867a46422011-09-01 00:55:05107 libcups2-dev libdbus-glib-1-dev libelf-dev libgconf2-dev
[email protected]4da8fad2011-04-11 18:42:42108 libgl1-mesa-dev libglu1-mesa-dev libglib2.0-dev libgnome-keyring-dev
[email protected]6acbd8dd2011-08-24 21:19:20109 libgtk2.0-dev libjpeg62-dev libkrb5-dev libnspr4-dev libnss3-dev
110 libpam0g-dev libsctp-dev libsqlite3-dev libxslt1-dev libxss-dev
111 libxtst-dev mesa-common-dev msttcorefonts patch perl libwww-perl
112 php5-cgi pkg-config python python-dev rpm subversion ttf-dejavu-core
[email protected]3492fc62011-08-31 20:33:33113 ttf-kochi-gothic ttf-kochi-mincho wdiff ruby libcurl4-gnutls-dev
[email protected]2635e752011-07-08 21:27:29114 ttf-indic-fonts ttf-thai-tlwg
[email protected]9dc4bed2010-11-04 19:23:30115 $chromeos_dev_list"
[email protected]fdc6bf52010-06-07 22:01:57116
117# Run-time libraries required by chromeos only
[email protected]34799f9d2010-07-08 17:51:33118chromeos_lib_list="libpulse0 libbz2-1.0 libcurl4-gnutls-dev"
[email protected]e041ed12009-03-10 16:43:01119
120# Full list of required run-time libraries
[email protected]a9259a52011-05-21 01:05:22121lib_list="libatk1.0-0 libc6 libasound2 libcairo2 libcups2 libdbus-glib-1-2
122 libexpat1 libfontconfig1 libfreetype6 libglib2.0-0 libgnome-keyring0
123 libgtk2.0-0 libpam0g libpango1.0-0 libpcre3 libpixman-1-0
[email protected]fd11101b2011-02-16 04:46:46124 libpng12-0 libstdc++6 libsqlite3-0 libx11-6 libxau6 libxcb1
125 libxcomposite1 libxcursor1 libxdamage1 libxdmcp6 libxext6 libxfixes3
126 libxi6 libxinerama1 libxrandr2 libxrender1 libxtst6 zlib1g
[email protected]9dc4bed2010-11-04 19:23:30127 $chromeos_lib_list"
[email protected]e041ed12009-03-10 16:43:01128
129# Debugging symbols for all of the run-time libraries
[email protected]84421462010-03-11 17:20:25130dbg_list="libatk1.0-dbg libc6-dbg libcairo2-dbg
[email protected]1a0f64a2011-05-20 17:53:55131 libfontconfig1-dbg libglib2.0-0-dbg libgtk2.0-0-dbg
132 libpango1.0-0-dbg libpcre3-dbg libpixman-1-0-dbg
[email protected]b944e322011-05-18 20:01:35133 libsqlite3-0-dbg
[email protected]e759c4b2010-03-10 19:04:58134 libx11-6-dbg libxau6-dbg libxcb1-dbg libxcomposite1-dbg
[email protected]e041ed12009-03-10 16:43:01135 libxcursor1-dbg libxdamage1-dbg libxdmcp6-dbg libxext6-dbg
136 libxfixes3-dbg libxi6-dbg libxinerama1-dbg libxrandr2-dbg
[email protected]9dc4bed2010-11-04 19:23:30137 libxrender1-dbg libxtst6-dbg zlib1g-dbg"
[email protected]e041ed12009-03-10 16:43:01138
[email protected]31a605532011-08-23 22:27:35139# Plugin lists needed for tests.
140plugin_list="flashplugin-installer"
141
[email protected]1a0f64a2011-05-20 17:53:55142# Some NSS packages were renamed in Natty.
143if egrep -q 'Ubuntu (10\.04|10\.10)' /etc/issue; then
144 dbg_list="${dbg_list} libnspr4-0d-dbg libnss3-1d-dbg"
145 lib_list="${lib_list} libnspr4-0d libnss3-1d"
[email protected]cd03d822010-05-13 21:11:20146else
[email protected]1a0f64a2011-05-20 17:53:55147 dbg_list="${dbg_list} libnspr4-dbg libnss3-dbg"
148 lib_list="${lib_list} libnspr4 libnss3"
[email protected]4da8fad2011-04-11 18:42:42149fi
150
[email protected]8ada8c52009-03-10 21:53:08151# Waits for the user to press 'Y' or 'N'. Either uppercase of lowercase is
152# accepted. Returns 0 for 'Y' and 1 for 'N'. If an optional parameter has
153# been provided to yes_no(), the function also accepts RETURN as a user input.
154# The parameter specifies the exit code that should be returned in that case.
155# The function will echo the user's selection followed by a newline character.
156# Users can abort the function by pressing CTRL-C. This will call "exit 1".
157yes_no() {
158 local c
159 while :; do
160 c="$(trap 'stty echo -iuclc icanon 2>/dev/null' EXIT INT TERM QUIT
161 stty -echo iuclc -icanon 2>/dev/null
162 dd count=1 bs=1 2>/dev/null | od -An -tx1)"
163 case "$c" in
164 " 0a") if [ -n "$1" ]; then
165 [ $1 -eq 0 ] && echo "Y" || echo "N"
166 return $1
167 fi
168 ;;
169 " 79") echo "Y"
170 return 0
171 ;;
172 " 6e") echo "N"
173 return 1
174 ;;
175 "") echo "Aborted" >&2
176 exit 1
177 ;;
178 *) # The user pressed an unrecognized key. As we are not echoing
179 # any incorrect user input, alert the user by ringing the bell.
180 (tput bel) 2>/dev/null
181 ;;
182 esac
183 done
184}
185
[email protected]1eae2bfb2010-01-26 18:17:53186if test "$do_inst_syms" = ""
187then
188 echo "This script installs all tools and libraries needed to build Chromium."
189 echo ""
190 echo "For most of the libraries, it can also install debugging symbols, which"
191 echo "will allow you to debug code in the system libraries. Most developers"
192 echo "won't need these symbols."
193 echo -n "Do you want me to install them for you (y/N) "
194 if yes_no 1; then
195 do_inst_syms=1
196 fi
197fi
198if test "$do_inst_syms" = "1"; then
[email protected]8ada8c52009-03-10 21:53:08199 echo "Installing debugging symbols."
200else
201 echo "Skipping installation of debugging symbols."
202 dbg_list=
203fi
204
[email protected]e041ed12009-03-10 16:43:01205sudo apt-get update
206
207# We initially run "apt-get" with the --reinstall option and parse its output.
208# This way, we can find all the packages that need to be newly installed
209# without accidentally promoting any packages from "auto" to "manual".
210# We then re-run "apt-get" with just the list of missing packages.
211echo "Finding missing packages..."
[email protected]31a605532011-08-23 22:27:35212packages="${dev_list} ${lib_list} ${dbg_list} ${plugin_list}"
[email protected]b6e064522009-08-10 18:47:51213# Intentially leaving $packages unquoted so it's more readable.
214echo "Packages required: " $packages
215echo
[email protected]79a9d2962009-08-06 21:10:58216new_list_cmd="sudo apt-get install --reinstall $(echo $packages)"
[email protected]b62f11e72010-05-03 17:20:45217if new_list="$(yes n | LANG=C $new_list_cmd)"; then
[email protected]b6e064522009-08-10 18:47:51218 # We probably never hit this following line.
[email protected]79a9d2962009-08-06 21:10:58219 echo "No missing packages, and the packages are up-to-date."
[email protected]b62f11e72010-05-03 17:20:45220elif [ $? -eq 1 ]; then
[email protected]79a9d2962009-08-06 21:10:58221 # We expect apt-get to have exit status of 1.
222 # This indicates that we canceled the install with "yes n|".
[email protected]b6e064522009-08-10 18:47:51223 new_list=$(echo "$new_list" |
[email protected]79a9d2962009-08-06 21:10:58224 sed -e '1,/The following NEW packages will be installed:/d;s/^ //;t;d')
[email protected]b6e064522009-08-10 18:47:51225 new_list=$(echo "$new_list" | sed 's/ *$//')
226 if [ -z "$new_list" ] ; then
227 echo "No missing packages, and the packages are up-to-date."
228 else
229 echo "Installing missing packages: $new_list."
230 sudo apt-get install ${new_list}
231 fi
232 echo
[email protected]79a9d2962009-08-06 21:10:58233else
234 # An apt-get exit status of 100 indicates that a real error has occurred.
[email protected]e041ed12009-03-10 16:43:01235
[email protected]79a9d2962009-08-06 21:10:58236 # I am intentionally leaving out the '"'s around new_list_cmd,
237 # as this makes it easier to cut and paste the output
[email protected]79a9d2962009-08-06 21:10:58238 echo "The following command failed: " ${new_list_cmd}
239 echo
240 echo "It produces the following output:"
241 yes n | $new_list_cmd || true
242 echo
243 echo "You will have to install the above packages yourself."
244 echo
245 exit 100
246fi
[email protected]e041ed12009-03-10 16:43:01247
[email protected]b62f11e72010-05-03 17:20:45248# Some operating systems already ship gold (on recent Debian and
249# Ubuntu you can do "apt-get install binutils-gold" to get it), but
[email protected]ae0637b2010-06-30 17:07:56250# older releases didn't. Additionally, gold 2.20 (included in Ubuntu
[email protected]b4ce3c22d2011-02-23 21:30:17251# Lucid) makes binaries that just segfault, and 2.20.1 does not support
252# --map-whole-files.
[email protected]ae0637b2010-06-30 17:07:56253# So install from source if we don't have a good version.
[email protected]c87aa982009-06-11 17:44:04254
255case `ld --version` in
[email protected]ce774642011-09-12 23:21:39256*gold*2.2[1-9].*)
257 echo "*** Warning ***"
258 echo "If the default linker is gold, linking may fail for:"
259 echo "the Linux kernel, kernel modules, Valgrind, and Wine."
260 echo "If you previously installed gold as the default linker,"
261 echo "you can restore the original linker by running:"
262 echo "'cd /usr/bin; sudo rm ld; sudo mv ld.orig ld'"
263 echo
264 if [ "$do_restore_usr_bin_ld" = "" ]
265 then
266 echo -n "Restore /usr/bin/ld to the original linker? (Y/n) "
267 if yes_no 0
268 then
269 do_restore_usr_bin_ld=1
270 fi
271 echo
272 fi
273 if [ "$do_restore_usr_bin_ld" = "1" ]
274 then
275 if sudo mv /usr/bin/ld.orig /usr/bin/ld
276 then
277 echo "Restored /usr/bin/ld.orig as /usr/bin/ld"
278 else
279 echo "Failed to restore /usr/bin/ld.orig as /usr/bin/ld"
280 fi
281 echo
282 fi
283 ;;
284esac
285
286# Check the gold version first.
287gold_up_to_date="1"
288case `/usr/local/gold/bin/ld --version` in
[email protected]b4ce3c22d2011-02-23 21:30:17289*gold*2.2[1-9].*) ;;
[email protected]c87aa982009-06-11 17:44:04290* )
[email protected]ce774642011-09-12 23:21:39291 gold_up_to_date="0"
292esac
293
294# Then check and make sure ld.bfd exists.
295if [ "$gold_up_to_date" = "1" ] && [ ! -x "/usr/local/gold/bin/ld.bfd" ]
296then
297 gold_up_to_date="0"
298fi
299
300if [ "$gold_up_to_date" = "0" ]
301then
[email protected]1eae2bfb2010-01-26 18:17:53302 if test "$do_inst_gold" = ""
303 then
[email protected]ce774642011-09-12 23:21:39304 echo "Gold is a new linker that links Chrome 5x faster than GNU ld."
305 echo -n "*** To use the gold linker, "
306 echo "you must pass -B/usr/local/gold/bin/ to g++ ***"
307 echo -n "Install the gold linker? (y/N) "
[email protected]1eae2bfb2010-01-26 18:17:53308 if yes_no 1; then
309 do_inst_gold=1
310 fi
311 fi
312 if test "$do_inst_gold" = "1"
313 then
[email protected]ae0637b2010-06-30 17:07:56314 # If the system provides a good version of gold, just install it.
[email protected]b4ce3c22d2011-02-23 21:30:17315 if apt-cache show binutils-gold | grep -Eq 'Version: 2.2[1-9].*'; then
[email protected]f95691682009-11-17 05:19:56316 echo "Installing binutils-gold. Backing up ld as ld.single."
317 sudo apt-get install binutils-gold
318 else
[email protected]ce774642011-09-12 23:21:39319 echo "Building binutils with gold..."
[email protected]f95691682009-11-17 05:19:56320 install_gold || exit 99
321 fi
[email protected]c87aa982009-06-11 17:44:04322 else
323 echo "Not installing gold."
324 fi
[email protected]ce774642011-09-12 23:21:39325fi
[email protected]c87aa982009-06-11 17:44:04326
[email protected]e041ed12009-03-10 16:43:01327# Install 32bit backwards compatibility support for 64bit systems
[email protected]b6e064522009-08-10 18:47:51328if [ "$(uname -m)" = "x86_64" ]; then
[email protected]1eae2bfb2010-01-26 18:17:53329 if test "$do_inst_lib32" = ""
330 then
331 echo "Installing 32bit libraries not already provided by the system"
332 echo
[email protected]b62f11e72010-05-03 17:20:45333 echo "This is only needed to build a 32-bit Chrome on your 64-bit system."
334 echo
[email protected]1eae2bfb2010-01-26 18:17:53335 echo "While we only need to install a relatively small number of library"
336 echo "files, we temporarily need to download a lot of large *.deb packages"
337 echo "that contain these files. We will create new *.deb packages that"
338 echo "include just the 32bit libraries. These files will then be found on"
339 echo "your system in places like /lib32, /usr/lib32, /usr/lib/debug/lib32,"
340 echo "/usr/lib/debug/usr/lib32. If you ever need to uninstall these files,"
341 echo "look for packages named *-ia32.deb."
342 echo "Do you want me to download all packages needed to build new 32bit"
343 echo -n "package files (Y/n) "
[email protected]628b7ca2010-01-28 02:44:26344 if yes_no 0; then
[email protected]1eae2bfb2010-01-26 18:17:53345 do_inst_lib32=1
346 fi
347 fi
348 if test "$do_inst_lib32" != "1"
349 then
[email protected]8ada8c52009-03-10 21:53:08350 echo "Exiting without installing any 32bit libraries."
351 exit 0
352 fi
[email protected]b62f11e72010-05-03 17:20:45353
354 # Standard 32bit compatibility libraries
355 echo "First, installing the limited existing 32-bit support..."
356 cmp_list="ia32-libs lib32asound2-dev lib32readline5-dev lib32stdc++6 lib32z1
357 lib32z1-dev libc6-dev-i386 libc6-i386 g++-multilib"
[email protected]a81e44e12010-05-17 21:16:53358 sudo apt-get install $cmp_list
[email protected]b62f11e72010-05-03 17:20:45359
[email protected]e041ed12009-03-10 16:43:01360 tmp=/tmp/install-32bit.$$
361 trap 'rm -rf "${tmp}"' EXIT INT TERM QUIT
362 mkdir -p "${tmp}/apt/lists/partial" "${tmp}/cache" "${tmp}/partial"
363 touch "${tmp}/status"
364
365 [ -r /etc/apt/apt.conf ] && cp /etc/apt/apt.conf "${tmp}/apt/"
[email protected]b6e064522009-08-10 18:47:51366 cat >>"${tmp}/apt/apt.conf" <<EOF
[email protected]79a9d2962009-08-06 21:10:58367 Apt::Architecture "i386";
368 Dir::Cache "${tmp}/cache";
369 Dir::Cache::Archives "${tmp}/";
370 Dir::State::Lists "${tmp}/apt/lists/";
371 Dir::State::status "${tmp}/status";
[email protected]b6e064522009-08-10 18:47:51372EOF
[email protected]1bf2ac972009-06-30 23:57:48373
[email protected]e041ed12009-03-10 16:43:01374 # Download 32bit packages
375 echo "Computing list of available 32bit packages..."
[email protected]a81e44e12010-05-17 21:16:53376 sudo apt-get -c="${tmp}/apt/apt.conf" update
[email protected]e041ed12009-03-10 16:43:01377
378 echo "Downloading available 32bit packages..."
[email protected]a81e44e12010-05-17 21:16:53379 sudo apt-get -c="${tmp}/apt/apt.conf" \
380 --yes --download-only --force-yes --reinstall install \
[email protected]e041ed12009-03-10 16:43:01381 ${lib_list} ${dbg_list}
382
383 # Open packages, remove everything that is not a library, move the
384 # library to a lib32 directory and package everything as a *.deb file.
385 echo "Repackaging and installing 32bit packages for use on 64bit systems..."
386 for i in ${lib_list} ${dbg_list}; do
387 orig="$(echo "${tmp}/${i}"_*_i386.deb)"
388 compat="$(echo "${orig}" |
389 sed -e 's,\(_[^_/]*_\)i386\(.deb\),-ia32\1amd64\2,')"
390 rm -rf "${tmp}/staging"
391 msg="$(fakeroot -u sh -exc '
392 # Unpack 32bit Debian archive
393 umask 022
394 mkdir -p "'"${tmp}"'/staging/dpkg/DEBIAN"
395 cd "'"${tmp}"'/staging"
396 ar x "'${orig}'"
397 tar zCfx dpkg data.tar.gz
398 tar zCfx dpkg/DEBIAN control.tar.gz
399
[email protected]34799f9d2010-07-08 17:51:33400 # Create a posix extended regular expression fragment that will
401 # recognize the includes which have changed. Should be rare,
402 # will almost always be empty.
403 includes=`sed -n -e "s/^[0-9a-z]* //g" \
404 -e "\,usr/include/,p" dpkg/DEBIAN/md5sums |
405 xargs -n 1 -I FILE /bin/sh -c \
406 "cmp -s dpkg/FILE /FILE || echo FILE" |
407 tr "\n" "|" |
408 sed -e "s,|$,,"`
[email protected]e041ed12009-03-10 16:43:01409
[email protected]34799f9d2010-07-08 17:51:33410 # If empty, set it to not match anything.
411 test -z "$includes" && includes="^//"
412
413 # Turn the conflicts into an extended RE for removal from the
414 # Provides line.
415 conflicts=`sed -n -e "/Conflicts/s/Conflicts: *//;T;s/, */|/g;p" \
416 dpkg/DEBIAN/control`
417
418 # Rename package, change architecture, remove conflicts and dependencies
419 sed -r -i \
420 -e "/Package/s/$/-ia32/" \
421 -e "/Architecture/s/:.*$/: amd64/" \
422 -e "/Depends/s/:.*/: ia32-libs/" \
423 -e "/Provides/s/($conflicts)(, *)?//g;T1;s/, *$//;:1" \
424 -e "/Recommends/d" \
425 -e "/Conflicts/d" \
426 dpkg/DEBIAN/control
427
428 # Only keep files that live in "lib" directories or the includes
429 # that have changed.
430 sed -r -i \
431 -e "/\/lib64\//d" -e "/\/.?bin\//d" \
432 -e "\,$includes,s,[ /]include/,&32/,g;s,include/32/,include32/,g" \
433 -e "s, lib/, lib32/,g" \
434 -e "s,/lib/,/lib32/,g" \
435 -e "t;d" \
436 -e "\,^/usr/lib32/debug\(.*/lib32\),s,^/usr/lib32/debug,/usr/lib/debug," \
437 dpkg/DEBIAN/md5sums
[email protected]e041ed12009-03-10 16:43:01438
439 # Re-run ldconfig after installation/removal
440 { echo "#!/bin/sh"; echo "[ \"x\$1\" = xconfigure ]&&ldconfig||:"; } \
441 >dpkg/DEBIAN/postinst
442 { echo "#!/bin/sh"; echo "[ \"x\$1\" = xremove ]&&ldconfig||:"; } \
443 >dpkg/DEBIAN/postrm
444 chmod 755 dpkg/DEBIAN/postinst dpkg/DEBIAN/postrm
445
446 # Remove any other control files
447 find dpkg/DEBIAN -mindepth 1 "(" -name control -o -name md5sums -o \
448 -name postinst -o -name postrm ")" -o -print |
449 xargs -r rm -rf
450
[email protected]34799f9d2010-07-08 17:51:33451 # Remove any files/dirs that live outside of "lib" directories,
452 # or are not in our list of changed includes.
453 find dpkg -mindepth 1 -regextype posix-extended \
454 "(" -name DEBIAN -o -name lib -o -regex "dpkg/($includes)" ")" \
455 -prune -o -print | tac |
456 xargs -r -n 1 sh -c "rm \$0 2>/dev/null || rmdir \$0 2>/dev/null || : "
[email protected]e041ed12009-03-10 16:43:01457 find dpkg -name lib64 -o -name bin -o -name "?bin" |
458 tac | xargs -r rm -rf
459
[email protected]34799f9d2010-07-08 17:51:33460 # Remove any symbolic links that were broken by the above steps.
461 find -L dpkg -type l -print | tac | xargs -r rm -rf
462
[email protected]e041ed12009-03-10 16:43:01463 # Rename lib to lib32, but keep debug symbols in /usr/lib/debug/usr/lib32
464 # That is where gdb looks for them.
465 find dpkg -type d -o -path "*/lib/*" -print |
466 xargs -r -n 1 sh -c "
467 i=\$(echo \"\${0}\" |
468 sed -e s,/lib/,/lib32/,g \
469 -e s,/usr/lib32/debug\\\\\(.*/lib32\\\\\),/usr/lib/debug\\\\1,);
470 mkdir -p \"\${i%/*}\";
471 mv \"\${0}\" \"\${i}\""
472
[email protected]34799f9d2010-07-08 17:51:33473 # Rename include to include32.
474 [ -d "dpkg/usr/include" ] && mv "dpkg/usr/include" "dpkg/usr/include32"
475
[email protected]e041ed12009-03-10 16:43:01476 # Prune any empty directories
477 find dpkg -type d | tac | xargs -r -n 1 rmdir 2>/dev/null || :
478
479 # Create our own Debian package
480 cd ..
481 dpkg --build staging/dpkg .' 2>&1)"
482 compat="$(eval echo $(echo "${compat}" |
483 sed -e 's,_[^_/]*_amd64.deb,_*_amd64.deb,'))"
484 [ -r "${compat}" ] || {
485 echo "${msg}" >&2
486 echo "Failed to build new Debian archive!" >&2
487 exit 1
488 }
489
490 msg="$(sudo dpkg -i "${compat}" 2>&1)" && {
491 echo "Installed ${compat##*/}"
492 } || {
493 # echo "${msg}" >&2
494 echo "Skipped ${compat##*/}"
495 }
496 done
497
498 # Add symbolic links for developing 32bit code
499 echo "Adding missing symbolic links, enabling 32bit code development..."
500 for i in $(find /lib32 /usr/lib32 -maxdepth 1 -name \*.so.\* |
501 sed -e 's/[.]so[.][0-9].*/.so/' |
502 sort -u); do
503 [ "x${i##*/}" = "xld-linux.so" ] && continue
504 [ -r "$i" ] && continue
505 j="$(ls "$i."* | sed -e 's/.*[.]so[.]\([^.]*\)$/\1/;t;d' |
506 sort -n | tail -n 1)"
507 [ -r "$i.$j" ] || continue
508 sudo ln -s "${i##*/}.$j" "$i"
509 done
510fi