|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# big thanks to: |
| 4 | +# @mcandre |
| 5 | +# @samm-git |
| 6 | +# @mcilloni |
| 7 | +# @marcelog |
| 8 | +# @bijanebrahimi |
| 9 | +# for their work on this subject which |
| 10 | +# I have been able to expand upon for cgo/golang |
| 11 | + |
| 12 | +freebsd_ver=12 |
| 13 | +freebsd_full_ver=12.4 |
| 14 | +binutils_ver=2.39 |
| 15 | +gmp_ver=6.2.1 |
| 16 | +mpfr_ver=4.1.1 |
| 17 | +mpc_ver=1.3.1 |
| 18 | +gcc_ver=7.5.0 |
| 19 | + |
| 20 | +mkdir -p /freebsdcross/x86_64-pc-freebsd${freebsd_ver} |
| 21 | + |
| 22 | +# binutils |
| 23 | +mkdir /tmp/freebsdbuild && cd /tmp/freebsdbuild && \ |
| 24 | + wget https://ftp.gnu.org/gnu/binutils/binutils-${binutils_ver}.tar.xz && \ |
| 25 | + tar -xf binutils-${binutils_ver}.tar.xz && cd binutils-${binutils_ver} && \ |
| 26 | + ./configure --enable-libssp --enable-gold --enable-ld \ |
| 27 | + --target=x86_64-pc-freebsd${freebsd_ver} --prefix=/freebsdcross/x86_64-pc-freebsd${freebsd_ver} && make -j4 && \ |
| 28 | + make install && \ |
| 29 | + rm -rf /tmp/freebsdbuild && mkdir /tmp/freebsdbuild |
| 30 | + |
| 31 | +# freebsd specific lbs |
| 32 | +cd /tmp/freebsdbuild && \ |
| 33 | + wget https://download.freebsd.org/ftp/releases/amd64/${freebsd_full_ver}-RELEASE/base.txz && \ |
| 34 | + cd /freebsdcross/x86_64-pc-freebsd${freebsd_ver} && \ |
| 35 | + tar -xf /tmp/freebsdbuild/base.txz ./lib/ ./usr/lib/ ./usr/include/ && \ |
| 36 | + cd /freebsdcross/x86_64-pc-freebsd${freebsd_ver}/usr/lib && \ |
| 37 | + find . -xtype l|xargs ls -l|grep ' /lib/' \ |
| 38 | + | awk '{print "ln -sf /freebsdcross/x86_64-pc-freebsd12"$11 " " $9}' \ |
| 39 | + | /bin/sh && \ |
| 40 | + rm -rf /tmp/freebsdbuild && mkdir /tmp/freebsdbuild |
| 41 | + |
| 42 | +# Compile GMP |
| 43 | +cd /tmp/freebsdbuild && \ |
| 44 | + wget https://ftp.gnu.org/gnu/gmp/gmp-${gmp_ver}.tar.xz && \ |
| 45 | + tar -xf gmp-${gmp_ver}.tar.xz && \ |
| 46 | + cd gmp-${gmp_ver} && \ |
| 47 | + ./configure --prefix=/freebsdcross/x86_64-pc-freebsd${freebsd_ver} --enable-shared --enable-static \ |
| 48 | + --enable-fft --enable-cxx --host=x86_64-pc-freebsd${freebsd_ver} && \ |
| 49 | + make -j4 && make install && \ |
| 50 | + rm -rf /tmp/freebsdbuild && mkdir /tmp/freebsdbuild |
| 51 | + |
| 52 | +# Compile MPFR |
| 53 | +cd /tmp/freebsdbuild && \ |
| 54 | + wget https://ftp.gnu.org/gnu/mpfr/mpfr-${mpfr_ver}.tar.xz && tar -xf mpfr-${mpfr_ver}.tar.xz && \ |
| 55 | + cd mpfr-${mpfr_ver} && \ |
| 56 | + ./configure --prefix=/freebsdcross/x86_64-pc-freebsd${freebsd_ver} --with-gnu-ld --enable-static \ |
| 57 | + --enable-shared --with-gmp=/freebsdcross/x86_64-pc-freebsd${freebsd_ver} --host=x86_64-pc-freebsd${freebsd_ver} && \ |
| 58 | + make -j4 && make install && \ |
| 59 | + rm -rf /tmp/freebsdbuild && mkdir /tmp/freebsdbuild |
| 60 | + |
| 61 | +# Compile MPC |
| 62 | +cd /tmp/freebsdbuild && \ |
| 63 | + wget https://ftp.gnu.org/gnu/mpc/mpc-${mpc_ver}.tar.gz && tar -xf mpc-${mpc_ver}.tar.gz && \ |
| 64 | + cd mpc-${mpc_ver} && \ |
| 65 | + ./configure --prefix=/freebsdcross/x86_64-pc-freebsd${freebsd_ver} --with-gnu-ld --enable-static \ |
| 66 | + --enable-shared --with-gmp=/freebsdcross/x86_64-pc-freebsd${freebsd_ver} \ |
| 67 | + --with-mpfr=/freebsdcross/x86_64-pc-freebsd${freebsd_ver} --host=x86_64-pc-freebsd${freebsd_ver} && \ |
| 68 | + make -j4 && make install && \ |
| 69 | + rm -rf /tmp/freebsdbuild && mkdir /tmp/freebsdbuild |
| 70 | + |
| 71 | +# gcc (change LD_LIBRARY_PATH to /freebsdcross or something) |
| 72 | +cd /tmp/freebsdbuild && \ |
| 73 | + wget https://ftp.gnu.org/gnu/gcc/gcc-${gcc_ver}/gcc-${gcc_ver}.tar.xz && \ |
| 74 | + tar xf gcc-${gcc_ver}.tar.xz && \ |
| 75 | + cd gcc-${gcc_ver} && mkdir build && cd build && \ |
| 76 | + ../configure --without-headers --with-gnu-as --with-gnu-ld --disable-nls \ |
| 77 | + --enable-languages=c,c++ --enable-libssp --enable-gold --enable-ld \ |
| 78 | + --disable-libitm --disable-libquadmath --target=x86_64-pc-freebsd${freebsd_ver} \ |
| 79 | + --prefix=/freebsdcross/x86_64-pc-freebsd${freebsd_ver} --with-gmp=/freebsdcross/x86_64-pc-freebsd${freebsd_ver} \ |
| 80 | + --with-mpc=/freebsdcross/x86_64-pc-freebsd${freebsd_ver} --with-mpfr=/freebsdcross/x86_64-pc-freebsd${freebsd_ver} --disable-libgomp \ |
| 81 | + --with-sysroot=/freebsdcross/x86_64-pc-freebsd${freebsd_ver} \ |
| 82 | + --with-build-sysroot=/freebsdcross/x86_64-pc-freebsd${freebsd_ver} && \ |
| 83 | + cd /tmp/freebsdbuild/gcc-${gcc_ver} && \ |
| 84 | + echo '#define HAVE_ALIGNED_ALLOC 1' >> libstdc++-v3/config.h.in && \ |
| 85 | + cd /tmp/freebsdbuild/gcc-${gcc_ver}/build && \ |
| 86 | + make -j4 && make install && \ |
| 87 | + rm -rf /tmp/freebsdbuild |
0 commit comments