Skip to content

Instantly share code, notes, and snippets.

@Adobe-Android
Created November 17, 2020 18:32
Show Gist options
  • Save Adobe-Android/c6061a6f72500ed6bd772661ad0900ae to your computer and use it in GitHub Desktop.
Save Adobe-Android/c6061a6f72500ed6bd772661ad0900ae to your computer and use it in GitHub Desktop.
#!/bin/bash
# stop script on first error
set -e
mkdir gcc_for_raspberrypi
cd gcc_for_raspberrypi
# variables that define the result
install_dir="$(pwd)/install"
sysroot_dir="$(pwd)/sysroot"
arch=armv8-a
tune=cortex-a72
gcc_version='10.2.0'
binutils_version='2.35.1'
# mount raspberry root
mkdir sysroot
sshfs -o ro [email protected]:/ ./sysroot
# get sources
curl -Lo binutils.tar.bz2 \
"https://ftpmirror.gnu.org/binutils/binutils-$binutils_version.tar.bz2"
curl -Lo gcc.tar.xz \
"https://ftp.wayne.edu/gnu/gcc/gcc-$gcc_version/gcc-$gcc_version.tar.xz"
# build binutils
mkdir binutils_source
cd binutils_source
tar --strip-components 1 -xf ../binutils.tar.bz2
mkdir ../binutils_build
cd ../binutils_build
../binutils_source/configure \
--prefix="$install_dir" \
--target=arm-linux-gnueabihf \
--with-arch=$arch \
--with-tune=$tune \
--with-fpu=vfp \
--with-float=hard \
--disable-multilib \
--with-sysroot="$sysroot_dir" \
--enable-gold=yes \
--enable-lto
make -j$(nproc)
make install
cd ..
# build gcc
mkdir gcc_source
cd gcc_source
tar --strip-components 1 -xf ../gcc.tar.xz
mkdir ../gcc_build
cd ../gcc_build
../gcc_source/configure \
--prefix="$install_dir" \
--target=arm-linux-gnueabihf \
--with-arch=$arch \
--with-tune=$tune \
--with-fpu=vfp \
--with-float=hard \
--disable-multilib \
--with-sysroot="$sysroot_dir" \
--enable-languages=c,c++,go,d
make -j$(nproc)
make install
cd ..
echo "Successfully compiled 'binutils' and 'gcc'"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment