OLD | NEW |
| (Empty) |
1 #!/bin/bash | |
2 # Copyright (c) 2012 The Native Client Authors. All rights reserved. | |
3 # Use of this source code is governed by a BSD-style license that can be | |
4 # found in the LICENSE file. | |
5 # | |
6 #@ This script builds the (trusted) cross toolchain for arm. | |
7 #@ It must be run from the native_client/ directory. | |
8 #@ | |
9 #@ The toolchain consists primarily of a jail with arm header and libraries. | |
10 #@ It also provides additional tools such as QEMU. | |
11 #@ It does NOT provide the actual cross compiler anymore. | |
12 #@ The cross compiler is now comming straight from a debian package. | |
13 #@ So there is a one-time step required for all machines using this TC. | |
14 #@ Which is especially true for build-bots: | |
15 #@ | |
16 #@ tools/llvm/trusted-toolchain-creator.armel.precise.sh InstallCrossArmBasePa
ckages | |
17 #@ | |
18 #@ | |
19 #@ Generally this script is invoked as: | |
20 #@ tools/llvm/trusted-toolchain-creator.armel.precise.sh <mode> <args>* | |
21 #@ Available modes are shown below. | |
22 #@ | |
23 #@ | |
24 #@ This Toolchain was tested with Ubuntu Lucid | |
25 #@ | |
26 #@ Usage of this TC: | |
27 #@ compile: arm-linux-gnueabi-gcc -march=armv7-a -isystem ${JAIL}/usr/include | |
28 #@ link: arm-linux-gnueabi-gcc -L${JAIL}/usr/lib -L${JAIL}/usr/lib/arm-linux
-gnueabi | |
29 #@ -L${JAIL}/lib -L${JAIL}/lib/arm-linux-gnueabi | |
30 #@ | |
31 #@ Usage of QEMU | |
32 #@ TBD | |
33 #@ | |
34 #@ List of modes: | |
35 | |
36 ###################################################################### | |
37 # Config | |
38 ###################################################################### | |
39 | |
40 set -o nounset | |
41 set -o errexit | |
42 | |
43 readonly SCRIPT_DIR=$(dirname $0) | |
44 | |
45 # this where we create the ARMEL "jail" | |
46 readonly INSTALL_ROOT=$(pwd)/toolchain/linux_arm-trusted | |
47 | |
48 readonly TMP=/tmp/arm-crosstool-natty | |
49 | |
50 readonly REQUIRED_TOOLS="wget" | |
51 | |
52 readonly MAKE_OPTS="-j8" | |
53 | |
54 ###################################################################### | |
55 # Package Config | |
56 ###################################################################### | |
57 | |
58 # this where we get the cross toolchain from for the manual install: | |
59 readonly CROSS_ARM_TC_REPO=http://archive.ubuntu.com/ubuntu | |
60 # this is where we get all the armel packages from | |
61 readonly ARMEL_REPO=http://ports.ubuntu.com/ubuntu-ports | |
62 # | |
63 readonly PACKAGE_LIST="${ARMEL_REPO}/dists/precise/main/binary-armel/Packages.bz
2" | |
64 | |
65 # Packages for the host system | |
66 # NOTE: at one point we should get rid of the 4.5 packages | |
67 readonly CROSS_ARM_TC_PACKAGES="\ | |
68 libc6-armel-cross \ | |
69 libc6-dev-armel-cross \ | |
70 libgcc1-armel-cross \ | |
71 libgomp1-armel-cross \ | |
72 linux-libc-dev-armel-cross \ | |
73 libgcc1-dbg-armel-cross \ | |
74 libgomp1-dbg-armel-cross \ | |
75 binutils-arm-linux-gnueabi \ | |
76 cpp-arm-linux-gnueabi \ | |
77 gcc-arm-linux-gnueabi \ | |
78 g++-arm-linux-gnueabi \ | |
79 cpp-4.5-arm-linux-gnueabi \ | |
80 gcc-4.5-arm-linux-gnueabi \ | |
81 g++-4.5-arm-linux-gnueabi \ | |
82 libmudflap0-dbg-armel-cross | |
83 " | |
84 | |
85 # Jail packages: these are good enough for native client | |
86 # NOTE: the package listing here should be updated using the | |
87 # GeneratePackageListXXX() functions below | |
88 readonly ARMEL_BASE_PACKAGES="\ | |
89 libssl-dev \ | |
90 libssl1.0.0 \ | |
91 libgcc1 \ | |
92 libc6 \ | |
93 libc6-dev \ | |
94 libstdc++6 \ | |
95 libx11-dev \ | |
96 libx11-6 \ | |
97 x11proto-core-dev \ | |
98 libxt-dev \ | |
99 libxt6 \ | |
100 zlib1g \ | |
101 zlib1g-dev" | |
102 | |
103 # Additional jail packages needed to build chrome | |
104 # NOTE: the package listing here should be updated using the | |
105 # GeneratePackageListXXX() functions below | |
106 readonly ARMEL_BASE_DEP_FILES="$(cat ${SCRIPT_DIR}/packagelist.precise.armel.bas
e)" | |
107 | |
108 readonly ARMEL_EXTRA_PACKAGES="\ | |
109 krb5-multidev \ | |
110 libasound2 \ | |
111 libasound2-dev \ | |
112 libatk1.0-0 \ | |
113 libatk1.0-dev \ | |
114 libbz2-1.0 \ | |
115 libbz2-dev \ | |
116 libcairo2 \ | |
117 libcairo2-dev \ | |
118 libcups2 \ | |
119 libcups2-dev \ | |
120 libdbus-1-3 \ | |
121 libdbus-1-dev \ | |
122 libexpat1 \ | |
123 libexpat1-dev \ | |
124 libfontconfig1 \ | |
125 libfontconfig1-dev \ | |
126 libfreetype6 \ | |
127 libfreetype6-dev \ | |
128 libgconf2-4 \ | |
129 libgconf2-dev \ | |
130 libgdk-pixbuf2.0-0 \ | |
131 libgdk-pixbuf2.0-dev \ | |
132 libgtk2.0-0 \ | |
133 libgtk2.0-dev \ | |
134 libglib2.0-0 \ | |
135 libglib2.0-dev \ | |
136 libgnome-keyring-dev \ | |
137 libkrb5-dev \ | |
138 libnspr4 \ | |
139 libnspr4-dev \ | |
140 libnss3 \ | |
141 libnss3-dev \ | |
142 liborbit2 \ | |
143 libpam0g \ | |
144 libpam0g-dev \ | |
145 libpango1.0-0 \ | |
146 libpango1.0-dev \ | |
147 libpcre3 \ | |
148 libpcre3-dev \ | |
149 libpixman-1-0 \ | |
150 libpixman-1-dev \ | |
151 libpng12-0 \ | |
152 libpng12-dev \ | |
153 libselinux1 \ | |
154 libudev0 \ | |
155 libudev-dev \ | |
156 libxext-dev \ | |
157 libxext6 \ | |
158 libxau-dev \ | |
159 libxau6 \ | |
160 libxcb1 \ | |
161 libxcb1-dev \ | |
162 libxcb-render0 \ | |
163 libxcb-render0-dev \ | |
164 libxcb-shm0 \ | |
165 libxcb-shm0-dev \ | |
166 libxcomposite1 \ | |
167 libxcomposite-dev \ | |
168 libxcursor1 \ | |
169 libxcursor-dev \ | |
170 libxdamage1 \ | |
171 libxdamage-dev \ | |
172 libxdmcp6 \ | |
173 libxfixes3 \ | |
174 libxfixes-dev \ | |
175 libxi6 \ | |
176 libxi-dev \ | |
177 libxinerama1 \ | |
178 libxinerama-dev \ | |
179 libxrandr2 \ | |
180 libxrandr-dev \ | |
181 libxrender1 \ | |
182 libxrender-dev \ | |
183 libxss1 \ | |
184 libxss-dev \ | |
185 libxtst6 \ | |
186 libxtst-dev \ | |
187 x11proto-composite-dev \ | |
188 x11proto-damage-dev \ | |
189 x11proto-fixes-dev \ | |
190 x11proto-input-dev \ | |
191 x11proto-record-dev \ | |
192 x11proto-render-dev \ | |
193 x11proto-scrnsaver-dev \ | |
194 x11proto-xext-dev" | |
195 | |
196 # NOTE: the package listing here should be updated using the | |
197 # GeneratePackageListXXX() functions below | |
198 readonly ARMEL_EXTRA_DEP_FILES="$(cat ${SCRIPT_DIR}/packagelist.precise.armel.ex
tra)" | |
199 | |
200 ###################################################################### | |
201 # Helper | |
202 ###################################################################### | |
203 | |
204 Banner() { | |
205 echo "######################################################################" | |
206 echo $* | |
207 echo "######################################################################" | |
208 } | |
209 | |
210 | |
211 SubBanner() { | |
212 echo "......................................................................" | |
213 echo $* | |
214 echo "......................................................................" | |
215 } | |
216 | |
217 | |
218 Usage() { | |
219 egrep "^#@" $0 | cut --bytes=3- | |
220 } | |
221 | |
222 | |
223 DownloadOrCopy() { | |
224 if [[ -f "$2" ]] ; then | |
225 echo "$2 already in place" | |
226 elif [[ $1 =~ 'http://' ]] ; then | |
227 SubBanner "downloading from $1 -> $2" | |
228 wget $1 -O $2 | |
229 else | |
230 SubBanner "copying from $1" | |
231 cp $1 $2 | |
232 fi | |
233 } | |
234 | |
235 # some sanity checks to make sure this script is run from the right place | |
236 # with the right tools | |
237 SanityCheck() { | |
238 Banner "Sanity Checks" | |
239 if [[ $(basename $(pwd)) != "native_client" ]] ; then | |
240 echo "ERROR: run this script from the native_client/ dir" | |
241 exit -1 | |
242 fi | |
243 | |
244 if ! mkdir -p "${INSTALL_ROOT}" ; then | |
245 echo "ERROR: ${INSTALL_ROOT} can't be created." | |
246 exit -1 | |
247 fi | |
248 | |
249 if ! mkdir -p "${TMP}" ; then | |
250 echo "ERROR: ${TMP} can't be created." | |
251 exit -1 | |
252 fi | |
253 | |
254 for tool in ${REQUIRED_TOOLS} ; do | |
255 if ! which ${tool} ; then | |
256 echo "Required binary $tool not found." | |
257 echo "Exiting." | |
258 exit 1 | |
259 fi | |
260 done | |
261 } | |
262 | |
263 | |
264 # TODO(robertm): consider wiping all of ${BASE_DIR} | |
265 ClearInstallDir() { | |
266 Banner "clearing dirs in ${INSTALL_ROOT}" | |
267 rm -rf ${INSTALL_ROOT}/* | |
268 } | |
269 | |
270 | |
271 CreateTarBall() { | |
272 local tarball=$1 | |
273 Banner "creating tar ball ${tarball}" | |
274 tar cfz ${tarball} -C ${INSTALL_ROOT} . | |
275 } | |
276 | |
277 ###################################################################### | |
278 # One of these has to be run ONCE per machine | |
279 ###################################################################### | |
280 | |
281 #@ | |
282 #@ InstallCrossArmBasePackages | |
283 #@ | |
284 InstallCrossArmBasePackages() { | |
285 sudo apt-get install ${CROSS_ARM_TC_PACKAGES} | |
286 } | |
287 | |
288 ###################################################################### | |
289 # | |
290 ###################################################################### | |
291 | |
292 #@ | |
293 #@ InstallTrustedLinkerScript | |
294 #@ | |
295 #@ This forces the loading address of sel_ldr like programs | |
296 #@ to higher memory areas where they do not conflict with | |
297 #@ untrusted binaries. | |
298 #@ This likely no longer used because of "nacl_helper_bootstrap". | |
299 InstallTrustedLinkerScript() { | |
300 local trusted_ld_script=${INSTALL_ROOT}/ld_script_arm_trusted | |
301 # We are using the output of "ld --verbose" which contains | |
302 # the linker script delimited by "=========". | |
303 # We are changing the image start address to 70000000 | |
304 # to move the sel_ldr and other images "out of the way" | |
305 Banner "installing trusted linker script to ${trusted_ld_script}" | |
306 | |
307 arm-linux-gnueabi-ld --verbose |\ | |
308 grep -A 10000 "=======" |\ | |
309 grep -v "=======" |\ | |
310 sed -e 's/00008000/70000000/g' > ${trusted_ld_script} | |
311 } | |
312 | |
313 HacksAndPatches() { | |
314 rel_path=toolchain/linux_arm-trusted | |
315 Banner "Misc Hacks & Patches" | |
316 # these are linker scripts with absolute pathnames in them | |
317 # which we rewrite here | |
318 lscripts="${rel_path}/usr/lib/arm-linux-gnueabi/libpthread.so \ | |
319 ${rel_path}/usr/lib/arm-linux-gnueabi/libc.so" | |
320 | |
321 SubBanner "Rewriting Linker Scripts" | |
322 sed -i -e 's|/usr/lib/arm-linux-gnueabi/||g' ${lscripts} | |
323 sed -i -e 's|/lib/arm-linux-gnueabi/||g' ${lscripts} | |
324 | |
325 # This is for chrome's ./build/linux/pkg-config-wrapper | |
326 # which overwrites PKG_CONFIG_PATH internally | |
327 SubBanner "Package Configs Symlink" | |
328 mkdir -p ${rel_path}/usr/share | |
329 ln -s ../lib/arm-linux-gnueabi/pkgconfig ${rel_path}/usr/share/pkgconfig | |
330 } | |
331 | |
332 | |
333 InstallMissingArmLibrariesAndHeadersIntoJail() { | |
334 Banner "Install Libs And Headers Into Jail" | |
335 | |
336 mkdir -p ${TMP}/armel-packages | |
337 mkdir -p ${INSTALL_ROOT} | |
338 for file in $@ ; do | |
339 local package="${TMP}/armel-packages/${file##*/}" | |
340 Banner "installing ${file}" | |
341 DownloadOrCopy ${ARMEL_REPO}/pool/${file} ${package} | |
342 SubBanner "extracting to ${INSTALL_ROOT}" | |
343 if [[ ! -s ${package} ]] ; then | |
344 echo | |
345 echo "ERROR: bad package ${package}" | |
346 exit -1 | |
347 fi | |
348 dpkg --fsys-tarfile ${package}\ | |
349 | tar -xvf - --exclude=./usr/share -C ${INSTALL_ROOT} | |
350 done | |
351 } | |
352 | |
353 | |
354 CleanupJailSymlinks() { | |
355 Banner "jail symlink cleanup" | |
356 | |
357 pushd ${INSTALL_ROOT} | |
358 find usr/lib -type l -printf '%p %l\n' | while read link target; do | |
359 # skip links with non-absolute paths | |
360 if [[ ${target} != /* ]] ; then | |
361 continue | |
362 fi | |
363 echo "${link}: ${target}" | |
364 case "${link}" in | |
365 usr/lib/arm-linux-gnueabi/*) | |
366 # Relativize the symlink. | |
367 ln -snfv "../../..${target}" "${link}" | |
368 ;; | |
369 usr/lib/*) | |
370 # Relativize the symlink. | |
371 ln -snfv "../..${target}" "${link}" | |
372 ;; | |
373 esac | |
374 # make sure we catch new bad links | |
375 if [ "${link}" == "usr/lib/arm-linux-gnueabi/libnss_db.so" ] ; then | |
376 echo "ignoring known bad link: ${link}" | |
377 elif [ ! -r "${link}" ]; then | |
378 echo "ERROR: FOUND BAD LINK ${link}" | |
379 exit -1 | |
380 fi | |
381 done | |
382 popd | |
383 } | |
384 | |
385 #@ | |
386 #@ BuildAndInstallQemu | |
387 #@ | |
388 #@ Build ARM emulator including some patches for better tracing | |
389 # | |
390 # Historic Notes: | |
391 # Traditionally we were builidng static 32 bit images of qemu on a | |
392 # 64bit system which would run then on both x86-32 and x86-64 systems. | |
393 # The latest version of qemu contains new dependencies which | |
394 # currently make it impossible to build such images on 64bit systems | |
395 # We can build a static 64bit qemu but it does not work with | |
396 # the sandboxed translators for unknown reason. | |
397 # So instead we chose to build 32bit shared images. | |
398 # | |
399 | |
400 #readonly QEMU_TARBALL=$(readlink -f ../third_party/qemu/qemu-1.0.1.tar.gz) | |
401 #readonly QEMU_DIR=qemu-1.0.1 | |
402 readonly QEMU_TARBALL=$(readlink -f ../third_party/qemu/qemu-1.0.1.tar.gz) | |
403 readonly QEMU_PATCH=$(readlink -f ../third_party/qemu/qemu-1.0.1.patch_arm) | |
404 readonly QEMU_DIR=qemu-1.0.1 | |
405 | |
406 BuildAndInstallQemu() { | |
407 local saved_dir=$(pwd) | |
408 local tmpdir="${TMP}/qemu.nacl" | |
409 | |
410 Banner "Building qemu in ${tmpdir}" | |
411 rm -rf ${tmpdir} | |
412 mkdir ${tmpdir} | |
413 cd ${tmpdir} | |
414 SubBanner "Untaring ${QEMU_TARBALL}" | |
415 tar zxf ${QEMU_TARBALL} | |
416 cd ${QEMU_DIR} | |
417 | |
418 SubBanner "Patching ${QEMU_PATCH}" | |
419 patch -p1 < ${QEMU_PATCH} | |
420 | |
421 SubBanner "Configuring" | |
422 env -i PATH=/usr/bin/:/bin \ | |
423 ./configure \ | |
424 --extra-cflags="-m32" \ | |
425 --extra-ldflags="-Wl,-rpath=/lib32" \ | |
426 --disable-system \ | |
427 --enable-linux-user \ | |
428 --disable-darwin-user \ | |
429 --disable-bsd-user \ | |
430 --target-list=arm-linux-user \ | |
431 --disable-smartcard-nss \ | |
432 --disable-sdl | |
433 | |
434 # see above for why we can no longer use -static | |
435 # --static | |
436 | |
437 SubBanner "Make" | |
438 env -i PATH=/usr/bin/:/bin \ | |
439 V=99 make MAKE_OPTS=${MAKE_OPTS} | |
440 | |
441 SubBanner "Install ${INSTALL_ROOT}" | |
442 cp arm-linux-user/qemu-arm ${INSTALL_ROOT} | |
443 cd ${saved_dir} | |
444 cp tools/llvm/qemu_tool.sh ${INSTALL_ROOT} | |
445 ln -sf qemu_tool.sh ${INSTALL_ROOT}/run_under_qemu_arm | |
446 } | |
447 | |
448 #@ | |
449 #@ BuildJail <tarball-name> | |
450 #@ | |
451 #@ Build everything and package it | |
452 BuildJail() { | |
453 ClearInstallDir | |
454 InstallMissingArmLibrariesAndHeadersIntoJail \ | |
455 ${ARMEL_BASE_DEP_FILES} \ | |
456 ${ARMEL_EXTRA_DEP_FILES} | |
457 CleanupJailSymlinks | |
458 InstallTrustedLinkerScript | |
459 HacksAndPatches | |
460 AddChromeWrapperScripts | |
461 BuildAndInstallQemu | |
462 CreateTarBall $1 | |
463 } | |
464 | |
465 #@ | |
466 #@ AddChromeWrapperScripts | |
467 #@ | |
468 #@ Add some script which simplify cross compiling chrome. | |
469 AddChromeWrapperScripts() { | |
470 SubBanner "Installing Chrome Wrapper" | |
471 | |
472 cp -a tools/llvm/chrome.cc.arm.sh ${INSTALL_ROOT}/chrome.cc.arm.sh | |
473 cp -a tools/llvm/chrome.cc.arm.sh ${INSTALL_ROOT}/chrome.c++.arm.sh | |
474 | |
475 cp -a tools/llvm/chrome.cc.host.sh ${INSTALL_ROOT}/chrome.cc.host.sh | |
476 cp -a tools/llvm/chrome.cc.host.sh ${INSTALL_ROOT}/chrome.c++.host.sh | |
477 | |
478 chmod a+rx ${INSTALL_ROOT}/chrome.c*.sh | |
479 } | |
480 | |
481 #@ | |
482 #@ GeneratePackageList | |
483 #@ | |
484 #@ This will need some manual intervention, e.g. "pool/" | |
485 #@ needs to be stripped and special characters like may "+" cause problems | |
486 #@ | |
487 GeneratePackageList() { | |
488 local package_list="${TMP}/Packages.precise.bz2" | |
489 DownloadOrCopy ${PACKAGE_LIST} ${package_list} | |
490 bzcat ${package_list} | egrep '^(Package:|Filename:)' > ${TMP}/Packages | |
491 echo ${ARMEL_EXTRA_PACKAGES} | |
492 echo "# BEGIN:" | |
493 for pkg in $@ ; do | |
494 grep -A 1 "${pkg}\$" ${TMP}/Packages | egrep -o "pool/.*" | |
495 done | |
496 echo "# END:" | |
497 } | |
498 | |
499 GeneratePackageListBase() { | |
500 GeneratePackageList "${ARMEL_BASE_PACKAGES}" | |
501 } | |
502 | |
503 GeneratePackageListExtra() { | |
504 GeneratePackageList "${ARMEL_EXTRA_PACKAGES}" | |
505 } | |
506 | |
507 | |
508 if [[ $# -eq 0 ]] ; then | |
509 echo "ERROR: you must specify a mode on the commandline" | |
510 echo | |
511 Usage | |
512 exit -1 | |
513 elif [[ "$(type -t $1)" != "function" ]]; then | |
514 echo "ERROR: unknown function '$1'." >&2 | |
515 echo "For help, try:" | |
516 echo " $0 help" | |
517 exit 1 | |
518 else | |
519 SanityCheck | |
520 "$@" | |
521 fi | |
OLD | NEW |