Although both the avr-libc and gcc sites have some information on building gcc, I found both fell short of being concise and unambiguous. The biggest source of problems I encountered was other libraries that gcc requires for building. GCC's prerequisites indicates, "Several support libraries are necessary to build GCC, some are required, others optional." I (mis)interpreted the list of libraries starting with GNU Multiple Precision Library as being required only if those features were enabled in the compiler. In the end I was only able to build avr-gcc 4.9.2 when I included GMP, MPFR, and MPC. The ISL library was not required.
Required source files
The first thing to download before GCC is gnu binutils, which includes utilities like objdump for disassembling files. If you already have an earlier version of binutils, it is not necessary to build a new version. For example, on my server I have Atmel AVR Toolchain 3.4.4, which includes avr-gcc 4.8.1 and binutils 2.24. In order to build avr-gcc 4.9.2 I don't need to make a new build of binutils. I did try building binutils 2.25 (the latest), but instead of debugging a compile error I decided to stick with 2.24. For building binutils, the following configure options were sufficient (though perhaps not necessary):
-v --target=avr --quiet --enable-install-libbfd --with-dwarf2 --disable-werror CFLAGS="-Wno-format-security"
The next thing to download is GCC, followed by GMP, MPFR, and MPC. I used GMP 5.1.3, MPFR 3.1.2, and MPC 1.0.3. After extracting all the packages, links in the GCC source directory need to be made, named gmp, mpfr, and mpc respectively, linking to their source trees. Then gcc can be configured with the following options before running make:
-v --target=avr --disable-nls --enable-languages="c,c++" --disable-libssp --with-dwarf2
Build script
Rather than downloading, extracting, and building gcc manually, I started with a build script made by Rod Moffitt and a couple other contributors. To use it, first run getfiles.gcc.sh which will download the files, then buildavr-gcc.sh. After a long build process, the binaries will be in /usr/local/avr/bin/, which you should then add to your shell PATH variable.
Binaries
You can download my build for Linux x86_64. It's dynamically linked, and built on CentOS 6, so you may have to add some symlinks in /lib64 for other Linux distributions.
build script is a dead link
ReplyDelete