2 ################################################################
3 # A script to build a GNU GCC and Binutils cross-compiler
4 # Based on https://wiki.osdev.org/GCC_Cross-Compiler
6 # Copyright (c) 2022, the Native authors.
7 # SPDX-License-Identifier: BSD-2-Clause
8 ################################################################
10 ################################################################
12 ################################################################
14 # Exit if there is an error
21 # Always use the latest working version (test before updating)
25 # Tar file extension to use
26 # Always use the one with the smallest file size (check when updating version)
31 # Currrently automatic using nproc
32 CORES
=$
(($
(nproc
) + 1))
36 export PATH
="$PREFIX/bin:$PATH"
38 echo "Building $TARGET Binutils $BUT_VER and GCC $GCC_VER..."
39 echo "Cores: $CORES, load: $LOAD"
41 ################################################################
43 ################################################################
45 BUT_TARBALL
=binutils-
$BUT_VER.
tar.
$BUT_EXT
46 GCC_TARBALL
=gcc-
$GCC_VER.
tar.
$GCC_EXT
52 echo "Downloading Binutils tarball..."
53 if [ ! -f $BUT_TARBALL ]; then
54 wget https
://ftp.gnu.org
/gnu
/binutils
/$BUT_TARBALL
57 echo "Downloading GCC tarball..."
58 if [ ! -f $GCC_TARBALL ]; then
59 wget https
://ftp.gnu.org
/gnu
/gcc
/gcc-
$GCC_VER/$GCC_TARBALL
63 printf "%s" "Unzipping Binutils tarball"
64 tar -xf $BUT_TARBALL --checkpoint=.400
66 printf "%s" "Unzipping GCC tarball"
67 tar -xf $GCC_TARBALL --checkpoint=.400
69 ################################################################
71 ################################################################
73 echo "Removing old build directories..."
74 rm -rf buildcc-gcc build-binutils
77 mkdir buildcc-binutils
79 echo "Configuring Binutils..."
80 ..
/binutils-
$BUT_VER/configure
--target=$TARGET --prefix="$PREFIX" --with-sysroot --disable-nls --disable-werror
81 echo "Building Binutils..."
83 echo "Installing Binutils..."
84 make install -j$CORES -l$LOAD
89 echo "Downloading prerequisites for GCC..."
90 contrib
/download_prerequisites
94 echo "Configuring GCC..."
95 ..
/gcc-
$GCC_VER/configure
--target=$TARGET --prefix="$PREFIX" --disable-nls --enable-languages=c
--without-headers
96 echo "Building all-gcc..."
97 make all-gcc
-j$CORES -l$LOAD
98 echo "Building all-target-libgcc..."
99 make all-target-libgcc
-j$CORES -l$LOAD
100 echo "Installing GCC..."
101 make install-gcc
-j$CORES -l$LOAD
102 echo "Installing target-libgcc..."
103 make install-target-libgcc
-j$CORES -l$LOAD
106 echo "Removing build directory..."
109 echo "Build complete, binaries are in $PREFIX/bin"
111 ################################################################
112 # Basic Testing (just prints info for now)
113 ################################################################
115 echo "Testing GCC..."