James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # Copyright 2014 The Chromium 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 | # Script to build binutils for both i386 and AMD64 Linux architectures. |
| 7 | # Must be run on an AMD64 supporting machine which has debootstrap and sudo |
| 8 | # installed. |
| 9 | # Uses Ubuntu Lucid chroots as build environment. |
| 10 | |
| 11 | set -e |
| 12 | |
| 13 | if [ x"$(whoami)" = x"root" ]; then |
| 14 | echo "Script must not be run as root." |
| 15 | exit 1 |
| 16 | fi |
| 17 | sudo -v |
| 18 | |
| 19 | OUTPUTDIR="${1:-$PWD/output-$(date +%Y%m%d-%H%M%S)}" |
| 20 | if [ ! -d "$OUTPUTDIR" ]; then |
| 21 | mkdir -p "$OUTPUTDIR" |
| 22 | fi |
| 23 | |
| 24 | # Download the source |
| 25 | VERSION=2.24 |
| 26 | wget -c http://ftp.gnu.org/gnu/binutils/binutils-$VERSION.tar.bz2 |
| 27 | |
| 28 | # Verify the signature |
| 29 | wget -c -q http://ftp.gnu.org/gnu/binutils/binutils-$VERSION.tar.bz2.sig |
| 30 | if ! gpg --verify binutils-$VERSION.tar.bz2.sig; then |
| 31 | echo "GPG Signature failed to verify." |
| 32 | echo "" |
| 33 | echo "You may need to import the vendor GPG key with:" |
| 34 | echo "# gpg --keyserver pgp.mit.edu --recv-key 4AE55E93" |
| 35 | exit 1 |
| 36 | fi |
| 37 | |
| 38 | |
| 39 | if [ ! -d binutils-$VERSION ]; then |
| 40 | # Extract the source |
| 41 | tar jxf binutils-$VERSION.tar.bz2 |
| 42 | |
| 43 | # Patch the source |
| 44 | ( |
| 45 | cd binutils-$VERSION |
| 46 | patch -p1 < ../ehframe-race.patch |
James Robinson | 7b766f4 | 2015-02-06 15:14:04 -0800 | [diff] [blame] | 47 | patch -p1 < ../unlock-thin.patch |
| 48 | patch -p1 < ../plugin-dso-fix.patch |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 49 | ) |
| 50 | fi |
| 51 | |
| 52 | for ARCH in i386 amd64; do |
| 53 | if [ ! -d lucid-chroot-$ARCH ]; then |
| 54 | # Refresh sudo credentials |
| 55 | sudo -v |
| 56 | |
| 57 | # Create the chroot |
| 58 | echo "" |
| 59 | echo "Building chroot for $ARCH" |
| 60 | echo "=============================" |
| 61 | sudo debootstrap \ |
| 62 | --arch=$ARCH \ |
| 63 | --include=build-essential,flex,bison \ |
| 64 | lucid lucid-chroot-$ARCH |
| 65 | echo "=============================" |
| 66 | fi |
| 67 | |
| 68 | BUILDDIR=lucid-chroot-$ARCH/build |
| 69 | |
| 70 | # Clean up any previous failed build attempts inside chroot |
| 71 | if [ -d "$BUILDDIR" ]; then |
| 72 | sudo rm -rf "$BUILDDIR" |
| 73 | fi |
| 74 | |
| 75 | # Copy data into the chroot |
| 76 | sudo mkdir -p "$BUILDDIR" |
| 77 | sudo cp -a binutils-$VERSION "$BUILDDIR" |
| 78 | sudo cp -a build-one.sh "$BUILDDIR" |
| 79 | |
| 80 | # Do the build |
| 81 | PREFIX= |
| 82 | case $ARCH in |
| 83 | i386) |
| 84 | PREFIX="setarch linux32" |
| 85 | ARCHNAME=i686-pc-linux-gnu |
| 86 | ;; |
| 87 | amd64) |
| 88 | PREFIX="setarch linux64" |
| 89 | ARCHNAME=x86_64-unknown-linux-gnu |
| 90 | ;; |
| 91 | esac |
| 92 | echo "" |
| 93 | echo "Building binutils for $ARCH" |
| 94 | LOGFILE="$OUTPUTDIR/build-$ARCH.log" |
| 95 | if ! sudo $PREFIX chroot lucid-chroot-$ARCH /build/build-one.sh /build/binutils-$VERSION > $LOGFILE 2>&1; then |
| 96 | echo "Build failed! See $LOGFILE for details." |
| 97 | exit 1 |
| 98 | fi |
| 99 | |
| 100 | # Copy data out of the chroot |
| 101 | sudo chown -R $(whoami) "$BUILDDIR/output/" |
| 102 | |
| 103 | # Strip the output binaries |
| 104 | for i in "$BUILDDIR/output/$ARCHNAME/bin/*"; do |
| 105 | strip $i |
| 106 | done |
| 107 | |
| 108 | # Copy them out of the chroot |
| 109 | cp -a "$BUILDDIR/output/$ARCHNAME" "$OUTPUTDIR" |
| 110 | |
James Robinson | 7b766f4 | 2015-02-06 15:14:04 -0800 | [diff] [blame] | 111 | # Copy plugin header out of the chroot |
| 112 | mkdir "$OUTPUTDIR/$ARCHNAME/include" |
| 113 | cp "$BUILDDIR/binutils-$VERSION/include/plugin-api.h" "$OUTPUTDIR/$ARCHNAME/include/" |
| 114 | |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 115 | # Clean up chroot |
| 116 | sudo rm -rf "$BUILDDIR" |
| 117 | done |
| 118 | |
| 119 | echo "Check you are happy with the binaries in" |
| 120 | echo " $OUTPUTDIR" |
| 121 | echo "Then" |
| 122 | echo " * upload to Google Storage using the upload.sh script" |
| 123 | echo " * roll dependencies" |