3 # Copyright (c) 2013 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.
7 #@ This script builds a Debian Wheezy sysroot for building Google Chrome.
9 #@ Generally this script is invoked as:
10 #@ sysroot-creator-debian.wheezy.sh <mode> <args>*
11 #@ Available modes are shown below.
15 ######################################################################
17 ######################################################################
22 readonly SCRIPT_DIR=$(dirname $0)
24 # This is where the staging sysroot is.
25 readonly INSTALL_ROOT_AMD64=$(pwd)/debian_wheezy_amd64_staging
26 readonly INSTALL_ROOT_I386=$(pwd)/debian_wheezy_i386_staging
28 readonly REQUIRED_TOOLS="wget"
30 ######################################################################
32 ######################################################################
34 # this is where we get all the debian packages from
35 readonly DEBIAN_REPO=http://http.us.debian.org/debian
37 readonly PACKAGE_LIST_AMD64="${DEBIAN_REPO}/dists/wheezy/main/binary-amd64/Packages.bz2"
38 readonly PACKAGE_LIST_I386="${DEBIAN_REPO}/dists/wheezy/main/binary-i386/Packages.bz2"
40 # Sysroot packages: these are the packages needed to build chrome.
41 # NOTE: When DEBIAN_PACKAGES is modified, the packagelist files must be updated
42 # by running this script in GeneratePackageList mode.
43 readonly DEBIAN_PACKAGES="\
58 libcairo-script-interpreter2 \
84 libgdk-pixbuf2.0-dev \
88 libgnome-keyring-dev \
131 libpulse-mainloop-glib0 \
180 x11proto-composite-dev \
182 x11proto-damage-dev \
187 x11proto-record-dev \
188 x11proto-render-dev \
189 x11proto-scrnsaver-dev \
194 readonly DEBIAN_DEP_LIST_AMD64="${SCRIPT_DIR}/packagelist.debian.wheezy.amd64"
195 readonly DEBIAN_DEP_LIST_I386="${SCRIPT_DIR}/packagelist.debian.wheezy.i386"
196 readonly DEBIAN_DEP_FILES_AMD64="$(cat ${DEBIAN_DEP_LIST_AMD64})"
197 readonly DEBIAN_DEP_FILES_I386="$(cat ${DEBIAN_DEP_LIST_I386})"
199 ######################################################################
201 ######################################################################
204 echo "######################################################################"
206 echo "######################################################################"
211 echo "......................................................................"
213 echo "......................................................................"
218 egrep "^#@" "$0" | cut --bytes=3-
223 if [ -f "$2" ] ; then
224 echo "$2 already in place"
229 echo "$1" | grep -qs ^http:// && HTTP=1
230 if [ "$HTTP" = "1" ]; then
231 SubBanner "downloading from $1 -> $2"
234 SubBanner "copying from $1"
240 SetEnvironmentVariables() {
242 echo $1 | grep -qs Amd64$ && ARCH=AMD64
243 if [ -z "$ARCH" ]; then
244 echo $1 | grep -qs I386$ && ARCH=I386
248 INSTALL_ROOT="$INSTALL_ROOT_AMD64";
251 INSTALL_ROOT="$INSTALL_ROOT_I386";
254 echo "ERROR: Unexpected bad architecture."
264 # some sanity checks to make sure this script is run from the right place
265 # with the right tools
267 Banner "Sanity Checks"
269 if [ "$(basename $(pwd))" != "sysroot_scripts" ] ; then
270 echo -n "ERROR: run this script from "
271 echo "src/chrome/installer/linux/sysroot_scripts"
275 if ! mkdir -p "${INSTALL_ROOT}" ; then
276 echo "ERROR: ${INSTALL_ROOT} can't be created."
280 TMP=$(mktemp -q -t -d debian-wheezy-XXXXXX)
281 if [ -z "$TMP" ]; then
282 echo "ERROR: temp dir can't be created."
287 for tool in ${REQUIRED_TOOLS} ; do
288 if ! which ${tool} ; then
289 echo "Required binary $tool not found."
298 # Change directory to where this script is.
304 Banner "clearing dirs in ${INSTALL_ROOT}"
305 rm -rf ${INSTALL_ROOT}/*
311 Banner "creating tar ball ${tarball}"
312 tar zcf ${tarball} -C ${INSTALL_ROOT} .
315 ######################################################################
317 ######################################################################
319 HacksAndPatchesAmd64() {
320 Banner "Misc Hacks & Patches"
321 # these are linker scripts with absolute pathnames in them
322 # which we rewrite here
323 lscripts="${INSTALL_ROOT}/usr/lib/x86_64-linux-gnu/libpthread.so \
324 ${INSTALL_ROOT}/usr/lib/x86_64-linux-gnu/libc.so"
326 #SubBanner "Rewriting Linker Scripts"
327 sed -i -e 's|/usr/lib/x86_64-linux-gnu/||g' ${lscripts}
328 sed -i -e 's|/lib/x86_64-linux-gnu/||g' ${lscripts}
330 # This is for chrome's ./build/linux/pkg-config-wrapper
331 # which overwrites PKG_CONFIG_PATH internally
332 SubBanner "Package Configs Symlink"
333 mkdir -p ${INSTALL_ROOT}/usr/share
334 ln -s ../lib/x86_64-linux-gnu/pkgconfig ${INSTALL_ROOT}/usr/share/pkgconfig
336 SubBanner "Adding an additional ld.conf include"
337 LD_SO_HACK_CONF="${INSTALL_ROOT}/etc/ld.so.conf.d/zz_hack.conf"
338 echo /usr/lib/gcc/x86_64-linux-gnu/4.6 > "$LD_SO_HACK_CONF"
339 echo /usr/lib >> "$LD_SO_HACK_CONF"
343 HacksAndPatchesI386() {
344 Banner "Misc Hacks & Patches"
345 # these are linker scripts with absolute pathnames in them
346 # which we rewrite here
347 lscripts="${INSTALL_ROOT}/usr/lib/i386-linux-gnu/libpthread.so \
348 ${INSTALL_ROOT}/usr/lib/i386-linux-gnu/libc.so"
350 #SubBanner "Rewriting Linker Scripts"
351 sed -i -e 's|/usr/lib/i386-linux-gnu/||g' ${lscripts}
352 sed -i -e 's|/lib/i386-linux-gnu/||g' ${lscripts}
354 # This is for chrome's ./build/linux/pkg-config-wrapper
355 # which overwrites PKG_CONFIG_PATH internally
356 SubBanner "Package Configs Symlink"
357 mkdir -p ${INSTALL_ROOT}/usr/share
358 ln -s ../lib/i386-linux-gnu/pkgconfig ${INSTALL_ROOT}/usr/share/pkgconfig
360 SubBanner "Adding an additional ld.conf include"
361 LD_SO_HACK_CONF="${INSTALL_ROOT}/etc/ld.so.conf.d/zz_hack.conf"
362 echo /usr/lib/gcc/i486-linux-gnu/4.6 > "$LD_SO_HACK_CONF"
363 echo /usr/lib >> "$LD_SO_HACK_CONF"
367 InstallIntoSysroot() {
368 Banner "Install Libs And Headers Into Jail"
370 mkdir -p ${TMP}/debian-packages
371 mkdir -p ${INSTALL_ROOT}
373 local package="${TMP}/debian-packages/${file##*/}"
374 Banner "installing ${file}"
375 DownloadOrCopy ${DEBIAN_REPO}/pool/${file} ${package}
376 SubBanner "extracting to ${INSTALL_ROOT}"
377 if [ ! -s "${package}" ] ; then
379 echo "ERROR: bad package ${package}"
382 dpkg --fsys-tarfile ${package}\
383 | tar -xvf - --exclude=./usr/share -C ${INSTALL_ROOT}
388 CleanupJailSymlinks() {
389 Banner "jail symlink cleanup"
393 find lib lib64 usr/lib -type l -printf '%p %l\n' | while read link target; do
394 # skip links with non-absolute paths
395 echo "${target}" | grep -qs ^/ || continue
396 echo "${link}: ${target}"
398 usr/lib/gcc/x86_64-linux-gnu/4.*/* | usr/lib/gcc/i486-linux-gnu/4.*/*)
399 # Relativize the symlink.
400 ln -snfv "../../../../..${target}" "${link}"
402 usr/lib/x86_64-linux-gnu/* | usr/lib/i386-linux-gnu/*)
403 # Relativize the symlink.
404 ln -snfv "../../..${target}" "${link}"
407 # Relativize the symlink.
408 ln -snfv "../..${target}" "${link}"
411 # Relativize the symlink.
412 ln -snfv "..${target}" "${link}"
417 find lib lib64 usr/lib -type l -printf '%p %l\n' | while read link target; do
418 # Make sure we catch new bad links.
419 if [ ! -r "${link}" ]; then
420 echo "ERROR: FOUND BAD LINK ${link}"
429 #@ BuildSysrootAmd64 <tarball-name>
431 #@ Build everything and package it
432 BuildSysrootAmd64() {
434 InstallIntoSysroot ${DEBIAN_DEP_FILES_AMD64}
441 #@ BuildSysrootI386 <tarball-name>
443 #@ Build everything and package it
446 InstallIntoSysroot ${DEBIAN_DEP_FILES_I386}
453 # GeneratePackageList
455 # Looks up package names in ${TMP}/Packages and write list of URLs
458 GeneratePackageList() {
460 echo "Updating: ${output_file}"
461 /bin/rm -f ${output_file}
464 local pkg_full=$(grep -A 1 " ${pkg}\$" ${TMP}/Packages | egrep -o "pool/.*")
465 if [ -z "${pkg_full}" ]; then
466 echo "ERROR: missing package: $pkg"
469 echo $pkg_full | sed "s/^pool\///" >> $output_file
471 # sort -o does an in-place sort of this file
472 sort $output_file -o $output_file
476 #@ UpdatePackageListsAmd64
478 #@ Regenerate the package lists such that they contain an up-to-date
479 #@ list of URLs within the Debian archive. (For amd64)
480 UpdatePackageListsAmd64() {
481 local package_list="${TMP}/Packages.wheezy_amd64.bz2"
482 DownloadOrCopy ${PACKAGE_LIST_AMD64} ${package_list}
483 bzcat ${package_list} | egrep '^(Package:|Filename:)' > ${TMP}/Packages
485 GeneratePackageList ${DEBIAN_DEP_LIST_AMD64} "${DEBIAN_PACKAGES}"
489 #@ UpdatePackageListsI386
491 #@ Regenerate the package lists such that they contain an up-to-date
492 #@ list of URLs within the Debian archive. (For i386)
493 UpdatePackageListsI386() {
494 local package_list="${TMP}/Packages.wheezy_i386.bz2"
495 DownloadOrCopy ${PACKAGE_LIST_I386} ${package_list}
496 bzcat ${package_list} | egrep '^(Package:|Filename:)' > ${TMP}/Packages
498 GeneratePackageList ${DEBIAN_DEP_LIST_I386} "${DEBIAN_PACKAGES}"
501 if [ $# -eq 0 ] ; then
502 echo "ERROR: you must specify a mode on the commandline"
506 elif [ "$(type -t $1)" != "function" ]; then
507 echo "ERROR: unknown function '$1'." >&2
508 echo "For help, try:"
513 SetEnvironmentVariables "$1"