diff --git a/Readme.md b/Readme.md index 7a1377c..bdd61aa 100644 --- a/Readme.md +++ b/Readme.md @@ -9,9 +9,9 @@ Therefore, the resulting binaries may differ significantly from Atmel's. And you Edit the `build.conf` file, currently the only thing worth changing is `AVR_VERSION` on the first line to match whatever the [latest version is](http://distribute.atmel.no/tools/opensource/Atmel-AVR-GNU-Toolchain/). -At time of writing, the latest toolchain available is based on Atmel 3.5.4 version. It contains: +At time of writing, the latest toolchain available is based on Atmel 3.6.1 version. It contains: - binutils-2.26 - - gcc-4.9.2 + - gcc-5.4.0 - avr-libc-2.0.0 - gdb-7.8 diff --git a/atpack.build.bash b/atpack.build.bash new file mode 100755 index 0000000..0d33d8f --- /dev/null +++ b/atpack.build.bash @@ -0,0 +1,88 @@ +#!/bin/bash -ex +# Copyright (c) 2017 Arduino LLC +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +source build.conf + +mkdir -p atpack +cd atpack +rm -rf * +mv ../*.atpack . + +mv ${ATMEL_ATMEGA_PACK_FILENAME}.atpack ${ATMEL_ATMEGA_PACK_FILENAME}.zip +unzip ${ATMEL_ATMEGA_PACK_FILENAME}.zip + +ALL_FILES=`find ../objdir` + +#copy relevant files to the right folders +# 1- copy includes definitions +EXTRA_INCLUDES=`diff -q ../objdir/avr/include/avr ../atpack/include/avr | grep "Only in" | grep atpack | cut -f4 -d" "` +for x in $EXTRA_INCLUDES; do + cp include/avr/${x} ../objdir/avr/include/avr +done + +# 2 - compact specs into a single folder +SPECS_FOLDERS=`ls gcc/dev` +mkdir temp +for folder in $SPECS_FOLDERS; do + cp -r gcc/dev/${folder}/* temp/ +done + +# 3 - find different files (device-specs) +EXTRA_SPECS=`diff -q ../objdir/lib/gcc/avr/${GCC_VERSION}/device-specs/ temp/device-specs | grep "Only in" | grep temp | cut -f4 -d" "` +for x in $EXTRA_SPECS; do + cp temp/device-specs/${x} ../objdir/lib/gcc/avr/${GCC_VERSION}/device-specs/ +done + +#since https://github.com/gcc-mirror/gcc/commit/21a6b87b86defda10ac903a9cd49e34b1f8ce6fb a lot of devices has specs but avr-libc doesn't support them yet +ALL_DEVICE_SPECS=`ls temp/device-specs` +rm -rf temp/device-specs + +EXTRA_LIBS=`diff -r -q ../objdir/avr/lib temp/ | grep "Only in" | grep temp | cut -f4 -d" "` +for x in $EXTRA_LIBS; do + if [ ! -d temp/${x} ]; then + cd temp + LOCATION=`find . | grep ${x}` + cd .. + else + LOCATION=${x} + fi + cp -r temp/${LOCATION} ../objdir/avr/lib/${LOCATION} +done + +# 4 - extract the correct includes and add them to io.h +# ARGH! difficult! +for x in $ALL_DEVICE_SPECS; do + DEFINITION=`cat ../objdir/lib/gcc/avr/${GCC_VERSION}/device-specs/${x} | grep __AVR_DEVICE_NAME__ | cut -f1 -d" " | cut -f2 -d"D"` + FANCY_NAME=`cat ../objdir/lib/gcc/avr/${GCC_VERSION}/device-specs/${x} | grep __AVR_DEVICE_NAME__ | cut -f2 -d"="` + LOWERCASE_DEFINITION="${DEFINITION,,}" + HEADER_TEMP="${LOWERCASE_DEFINITION#__avr_atmega}" + HEADER="${HEADER_TEMP%__}" + _DEFINITION="#elif defined (${DEFINITION})" + _HEADER="# include " + if [ "$(grep -c "${DEFINITION}" ../objdir/avr/include/avr/io.h)" == 0 ]; then + NEWFILE=`awk '/iom3000.h/ { print; print "____DEFINITION____"; print "____HEADER____"; next }1' ../objdir/avr/include/avr/io.h | sed "s/____DEFINITION____/$_DEFINITION/g" | sed "s@____HEADER____@$_HEADER@g"` + echo "$NEWFILE" > ../objdir/avr/include/avr/io.h + fi +done + +#NEW_ALL_FILES=`find ../objdir` + +#echo "NEW FILES ADDED: " +#diff <(echo "$ALL_FILES" ) <(echo "$NEW_ALL_FILES") + +cd .. + diff --git a/automake-patches/0001-fix-perl-522.patch b/automake-patches/0001-fix-perl-522.patch new file mode 100644 index 0000000..62e2391 --- /dev/null +++ b/automake-patches/0001-fix-perl-522.patch @@ -0,0 +1,11 @@ +--- /automake.in 2017-12-18 12:26:59.455263520 +0100 ++++ /automake.in 2017-12-18 12:27:21.228596603 +0100 +@@ -4110,7 +4110,7 @@ + sub substitute_ac_subst_variables ($) + { + my ($text) = @_; +- $text =~ s/\${([^ \t=:+{}]+)}/&substitute_ac_subst_variables_worker ($1)/ge; ++ $text =~ s/\$[{]([^ \t=:+{}]+)}/substitute_ac_subst_variables_worker ($1)/ge; + return $text; + } + diff --git a/avr-gcc-patches/0001-gcc-lto-wrapper.patch b/avr-gcc-patches/0001-gcc-lto-wrapper.patch index 8fc612e..1e48f33 100644 --- a/avr-gcc-patches/0001-gcc-lto-wrapper.patch +++ b/avr-gcc-patches/0001-gcc-lto-wrapper.patch @@ -1,5 +1,5 @@ ---- gcc/lto-wrapper.c.orig 2016-06-14 21:13:06.985134945 +0200 -+++ gcc/lto-wrapper.c 2016-06-14 21:15:37.825167119 +0200 +--- gcc/lto-wrapper.c 2016-08-22 11:19:17.000000000 +0200 ++++ gcc/lto-wrapper.c 2017-12-18 12:48:25.685248735 +0100 @@ -594,7 +594,7 @@ filename[p - argv[i]] = '\0'; file_offset = (off_t) loffset; diff --git a/binutils.build.bash b/binutils.build.bash index d930231..993f4b8 100755 --- a/binutils.build.bash +++ b/binutils.build.bash @@ -23,6 +23,10 @@ then exit 1 fi +if [[ x$CROSS_COMPILE != x ]] ; then + EXTRA_CONFARGS="--host=$OUTPUT_TAG" +fi + cd toolsdir/bin TOOLS_BIN_PATH=`pwd` cd - @@ -58,12 +62,13 @@ CONFARGS=" \ --disable-werror \ --enable-install-libiberty \ --enable-install-libbfd \ - --enable-lto \ - --enable-plugins\ - --with-pic \ + --disable-libdecnumber \ + --disable-gdb \ + --disable-readline \ + --disable-sim \ --target=avr" -CFLAGS="-w -O2 -g0 $CFLAGS" CXXFLAGS="-w -O2 -g0 $CXXFLAGS" LDFLAGS="-s $LDFLAGS" ../binutils/configure $CONFARGS +CFLAGS="-w -O2 -g0 $CFLAGS" CXXFLAGS="-w -O2 -g0 $CXXFLAGS" LDFLAGS="-s $LDFLAGS" ../binutils/configure $CONFARGS $EXTRA_CONFARGS if [ -z "$MAKE_JOBS" ]; then MAKE_JOBS="2" diff --git a/build.conf b/build.conf index ef0e2d6..947b431 100644 --- a/build.conf +++ b/build.conf @@ -1,7 +1,8 @@ -AVR_VERSION=3.5.4 +AVR_VERSION=3.6.1 BUILD_NUMBER=arduino2 AVR_SOURCES="http://distribute.atmel.no/tools/opensource/Atmel-AVR-GNU-Toolchain/${AVR_VERSION}" +ATMEL_PACKS_SOURCES="http://packs.download.atmel.com/" GNU_SOURCES="http://mirror.switch.ch/ftp/mirror/gnu" MPC_SOURCES="http://www.multiprecision.org/downloads" @@ -15,6 +16,10 @@ MPC_SOURCES="http://www.multiprecision.org/downloads" # MPFR_VERSION=3.0.0 # MPC_VERSION=0.9 +ATMEL_ATMEGA_PACK_VERSION=1.2.203 +ATMEL_ATMEGA_PACK_FILENAME=Atmel.ATmega_DFP.${ATMEL_ATMEGA_PACK_VERSION} +ATMEL_ATMEGA_PACK_URL=${ATMEL_PACKS_SOURCES}/${ATMEL_ATMEGA_PACK_FILENAME}.atpack + # With any luck, you don't need to edit the below ################################################################################ diff --git a/gcc.build.bash b/gcc.build.bash index f81d91b..7b82dc6 100755 --- a/gcc.build.bash +++ b/gcc.build.bash @@ -57,20 +57,20 @@ fi tar xfv avr-gcc.tar.bz2 -pushd gcc +#pushd gcc #pushd gcc/config/avr/ #sh genopt.sh avr-mcus.def > avr-tables.opt #cat avr-mcus.def | awk -f genmultilib.awk FORMAT="Makefile" > t-multilib #popd -pushd gcc -for p in ../../avr-gcc-patches/*.patch -do - echo Applying $p - patch -p1 < $p -done -autoconf -popd -popd +#pushd gcc +#for p in ../../avr-gcc-patches/*.patch +#do +# echo Applying $p +# patch -p1 < $p +#done +#autoconf +#popd +#popd mv gmp-${GMP_VERSION} gcc/gmp mv mpfr-${MPFR_VERSION} gcc/mpfr @@ -81,6 +81,10 @@ cd objdir PREFIX=`pwd` cd - +if [[ x$CROSS_COMPILE != x ]] ; then + EXTRA_CONFARGS="--host=$OUTPUT_TAG" +fi + mkdir -p gcc-build cd gcc-build @@ -88,25 +92,16 @@ CONFARGS=" \ --enable-fixed-point \ --enable-languages=c,c++ \ --prefix=$PREFIX \ - --enable-long-long \ --disable-nls \ - --disable-checking \ --disable-libssp \ - --disable-libada \ + --disable-libada \ --disable-shared \ - --enable-lto \ - --with-avrlibc=yes \ + --with-avrlibc=yes \ --with-dwarf2 \ - --disable-doc \ + --disable-doc \ --target=avr" -if [ `uname -s` == "Darwin" ] -then - # Use default system libraries (no other Macports libraries) - LDFLAGS="$LDFLAGS -L/usr/lib" -fi - -CFLAGS="-w -O2 -g0 $CFLAGS" CXXFLAGS="-w -O2 -g0 $CXXFLAGS" LDFLAGS="-s $LDFLAGS" ../gcc/configure $CONFARGS +CFLAGS="-w -O2 -g0 $CFLAGS" CXXFLAGS="-w -O2 -g0 $CXXFLAGS" LDFLAGS="-s $LDFLAGS" ../gcc/configure $CONFARGS $EXTRA_CONFARGS if [ -z "$MAKE_JOBS" ]; then MAKE_JOBS="2" diff --git a/gdb.build.bash b/gdb.build.bash index 967b574..065679b 100755 --- a/gdb.build.bash +++ b/gdb.build.bash @@ -27,6 +27,10 @@ cd toolsdir/bin TOOLS_BIN_PATH=`pwd` cd - +if [[ x$CROSS_COMPILE != x ]] ; then + EXTRA_CONFARGS="--host=$OUTPUT_TAG" +fi + export PATH="$TOOLS_BIN_PATH:$PATH" if [[ ! -f avr-gdb.tar.bz2 ]] ; @@ -36,13 +40,13 @@ fi tar xfv avr-gdb.tar.bz2 -cd gdb -for p in ../avr-gdb-patches/*.patch -do - echo Applying $p - patch -p1 < $p -done -cd - +#cd gdb +#for p in ../avr-gdb-patches/*.patch +#do +# echo Applying $p +# patch -p1 < $p +#done +#cd - mkdir -p objdir cd objdir @@ -59,7 +63,7 @@ CONFARGS=" \ --disable-binutils \ --target=avr" -CFLAGS="-w -O2 -g0 $CFLAGS" CXXFLAGS="-w -O2 -g0 $CXXFLAGS" LDFLAGS="-s $LDFLAGS" ../gdb/configure $CONFARGS +CFLAGS="-w -O2 -g0 $CFLAGS" CXXFLAGS="-w -O2 -g0 $CXXFLAGS" LDFLAGS="-s $LDFLAGS" ../gdb/configure $CONFARGS $EXTRA_CONFARGS if [ -z "$MAKE_JOBS" ]; then MAKE_JOBS="2" diff --git a/package-avr-gcc.bash b/package-avr-gcc.bash index 32eecf9..e4a7de4 100755 --- a/package-avr-gcc.bash +++ b/package-avr-gcc.bash @@ -28,7 +28,23 @@ if [[ $CROSS_COMPILE == "mingw" ]] ; then export CXX="i686-w64-mingw32-g++" export CROSS_COMPILE_HOST="i686-w64-mingw32" export TARGET_OS="Windows" - OUTPUT_TAG=i686-w64-mingw32 + export OUTPUT_TAG=i686-w64-mingw32 + +elif [[ $CROSS_COMPILE == "osxcross" ]] ; then + + export CC="o32-clang" + export CXX="o32-clang++" + export CROSS_COMPILE_HOST="i386-apple-darwin13" + export TARGET_OS="OSX" + export OUTPUT_TAG=i386-apple-darwin13 + +elif [[ $CROSS_COMPILE == "arm-cross" ]] ; then + + export CC="arm-linux-gnueabihf-gcc" + export CXX="arm-linux-gnueabihf-g++" + export CROSS_COMPILE_HOST="arm-linux-gnueabihf" + export TARGET_OS="LinuxARM" + export OUTPUT_TAG=arm-linux-gnueabihf elif [[ $OS == "GNU/Linux" ]] ; then @@ -83,6 +99,11 @@ rm -rf toolsdir objdir *-build rm -rf objdir/{info,man,share} +if [[ -f ${ATMEL_ATMEGA_PACK_FILENAME}.atpack ]] ; then +#add extra files from atpack (only if the package is altrady there) +${BASH} ./atpack.build.bash +fi + # if producing a windows build, compress as zip and # copy *toolchain-precompiled* content to any folder containing a .exe if [[ ${OUTPUT_TAG} == *"mingw"* ]] ; then diff --git a/toolchain-precompiled/libwinpthread-1.dll b/toolchain-precompiled/libwinpthread-1.dll new file mode 100755 index 0000000..10e5670 Binary files /dev/null and b/toolchain-precompiled/libwinpthread-1.dll differ diff --git a/tools.bash b/tools.bash index 3d0a67a..723d771 100755 --- a/tools.bash +++ b/tools.bash @@ -58,6 +58,8 @@ tar xfjv automake-${AUTOMAKE_VERSION}.tar.bz2 cd automake-${AUTOMAKE_VERSION} +patch -p1 < ../automake-patches/0001-fix-perl-522.patch + cp ../config.guess-am-1.11.4 lib/config.guess ./bootstrap