updated to work with new gcc and avrlibc
[openmag.git] / src / toolchains / avr-toolchain / make-avr-gcc / buildavr-no-insight.sh
blob0211cca15bda51a5835f41a0e7499c66cbcad784
1 #!/bin/bash
3 # AVR GNU development tools install script
4 # $Id: buildavr.sh,v 1.21 2004/11/09 02:25:48 rmoffitt Exp $
5 # Modified by AJ Erasmus 2005/03/22
6 # Use the same source and patches as for WinAVR 20050214
7 # Updated script to compile the C and C++ compilers, as well
8 # as allow the output of dwarf-2 debug information 2005/03/25
9 # Updated script to add new devices 2005/03/26
12 # Copyright (C) 2003-2004 Rod Moffitt rod@rod.info http://rod.info
14 # This program is free software; you can redistribute it and/or
15 # modify it under the terms of the GNU General Public License
16 # as published by the Free Software Foundation; either version 2
17 # of the License, or (at your option) any later version.
19 # This program is distributed in the hope that it will be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 # GNU General Public License for more details.
24 # You should have received a copy of the GNU General Public License
25 # along with this program; if not, write to the Free Software
26 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28 # run the script as is to get a list of the files necessary to build,
29 # takes optionally three arguments, the location of the source files,
30 # where to install and build the tools and the path where to output a
31 # log file
33 # start of configuration, edit these defaults to suit your environment, or
34 # simply override them via the command line - you will need write
35 # permission to $prefix (make sure it's empty or non-existent!)
37 # location of source tarballs
38 archive=${PWD}
40 # GNU tools will be installed under this directory
41 prefix=/home/sean/local2
43 # build log file - see this if any errors occur
44 buildlog=/tmp/buildavr.log
46 # end of configuration
48 # what are we building for?
49 target=avr
51 # the files below shouldn't be changed unless a new release has been made
52 # and I (Rod) haven't updated this script!
53 insightver=6.1
54 insightbase=insight-${insightver}
55 insighttar=${insightbase}.tar.bz2
56 #sourcefiles="${insighttar} insight-6.1_reg_window.patch"
58 binutilsver=2.18
59 binutilsbase=binutils-${binutilsver}
60 binutilstar=${binutilsbase}.tar.bz2
61 #sourcefiles="${sourcefiles} ${binutilstar} binutils-2.1n5-no-lma-eeprom.patch binutils-2.15-avr-coff.patch binutils-2.15-avr-new-devs.patch"
62 sourcefiles="${sourcefiles} ${binutilstar} binutils-patch-aa.diff binutils-patch-coff-avr.diff binutils-patch-avr-size.diff binutils-patch-newdevices.diff binutils-patch-bug5215.diff binutils-patch-newsections.diff binutils-makeinfo.patch"
65 gccver=4.2.2
66 gcccore=gcc-${gccver}
67 gcccoretar=${gcccore}.tar.bz2
68 gccbase=gcc-${gccver}
69 #sourcefiles="${sourcefiles} ${gcccoretar} gcc-binary-constants.patch gcc-3_4_x-avr-new-devs2.patch gcc-avr-misspelled-sig-1.patch"
70 #sourcefiles="${sourcefiles} ${gcccoretar} gcc-patch-attribute_alias.diff gcc-patch-dwarf.diff gcc-patch-newdevices.diff gcc-patch-zz-atmega256x.diff"
71 sourcefiles="${sourcefiles} ${gcccoretar} gcc-patch-0b-constants.diff gcc-patch-bug11259.diff gcc-patch-bug25672.diff gcc-patch-bug30243.diff gcc-patch-constraint-desc.diff gcc-patch-doc-progmem.diff gcc-patch-dwarf.diff gcc-patch-libiberty-Makefile.in.diff gcc-patch-newdevices.diff gcc-patch-os_main-os_task.diff gcc-patch-zero_extend.diff gcc-patch-zz-atmega256x.diff"
73 avrlibcver=1.6.1
74 avrlibcbase=avr-libc-${avrlibcver}
75 avrlibctar=${avrlibcbase}.tar.bz2
76 sourcefiles="${sourcefiles} ${avrlibctar}"
78 function buildandinstall()
80 mkdir -p $prefix/source $prefix/build
82 cd $prefix/source
84 echo "($0) installing binutils source"
85 tar xvjf $archive/${binutilstar}
86 cerror "binutils source installation failed"
88 cd ${binutilsbase}
90 echo "($0) patching binutils source"
91 patch -p0 < $archive/binutils-patch-aa.diff
92 cerror "binutils patching failed"
94 patch -p0 < $archive/binutils-patch-bug5215.diff
95 cerror "binutils patching failed"
97 patch -p0 < $archive/binutils-patch-coff-avr.diff
98 cerror "binutils patching failed"
100 patch -p0 < $archive/binutils-patch-newdevices.diff
101 cerror "binutils patching failed"
103 patch -p0 < $archive/binutils-patch-newsections.diff
104 cerror "binutils patching failed"
106 patch -p0 < $archive/binutils-patch-avr-size.diff
107 cerror "binutils patching failed"
109 patch -p0 < $archive/binutils-makeinfo.patch
110 cerror "binutils patching failed"
113 mkdir -p ../../build/${binutilsbase}
114 cd ../../build/${binutilsbase}
116 echo "($0) configuring binutils source"
117 ../../source/${binutilsbase}/configure -v --target=${target} \
118 --prefix=$prefix --with-gnu-ld --with-gnu-as --quiet --enable-install-libbfd --with-dwarf2
119 cerror "binutils configuration failed"
121 echo "($0) building binutils"
122 make all install clean
123 cerror "binutils build failed"
125 # path to the newly installed binutils is needed to build GCC
126 PATH=$prefix/bin:$PATH
128 cd $prefix/source
130 echo "($0) installing GCC source"
131 tar xvjf $archive/${gcccoretar}
132 cerror "GCC source installation failed"
134 cd ${gccbase}
136 echo "($0) patching GCC source"
137 patch -p0 < $archive/gcc-patch-0b-constants.diff
138 cerror "GCC patching failed"
140 echo "($0) patching GCC source"
141 patch -p0 < $archive/gcc-patch-bug11259.diff
142 cerror "GCC patching failed"
144 echo "($0) patching GCC source"
145 patch -p0 < $archive/gcc-patch-bug25672.diff
146 cerror "GCC patching failed"
148 echo "($0) patching GCC source"
149 patch -p0 < $archive/gcc-patch-bug30243.diff
150 cerror "GCC patching failed"
152 echo "($0) patching GCC source"
153 patch -p0 < $archive/gcc-patch-constraint-desc.diff
154 cerror "GCC patching failed"
156 echo "($0) patching GCC source"
157 patch -p0 < $archive/gcc-patch-doc-progmem.diff
158 cerror "GCC patching failed"
160 echo "($0) patching GCC source"
161 patch -p0 < $archive/gcc-patch-dwarf.diff
162 cerror "GCC patching failed"
164 echo "($0) patching GCC source"
165 patch -p0 < $archive/gcc-patch-libiberty-Makefile.in.diff
166 cerror "GCC patching failed"
168 echo "($0) patching GCC source"
169 patch -p0 < $archive/gcc-patch-newdevices.diff
170 cerror "GCC patching failed"
172 echo "($0) patching GCC source"
173 patch -p0 < $archive/gcc-patch-os_main-os_task.diff
174 cerror "GCC patching failed"
176 echo "($0) patching GCC source"
177 patch -p0 < $archive/gcc-patch-zero_extend.diff
178 cerror "GCC patching failed"
180 echo "($0) patching GCC source"
181 patch -p0 < $archive/gcc-patch-zz-atmega256x.diff
182 cerror "GCC patching failed"
186 mkdir -p ../../build/${gcccore}
187 cd ../../build/${gcccore}
189 echo "($0) configuring GCC source"
190 ../../source/${gccbase}/configure -v --target=${target} --disable-nls \
191 --prefix=$prefix --with-gnu-ld --with-gnu-as --enable-languages="c,c++" --quiet --disable-libssp --with-dwarf2
192 cerror "GCC configuration failed"
194 echo "($0) building GCC"
195 # make all install clean LANGUAGES="c obj-c++"
196 make all install clean LANGUAGES="c c++"
197 cerror "GCC build failed"
199 cd $prefix/source
201 echo "($0) installing libc"
202 tar xvjf $archive/${avrlibctar}
203 cerror "libc source installation failed"
205 cd $avrlibcbase
206 # sh reconf
207 # sh doconf
208 # ./bootstrap
209 # cerror "libc source setup failed"
211 mkdir -p ../../build/${avrlibcbase}
212 cd ../../build/${avrlibcbase}
214 echo "($0) configuring libc source"
215 CC=$prefix/bin/avr-gcc ../../source/${avrlibcbase}/configure -v \
216 --build=`../../source/${avrlibcbase}/config.guess` --target=${target} --host=avr --prefix=$prefix --quiet
217 cerror "libc configuration failed"
219 echo "($0) building libc"
220 make all install clean
221 cerror "libc build failed"
223 # strip all the binaries
224 find $prefix -type d -name bin -exec find \{\} -type f \; | xargs strip > /dev/null 2>&1
226 cecho "\n"
227 cecho "${cyan}installation of ${target} GNU tools complete\n"
228 cecho "${cyan}add ${GREEN}$prefix/bin${cyan} to your path to use the ${target} GNU tools\n"
229 cecho "${cyan}you might want to run the following to save disk space:\n"
230 cecho "\n"
231 cecho "${green}rm -rf $prefix/source $prefix/build\n"
234 # color definitions
235 RED='\e[1;31m'
236 green='\e[0;32m'
237 GREEN='\e[1;32m'
238 cyan='\e[0;36m'
239 yellow='\e[0;33m'
240 NC='\e[0m' # no color
242 function cecho()
244 echo -ne "($green$0$NC) $1$NC"
247 function cerror()
249 if [ $? -ne 0 ];
250 then
251 cecho "$RED$1$NC\n"
252 exit
256 function ask()
258 cecho "$@ [y/n] "
259 read ans
261 case "$ans" in
262 y*|Y*) return 0 ;;
263 *) return 1 ;;
264 esac
267 # source command line overrides
269 until [ -z "$1" ];
271 eval "$1"
272 shift
273 done
275 cecho "${cyan}about to build and install ${target} GNU development tools using\n"
276 cecho "${cyan}the following settings (override via the command line):\n"
277 cecho "\n"
278 cecho " ${yellow}archive=${archive} $cyan(location of source tarballs)\n"
279 cecho " ${yellow}prefix=${prefix} $cyan(installation prefix/directory)\n"
280 cecho " ${yellow}buildlog=${buildlog} $cyan(build log)\n"
281 cecho "\n"
282 ask "${cyan}proceed?";
284 if [ "$?" -eq 1 ]
285 then
286 exit
289 # check on target directory
291 if [ -d $prefix ];
292 then
293 cecho "\n"
294 ask "${RED}$prefix already exists, continue?";
296 if [ "$?" -eq 1 ]
297 then
298 exit
302 mkdir -p $prefix 2> /dev/null
304 if [ ! -w $prefix ];
305 then
306 cecho "\n"
307 cecho "${RED}failed! to create install directory $prefix\n";
308 exit
311 # check for required files
313 missingfiles=;
315 for file in $sourcefiles;
317 if [ ! -f $archive/$file ];
318 then
319 missingfiles="${missingfiles} $file";
321 done
323 if [ -n "$missingfiles" ];
324 then
325 cecho "\n"
326 cecho "${RED}error! required source file(s):\n";
327 cecho "\n"
329 for file in $missingfiles;
331 cecho " ${yellow}$file\n"
332 done
334 cecho "\n"
335 cecho "${cyan}were missing - download them to $archive first\n";
336 exit
339 buildandinstall 2>&1 | tee $buildlog
341 exit