|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +set -ex |
| 4 | + |
| 5 | +ARCH=x86_64 |
| 6 | +BINUTILS=2.25.1 |
| 7 | +GCC=5.3.0 |
| 8 | +URL_DFLY_ISO=http://mirror-master.dragonflybsd.org/iso-images/dfly-x86_64-4.4.3_REL.iso.bz2 |
| 9 | + |
| 10 | +mkdir binutils |
| 11 | +cd binutils |
| 12 | + |
| 13 | +# First up, build binutils |
| 14 | +curl https://ftp.gnu.org/gnu/binutils/binutils-$BINUTILS.tar.bz2 | tar xjf - |
| 15 | +mkdir binutils-build |
| 16 | +cd binutils-build |
| 17 | +../binutils-$BINUTILS/configure \ |
| 18 | + --target=$ARCH-unknown-dragonfly |
| 19 | +make -j10 |
| 20 | +make install |
| 21 | +cd ../.. |
| 22 | +rm -rf binutils |
| 23 | + |
| 24 | +# Next, download the DragonFly libc and relevant header files |
| 25 | +mkdir dragonfly |
| 26 | +curl $URL_DFLY_ISO | bzcat | bsdtar xf - -C dragonfly ./usr/include ./usr/lib ./lib |
| 27 | + |
| 28 | +dst=/usr/local/$ARCH-unknown-dragonfly |
| 29 | + |
| 30 | +cp -r dragonfly/usr/include $dst/ |
| 31 | +cp dragonfly/usr/lib/crt1.o $dst/lib |
| 32 | +cp dragonfly/usr/lib/Scrt1.o $dst/lib |
| 33 | +cp dragonfly/usr/lib/crti.o $dst/lib |
| 34 | +cp dragonfly/usr/lib/crtn.o $dst/lib |
| 35 | +cp dragonfly/usr/lib/libc.a $dst/lib |
| 36 | +cp dragonfly/usr/lib/libutil.a $dst/lib |
| 37 | +#cp dragonfly/usr/lib/libutil_p.a $dst/lib |
| 38 | +cp dragonfly/usr/lib/libm.a $dst/lib |
| 39 | +cp dragonfly/usr/lib/librt.so.0 $dst/lib |
| 40 | +cp dragonfly/usr/lib/libexecinfo.so.1 $dst/lib |
| 41 | +cp dragonfly/lib/libc.so.8 $dst/lib |
| 42 | +cp dragonfly/lib/libm.so.4 $dst/lib |
| 43 | +cp dragonfly/lib/libutil.so.4 $dst/lib |
| 44 | +#cp dragonfly/lib/libthr.so.3 $dst/lib/libpthread.so |
| 45 | +cp dragonfly/usr/lib/libpthread.so $dst/lib/libpthread.so |
| 46 | +cp dragonfly/usr/lib/thread/libthread_xu.so.2 $dst/lib/libpthread.so.0 |
| 47 | + |
| 48 | +ln -s libc.so.8 $dst/lib/libc.so |
| 49 | +ln -s libm.so.4 $dst/lib/libm.so |
| 50 | +ln -s librt.so.0 $dst/lib/librt.so |
| 51 | +ln -s libutil.so.4 $dst/lib/libutil.so |
| 52 | +ln -s libexecinfo.so.1 $dst/lib/libexecinfo.so |
| 53 | +rm -rf dragonfly |
| 54 | + |
| 55 | +# Finally, download and build gcc to target FreeBSD |
| 56 | +mkdir gcc |
| 57 | +cd gcc |
| 58 | +curl https://ftp.gnu.org/gnu/gcc/gcc-$GCC/gcc-$GCC.tar.bz2 | tar xjf - |
| 59 | +cd gcc-$GCC |
| 60 | + |
| 61 | +# The following three patches are taken from DragonFly's dports collection: |
| 62 | +# https://github.com/DragonFlyBSD/DPorts/tree/master/lang/gcc5 |
| 63 | +# The dports specification for gcc5 contains a few more patches, but they are |
| 64 | +# not relevant in this situation, as they are for a language we don't need |
| 65 | +# (e.g. java), or a platform which is not supported by DragonFly (e.g. i386, |
| 66 | +# powerpc64, ia64, arm). |
| 67 | +# |
| 68 | +# These patches probably only need to be updated in case the gcc version is |
| 69 | +# updated. |
| 70 | + |
| 71 | +patch -p0 <<'EOF' |
| 72 | +--- libatomic/configure.tgt.orig 2015-07-09 16:08:55 UTC |
| 73 | ++++ libatomic/configure.tgt |
| 74 | +@@ -110,7 +110,7 @@ case "${target}" in |
| 75 | + ;; |
| 76 | + |
| 77 | + *-*-linux* | *-*-gnu* | *-*-k*bsd*-gnu \ |
| 78 | +- | *-*-netbsd* | *-*-freebsd* | *-*-openbsd* \ |
| 79 | ++ | *-*-netbsd* | *-*-freebsd* | *-*-openbsd* | *-*-dragonfly* \ |
| 80 | + | *-*-solaris2* | *-*-sysv4* | *-*-irix6* | *-*-osf* | *-*-hpux11* \ |
| 81 | + | *-*-darwin* | *-*-aix* | *-*-cygwin*) |
| 82 | + # POSIX system. The OS is supported. |
| 83 | +EOF |
| 84 | + |
| 85 | +patch -p0 <<'EOF' |
| 86 | +--- libstdc++-v3/config/os/bsd/dragonfly/os_defines.h.orig 2015-07-09 16:08:54 UTC |
| 87 | ++++ libstdc++-v3/config/os/bsd/dragonfly/os_defines.h |
| 88 | +@@ -29,4 +29,9 @@ |
| 89 | + // System-specific #define, typedefs, corrections, etc, go here. This |
| 90 | + // file will come before all others. |
| 91 | + |
| 92 | ++#define _GLIBCXX_USE_C99_CHECK 1 |
| 93 | ++#define _GLIBCXX_USE_C99_DYNAMIC (!(__ISO_C_VISIBLE >= 1999)) |
| 94 | ++#define _GLIBCXX_USE_C99_LONG_LONG_CHECK 1 |
| 95 | ++#define _GLIBCXX_USE_C99_LONG_LONG_DYNAMIC (_GLIBCXX_USE_C99_DYNAMIC || !defined __LONG_LONG_SUPPORTED) |
| 96 | ++ |
| 97 | + #endif |
| 98 | +EOF |
| 99 | + |
| 100 | +patch -p0 <<'EOF' |
| 101 | +--- libstdc++-v3/configure.orig 2016-05-26 18:34:47.163132921 +0200 |
| 102 | ++++ libstdc++-v3/configure 2016-05-26 18:35:29.594590648 +0200 |
| 103 | +@@ -52013,7 +52013,7 @@ |
| 104 | + |
| 105 | + ;; |
| 106 | + |
| 107 | +- *-freebsd*) |
| 108 | ++ *-freebsd* | *-dragonfly*) |
| 109 | + SECTION_FLAGS='-ffunction-sections -fdata-sections' |
| 110 | + |
| 111 | + |
| 112 | +EOF |
| 113 | + |
| 114 | +./contrib/download_prerequisites |
| 115 | + |
| 116 | +mkdir ../gcc-build |
| 117 | +cd ../gcc-build |
| 118 | +../gcc-$GCC/configure \ |
| 119 | + --enable-languages=c,c++ \ |
| 120 | + --target=$ARCH-unknown-dragonfly \ |
| 121 | + --disable-multilib \ |
| 122 | + --disable-nls \ |
| 123 | + --disable-libgomp \ |
| 124 | + --disable-libquadmath \ |
| 125 | + --disable-libssp \ |
| 126 | + --disable-libvtv \ |
| 127 | + --disable-libcilkrts \ |
| 128 | + --disable-libada \ |
| 129 | + --disable-libsanitizer \ |
| 130 | + --disable-libquadmath-support \ |
| 131 | + --disable-lto |
| 132 | +make -j10 |
| 133 | +make install |
| 134 | +cd ../.. |
| 135 | +rm -rf gcc |
0 commit comments