Skip to content

Instantly share code, notes, and snippets.

@buzzy
Forked from tautologico/buildcrossgcc.sh
Last active June 14, 2019 09:16
Show Gist options
  • Save buzzy/27786415ea20828d04e1dd4d19159fad to your computer and use it in GitHub Desktop.
Save buzzy/27786415ea20828d04e1dd4d19159fad to your computer and use it in GitHub Desktop.
Build gcc cross-compiler for armv7-a (Cortex-A)
#!/bin/sh
# Download binutils, gcc, the linux kernel, glibc
# define the prefix
export PREFIX=/opt/armhf
# change PATH to include the target directory
export PATH=$PREFIX/bin:$PATH
# Build binutils
cd ~/tmp/binutils
./configure --prefix=$PREFIX --target=arm-linux-gnueabihf --with-arch=armv7a --with-fpu=vfp --with-float=hard --disable-multilib
make -j$(nproc)
make install
# Install the Linux kernel headers
cd ~/tmp/linux
make ARCH=arm INSTALL_HDR_PATH=$PREFIX/arm-linux-gnueabihf headers_install
# Build gcc (first phase)
cd ~/tmp/gcc
./contrib/download_prerequisites
mkdir build; cd build
../configure --prefix=$PREFIX --target=arm-linux-gnueabihf --enable-languages=c,c++ --with-arch=armv7-a --with-fpu=vfp --with-float=hard --disable-multilib --disable-bootstrap
make -j4 all-gcc
make install-gcc
# Build glibc (first phase)
cd ~/tmp/glibc
mkdir build; cd build
../configure --prefix=$PREFIX/arm-linux-gnueabihf --build=$MACHTYPE --host=arm-linux-gnueabihf --target=arm-linux-gnueabihf --with-arch=armv7a --with-fpu=vfp --with-float=hard --with-headers=$PREFIX/arm-linux-gnueabihf/include --disable-multilib libc_cv_forced_unwind=yes
make install-bootstrap-headers=yes install-headers
make -j4 csu/subdir_lib
install csu/crt1.o csu/crti.o csu/crtn.o $PREFIX/arm-linux-gnueabihf/lib
arm-linux-gnueabihf-gcc -nostdlib -nostartfiles -shared -x c /dev/null -o $PREFIX/arm-linux-gnueabihf/lib/libc.so
touch $PREFIX/arm-linux-gnueabihf/include/gnu/stubs.h
# Build gcc (second phase, libgcc)
cd ~/tmp/gcc/build
make -j4 all-target-libgcc
make install-target-libgcc
# Build glibc (second phase)
cd ~/tmp/glibc/build
make -j4
make install
# Build libstdc++
cd ~/tmp/gcc/build
make -j4
make install
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment