|
| 1 | +#!/bin/bash |
| 2 | +# Copyright 2016 The Rust Project Developers. See the COPYRIGHT |
| 3 | +# file at the top-level directory of this distribution and at |
| 4 | +# http://rust-lang.org/COPYRIGHT. |
| 5 | +# |
| 6 | +# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0> or the MIT license |
| 8 | +# <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your |
| 9 | +# option. This file may not be copied, modified, or distributed |
| 10 | +# except according to those terms. |
| 11 | + |
| 12 | +set -ex |
| 13 | + |
| 14 | +ARCH=x86_64 |
| 15 | +PATCH_TOOLCHAIN=$1 |
| 16 | +BINUTILS=2.25.1 |
| 17 | +GCC=6.4.0 |
| 18 | + |
| 19 | +hide_output() { |
| 20 | + set +x |
| 21 | + on_err=" |
| 22 | +echo ERROR: An error was encountered with the build. |
| 23 | +cat /tmp/build.log |
| 24 | +exit 1 |
| 25 | +" |
| 26 | + trap "$on_err" ERR |
| 27 | + bash -c "while true; do sleep 30; echo \$(date) - building ...; done" & |
| 28 | + PING_LOOP_PID=$! |
| 29 | + $@ &> /tmp/build.log |
| 30 | + trap - ERR |
| 31 | + kill $PING_LOOP_PID |
| 32 | + set -x |
| 33 | +} |
| 34 | + |
| 35 | +mkdir binutils |
| 36 | +cd binutils |
| 37 | + |
| 38 | +# First up, build binutils |
| 39 | +curl https://ftp.gnu.org/gnu/binutils/binutils-$BINUTILS.tar.bz2 | tar xjf - |
| 40 | +mkdir binutils-build |
| 41 | +cd binutils-build |
| 42 | +hide_output ../binutils-$BINUTILS/configure \ |
| 43 | + --target=$ARCH-unknown-dragonfly |
| 44 | +hide_output make -j10 |
| 45 | +hide_output make install |
| 46 | +cd ../.. |
| 47 | +rm -rf binutils |
| 48 | + |
| 49 | +# Next, download the DragonFly libc and relevant header files |
| 50 | + |
| 51 | +URL=http://mirror-master.dragonflybsd.org/iso-images/dfly-x86_64-5.0.0_REL.iso.bz2 |
| 52 | +mkdir dragonfly |
| 53 | +curl $URL | bzcat | bsdtar xf - -C dragonfly ./usr/include ./usr/lib ./lib |
| 54 | + |
| 55 | +dst=/usr/local/$ARCH-unknown-dragonfly |
| 56 | + |
| 57 | +mkdir -p $dst/lib |
| 58 | +cp -r dragonfly/usr/include $dst/ |
| 59 | +cp dragonfly/usr/lib/crt1.o $dst/lib |
| 60 | +cp dragonfly/usr/lib/Scrt1.o $dst/lib |
| 61 | +cp dragonfly/usr/lib/crti.o $dst/lib |
| 62 | +cp dragonfly/usr/lib/crtn.o $dst/lib |
| 63 | +cp dragonfly/usr/lib/libc.a $dst/lib |
| 64 | +cp dragonfly/usr/lib/libutil.a $dst/lib |
| 65 | +cp dragonfly/usr/lib/libm.a $dst/lib |
| 66 | +cp dragonfly/usr/lib/librt.so.0 $dst/lib |
| 67 | +cp dragonfly/usr/lib/libexecinfo.so.1 $dst/lib |
| 68 | +cp dragonfly/lib/libc.so.8 $dst/lib |
| 69 | +cp dragonfly/lib/libm.so.4 $dst/lib |
| 70 | +cp dragonfly/lib/libutil.so.4 $dst/lib |
| 71 | +cp dragonfly/usr/lib/libpthread.so $dst/lib/libpthread.so |
| 72 | +cp dragonfly/usr/lib/thread/libthread_xu.so.2 $dst/lib/libpthread.so.0 |
| 73 | + |
| 74 | +ln -s libc.so.8 $dst/lib/libc.so |
| 75 | +ln -s libm.so.4 $dst/lib/libm.so |
| 76 | +ln -s librt.so.0 $dst/lib/librt.so |
| 77 | +ln -s libutil.so.4 $dst/lib/libutil.so |
| 78 | +ln -s libexecinfo.so.1 $dst/lib/libexecinfo.so |
| 79 | +rm -rf dragonfly |
| 80 | + |
| 81 | +# Finally, download and build gcc to target DragonFly |
| 82 | +mkdir gcc |
| 83 | +cd gcc |
| 84 | +curl https://ftp.gnu.org/gnu/gcc/gcc-$GCC/gcc-$GCC.tar.gz | tar xzf - |
| 85 | +cd gcc-$GCC |
| 86 | + |
| 87 | +# The following three patches are taken from DragonFly's dports collection: |
| 88 | +# https://github.com/DragonFlyBSD/DPorts/tree/master/lang/gcc5 |
| 89 | +# The dports specification for gcc5 contains a few more patches, but they are |
| 90 | +# not relevant in this situation, as they are for a language we don't need |
| 91 | +# (e.g. java), or a platform which is not supported by DragonFly (e.g. i386, |
| 92 | +# powerpc64, ia64, arm). |
| 93 | +# |
| 94 | +# These patches probably only need to be updated in case the gcc version is |
| 95 | +# updated. |
| 96 | + |
| 97 | +patch -p0 < $PATCH_TOOLCHAIN |
| 98 | + |
| 99 | +./contrib/download_prerequisites |
| 100 | + |
| 101 | +mkdir ../gcc-build |
| 102 | +cd ../gcc-build |
| 103 | +hide_output ../gcc-$GCC/configure \ |
| 104 | + --enable-languages=c,c++ \ |
| 105 | + --target=$ARCH-unknown-dragonfly \ |
| 106 | + --disable-multilib \ |
| 107 | + --disable-nls \ |
| 108 | + --disable-libgomp \ |
| 109 | + --disable-libquadmath \ |
| 110 | + --disable-libssp \ |
| 111 | + --disable-libvtv \ |
| 112 | + --disable-libcilkrts \ |
| 113 | + --disable-libada \ |
| 114 | + --disable-libsanitizer \ |
| 115 | + --disable-libquadmath-support \ |
| 116 | + --disable-lto |
| 117 | +hide_output make -j10 |
| 118 | +hide_output make install |
| 119 | +cd ../.. |
| 120 | +rm -rf gcc |
0 commit comments