Skip to content

Instantly share code, notes, and snippets.

@yukkeorg
Forked from ZakKemble/avr-gcc-build.sh
Created April 18, 2019 13:29
Show Gist options
  • Select an option

  • Save yukkeorg/d5637c5934c6d91bc481c50aa07989f5 to your computer and use it in GitHub Desktop.

Select an option

Save yukkeorg/d5637c5934c6d91bc481c50aa07989f5 to your computer and use it in GitHub Desktop.

Revisions

  1. @ZakKemble ZakKemble revised this gist Feb 28, 2019. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions avr-gcc-build.sh
    Original file line number Diff line number Diff line change
    @@ -48,8 +48,8 @@ fi
    # Stop on errors
    set -e

    NAME_BINUTILS="binutils-2.31.1"
    NAME_GCC="gcc-8.2.0"
    NAME_BINUTILS="binutils-2.32"
    NAME_GCC="gcc-8.3.0"
    NAME_LIBC="avr-libc-2.0.0"

    HOST_WIN32="i686-w64-mingw32"
  2. @ZakKemble ZakKemble revised this gist Sep 6, 2018. 1 changed file with 4 additions and 2 deletions.
    6 changes: 4 additions & 2 deletions avr-gcc-build.sh
    Original file line number Diff line number Diff line change
    @@ -48,8 +48,8 @@ fi
    # Stop on errors
    set -e

    NAME_BINUTILS="binutils-2.30"
    NAME_GCC="gcc-8.1.0"
    NAME_BINUTILS="binutils-2.31.1"
    NAME_GCC="gcc-8.2.0"
    NAME_LIBC="avr-libc-2.0.0"

    HOST_WIN32="i686-w64-mingw32"
    @@ -69,6 +69,7 @@ OPTS_GCC="
    --with-dwarf2
    --disable-shared
    --enable-static
    --enable-mingw-wildcard
    "

    OPTS_LIBC=""
    @@ -154,6 +155,7 @@ echo "Extracting..."
    tar xf $NAME_GCC.tar.xz
    mkdir -p $NAME_GCC/obj-avr
    cd $NAME_GCC
    chmod +x ./contrib/download_prerequisites
    ./contrib/download_prerequisites
    cd obj-avr
    # fixGCCAVR
  3. @ZakKemble ZakKemble revised this gist May 7, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion avr-gcc-build.sh
    Original file line number Diff line number Diff line change
    @@ -49,7 +49,7 @@ fi
    set -e

    NAME_BINUTILS="binutils-2.30"
    NAME_GCC="gcc-7.3.0"
    NAME_GCC="gcc-8.1.0"
    NAME_LIBC="avr-libc-2.0.0"

    HOST_WIN32="i686-w64-mingw32"
  4. @ZakKemble ZakKemble revised this gist Mar 2, 2018. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions avr-gcc-build.sh
    Original file line number Diff line number Diff line change
    @@ -48,8 +48,8 @@ fi
    # Stop on errors
    set -e

    NAME_BINUTILS="binutils-2.29"
    NAME_GCC="gcc-7.2.0"
    NAME_BINUTILS="binutils-2.30"
    NAME_GCC="gcc-7.3.0"
    NAME_LIBC="avr-libc-2.0.0"

    HOST_WIN32="i686-w64-mingw32"
  5. @ZakKemble ZakKemble revised this gist Aug 22, 2017. 1 changed file with 9 additions and 9 deletions.
    18 changes: 9 additions & 9 deletions avr-gcc-build.sh
    Original file line number Diff line number Diff line change
    @@ -48,8 +48,8 @@ fi
    # Stop on errors
    set -e

    NAME_BINUTILS="binutils-2.28"
    NAME_GCC="gcc-7.1.0"
    NAME_BINUTILS="binutils-2.29"
    NAME_GCC="gcc-7.2.0"
    NAME_LIBC="avr-libc-2.0.0"

    HOST_WIN32="i686-w64-mingw32"
    @@ -117,12 +117,12 @@ CC=""
    export CC

    echo "Downloading sources..."
    rm -f $NAME_BINUTILS.tar.bz2
    rm -f $NAME_BINUTILS.tar.xz
    rm -rf $NAME_BINUTILS/
    wget ftp://ftp.mirrorservice.org/sites/ftp.gnu.org/gnu/binutils/$NAME_BINUTILS.tar.bz2
    rm -f $NAME_GCC.tar.bz2
    wget ftp://ftp.mirrorservice.org/sites/ftp.gnu.org/gnu/binutils/$NAME_BINUTILS.tar.xz
    rm -f $NAME_GCC.tar.xz
    rm -rf $NAME_GCC/
    wget ftp://ftp.mirrorservice.org/sites/sourceware.org/pub/gcc/releases/$NAME_GCC/$NAME_GCC.tar.bz2
    wget ftp://ftp.mirrorservice.org/sites/sourceware.org/pub/gcc/releases/$NAME_GCC/$NAME_GCC.tar.xz
    if [ $BUILD_LIBC -eq 1 ]; then
    rm -f $NAME_LIBC.tar.bz2
    rm -rf $NAME_LIBC/
    @@ -140,7 +140,7 @@ confMake()
    # Make AVR-Binutils
    echo "Making Binutils..."
    echo "Extracting..."
    bunzip2 -c $NAME_BINUTILS.tar.bz2 | tar xf -
    tar xf $NAME_BINUTILS.tar.xz
    mkdir -p $NAME_BINUTILS/obj-avr
    cd $NAME_BINUTILS/obj-avr
    [ $BUILD_LINUX -eq 1 ] && confMake "$PREFIX_LINUX" "$OPTS_BINUTILS"
    @@ -151,12 +151,12 @@ cd ../../
    # Make AVR-GCC
    echo "Making GCC..."
    echo "Extracting..."
    bunzip2 -c $NAME_GCC.tar.bz2 | tar xf -
    tar xf $NAME_GCC.tar.xz
    mkdir -p $NAME_GCC/obj-avr
    cd $NAME_GCC
    ./contrib/download_prerequisites
    cd obj-avr
    fixGCCAVR
    # fixGCCAVR
    [ $BUILD_LINUX -eq 1 ] && confMake "$PREFIX_LINUX" "$OPTS_GCC"
    [ $BUILD_WIN32 -eq 1 ] && confMake "$PREFIX_WIN32" "$OPTS_GCC" --host=$HOST_WIN32 --build=`../config.guess`
    [ $BUILD_WIN64 -eq 1 ] && confMake "$PREFIX_WIN64" "$OPTS_GCC" --host=$HOST_WIN64 --build=`../config.guess`
  6. @ZakKemble ZakKemble revised this gist May 23, 2017. 1 changed file with 26 additions and 2 deletions.
    28 changes: 26 additions & 2 deletions avr-gcc-build.sh
    Original file line number Diff line number Diff line change
    @@ -48,8 +48,8 @@ fi
    # Stop on errors
    set -e

    NAME_BINUTILS="binutils-2.26"
    NAME_GCC="gcc-6.1.0"
    NAME_BINUTILS="binutils-2.28"
    NAME_GCC="gcc-7.1.0"
    NAME_LIBC="avr-libc-2.0.0"

    HOST_WIN32="i686-w64-mingw32"
    @@ -81,6 +81,29 @@ makeDir()
    mkdir -p "$1"
    }

    fixGCCAVR()
    {
    # In GCC 7.1.0 there seems to be an issue with INT8_MAX and some other things being undefined in /gcc/config/avr/avr.c when building for Windows.
    # Adding '#include <stdint.h>' doesn't fix it, but manually defining the values does the trick.

    echo "Fixing missing defines..."

    DEFSFIX="
    #if (defined _WIN32 || defined __CYGWIN__)
    #define INT8_MIN (-128)
    #define INT16_MIN (-32768)
    #define INT8_MAX 127
    #define INT16_MAX 32767
    #define UINT8_MAX 0xff
    #define UINT16_MAX 0xffff
    #endif
    "

    ORIGINAL=$(cat ../gcc/config/avr/avr.c)
    echo "$DEFSFIX" > ../gcc/config/avr/avr.c
    echo "$ORIGINAL" >> ../gcc/config/avr/avr.c
    }

    echo "Clearing output directories..."
    [ $BUILD_LINUX -eq 1 ] && makeDir "$PREFIX_LINUX"
    [ $BUILD_WIN32 -eq 1 ] && makeDir "$PREFIX_WIN32"
    @@ -133,6 +156,7 @@ mkdir -p $NAME_GCC/obj-avr
    cd $NAME_GCC
    ./contrib/download_prerequisites
    cd obj-avr
    fixGCCAVR
    [ $BUILD_LINUX -eq 1 ] && confMake "$PREFIX_LINUX" "$OPTS_GCC"
    [ $BUILD_WIN32 -eq 1 ] && confMake "$PREFIX_WIN32" "$OPTS_GCC" --host=$HOST_WIN32 --build=`../config.guess`
    [ $BUILD_WIN64 -eq 1 ] && confMake "$PREFIX_WIN64" "$OPTS_GCC" --host=$HOST_WIN64 --build=`../config.guess`
  7. @ZakKemble ZakKemble created this gist May 23, 2017.
    158 changes: 158 additions & 0 deletions avr-gcc-build.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,158 @@
    #!/bin/bash

    # http://www.nongnu.org/avr-libc/user-manual/install_tools.html

    # For optimum compile time this should generally be set to the number of CPU cores your machine has
    JOBCOUNT=4

    # Build Linux toolchain
    # A Linux AVR-GCC toolchain is required to build a Windows toolchain
    # If the Linux toolchain has already been built then you can set this to 0
    BUILD_LINUX=1

    # Build 32 bit Windows toolchain
    BUILD_WIN32=1

    # Build 64 bit Windows toolchain
    BUILD_WIN64=1

    # Build AVR-LibC
    BUILD_LIBC=1

    # Output locations for built toolchains
    PREFIX_LINUX=/omgwtfbbq/linux
    PREFIX_WIN32=/omgwtfbbq/win32
    PREFIX_WIN64=/omgwtfbbq/win64
    PREFIX_LIBC=/omgwtfbbq/libc

    # Install packages
    if hash apt-get 2>/dev/null; then
    # This works for Debian 8 and Ubuntu 16.04
    apt-get install wget make mingw-w64 gcc g++ bzip2
    elif hash yum 2>/dev/null; then
    # This works for CentOS 7
    yum install wget
    rpm -q epel-release-7-6.noarch >/dev/null
    if [ $? -ne 0 ]; then
    # EPEL is for the MinGW stuff
    rm -f epel-release-7-6.noarch.rpm
    wget https://www.mirrorservice.org/sites/dl.fedoraproject.org/pub/epel//7/x86_64/e/epel-release-7-6.noarch.rpm
    rpm -Uvh epel-release-7-6.noarch.rpm
    fi
    yum install make mingw64-gcc mingw64-gcc-c++ mingw32-gcc mingw32-gcc-c++ gcc gcc-c++ bzip2
    elif hash pacman 2>/dev/null; then
    # This works for Arch
    pacman -S --needed wget make mingw-w64-binutils mingw-w64-gcc mingw-w64-crt mingw-w64-headers mingw-w64-winpthreads gcc bzip2
    fi

    # Stop on errors
    set -e

    NAME_BINUTILS="binutils-2.26"
    NAME_GCC="gcc-6.1.0"
    NAME_LIBC="avr-libc-2.0.0"

    HOST_WIN32="i686-w64-mingw32"
    HOST_WIN64="x86_64-w64-mingw32"

    OPTS_BINUTILS="
    --target=avr
    --disable-nls
    "

    OPTS_GCC="
    --target=avr
    --enable-languages=c,c++
    --disable-nls
    --disable-libssp
    --disable-libada
    --with-dwarf2
    --disable-shared
    --enable-static
    "

    OPTS_LIBC=""

    TIME_START=$(date +%s)

    makeDir()
    {
    rm -rf "$1/"
    mkdir -p "$1"
    }

    echo "Clearing output directories..."
    [ $BUILD_LINUX -eq 1 ] && makeDir "$PREFIX_LINUX"
    [ $BUILD_WIN32 -eq 1 ] && makeDir "$PREFIX_WIN32"
    [ $BUILD_WIN64 -eq 1 ] && makeDir "$PREFIX_WIN64"
    [ $BUILD_LIBC -eq 1 ] && makeDir "$PREFIX_LIBC"

    PATH="$PATH":"$PREFIX_LINUX"/bin
    export PATH

    CC=""
    export CC

    echo "Downloading sources..."
    rm -f $NAME_BINUTILS.tar.bz2
    rm -rf $NAME_BINUTILS/
    wget ftp://ftp.mirrorservice.org/sites/ftp.gnu.org/gnu/binutils/$NAME_BINUTILS.tar.bz2
    rm -f $NAME_GCC.tar.bz2
    rm -rf $NAME_GCC/
    wget ftp://ftp.mirrorservice.org/sites/sourceware.org/pub/gcc/releases/$NAME_GCC/$NAME_GCC.tar.bz2
    if [ $BUILD_LIBC -eq 1 ]; then
    rm -f $NAME_LIBC.tar.bz2
    rm -rf $NAME_LIBC/
    wget ftp://ftp.mirrorservice.org/sites/download.savannah.gnu.org/releases/avr-libc/$NAME_LIBC.tar.bz2
    fi

    confMake()
    {
    ../configure --prefix=$1 $2 $3 $4
    make -j $JOBCOUNT
    make install-strip
    rm -rf *
    }

    # Make AVR-Binutils
    echo "Making Binutils..."
    echo "Extracting..."
    bunzip2 -c $NAME_BINUTILS.tar.bz2 | tar xf -
    mkdir -p $NAME_BINUTILS/obj-avr
    cd $NAME_BINUTILS/obj-avr
    [ $BUILD_LINUX -eq 1 ] && confMake "$PREFIX_LINUX" "$OPTS_BINUTILS"
    [ $BUILD_WIN32 -eq 1 ] && confMake "$PREFIX_WIN32" "$OPTS_BINUTILS" --host=$HOST_WIN32 --build=`../config.guess`
    [ $BUILD_WIN64 -eq 1 ] && confMake "$PREFIX_WIN64" "$OPTS_BINUTILS" --host=$HOST_WIN64 --build=`../config.guess`
    cd ../../

    # Make AVR-GCC
    echo "Making GCC..."
    echo "Extracting..."
    bunzip2 -c $NAME_GCC.tar.bz2 | tar xf -
    mkdir -p $NAME_GCC/obj-avr
    cd $NAME_GCC
    ./contrib/download_prerequisites
    cd obj-avr
    [ $BUILD_LINUX -eq 1 ] && confMake "$PREFIX_LINUX" "$OPTS_GCC"
    [ $BUILD_WIN32 -eq 1 ] && confMake "$PREFIX_WIN32" "$OPTS_GCC" --host=$HOST_WIN32 --build=`../config.guess`
    [ $BUILD_WIN64 -eq 1 ] && confMake "$PREFIX_WIN64" "$OPTS_GCC" --host=$HOST_WIN64 --build=`../config.guess`
    cd ../../

    # Make AVR-LibC
    if [ $BUILD_LIBC -eq 1 ]; then
    echo "Making AVR-LibC..."
    echo "Extracting..."
    bunzip2 -c $NAME_LIBC.tar.bz2 | tar xf -
    mkdir -p $NAME_LIBC/obj-avr
    cd $NAME_LIBC/obj-avr
    confMake "$PREFIX_LIBC" "$OPTS_LIBC" --host=avr --build=`../config.guess`
    cd ../../
    fi

    TIME_END=$(date +%s)
    TIME_RUN=$(($TIME_END - $TIME_START))

    echo ""
    echo "Done in $TIME_RUN seconds"

    exit 0