Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / chrome / installer / linux / sysroot_scripts / sysroot-creator-debian.wheezy.sh
1 #!/bin/sh
2 #
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.
6 #
7 #@ This script builds a Debian Wheezy sysroot for building Google Chrome.
8 #@
9 #@  Generally this script is invoked as:
10 #@  sysroot-creator-debian.wheezy.sh <mode> <args>*
11 #@  Available modes are shown below.
12 #@
13 #@ List of modes:
14
15 ######################################################################
16 # Config
17 ######################################################################
18
19 set -o nounset
20 set -o errexit
21
22 readonly SCRIPT_DIR=$(dirname $0)
23
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
27
28 readonly REQUIRED_TOOLS="wget"
29
30 ######################################################################
31 # Package Config
32 ######################################################################
33
34 # This is where we get all the debian packages from.
35 readonly DEBIAN_REPO=http://http.us.debian.org/debian
36 readonly REPO_BASEDIR="${DEBIAN_REPO}/dists/wheezy"
37
38 readonly RELEASE_FILE="Release"
39 readonly RELEASE_FILE_GPG="Release.gpg"
40 readonly RELEASE_LIST="${REPO_BASEDIR}/${RELEASE_FILE}"
41 readonly RELEASE_LIST_GPG="${REPO_BASEDIR}/${RELEASE_FILE_GPG}"
42 readonly PACKAGE_FILE_AMD64="main/binary-amd64/Packages.bz2"
43 readonly PACKAGE_FILE_I386="main/binary-i386/Packages.bz2"
44 readonly PACKAGE_LIST_AMD64="${REPO_BASEDIR}/${PACKAGE_FILE_AMD64}"
45 readonly PACKAGE_LIST_I386="${REPO_BASEDIR}/${PACKAGE_FILE_I386}"
46
47 # Sysroot packages: these are the packages needed to build chrome.
48 # NOTE: When DEBIAN_PACKAGES is modified, the packagelist files must be updated
49 # by running this script in GeneratePackageList mode.
50 readonly DEBIAN_PACKAGES="\
51   comerr-dev \
52   gcc-4.6 \
53   krb5-multidev \
54   libasound2 \
55   libasound2-dev \
56   libatk1.0-0 \
57   libatk1.0-dev \
58   libavahi-client3 \
59   libavahi-common3 \
60   libc6 \
61   libc6-dev \
62   libcairo2 \
63   libcairo2-dev \
64   libcairo-gobject2 \
65   libcairo-script-interpreter2 \
66   libcap-dev \
67   libcap2 \
68   libcomerr2 \
69   libcups2 \
70   libcups2-dev \
71   libdbus-1-3 \
72   libdbus-1-dev \
73   libdbus-glib-1-2 \
74   libdrm2 \
75   libelf1 \
76   libelf-dev \
77   libexif12 \
78   libexif-dev \
79   libexpat1 \
80   libexpat1-dev \
81   libffi5 \
82   libfontconfig1 \
83   libfontconfig1-dev \
84   libfreetype6 \
85   libfreetype6-dev \
86   libgcc1 \
87   libgcc1 \
88   libgconf-2-4 \
89   libgconf2-4 \
90   libgconf2-dev \
91   libgcrypt11 \
92   libgcrypt11-dev \
93   libgdk-pixbuf2.0-0 \
94   libgdk-pixbuf2.0-dev \
95   libgl1-mesa-dev \
96   libgl1-mesa-glx \
97   libglapi-mesa \
98   libglib2.0-0 \
99   libglib2.0-dev \
100   libgnome-keyring0 \
101   libgnome-keyring-dev \
102   libgnutls26 \
103   libgnutls-dev \
104   libgnutls-openssl27 \
105   libgnutlsxx27 \
106   libgomp1 \
107   libgpg-error0 \
108   libgpg-error-dev \
109   libgssapi-krb5-2 \
110   libgssrpc4 \
111   libgtk2.0-0 \
112   libgtk2.0-dev \
113   libk5crypto3 \
114   libkadm5clnt-mit8 \
115   libkadm5srv-mit8 \
116   libkdb5-6 \
117   libkeyutils1 \
118   libkrb5-3 \
119   libkrb5-dev \
120   libkrb5support0 \
121   libnspr4 \
122   libnspr4-dev \
123   libnss3 \
124   libnss3-dev \
125   libnss-db \
126   liborbit2 \
127   libp11-2 \
128   libp11-kit0 \
129   libpam0g \
130   libpam0g-dev \
131   libpango1.0-0 \
132   libpango1.0-dev \
133   libpci3 \
134   libpci-dev \
135   libpcre3 \
136   libpcre3-dev \
137   libpcrecpp0 \
138   libpixman-1-0 \
139   libpixman-1-dev \
140   libpng12-0 \
141   libpng12-dev \
142   libpulse0 \
143   libpulse-dev \
144   libpulse-mainloop-glib0 \
145   libquadmath0 \
146   libselinux1 \
147   libspeechd2 \
148   libspeechd-dev \
149   libssl1.0.0 \
150   libssl-dev \
151   libstdc++6 \
152   libstdc++6-4.6-dev \
153   libtasn1-3 \
154   libudev0 \
155   libudev-dev \
156   libx11-6 \
157   libx11-dev \
158   libx11-xcb1 \
159   libxau6 \
160   libxau-dev \
161   libxcb1 \
162   libxcb1-dev \
163   libxcb-glx0 \
164   libxcb-render0 \
165   libxcb-render0-dev \
166   libxcb-shm0 \
167   libxcb-shm0-dev \
168   libxcomposite1 \
169   libxcomposite-dev \
170   libxcursor1 \
171   libxcursor-dev \
172   libxdamage1 \
173   libxdamage-dev \
174   libxdmcp6 \
175   libxext6 \
176   libxext-dev \
177   libxfixes3 \
178   libxfixes-dev \
179   libxi6 \
180   libxi-dev \
181   libxinerama1 \
182   libxinerama-dev \
183   libxrandr2 \
184   libxrandr-dev \
185   libxrender1 \
186   libxrender-dev \
187   libxss1 \
188   libxss-dev \
189   libxt6 \
190   libxt-dev \
191   libxtst6 \
192   libxtst-dev \
193   libxxf86vm1 \
194   linux-libc-dev \
195   mesa-common-dev \
196   speech-dispatcher \
197   x11proto-composite-dev \
198   x11proto-core-dev \
199   x11proto-damage-dev \
200   x11proto-fixes-dev \
201   x11proto-input-dev \
202   x11proto-kb-dev \
203   x11proto-randr-dev \
204   x11proto-record-dev \
205   x11proto-render-dev \
206   x11proto-scrnsaver-dev \
207   x11proto-xext-dev \
208   zlib1g \
209   zlib1g-dev"
210
211 readonly DEBIAN_DEP_LIST_AMD64="${SCRIPT_DIR}/packagelist.debian.wheezy.amd64"
212 readonly DEBIAN_DEP_LIST_I386="${SCRIPT_DIR}/packagelist.debian.wheezy.i386"
213
214 ######################################################################
215 # Helper
216 ######################################################################
217
218 Banner() {
219   echo "######################################################################"
220   echo $*
221   echo "######################################################################"
222 }
223
224
225 SubBanner() {
226   echo "......................................................................"
227   echo $*
228   echo "......................................................................"
229 }
230
231
232 Usage() {
233   egrep "^#@" "$0" | cut --bytes=3-
234 }
235
236
237 DownloadOrCopy() {
238   if [ -f "$2" ] ; then
239     echo "$2 already in place"
240     return
241   fi
242
243   HTTP=0
244   echo "$1" | grep -qs ^http:// && HTTP=1
245   if [ "$HTTP" = "1" ]; then
246     SubBanner "downloading from $1 -> $2"
247     wget "$1" -O "$2"
248   else
249     SubBanner "copying from $1"
250     cp "$1" "$2"
251   fi
252 }
253
254
255 SetEnvironmentVariables() {
256   ARCH=""
257   echo $1 | grep -qs Amd64$ && ARCH=AMD64
258   if [ -z "$ARCH" ]; then
259     echo $1 | grep -qs I386$ && ARCH=I386
260   fi
261   case "$ARCH" in
262     AMD64)
263       INSTALL_ROOT="$INSTALL_ROOT_AMD64";
264       ;;
265     I386)
266       INSTALL_ROOT="$INSTALL_ROOT_I386";
267       ;;
268     *)
269       echo "ERROR: Unexpected bad architecture."
270       exit 1
271       ;;
272   esac
273 }
274
275 Cleanup() {
276   rm -rf "$TMP"
277 }
278
279 # some sanity checks to make sure this script is run from the right place
280 # with the right tools
281 SanityCheck() {
282   Banner "Sanity Checks"
283
284   if [ "$(basename $(pwd))" != "sysroot_scripts" ] ; then
285     echo -n "ERROR: run this script from "
286     echo "src/chrome/installer/linux/sysroot_scripts"
287     exit 1
288   fi
289
290   if ! mkdir -p "${INSTALL_ROOT}" ; then
291      echo "ERROR: ${INSTALL_ROOT} can't be created."
292     exit 1
293   fi
294
295   TMP=$(mktemp -q -t -d debian-wheezy-XXXXXX)
296   if [ -z "$TMP" ]; then
297     echo "ERROR: temp dir can't be created."
298     exit 1
299   fi
300   trap Cleanup 0
301
302   for tool in ${REQUIRED_TOOLS} ; do
303     if ! which ${tool} ; then
304       echo "Required binary $tool not found."
305       echo "Exiting."
306       exit 1
307     fi
308   done
309 }
310
311
312 ChangeDirectory() {
313   # Change directory to where this script is.
314   cd $(dirname "$0")
315 }
316
317
318 ClearInstallDir() {
319   Banner "Clearing dirs in ${INSTALL_ROOT}"
320   rm -rf ${INSTALL_ROOT}/*
321 }
322
323
324 CreateTarBall() {
325   local tarball=$1
326   Banner "Creating tar ball ${tarball}"
327   tar zcf ${tarball} -C ${INSTALL_ROOT} .
328 }
329
330 CheckBuildSysrootArgs() {
331   if [ "$#" -ne "1" ]; then
332     echo "ERROR: BuildSysroot commands only take 1 argument"
333     exit 1
334   fi
335
336   if [ -z "$1" ]; then
337     echo "ERROR: tarball name required"
338     exit 1
339   fi
340 }
341
342 ExtractPackageBz2() {
343   bzcat "$1" | egrep '^(Package:|Filename:|SHA256:) ' > "$2"
344 }
345
346 GeneratePackageListAmd64() {
347   local output_file="$1"
348   local package_list="${TMP}/Packages.wheezy_amd64.bz2"
349   DownloadOrCopy ${PACKAGE_LIST_AMD64} ${package_list}
350   VerifyPackageListing ${PACKAGE_FILE_AMD64} ${package_list}
351   ExtractPackageBz2 "$package_list" "${TMP}/Packages"
352
353   GeneratePackageList "$output_file" "${DEBIAN_PACKAGES}"
354 }
355
356 GeneratePackageListI386() {
357   local output_file="$1"
358   local package_list="${TMP}/Packages.wheezy_i386.bz2"
359   DownloadOrCopy ${PACKAGE_LIST_I386} ${package_list}
360   VerifyPackageListing ${PACKAGE_FILE_I386} ${package_list}
361   ExtractPackageBz2 "$package_list" "${TMP}/Packages"
362
363   GeneratePackageList "$output_file" "${DEBIAN_PACKAGES}"
364 }
365
366 StripChecksumsFromPackageList() {
367   local package_file="$1"
368   sed -i 's/ [a-f0-9]\{64\}$//' "$package_file"
369 }
370
371 VerifyPackageFilesMatch() {
372   local downloaded_package_file="$1"
373   local stored_package_file="$2"
374   diff -u "$downloaded_package_file" "$stored_package_file"
375   if [ "$?" -ne "0" ]; then
376     echo "ERROR: downloaded package files does not match $2."
377     echo "You may need to run UpdatePackageLists."
378     exit 1
379   fi
380 }
381
382 ######################################################################
383 #
384 ######################################################################
385
386 HacksAndPatchesAmd64() {
387   Banner "Misc Hacks & Patches"
388   # these are linker scripts with absolute pathnames in them
389   # which we rewrite here
390   lscripts="${INSTALL_ROOT}/usr/lib/x86_64-linux-gnu/libpthread.so \
391             ${INSTALL_ROOT}/usr/lib/x86_64-linux-gnu/libc.so"
392
393   #SubBanner "Rewriting Linker Scripts"
394   sed -i -e 's|/usr/lib/x86_64-linux-gnu/||g'  ${lscripts}
395   sed -i -e 's|/lib/x86_64-linux-gnu/||g' ${lscripts}
396
397   # This is for chrome's ./build/linux/pkg-config-wrapper
398   # which overwrites PKG_CONFIG_PATH internally
399   SubBanner "Package Configs Symlink"
400   mkdir -p ${INSTALL_ROOT}/usr/share
401   ln -s ../lib/x86_64-linux-gnu/pkgconfig ${INSTALL_ROOT}/usr/share/pkgconfig
402
403   SubBanner "Adding an additional ld.conf include"
404   LD_SO_HACK_CONF="${INSTALL_ROOT}/etc/ld.so.conf.d/zz_hack.conf"
405   echo /usr/lib/gcc/x86_64-linux-gnu/4.6 > "$LD_SO_HACK_CONF"
406   echo /usr/lib >> "$LD_SO_HACK_CONF"
407 }
408
409
410 HacksAndPatchesI386() {
411   Banner "Misc Hacks & Patches"
412   # these are linker scripts with absolute pathnames in them
413   # which we rewrite here
414   lscripts="${INSTALL_ROOT}/usr/lib/i386-linux-gnu/libpthread.so \
415             ${INSTALL_ROOT}/usr/lib/i386-linux-gnu/libc.so"
416
417   #SubBanner "Rewriting Linker Scripts"
418   sed -i -e 's|/usr/lib/i386-linux-gnu/||g'  ${lscripts}
419   sed -i -e 's|/lib/i386-linux-gnu/||g' ${lscripts}
420
421   # This is for chrome's ./build/linux/pkg-config-wrapper
422   # which overwrites PKG_CONFIG_PATH internally
423   SubBanner "Package Configs Symlink"
424   mkdir -p ${INSTALL_ROOT}/usr/share
425   ln -s ../lib/i386-linux-gnu/pkgconfig ${INSTALL_ROOT}/usr/share/pkgconfig
426
427   SubBanner "Adding an additional ld.conf include"
428   LD_SO_HACK_CONF="${INSTALL_ROOT}/etc/ld.so.conf.d/zz_hack.conf"
429   echo /usr/lib/gcc/i486-linux-gnu/4.6 > "$LD_SO_HACK_CONF"
430   echo /usr/lib >> "$LD_SO_HACK_CONF"
431 }
432
433
434 InstallIntoSysroot() {
435   Banner "Install Libs And Headers Into Jail"
436
437   mkdir -p ${TMP}/debian-packages
438   mkdir -p ${INSTALL_ROOT}
439   while (( "$#" )); do
440     local file="$1"
441     local package="${TMP}/debian-packages/${file##*/}"
442     shift
443     local sha256sum="$1"
444     shift
445     if [ "${#sha256sum}" -ne "64" ]; then
446       echo "Bad sha256sum from package list"
447       exit 1
448     fi
449
450     Banner "Installing ${file}"
451     DownloadOrCopy ${DEBIAN_REPO}/pool/${file} ${package}
452     if [ ! -s "${package}" ] ; then
453       echo
454       echo "ERROR: bad package ${package}"
455       exit 1
456     fi
457     echo "${sha256sum}  ${package}" | sha256sum --quiet -c
458
459     SubBanner "Extracting to ${INSTALL_ROOT}"
460     dpkg --fsys-tarfile ${package}\
461       | tar -xvf - --exclude=./usr/share -C ${INSTALL_ROOT}
462   done
463 }
464
465
466 CleanupJailSymlinks() {
467   Banner "Jail symlink cleanup"
468
469   SAVEDPWD=$(pwd)
470   cd ${INSTALL_ROOT}
471   find lib lib64 usr/lib -type l -printf '%p %l\n' | while read link target; do
472     # skip links with non-absolute paths
473     echo "${target}" | grep -qs ^/ || continue
474     echo "${link}: ${target}"
475     case "${link}" in
476       usr/lib/gcc/x86_64-linux-gnu/4.*/* | usr/lib/gcc/i486-linux-gnu/4.*/*)
477         # Relativize the symlink.
478         ln -snfv "../../../../..${target}" "${link}"
479         ;;
480       usr/lib/x86_64-linux-gnu/* | usr/lib/i386-linux-gnu/*)
481         # Relativize the symlink.
482         ln -snfv "../../..${target}" "${link}"
483         ;;
484       usr/lib/*)
485         # Relativize the symlink.
486         ln -snfv "../..${target}" "${link}"
487         ;;
488       lib64/* | lib/*)
489         # Relativize the symlink.
490         ln -snfv "..${target}" "${link}"
491         ;;
492     esac
493   done
494
495   find lib lib64 usr/lib -type l -printf '%p %l\n' | while read link target; do
496     # Make sure we catch new bad links.
497     if [ ! -r "${link}" ]; then
498       echo "ERROR: FOUND BAD LINK ${link}"
499       ls -l ${link}
500       exit 1
501     fi
502   done
503   cd "$SAVEDPWD"
504 }
505
506 #@
507 #@ BuildSysrootAmd64 <tarball-name>
508 #@
509 #@    Build everything and package it
510 BuildSysrootAmd64() {
511   CheckBuildSysrootArgs $@
512   ClearInstallDir
513   local package_file="$TMP/package_with_sha256sum_amd64"
514   GeneratePackageListAmd64 "$package_file"
515   local files_and_sha256sums="$(cat ${package_file})"
516   StripChecksumsFromPackageList "$package_file"
517   VerifyPackageFilesMatch "$package_file" "$DEBIAN_DEP_LIST_AMD64"
518   InstallIntoSysroot ${files_and_sha256sums}
519   CleanupJailSymlinks
520   HacksAndPatchesAmd64
521   CreateTarBall "$1"
522 }
523
524 #@
525 #@ BuildSysrootI386 <tarball-name>
526 #@
527 #@    Build everything and package it
528 BuildSysrootI386() {
529   CheckBuildSysrootArgs $@
530   ClearInstallDir
531   local package_file="$TMP/package_with_sha256sum_amd64"
532   GeneratePackageListI386 "$package_file"
533   local files_and_sha256sums="$(cat ${package_file})"
534   StripChecksumsFromPackageList "$package_file"
535   VerifyPackageFilesMatch "$package_file" "$DEBIAN_DEP_LIST_I386"
536   InstallIntoSysroot ${files_and_sha256sums}
537   CleanupJailSymlinks
538   HacksAndPatchesI386
539   CreateTarBall "$1"
540 }
541
542 #
543 # CheckForDebianGPGKeys
544 #
545 #     Make sure the Debian GPG keys exist. Otherwise print a helpful message.
546 #
547 CheckForDebianGPGKeys() {
548   if [ ! -e "/etc/apt/trusted.gpg.d/debian-archive-wheezy-automatic.gpg" ]  ||
549      [ ! -e "/etc/apt/trusted.gpg.d/debian-archive-wheezy-stable.gpg" ]; then
550     echo "Debian GPG keys missing. Install the debian-archive-keyring package."
551     exit 1
552   fi
553 }
554
555 #
556 # VerifyPackageListing
557 #
558 #     Verifies the downloaded Packages.bz2 file has the right checksums.
559 #
560 VerifyPackageListing() {
561   local file_path=$1
562   local output_file=$2
563   local release_file="${TMP}/${RELEASE_FILE}"
564   local release_file_gpg="${TMP}/${RELEASE_FILE_GPG}"
565
566   CheckForDebianGPGKeys
567
568   DownloadOrCopy ${RELEASE_LIST} ${release_file}
569   DownloadOrCopy ${RELEASE_LIST_GPG} ${release_file_gpg}
570   echo "Verifying: ${release_file} with ${release_file_gpg}"
571   gpgv --keyring /etc/apt/trusted.gpg.d/debian-archive-wheezy-automatic.gpg \
572        --keyring /etc/apt/trusted.gpg.d/debian-archive-wheezy-stable.gpg \
573        ${release_file_gpg} ${release_file}
574
575   echo "Verifying: ${output_file}"
576   local checksums=$(grep ${file_path} ${release_file} | cut -d " " -f 2)
577   local sha256sum=$(echo ${checksums} | cut -d " " -f 3)
578
579   if [ "${#sha256sum}" -ne "64" ]; then
580     echo "Bad sha256sum from ${RELEASE_LIST}"
581     exit 1
582   fi
583
584   echo "${sha256sum}  ${output_file}" | sha256sum --quiet -c
585 }
586
587 #
588 # GeneratePackageList
589 #
590 #     Looks up package names in ${TMP}/Packages and write list of URLs
591 #     to output file.
592 #
593 GeneratePackageList() {
594   local output_file="$1"
595   echo "Updating: ${output_file}"
596   /bin/rm -f "${output_file}"
597   shift
598   for pkg in $@ ; do
599     local pkg_full=$(grep -A 1 " ${pkg}\$" "${TMP}/Packages" | \
600       egrep -o "pool/.*")
601     if [ -z "${pkg_full}" ]; then
602         echo "ERROR: missing package: $pkg"
603         exit 1
604     fi
605     local pkg_nopool=$(echo "$pkg_full" | sed "s/^pool\///")
606     local sha256sum=$(grep -A 4 " ${pkg}\$" "${TMP}/Packages" | \
607       grep ^SHA256: | sed 's/^SHA256: //')
608     if [ "${#sha256sum}" -ne "64" ]; then
609       echo "Bad sha256sum from Packages"
610       exit 1
611     fi
612     echo $pkg_nopool $sha256sum >> "$output_file"
613   done
614   # sort -o does an in-place sort of this file
615   sort "$output_file" -o "$output_file"
616 }
617
618 #@
619 #@ UpdatePackageListsAmd64
620 #@
621 #@     Regenerate the package lists such that they contain an up-to-date
622 #@     list of URLs within the Debian archive. (For amd64)
623 UpdatePackageListsAmd64() {
624   GeneratePackageListAmd64 "$DEBIAN_DEP_LIST_AMD64"
625   StripChecksumsFromPackageList "$DEBIAN_DEP_LIST_AMD64"
626 }
627
628 #@
629 #@ UpdatePackageListsI386
630 #@
631 #@     Regenerate the package lists such that they contain an up-to-date
632 #@     list of URLs within the Debian archive. (For i386)
633 UpdatePackageListsI386() {
634   GeneratePackageListI386 "$DEBIAN_DEP_LIST_I386"
635   StripChecksumsFromPackageList "$DEBIAN_DEP_LIST_I386"
636 }
637
638 if [ $# -eq 0 ] ; then
639   echo "ERROR: you must specify a mode on the commandline"
640   echo
641   Usage
642   exit 1
643 elif [ "$(type -t $1)" != "function" ]; then
644   echo "ERROR: unknown function '$1'." >&2
645   echo "For help, try:"
646   echo "    $0 help"
647   exit 1
648 else
649   ChangeDirectory
650   SetEnvironmentVariables "$1"
651   SanityCheck
652   "$@"
653 fi