build-avr-toolchain 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. #!/bin/bash
  2. # http://www.nongnu.org/avr-libc/user-manual/install_tools.html
  3. # Stop on errors
  4. set -e
  5. if [ ! -f .prereq ];then ./prerequise.sh ;fi
  6. archi=$(uname -m | awk {'print$1'} | head -c3)
  7. echo $archi
  8. source avr-file-names
  9. function binutils (){
  10. # Figure out which version of the patch to use
  11. OLD_PATCH_CUTOFF="2.32"
  12. OLD_PATCH_CUTOFF_MAJ=${OLD_PATCH_CUTOFF%%.*}
  13. OLD_PATCH_CUTOFF_MIN=${OLD_PATCH_CUTOFF#*.}
  14. BINUTILS_VER=${NAME_BINUTILS#binutils-}
  15. BINUTILS_VER_MAJ=${BINUTILS_VER%%.*}
  16. BINUTILS_VER_MIN_TMP=${BINUTILS_VER#*.}
  17. BINUTILS_VER_MIN=${BINUTILS_VER_MIN_TMP%.*}
  18. if [ $BINUTILS_VER_MAJ -eq "1" ]; then
  19. echo "ERROR: Binutils version 1.xx is too old -- use at least version 2.xx"
  20. exit 1;
  21. fi
  22. if [ $BINUTILS_VER_MAJ -gt $OLD_PATCH_CUTOFF_MAJ ] || \
  23. ( [ $BINUTILS_VER_MAJ -eq $OLD_PATCH_CUTOFF_MAJ ] && [ $BINUTILS_VER_MIN -gt $OLD_PATCH_CUTOFF_MIN ] ) ; then
  24. NAME_BINUTILS_SIZE_PATCH="avr-binutils-size-2.33.patch";
  25. else
  26. NAME_BINUTILS_SIZE_PATCH="avr-binutils-size-2.32.patch";
  27. fi
  28. TIME_START=$(date +%s)
  29. makeDir()
  30. {
  31. rm -rf "$1/"
  32. mkdir -p "$1"
  33. }
  34. echo "Downloading sources..."
  35. if [ ! -f $NAME_BINUTILS.tar.xz ]; then
  36. wget http://wareck.free.fr/cross_compilation/avr_toolchain/$NAME_BINUTILS.tar.xz
  37. fi
  38. # Make AVR-Binutils
  39. NAME_BINUTILS_BLD=${NAME_BINUTILS}_bld
  40. echo "Making Binutils in $NAME_BINUTILS_BLD..."
  41. echo "Extracting..."
  42. rm -rf $NAME_BINUTILS/
  43. tar xJf $NAME_BINUTILS.tar.xz
  44. # Patch the size function
  45. cd $NAME_BINUTILS/binutils
  46. patch -p 1 < ../../pack/$NAME_BINUTILS_SIZE_PATCH
  47. cd ../..
  48. makeDir $NAME_BINUTILS_BLD
  49. cd $NAME_BINUTILS_BLD
  50. ../$NAME_BINUTILS/configure --prefix=$PREFIX --target=avr --disable-nls
  51. make -j $JOBCOUNT
  52. sudo make install-strip
  53. cd ..
  54. TIME_END=$(date +%s)
  55. TIME_RUN=$(($TIME_END - $TIME_START))
  56. echo ""
  57. echo "Done in $TIME_RUN seconds"
  58. }
  59. function avr-gcc () {
  60. source avr-file-names
  61. TIME_START=$(date +%s)
  62. makeDir()
  63. {
  64. rm -rf "$1/"
  65. mkdir -p "$1"
  66. }
  67. echo "Downloading sources..."
  68. if [ ! -f $NAME_GCC.tar.xz ]; then
  69. wget http://wareck.free.fr/cross_compilation/avr_toolchain/$NAME_GCC.tar.xz
  70. fi
  71. # Make AVR-GCC
  72. NAME_GCC_BLD=${NAME_GCC}_bld
  73. echo "Making GCC in $NAME_GCC_BLD..."
  74. echo "Extracting..."
  75. rm -rf $NAME_GCC/
  76. tar xJf $NAME_GCC.tar.xz
  77. # Patch the download_prerequisites script
  78. cd $NAME_GCC
  79. sed -i 's/ftp/https/g' ./contrib/download_prerequisites
  80. ./contrib/download_prerequisites
  81. cd ..
  82. makeDir $NAME_GCC_BLD
  83. cd $NAME_GCC_BLD
  84. ../$NAME_GCC/configure --prefix=$PREFIX --target=avr --enable-languages=c,c++ --disable-nls --disable-libssp --disable-libada --with-dwarf2 --disable-shared --enable-static
  85. make -j $JOBCOUNT
  86. sudo make install-strip
  87. cd ..
  88. TIME_END=$(date +%s)
  89. TIME_RUN=$(($TIME_END - $TIME_START))
  90. echo ""
  91. echo "Done in $TIME_RUN seconds"
  92. }
  93. function avr-gdb () {
  94. source avr-file-names
  95. TIME_START=$(date +%s)
  96. makeDir()
  97. {
  98. rm -rf "$1/"
  99. mkdir -p "$1"
  100. }
  101. echo "Downloading sources..."
  102. if [ ! -f $NAME_GDB.tar.xz ]; then
  103. wget http://wareck.free.fr/cross_compilation/avr_toolchain/$NAME_GDB.tar.xz
  104. fi
  105. # Make AVR-libc
  106. NAME_GDB_BLD=${NAME_GDB}_bld
  107. echo "Making AVR-GDB in $NAME_GDB_BLD..."
  108. echo "Extracting..."
  109. rm -rf $NAME_GDB/
  110. tar xJf $NAME_GDB.tar.xz
  111. makeDir $NAME_GDB_BLD
  112. cd $NAME_GDB_BLD
  113. ../$NAME_GDB/configure --prefix=$PREFIX --target=avr
  114. make -j $JOBCOUNT
  115. sudo make install
  116. cd ..
  117. TIME_END=$(date +%s)
  118. TIME_RUN=$(($TIME_END - $TIME_START))
  119. echo ""
  120. echo "Done in $TIME_RUN seconds"
  121. }
  122. function avr-libc () {
  123. source avr-file-names
  124. TIME_START=$(date +%s)
  125. makeDir()
  126. {
  127. rm -rf "$1/"
  128. mkdir -p "$1"
  129. }
  130. echo "Downloading sources..."
  131. if [ ! -f $NAME_LIBC.tar.xz ]; then
  132. wget http://wareck.free.fr/cross_compilation/avr_toolchain/$NAME_LIBC.tar.xz
  133. fi
  134. # Make AVR-libc
  135. NAME_LIBC_BLD=${NAME_LIBC}_bld
  136. echo "Making AVR-LIBC in $NAME_LIBC_BLD..."
  137. echo "Extracting..."
  138. rm -rf $NAME_LIBC/
  139. tar xJf $NAME_LIBC.tar.xz
  140. makeDir $NAME_LIBC_BLD
  141. AR='avr-ar'
  142. AS='avr-as'
  143. CC='avr-gcc'
  144. CCAS='gcc'
  145. cd $NAME_LIBC_BLD
  146. ../$NAME_LIBC/configure --prefix=$PREFIX --build=$(../$NAME_LIBC/config.guess) --host=avr
  147. make -j $JOBCOUNT
  148. sudo env "PATH=$PATH" make install-strip
  149. cd ..
  150. TIME_END=$(date +%s)
  151. TIME_RUN=$(($TIME_END - $TIME_START))
  152. echo ""
  153. echo "Done in $TIME_RUN seconds"
  154. }
  155. function build-simu (){
  156. source avr-file-names
  157. TIME_START=$(date +%s)
  158. echo "Downloading sources..."
  159. wget -c http://wareck.free.fr/cross_compilation/avr_toolchain/simulavr.tar.xz
  160. tar xfJ simulavr.tar.xz
  161. # Make simulavr
  162. echo "Making simulavr in $NAME_SIMULAVR..."
  163. cd $NAME_SIMULAVR/
  164. git checkout traumflug
  165. cp ../pack/simulavr_patch1.patch .
  166. cp ../pack/simulavr_patch2.patch .
  167. patch -p1 < simulavr_patch1.patch
  168. patch -p1 < simulavr_patch2.patch
  169. ./bootstrap
  170. ./configure --enable-tcl --prefix=$PREFIX
  171. make
  172. sudo make install-strip
  173. cd ..
  174. TIME_END=$(date +%s)
  175. TIME_RUN=$(($TIME_END - $TIME_START))
  176. echo ""
  177. echo "Done in $TIME_RUN seconds"
  178. }
  179. function avdude(){
  180. source avr-file-names
  181. TIME_START=$(date +%s)
  182. makeDir()
  183. {
  184. rm -rf "$1/"
  185. mkdir -p "$1"
  186. }
  187. echo "Downloading sources..."
  188. if [ ! $archi = "arm" ]; then NAME_AVRDUDE=$NAME_AVRDUDE7;fi
  189. if [ ! -f $NAME_AVRDUDE.tar.xz ]; then
  190. wget http://wareck.free.fr/cross_compilation/avr_toolchain/$NAME_AVRDUDE.tar.xz
  191. fi
  192. # Make avrdude
  193. NAME_AVRDUDE_BLD=${NAME_AVRDUDE}_bld
  194. echo "Making AVRDUDE in $NAME_AVRDUDE_BLD..."
  195. echo "Extracting..."
  196. rm -rf $NAME_AVRDUDE/
  197. tar xJf $NAME_AVRDUDE.tar.xz
  198. makeDir $NAME_AVRDUDE_BLD
  199. cd $NAME_AVRDUDE_BLD
  200. if [ $archi = "arm" ]
  201. then
  202. ../$NAME_AVRDUDE/configure --prefix=$PREFIX --enable-linuxgpio=yes
  203. else
  204. ../$NAME_AVRDUDE/configure --prefix=$PREFIX
  205. fi
  206. make -j $JOBCOUNT
  207. sudo make install-strip
  208. cd ..
  209. TIME_END=$(date +%s)
  210. TIME_RUN=$(($TIME_END - $TIME_START))
  211. echo ""
  212. echo "Done in $TIME_RUN seconds"
  213. }
  214. binutils
  215. avr-gcc
  216. avr-gdb
  217. avr-libc
  218. build-simu
  219. avdude