- add sources.
[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
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"
39
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="\
44   comerr-dev \
45   gcc-4.6 \
46   krb5-multidev \
47   libasound2 \
48   libasound2-dev \
49   libatk1.0-0 \
50   libatk1.0-dev \
51   libavahi-client3 \
52   libavahi-common3 \
53   libc6 \
54   libc6-dev \
55   libcairo2 \
56   libcairo2-dev \
57   libcairo-gobject2 \
58   libcairo-script-interpreter2 \
59   libcap-dev \
60   libcap2 \
61   libcomerr2 \
62   libcups2 \
63   libcups2-dev \
64   libdbus-1-3 \
65   libdbus-1-dev \
66   libdbus-glib-1-2 \
67   libelf1 \
68   libelf-dev \
69   libexpat1 \
70   libexpat1-dev \
71   libffi5 \
72   libfontconfig1 \
73   libfontconfig1-dev \
74   libfreetype6 \
75   libfreetype6-dev \
76   libgcc1 \
77   libgcc1 \
78   libgconf-2-4 \
79   libgconf2-4 \
80   libgconf2-dev \
81   libgcrypt11 \
82   libgcrypt11-dev \
83   libgdk-pixbuf2.0-0 \
84   libgdk-pixbuf2.0-dev \
85   libglib2.0-0 \
86   libglib2.0-dev \
87   libgnome-keyring0 \
88   libgnome-keyring-dev \
89   libgnutls26 \
90   libgnutls-dev \
91   libgnutls-openssl27 \
92   libgnutlsxx27 \
93   libgomp1 \
94   libgpg-error0 \
95   libgpg-error-dev \
96   libgssapi-krb5-2 \
97   libgssrpc4 \
98   libgtk2.0-0 \
99   libgtk2.0-dev \
100   libk5crypto3 \
101   libkadm5clnt-mit8 \
102   libkadm5srv-mit8 \
103   libkdb5-6 \
104   libkeyutils1 \
105   libkrb5-3 \
106   libkrb5-dev \
107   libkrb5support0 \
108   libnspr4 \
109   libnspr4-dev \
110   libnss3 \
111   libnss3-dev \
112   libnss-db \
113   liborbit2 \
114   libp11-2 \
115   libp11-kit0 \
116   libpam0g \
117   libpam0g-dev \
118   libpango1.0-0 \
119   libpango1.0-dev \
120   libpci3 \
121   libpci-dev \
122   libpcre3 \
123   libpcre3-dev \
124   libpcrecpp0 \
125   libpixman-1-0 \
126   libpixman-1-dev \
127   libpng12-0 \
128   libpng12-dev \
129   libpulse0 \
130   libpulse-dev \
131   libpulse-mainloop-glib0 \
132   libquadmath0 \
133   libselinux1 \
134   libspeechd2 \
135   libspeechd-dev \
136   libssl1.0.0 \
137   libssl-dev \
138   libstdc++6 \
139   libstdc++6-4.6-dev \
140   libtasn1-3 \
141   libudev0 \
142   libudev-dev \
143   libx11-6 \
144   libx11-dev \
145   libxau6 \
146   libxau-dev \
147   libxcb1 \
148   libxcb1-dev \
149   libxcb-render0 \
150   libxcb-render0-dev \
151   libxcb-shm0 \
152   libxcb-shm0-dev \
153   libxcomposite1 \
154   libxcomposite-dev \
155   libxcursor1 \
156   libxcursor-dev \
157   libxdamage1 \
158   libxdamage-dev \
159   libxdmcp6 \
160   libxext6 \
161   libxext-dev \
162   libxfixes3 \
163   libxfixes-dev \
164   libxi6 \
165   libxi-dev \
166   libxinerama1 \
167   libxinerama-dev \
168   libxrandr2 \
169   libxrandr-dev \
170   libxrender1 \
171   libxrender-dev \
172   libxss1 \
173   libxss-dev \
174   libxt6 \
175   libxt-dev \
176   libxtst6 \
177   libxtst-dev \
178   linux-libc-dev \
179   speech-dispatcher \
180   x11proto-composite-dev \
181   x11proto-core-dev \
182   x11proto-damage-dev \
183   x11proto-fixes-dev \
184   x11proto-input-dev \
185   x11proto-kb-dev \
186   x11proto-randr-dev \
187   x11proto-record-dev \
188   x11proto-render-dev \
189   x11proto-scrnsaver-dev \
190   x11proto-xext-dev \
191   zlib1g \
192   zlib1g-dev"
193
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})"
198
199 ######################################################################
200 # Helper
201 ######################################################################
202
203 Banner() {
204   echo "######################################################################"
205   echo $*
206   echo "######################################################################"
207 }
208
209
210 SubBanner() {
211   echo "......................................................................"
212   echo $*
213   echo "......................................................................"
214 }
215
216
217 Usage() {
218   egrep "^#@" "$0" | cut --bytes=3-
219 }
220
221
222 DownloadOrCopy() {
223   if [ -f "$2" ] ; then
224     echo "$2 already in place"
225     return
226   fi
227
228   HTTP=0
229   echo "$1" | grep -qs ^http:// && HTTP=1
230   if [ "$HTTP" = "1" ]; then
231     SubBanner "downloading from $1 -> $2"
232     wget "$1" -O "$2"
233   else
234     SubBanner "copying from $1"
235     cp "$1" "$2"
236   fi
237 }
238
239
240 SetEnvironmentVariables() {
241   ARCH=""
242   echo $1 | grep -qs Amd64$ && ARCH=AMD64
243   if [ -z "$ARCH" ]; then
244     echo $1 | grep -qs I386$ && ARCH=I386
245   fi
246   case "$ARCH" in
247     AMD64)
248       INSTALL_ROOT="$INSTALL_ROOT_AMD64";
249       ;;
250     I386)
251       INSTALL_ROOT="$INSTALL_ROOT_I386";
252       ;;
253     *)
254       echo "ERROR: Unexpected bad architecture."
255       exit 1
256       ;;
257   esac
258 }
259
260 Cleanup() {
261   rm -rf "$TMP"
262 }
263
264 # some sanity checks to make sure this script is run from the right place
265 # with the right tools
266 SanityCheck() {
267   Banner "Sanity Checks"
268
269   if [ "$(basename $(pwd))" != "sysroot_scripts" ] ; then
270     echo -n "ERROR: run this script from "
271     echo "src/chrome/installer/linux/sysroot_scripts"
272     exit 1
273   fi
274
275   if ! mkdir -p "${INSTALL_ROOT}" ; then
276      echo "ERROR: ${INSTALL_ROOT} can't be created."
277     exit 1
278   fi
279
280   TMP=$(mktemp -q -t -d debian-wheezy-XXXXXX)
281   if [ -z "$TMP" ]; then
282     echo "ERROR: temp dir can't be created."
283     exit 1
284   fi
285   trap Cleanup 0
286
287   for tool in ${REQUIRED_TOOLS} ; do
288     if ! which ${tool} ; then
289       echo "Required binary $tool not found."
290       echo "Exiting."
291       exit 1
292     fi
293   done
294 }
295
296
297 ChangeDirectory() {
298   # Change directory to where this script is.
299   cd $(dirname "$0")
300 }
301
302
303 ClearInstallDir() {
304   Banner "clearing dirs in ${INSTALL_ROOT}"
305   rm -rf ${INSTALL_ROOT}/*
306 }
307
308
309 CreateTarBall() {
310   local tarball=$1
311   Banner "creating tar ball ${tarball}"
312   tar zcf ${tarball} -C ${INSTALL_ROOT} .
313 }
314
315 ######################################################################
316 #
317 ######################################################################
318
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"
325
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}
329
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
335
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"
340 }
341
342
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"
349
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}
353
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
359
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"
364 }
365
366
367 InstallIntoSysroot() {
368   Banner "Install Libs And Headers Into Jail"
369
370   mkdir -p ${TMP}/debian-packages
371   mkdir -p ${INSTALL_ROOT}
372   for file in $@ ; do
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
378       echo
379       echo "ERROR: bad package ${package}"
380       exit 1
381     fi
382     dpkg --fsys-tarfile ${package}\
383       | tar -xvf - --exclude=./usr/share -C ${INSTALL_ROOT}
384   done
385 }
386
387
388 CleanupJailSymlinks() {
389   Banner "jail symlink cleanup"
390
391   SAVEDPWD=$(pwd)
392   cd ${INSTALL_ROOT}
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}"
397     case "${link}" in
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}"
401         ;;
402       usr/lib/x86_64-linux-gnu/* | usr/lib/i386-linux-gnu/*)
403         # Relativize the symlink.
404         ln -snfv "../../..${target}" "${link}"
405         ;;
406       usr/lib/*)
407         # Relativize the symlink.
408         ln -snfv "../..${target}" "${link}"
409         ;;
410       lib64/* | lib/*)
411         # Relativize the symlink.
412         ln -snfv "..${target}" "${link}"
413         ;;
414     esac
415   done
416
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}"
421       ls -l ${link}
422       exit 1
423     fi
424   done
425   cd "$SAVEDPWD"
426 }
427
428 #@
429 #@ BuildSysrootAmd64 <tarball-name>
430 #@
431 #@    Build everything and package it
432 BuildSysrootAmd64() {
433   ClearInstallDir
434   InstallIntoSysroot ${DEBIAN_DEP_FILES_AMD64}
435   CleanupJailSymlinks
436   HacksAndPatchesAmd64
437   CreateTarBall $1
438 }
439
440 #@
441 #@ BuildSysrootI386 <tarball-name>
442 #@
443 #@    Build everything and package it
444 BuildSysrootI386() {
445   ClearInstallDir
446   InstallIntoSysroot ${DEBIAN_DEP_FILES_I386}
447   CleanupJailSymlinks
448   HacksAndPatchesI386
449   CreateTarBall $1
450 }
451
452 #
453 # GeneratePackageList
454 #
455 #     Looks up package names in ${TMP}/Packages and write list of URLs
456 #     to output file.
457 #
458 GeneratePackageList() {
459   local output_file=$1
460   echo "Updating: ${output_file}"
461   /bin/rm -f ${output_file}
462   shift
463   for pkg in $@ ; do
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"
467         exit 1
468     fi
469     echo $pkg_full | sed "s/^pool\///" >> $output_file
470   done
471   # sort -o does an in-place sort of this file
472   sort $output_file -o $output_file
473 }
474
475 #@
476 #@ UpdatePackageListsAmd64
477 #@
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
484
485   GeneratePackageList ${DEBIAN_DEP_LIST_AMD64} "${DEBIAN_PACKAGES}"
486 }
487
488 #@
489 #@ UpdatePackageListsI386
490 #@
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
497
498   GeneratePackageList ${DEBIAN_DEP_LIST_I386} "${DEBIAN_PACKAGES}"
499 }
500
501 if [ $# -eq 0 ] ; then
502   echo "ERROR: you must specify a mode on the commandline"
503   echo
504   Usage
505   exit 1
506 elif [ "$(type -t $1)" != "function" ]; then
507   echo "ERROR: unknown function '$1'." >&2
508   echo "For help, try:"
509   echo "    $0 help"
510   exit 1
511 else
512   ChangeDirectory
513   SetEnvironmentVariables "$1"
514   SanityCheck
515   "$@"
516 fi