Skip to content

Instantly share code, notes, and snippets.

@tautologico
Last active March 18, 2024 11:43
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save tautologico/3db84cf76fb85e9e3da8024251530d67 to your computer and use it in GitHub Desktop.
Save tautologico/3db84cf76fb85e9e3da8024251530d67 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 -j4
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
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
@KKALLER
Copy link

KKALLER commented Mar 18, 2024

i can't get this to work, i'm using Ubuntu 22.04.4 LTS 64-bit....is that why? i'm trying to use the compiler since i think that it will compile stuff for retroleap OS on leasterGS device (eventually leapster explorer and certain leapster 2) but the leapsterGS has a cortex arm 9 cpu 32 bit, but the retroleap OS is GMenuNX (a fork of GMenu2X) most likely arm 7 since retroarch 1.9.7 is arm7 and runs well. OS source code: https://www.github.com/retrofw/gmenunx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment