Skip to content

Instantly share code, notes, and snippets.

@bijanebrahimi
Last active April 17, 2024 19:54
Show Gist options
  • Star 14 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save bijanebrahimi/62596745808f8667c40ff91b07d9e7b8 to your computer and use it in GitHub Desktop.
Save bijanebrahimi/62596745808f8667c40ff91b07d9e7b8 to your computer and use it in GitHub Desktop.
build a linux cross compiler for FreeBSD targets
#!/bin/bash
export TARGET=amd64-marcel-freebsd9.2
export PREFIX=/usr/cross-build
export TARGET_PREFIX=$PREFIX/$TARGET
export PATH=$PATH:$PREFIX/bin
mkdir -p $TARGET_PREFIX{,/lib,/include}
mkdir build-{binutils,gmp,mpfr,mpci,gcc}
# Copy FreeBSD /usr/{include,lib} in $TARGET_PREFIX
echo "Please copy FreeBSD's /usr/{include,lib} to $TARGET_PREFIX"
# BINUTILS
wget https://ftp.gnu.org/gnu/binutils/binutils-2.27.tar.gz
tar zxvf binutils-2.27.tar.gz
cd build-binutils
../binutils-2.27/configure --target=$TARGET --prefix=$PREFIX -v
make -j 4
sudo make install
# GMP
wget https://ftp.gnu.org/gnu/gmp/gmp-6.1.1.tar.xz
tar xvf gmp-6.1.1.tar.xz
cd build-gmp
../gmp-6.1.1/configure --prefix=$PREFIX --enable-shared --enable-static --enable-mpbsd --enable-fft --enable-cxx --host=$TARGET
make -j 4
sudo make install
# MPFR
wget https://ftp.gnu.org/gnu/mpfr/mpfr-3.1.5.tar.xz
tar xvf mpfr-3.1.5.tar.xz
cd build-mpfr
../mpfr-3.1.5/configure --prefix=$PREFIX --with-gnu-ld --with-gmp=$PREFIX --enable-static --enable-shared --host=$TARGET
make -j 4
sudo make install
# MPC
wget https://ftp.gnu.org/gnu/mpc/mpc-1.0.3.tar.gz
tar zxvf mpc-1.0.3.tar.gz
cd build-mpc
../mpc-1.0.3/configure --prefix=$PREFIX --with-gnu-ld --with-gmp=$PREFIX --with-mpfr=$PREFIX --enable-static --enable-shared --host=$TARGET
make -j 4
sudo make install
# GCC
wget https://ftp.gnu.org/gnu/gcc/gcc-6.2.0/gcc-6.2.0.tar.gz
tar zxvf gcc-6.2.0.tar.gz
cd build-gcc
../gcc-6.2.0/configure --without-headers --with-gnu-as --with-gnu-ld --enable-languages=c,c++ --disable-nls --enable-libssp --enable-gold --enable-ld --target=$TARGET --prefix=$PREFIX --with-gmp=$PREFIX --with-mpc=$PREFIX --with-mpfr=$PREFIX --disable-libgomp
LD_LIBRARY_PATH=$PREFIX/lib make -j 4
sudo make install
# DONE!
gcc helloworld.c -o helloworld-linux
LD_LIBRARY_PATH=$PREFIX/lib amd64-marcel-freebsd9.2-gcc helloworld.c -o helloworld-freebsd
# GDB
wget https://ftp.gnu.org/gnu/gdb/gdb-7.11.tar.xz
tar xvf gdb-7.11.tar.xz
../gdb-7.11.1/configure --prefix=$PREFIX --target=$TARGET
make -j 4
sudo make install
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment