Skip to content

Instantly share code, notes, and snippets.

@preshing
Last active August 1, 2025 16:21
Show Gist options
  • Save preshing/41d5c7248dea16238b60 to your computer and use it in GitHub Desktop.
Save preshing/41d5c7248dea16238b60 to your computer and use it in GitHub Desktop.

Revisions

  1. preshing revised this gist Jan 31, 2015. 1 changed file with 6 additions and 6 deletions.
    12 changes: 6 additions & 6 deletions build_cross_gcc
    Original file line number Diff line number Diff line change
    @@ -32,7 +32,7 @@ export PATH=$INSTALL_PATH/bin:$PATH
    # Download packages
    export http_proxy=$HTTP_PROXY https_proxy=$HTTP_PROXY ftp_proxy=$HTTP_PROXY
    wget -nc https://ftp.gnu.org/gnu/binutils/$BINUTILS_VERSION.tar.gz
    wget -nc https://ftp.gnu.org/gnu/gcc/gcc-4.9.2/$GCC_VERSION.tar.gz
    wget -nc https://ftp.gnu.org/gnu/gcc/$GCC_VERSION/$GCC_VERSION.tar.gz
    if [ $USE_NEWLIB -ne 0 ]; then
    wget -nc -O newlib-master.zip https://github.com/bminor/newlib/archive/master.zip || true
    unzip -qo newlib-master.zip
    @@ -50,7 +50,7 @@ wget -nc ftp://gcc.gnu.org/pub/gcc/infrastructure/$CLOOG_VERSION.tar.gz
    for f in *.tar*; do tar xfk $f; done

    # Make symbolic links
    cd gcc-4.9.2
    cd $GCC_VERSION
    ln -sf `ls -1d ../mpfr-*/` mpfr
    ln -sf `ls -1d ../gmp-*/` gmp
    ln -sf `ls -1d ../mpc-*/` mpc
    @@ -61,14 +61,14 @@ cd ..
    # Step 1. Binutils
    mkdir -p build-binutils
    cd build-binutils
    ../binutils-2.24/configure --prefix=$INSTALL_PATH --target=$TARGET $CONFIGURATION_OPTIONS
    ../$BINUTILS_VERSION/configure --prefix=$INSTALL_PATH --target=$TARGET $CONFIGURATION_OPTIONS
    make $PARALLEL_MAKE
    make install
    cd ..

    # Step 2. Linux Kernel Headers
    if [ $USE_NEWLIB -eq 0 ]; then
    cd linux-3.17.2
    cd $LINUX_KERNEL_VERSION
    make ARCH=$LINUX_ARCH INSTALL_HDR_PATH=$INSTALL_PATH/$TARGET headers_install
    cd ..
    fi
    @@ -79,7 +79,7 @@ cd build-gcc
    if [ $USE_NEWLIB -ne 0 ]; then
    NEWLIB_OPTION=--with-newlib
    fi
    ../gcc-4.9.2/configure --prefix=$INSTALL_PATH --target=$TARGET --enable-languages=c,c++ $CONFIGURATION_OPTIONS $NEWLIB_OPTION
    ../$GCC_VERSION/configure --prefix=$INSTALL_PATH --target=$TARGET --enable-languages=c,c++ $CONFIGURATION_OPTIONS $NEWLIB_OPTION
    make $PARALLEL_MAKE all-gcc
    make install-gcc
    cd ..
    @@ -96,7 +96,7 @@ else
    # Step 4. Standard C Library Headers and Startup Files
    mkdir -p build-glibc
    cd build-glibc
    ../glibc-2.20/configure --prefix=$INSTALL_PATH/$TARGET --build=$MACHTYPE --host=$TARGET --target=$TARGET --with-headers=$INSTALL_PATH/$TARGET/include $CONFIGURATION_OPTIONS libc_cv_forced_unwind=yes
    ../$GLIBC_VERSION/configure --prefix=$INSTALL_PATH/$TARGET --build=$MACHTYPE --host=$TARGET --target=$TARGET --with-headers=$INSTALL_PATH/$TARGET/include $CONFIGURATION_OPTIONS libc_cv_forced_unwind=yes
    make install-bootstrap-headers=yes install-headers
    make $PARALLEL_MAKE csu/subdir_lib
    install csu/crt1.o csu/crti.o csu/crtn.o $INSTALL_PATH/$TARGET/lib
  2. preshing revised this gist Nov 20, 2014. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion build_cross_gcc
    Original file line number Diff line number Diff line change
    @@ -119,7 +119,6 @@ fi

    # Step 7. Standard C++ Library & the rest of GCC
    cd build-gcc
    echo pm=$PARALLEL_MAKE
    make $PARALLEL_MAKE all
    make install
    cd ..
  3. preshing revised this gist Nov 20, 2014. 1 changed file with 7 additions and 7 deletions.
    14 changes: 7 additions & 7 deletions build_cross_gcc
    Original file line number Diff line number Diff line change
    @@ -37,8 +37,8 @@ if [ $USE_NEWLIB -ne 0 ]; then
    wget -nc -O newlib-master.zip https://github.com/bminor/newlib/archive/master.zip || true
    unzip -qo newlib-master.zip
    else
    wget https://www.kernel.org/pub/linux/kernel/v3.x/$LINUX_KERNEL_VERSION.tar.xz
    wget https://ftp.gnu.org/gnu/glibc/$GLIBC_VERSION.tar.xz
    wget -nc https://www.kernel.org/pub/linux/kernel/v3.x/$LINUX_KERNEL_VERSION.tar.xz
    wget -nc https://ftp.gnu.org/gnu/glibc/$GLIBC_VERSION.tar.xz
    fi
    wget -nc https://ftp.gnu.org/gnu/mpfr/$MPFR_VERSION.tar.xz
    wget -nc https://ftp.gnu.org/gnu/gmp/$GMP_VERSION.tar.xz
    @@ -51,11 +51,11 @@ for f in *.tar*; do tar xfk $f; done

    # Make symbolic links
    cd gcc-4.9.2
    ln -sf mpfr ../$MPFR_VERSION
    ln -sf gmp ../$GMP_VERSION
    ln -sf mpc ../$MPC_VERSION
    ln -sf isl ../$ISL_VERSION
    ln -sf cloog ../$CLOOG_VERSION
    ln -sf `ls -1d ../mpfr-*/` mpfr
    ln -sf `ls -1d ../gmp-*/` gmp
    ln -sf `ls -1d ../mpc-*/` mpc
    ln -sf `ls -1d ../isl-*/` isl
    ln -sf `ls -1d ../cloog-*/` cloog
    cd ..

    # Step 1. Binutils
  4. preshing revised this gist Nov 19, 2014. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions build_cross_gcc
    Original file line number Diff line number Diff line change
    @@ -8,6 +8,8 @@ trap 'echo FAILED COMMAND: $previous_command' EXIT
    # Customize the variables (INSTALL_PATH, TARGET, etc.) to your liking before running.
    # If you get an error and need to resume the script from some point in the middle,
    # just delete/comment the preceding lines before running it again.
    #
    # See: http://preshing.com/20141119/how-to-build-a-gcc-cross-compiler
    #-------------------------------------------------------------------------------------------

    INSTALL_PATH=/opt/cross
  5. preshing created this gist Nov 19, 2014.
    126 changes: 126 additions & 0 deletions build_cross_gcc
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,126 @@
    #! /bin/bash
    set -e
    trap 'previous_command=$this_command; this_command=$BASH_COMMAND' DEBUG
    trap 'echo FAILED COMMAND: $previous_command' EXIT

    #-------------------------------------------------------------------------------------------
    # This script will download packages for, configure, build and install a GCC cross-compiler.
    # Customize the variables (INSTALL_PATH, TARGET, etc.) to your liking before running.
    # If you get an error and need to resume the script from some point in the middle,
    # just delete/comment the preceding lines before running it again.
    #-------------------------------------------------------------------------------------------

    INSTALL_PATH=/opt/cross
    TARGET=aarch64-linux
    USE_NEWLIB=0
    LINUX_ARCH=arm64
    CONFIGURATION_OPTIONS="--disable-multilib" # --disable-threads --disable-shared
    PARALLEL_MAKE=-j4
    BINUTILS_VERSION=binutils-2.24
    GCC_VERSION=gcc-4.9.2
    LINUX_KERNEL_VERSION=linux-3.17.2
    GLIBC_VERSION=glibc-2.20
    MPFR_VERSION=mpfr-3.1.2
    GMP_VERSION=gmp-6.0.0a
    MPC_VERSION=mpc-1.0.2
    ISL_VERSION=isl-0.12.2
    CLOOG_VERSION=cloog-0.18.1
    export PATH=$INSTALL_PATH/bin:$PATH

    # Download packages
    export http_proxy=$HTTP_PROXY https_proxy=$HTTP_PROXY ftp_proxy=$HTTP_PROXY
    wget -nc https://ftp.gnu.org/gnu/binutils/$BINUTILS_VERSION.tar.gz
    wget -nc https://ftp.gnu.org/gnu/gcc/gcc-4.9.2/$GCC_VERSION.tar.gz
    if [ $USE_NEWLIB -ne 0 ]; then
    wget -nc -O newlib-master.zip https://github.com/bminor/newlib/archive/master.zip || true
    unzip -qo newlib-master.zip
    else
    wget https://www.kernel.org/pub/linux/kernel/v3.x/$LINUX_KERNEL_VERSION.tar.xz
    wget https://ftp.gnu.org/gnu/glibc/$GLIBC_VERSION.tar.xz
    fi
    wget -nc https://ftp.gnu.org/gnu/mpfr/$MPFR_VERSION.tar.xz
    wget -nc https://ftp.gnu.org/gnu/gmp/$GMP_VERSION.tar.xz
    wget -nc https://ftp.gnu.org/gnu/mpc/$MPC_VERSION.tar.gz
    wget -nc ftp://gcc.gnu.org/pub/gcc/infrastructure/$ISL_VERSION.tar.bz2
    wget -nc ftp://gcc.gnu.org/pub/gcc/infrastructure/$CLOOG_VERSION.tar.gz

    # Extract everything
    for f in *.tar*; do tar xfk $f; done

    # Make symbolic links
    cd gcc-4.9.2
    ln -sf mpfr ../$MPFR_VERSION
    ln -sf gmp ../$GMP_VERSION
    ln -sf mpc ../$MPC_VERSION
    ln -sf isl ../$ISL_VERSION
    ln -sf cloog ../$CLOOG_VERSION
    cd ..

    # Step 1. Binutils
    mkdir -p build-binutils
    cd build-binutils
    ../binutils-2.24/configure --prefix=$INSTALL_PATH --target=$TARGET $CONFIGURATION_OPTIONS
    make $PARALLEL_MAKE
    make install
    cd ..

    # Step 2. Linux Kernel Headers
    if [ $USE_NEWLIB -eq 0 ]; then
    cd linux-3.17.2
    make ARCH=$LINUX_ARCH INSTALL_HDR_PATH=$INSTALL_PATH/$TARGET headers_install
    cd ..
    fi

    # Step 3. C/C++ Compilers
    mkdir -p build-gcc
    cd build-gcc
    if [ $USE_NEWLIB -ne 0 ]; then
    NEWLIB_OPTION=--with-newlib
    fi
    ../gcc-4.9.2/configure --prefix=$INSTALL_PATH --target=$TARGET --enable-languages=c,c++ $CONFIGURATION_OPTIONS $NEWLIB_OPTION
    make $PARALLEL_MAKE all-gcc
    make install-gcc
    cd ..

    if [ $USE_NEWLIB -ne 0 ]; then
    # Steps 4-6: Newlib
    mkdir -p build-newlib
    cd build-newlib
    ../newlib-master/configure --prefix=$INSTALL_PATH --target=$TARGET $CONFIGURATION_OPTIONS
    make $PARALLEL_MAKE
    make install
    cd ..
    else
    # Step 4. Standard C Library Headers and Startup Files
    mkdir -p build-glibc
    cd build-glibc
    ../glibc-2.20/configure --prefix=$INSTALL_PATH/$TARGET --build=$MACHTYPE --host=$TARGET --target=$TARGET --with-headers=$INSTALL_PATH/$TARGET/include $CONFIGURATION_OPTIONS libc_cv_forced_unwind=yes
    make install-bootstrap-headers=yes install-headers
    make $PARALLEL_MAKE csu/subdir_lib
    install csu/crt1.o csu/crti.o csu/crtn.o $INSTALL_PATH/$TARGET/lib
    $TARGET-gcc -nostdlib -nostartfiles -shared -x c /dev/null -o $INSTALL_PATH/$TARGET/lib/libc.so
    touch $INSTALL_PATH/$TARGET/include/gnu/stubs.h
    cd ..

    # Step 5. Compiler Support Library
    cd build-gcc
    make $PARALLEL_MAKE all-target-libgcc
    make install-target-libgcc
    cd ..

    # Step 6. Standard C Library & the rest of Glibc
    cd build-glibc
    make $PARALLEL_MAKE
    make install
    cd ..
    fi

    # Step 7. Standard C++ Library & the rest of GCC
    cd build-gcc
    echo pm=$PARALLEL_MAKE
    make $PARALLEL_MAKE all
    make install
    cd ..

    trap - EXIT
    echo 'Success!'