├── .github └── workflows │ └── build-avr-gcc.yml ├── README.md ├── build.sh └── test ├── main1.cpp └── main2.cpp /.github/workflows/build-avr-gcc.yml: -------------------------------------------------------------------------------- 1 | name: Build AVR GCC 2 | 3 | on: 4 | push: 5 | workflow_dispatch: 6 | 7 | jobs: 8 | build-avr-gcc: 9 | runs-on: ubuntu-24.04 10 | 11 | steps: 12 | - name: Install dependencies 13 | run: | 14 | sudo apt-get update 15 | sudo apt-get upgrade -y 16 | sudo apt-get install -y git wget autoconf build-essential netpbm libmpc-dev libmpfr-dev libgmp-dev libmpfr6 texinfo doxygen flex bison libexpat1-dev slang-xfig 17 | 18 | - name: Checkout 19 | uses: actions/checkout@v4 20 | 21 | - name: Build 22 | run: | 23 | ls 24 | bash ./build.sh 25 | 26 | - name: Compiling test files 27 | run: | 28 | /opt/avr-gcc/bin/avr-g++ --version 29 | /opt/avr-gcc/bin/avr-g++ -mmcu=atmega328p test/main1.cpp 30 | /opt/avr-gcc/bin/avr-g++ -mmcu=atmega328p test/main2.cpp 31 | 32 | #- name: Fake toolchain 33 | # run: | 34 | # mkdir -p /opt/avr-gcc/bin 35 | # cp $(which true) /opt/avr-gcc/bin/avr-g++ 36 | 37 | - name: Create tarball 38 | run: | 39 | tar cjf modm-avr-gcc.tar.bz2 -C /opt avr-gcc 40 | 41 | - name: Upload artifact 42 | uses: actions/upload-artifact@v4 43 | with: 44 | name: modm-avr-gcc 45 | path: modm-avr-gcc.tar.bz2 46 | 47 | - name: Create release 48 | if: github.ref_type == 'tag' 49 | uses: softprops/action-gh-release@v2 50 | with: 51 | name: AVR GCC ${{ github.ref }} 52 | draft: false 53 | prerelease: false 54 | files: modm-avr-gcc.tar.bz2 55 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Up-to-date AVR GNU GCC Toolchain from source 2 | 3 | ## Installation 4 | 5 | Download the latest `modm-avr-gcc.tar.bz2` from [Releases](https://github.com/modm-ext/docker-avr-gcc/releases) 6 | and unpack it to `/opt`: 7 | 8 | ```sh 9 | tar xf modm-avr-gcc.tar.bz2 --directory /opt 10 | ``` 11 | 12 | Add the `bin/` directory to your `$PATH`, 13 | e.g. by adding the following line to your `~/.bashrc` file: 14 | 15 | ```sh 16 | export PATH="/opt/avr-gcc/bin:$PATH" 17 | ``` 18 | 19 | ## Building in Github Actions 20 | 21 | There is a Github Actions job defined in `.github/workflows/` which builds the 22 | toolchain. For tagged commits, a Github release will be created with the 23 | toolchain put into a downloadable `.tar.bz2` at 24 | [Releases](https://github.com/modm-ext/docker-avr-gcc/releases). 25 | -------------------------------------------------------------------------------- /build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | SRC="src" 4 | BUILD="build" 5 | INSTALL="/opt/avr-gcc" # tar.bz2 needs a prefix of 'avr-gcc' 6 | DOWNLOAD="download" 7 | mkdir ${SRC} 8 | mkdir ${BUILD} 9 | mkdir ${INSTALL} 10 | root=$(pwd) 11 | cores=8 12 | VERSION_BINUTILS="2.44" 13 | VERSION_GCC="14.2.0" 14 | VERSION_LIBC="2.2.1" 15 | 16 | # Get sources 17 | wget -q "https://raw.githubusercontent.com/archlinux/svntogit-community/c3efadcb76f4d8b1a3784015e7c472f59dbfa7de/avr-binutils/repos/community-x86_64/avr-size.patch" & 18 | wget -q "https://raw.githubusercontent.com/osx-cross/homebrew-avr/d2e2566b06b90355952ed996707a0a1a24673cd3/Patch/avr-libc-add-mcu-atmega168pb.patch" & 19 | #wget -q "https://raw.githubusercontent.com/osx-cross/homebrew-avr/18d50ba2a168a3b90a25c96e4bc4c053df77d7dc/Patch/avr-binutils-elf-bfd-gdb-fix.patch" & 20 | wget -qO- "https://ftp.gnu.org/gnu/binutils/binutils-${VERSION_BINUTILS}.tar.bz2" | tar xj --directory ${SRC} & 21 | wget -qO- "https://ftp.gnu.org/gnu/gcc/gcc-${VERSION_GCC}/gcc-${VERSION_GCC}.tar.xz" | tar xJ --directory ${SRC} & 22 | wget -qO- "https://github.com/avrdudes/avr-libc/releases/download/avr-libc-${VERSION_LIBC//./_}-release/avr-libc-${VERSION_LIBC}.tar.bz2" | tar xj --directory ${SRC} & 23 | wait 24 | 25 | # Build binutils first 26 | cd ${SRC}/binutils-${VERSION_BINUTILS} 27 | # patch size file 28 | patch -g 0 -f -p1 -i ../../avr-size.patch 29 | mkdir build && cd build 30 | # configure and make 31 | ../configure \ 32 | --target=avr \ 33 | --prefix=${INSTALL}/ \ 34 | --disable-nls \ 35 | --disable-werror 36 | make -j${cores} 37 | make install 38 | 39 | # prepend path of newly compiled avr-binutils 40 | export PATH=${INSTALL}/bin:$PATH 41 | 42 | cd ${root} 43 | cd ${SRC}/gcc-${VERSION_GCC} 44 | mkdir build && cd build 45 | ../configure \ 46 | --target=avr \ 47 | --prefix=${INSTALL}/ \ 48 | --with-ld=${INSTALL}/bin/avr-ld \ 49 | --with-as=${INSTALL}/bin/avr-as \ 50 | --libdir=${INSTALL}/avr/lib \ 51 | --enable-languages=c,c++ \ 52 | --disable-nls \ 53 | --disable-libssp \ 54 | --disable-shared \ 55 | --disable-threads \ 56 | --disable-libgomp \ 57 | --with-dwarf2 \ 58 | --with-avrlibc \ 59 | #--with-system-zlib \ 60 | --disable-bootstrap 61 | make -j${cores} 62 | make install 63 | 64 | # prepend path of newly compiled avr-gcc 65 | #export PATH=${INSTALL}/bin:$PATH 66 | 67 | cd ${root} 68 | cd ${SRC}/avr-libc-${VERSION_LIBC} 69 | patch -g 0 -f -p1 -i ../../avr-libc-add-mcu-atmega168pb.patch 70 | build=`./config.guess` 71 | ./configure \ 72 | --build=${build} \ 73 | --prefix=${INSTALL} \ 74 | --host=avr 75 | make install -j${cores} 76 | 77 | cd ${root} 78 | rm -r build src 79 | rm avr-size.patch 80 | rm avr-libc-add-mcu-atmega168pb.patch 81 | 82 | -------------------------------------------------------------------------------- /test/main1.cpp: -------------------------------------------------------------------------------- 1 | int 2 | main() 3 | { 4 | return 0; 5 | } -------------------------------------------------------------------------------- /test/main2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int 4 | main() 5 | { 6 | DDRB = (1 << 1); 7 | PORTB |= (1 << 1); 8 | uint8_t read = PINB; 9 | (void) read; 10 | 11 | return 0; 12 | } --------------------------------------------------------------------------------