forked from RREE/build-avr-ada-toolchain
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild-avr-ada.sh
executable file
·469 lines (375 loc) · 14.8 KB
/
build-avr-ada.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
#!/bin/bash
#--------------------------------------------------------------------------
#- AVR-Ada - A GCC Ada environment for Microchip AVR8 (Ex-Atmel) --
#- * --
#- AVR-Ada 2.0.0 --
#- Copyright (C) 2005, 2007, 2012, 2016, 2019 Rolf Ebert --
#- Copyright (C) 2009 Neil Davenport --
#- Copyright (C) 2005 Stephane Riviere --
#- Copyright (C) 2003-2005 Bernd Trog --
#- avr-ada.sourceforge.net --
#- * --
#- --
#--------------------------------------------------------------------------
#- The AVR-Ada Library is free software; you can redistribute it and/or --
#- modify it under terms of the GNU General Public License as published --
#- by the Free Software Foundation; either version 2, or (at your --
#- option) any later version. The AVR-Ada Library 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. --
#--------------------------------------------------------------------------
#--------------------------------------------------------------------------
#- AVR-Ada EasyBake Build script --
#- * --
#- This script will download, prepare and build AVR-Ada without --
#- any human interaction and is designed to make the build process --
#- easier for beginners and experts alike --
#- * --
#- To use simply create a directory and copy this script to it then --
#- cd into the directory and type ./build-avr-ada.sh --
#-
#- N.B. This script was written for BASH. If you use another shell --
#- invoke with bash ./build-avr-ada.sh --
#- --
#--------------------------------------------------------------------------
#---------------------------------------------------------------------------
#
# $DOWNLOAD : should point to directory which contains the files
# specified by : FILE_BINUTILS, FILE_GCC and FILE_LIBC
# $AVR_BUILD : the temporary directory used to build AVR-Ada
# $PREFIX : the root of the installation directory
# $FILE_... : filenames of the source distributions without extension
#
#---------------------------------------------------------------------------
#
# ! ! ! ! ! !
#
# The script assumes write permissions to the installation
# directory. You can either run the script as root or provide a
# private installation path of the build user.
#
# ! ! ! ! ! !
#
BASE_DIR=$PWD
OS=`uname -s`
case "$OS" in
"Linux" )
PREFIX="/opt/avr_92_gnat"
WITHGMP="/usr"
WITHMPFR="/usr";;
"Darwin" )
PREFIX="/opt/avr_92_gnat"
WITHGMP="/opt/local"
WITHMPFR="/opt/local";;
* )
PREFIX="/mingw/avr_92_gnat"
WITHGMP="/mingw"
WITHMPFR="/mingw";;
esac
# Check if current user has write privileges to parent of $PREFIX
PREFIX_PARENT=$(dirname "$PREFIX")
if test ! -w "$PREFIX_PARENT"; then
while true; do
read -p "$PREFIX_PARENT is *not* writable by user $USER, continue as $USER? [y/n]" yn
case $yn in
[Yy]* ) break;;
[Nn]* ) exit;;
* ) echo "Please answer yes or no.";;
esac
done
fi
# add PREFIX/bin to the PATH
# Be sure to have the local directory very late in your PATH, best at the
# very end.
export PATH="${PREFIX}/bin:${PATH}"
# Only on MinGW:
# export PATH=/mingwRE/bin:${PATH}
# export LIBRARY_PATH=/mingwRE/lib:/mingw/lib
# export CPATH=/mingw/include
# !! unset CPATH before compiling avr-libc !!
source bin/versions.inc
source bin/config.inc
# actions:
download_files="yes"
delete_obj_dirs="no"
delete_build_dir="yes"
delete_install_dir="no" # Be carefull, will remove *all* software installed in $PREFIX!!!
build_binutils="yes"
build_gcc="yes"
build_mpfr="no"
build_mpc="no"
build_gmp="no"
build_libc="yes"
build_avradarts="yes"
build_avrdude="yes"
build_avrada="no"
# The following are advanced options not required for a normal build
# either delete the build directory completely
#
# delete_build_dir="yes"
#
# or delete only the obj directories. You probably want to keep the
# extracted and patched sources
#
# delete_build_dir="no"
# delete_obj_dirs="yes"
# no_extract="yes"
# no_patch="yes"
#
#CC="gcc -mno-cygwin"
CC=gcc
export CC
#echo "Please adjust the variables above to your environment."
#echo "No need to change anything below."
#exit
source bin/utilities.inc
#---------------------------------------------------------------------------
# build script
#---------------------------------------------------------------------------
export PATH=$PREFIX/bin:$PATH
echo "--------------------------------------------------------------"
echo "GCC AVR-Ada build script: all output is saved in log files"
echo "--------------------------------------------------------------"
echo
GCC_VERSION=`$CC -dumpversion`
# GCC_MAJOR=`echo $GCC_VERSION | awk -F. ' { print $1; } '`
# GCC_MINOR=`echo $GCC_VERSION | awk -F. ' { print $2; } '`
# GCC_PATCH=`echo $GCC_VERSION | awk -F. ' { print $3; } '`
if [[ "$GCC_VERSION" < "4.7.0" ]] ; then # string comparison (?)
echo "($GCC_VERSION) is too old"
echo "AVR-Ada V2 requires at least gcc-8 as build compiler"
exit 2
else
echo "Found native compiler gcc-"$GCC_VERSION
fi
if test "x$delete_build_dir" = "xyes" ; then
echo
echo "--------------------------------------------------------------"
echo "Deleting previous build and source files"
echo "--------------------------------------------------------------"
echo
echo "Deleting :" $AVR_BUILD
rm -fr $AVR_BUILD
else
if test "x$delete_obj_dirs" = "xyes" ; then
echo
echo "--------------------------------------------------------------"
echo "Deleting previous obj dirs"
echo "--------------------------------------------------------------"
echo
echo "Deleting :" $AVR_BUILD/binutils-obj
rm -fr $AVR_BUILD/binutils-obj
echo "Deleting :" $AVR_BUILD/gcc-obj
rm -fr $AVR_BUILD/gcc-obj
fi
fi
mkdir $AVR_BUILD
rm -f $AVR_BUILD/build.sum; touch $AVR_BUILD/build.sum
rm -f $AVR_BUILD/build.log; touch $AVR_BUILD/build.log
if test $delete_install_dir = "yes" ; then
echo "Deleting :" $PREFIX
rm -fr $PREFIX
fi
if test "x$download_files" = "xyes" ; then
bin/download.sh
fi
print_time > $AVR_BUILD/time_run.log
#---------------------------------------------------------------------------
cd $AVR_BUILD
#---------------------------------------------------------------------------
if test "x$build_binutils" = "xyes" ; then
header "Building Binutils"
if test "x$no_extract" != "xyes" ; then
unpack_package BINUTILS
fi
if test "x$no_patch" != "xyes" ; then
cd $AVR_BUILD/$FILE_BINUTILS
apply_patches BINUTILS > $AVR_BUILD/step10_bin_patch.log
fi
mkdir $AVR_BUILD/binutils-obj
cd $AVR_BUILD/binutils-obj
display "Configure binutils ... (log in $AVR_BUILD/step11_bin_configure.log)"
case "$OS" in
"Linux" | "Darwin" )
BINUTILS_OPS=;;
* )
BINUTILS_OPS=--build=x86-winnt-mingw32;;
esac
../$FILE_BINUTILS/configure \
--prefix=$PREFIX \
--target=avr \
--disable-nls \
--disable-shared \
--disable-threads \
--enable-cloog-backend=isl \
--disable-cloog-version-check \
--disable-isl-version-check \
--disable-ppl-version-check \
--with-gcc \
--with-gnu-as \
--with-gnu-ld \
--enable-multilib \
--enable-doc \
--disable-werror \
$BINUTILS_OPS \
&>$AVR_BUILD/step11_bin_configure.log
check_return_code
display "Make binutils bfd-headers ... (log in $AVR_BUILD/step12_bin_make.log)"
make all-bfd TARGET-bfd=headers &>$AVR_BUILD/step12_bin_make_bfd_headers.log
rm -f bfd/Makefile
make configure-host &>$AVR_BUILD/step13_bin_configure.log
check_return_code
make all &>$AVR_BUILD/step14_bin_make_all.log
check_return_code
display "Install binutils ... (log in $AVR_BUILD/step18_bin_install.log)"
make install &>$AVR_BUILD/step18_bin_install.log
check_return_code
fi
#---------------------------------------------------------------------------
if test "$build_gcc" = "yes" ; then
header "Building gcc cross compiler for AVR"
cd $AVR_BUILD
if test "x$no_extract" = "xyes" ; then
true
# do nothing
else
unpack_package GCC
if test "x$build_mpfr" = "xyes" ; then
unpack_package MPFR
mv $FILE_MPFR $FILE_GCC/mpfr
else
GCC_OPS="$GCC_OPS --with-mpfr=$PREFIX"
fi
if test "x$build_mpc" = "xyes" ; then
unpack_package MPC
mv $FILE_MPC $FILE_GCC/mpc
else
GCC_OPS="$GCC_OPS --with-mpc=$PREFIX"
fi
if test "x$build_gmp" = "xyes" ; then
unpack_package GMP
mv $FILE_GMP $FILE_GCC/gmp
else
GCC_OPS="$GCC_OPS --with-gmp=$PREFIX"
fi
fi
if test x$no_patch = "xyes" ; then
true
# do nothing
else
cd $AVR_BUILD/$FILE_GCC
apply_patches GCC >& $AVR_BUILD/step20_gcc_patch.log
fi
mkdir $AVR_BUILD/gcc-obj
cd $AVR_BUILD/gcc-obj
display "Configure GCC-AVR ... (log in $AVR_BUILD/step21_gcc_configure.log)"
echo "AVR-Ada V$VER_AVRADA" > ../$FILE_GCC/gcc/PKGVERSION
../$FILE_GCC/configure --prefix=$PREFIX \
--target=avr \
--enable-languages=ada,c,c++ \
--with-avrlibc \
--with-dwarf2 \
--disable-nls \
--disable-libssp \
--disable-libada \
--with-bugurl=http://avr-ada.sourceforge.net \
--with-gmp=$WITHGMP \
--with-mpfr=$WITHMPFR \
&>$AVR_BUILD/step21_gcc_configure.log
check_return_code
display "Make GCC/GNAT ... (log in $AVR_BUILD/step22_gcc_gcc_obj.log)"
make &> $AVR_BUILD/step22_gcc_gcc_obj.log
check_return_code
display "Make GNAT Tools ... (log in $AVR_BUILD/step23_gcc_tools_obj.log)"
make -C gcc cross-gnattools ada.all.cross &> $AVR_BUILD/step23_gcc_gcc_obj.log
check_return_code
#display "Make RTS ... (log in $AVR_BUILD/step24_gcc_rts_obj.log)"
#make -C gcc gnatlib &> $AVR_BUILD/step24_gcc_rts_obj.log
#check_return_code
display "Install GCC ... (log in $AVR_BUILD/step28_gcc_install.log)"
cd $AVR_BUILD/gcc-obj
make install &>$AVR_BUILD/step28_gcc_install.log
check_return_code
display "Adding GCC symlinks..."
ln -sf $PREFIX/bin/avr-gcc $PREFIX/bin/avr-gnatgcc
ln -sf $PREFIX/bin/avr-ar $PREFIX/bin/avr-elf-ar
fi
#---------------------------------------------------------------------------
if test "x$build_libc" = "xyes" ; then
#########################################################################
header "Building AVR libc"
export CPATH=
cd $AVR_BUILD
unpack_package LIBC
cd $AVR_BUILD/$FILE_LIBC
apply_patches LIBC &> $AVR_BUILD/step30_libc_patch.log
display "bootstrapping AVR-LIBC ... (log in $AVR_BUILD/step30_libc_bootstrap.log)"
./bootstrap &>$AVR_BUILD/step30_libc_bootstrap.log
display "configure AVR-LIBC ... (log in $AVR_BUILD/step31_libc_conf.log)"
CC=avr-gcc ./configure --build=`./config.guess` --host=avr --prefix=$PREFIX &>$AVR_BUILD/step31_libc_conf.log
check_return_code
display "Make AVR-LIBC ... (log in $AVR_BUILD/step32_libc_make.log)"
make &>$AVR_BUILD/step32_libc_make.log
check_return_code
display "Install AVR-LIBC ... (log in $AVR_BUILD/step38_libc_install.log)"
make install &>$AVR_BUILD/step38_libc_install.log
check_return_code
fi
print_time >> $AVR_BUILD/time_run.log
#---------------------------------------------------------------------------
if test "x$build_avrdude" = "xyes" ; then
#########################################################################
header "Building avrdude"
cd $AVR_BUILD
unpack_package AVRDUDE
cd $AVR_BUILD/$FILE_AVRDUDE
apply_patches AVRDUDE &> $AVR_BUILD/step40_avrdude_patch.log
display "configure avrdude ... (log in $AVR_BUILD/step41_avrdude_conf.log)"
./configure --prefix=$PREFIX &>$AVR_BUILD/step41_avrdude_conf.log
check_return_code
display "Make avrdude ... (log in $AVR_BUILD/step42_avrdude_make.log)"
make &>$AVR_BUILD/step42_avrdude_make.log
check_return_code
display "Install avrdude ... (log in $AVR_BUILD/step48_avrdude_install.log)"
make install &>$AVR_BUILD/step48_avrdude_install.log
check_return_code
fi
print_time >> $AVR_BUILD/time_run.log
#---------------------------------------------------------------------------
if test "x$build_avradarts" = "xyes" ; then
#########################################################################
header "Building AVR-Ada RTS"
AVRGCC_VERSION=`avr-gcc -dumpversion`
AVRGCC_MAJOR=`echo $AVRGCC_VERSION | awk -F. ' { print $1; } '`
FILE_AVRADARTS=avr-ada-rts-gcc-$AVRGCC_MAJOR
# mkdir -p $AVR_BUILD/$FILE_AVRADARTS
cp -a $AVRADA_RTS/gcc-$AVRGCC_MAJOR $AVR_BUILD/$FILE_AVRADARTS
cd $AVR_BUILD/$FILE_AVRADARTS
display "build AVR-Ada RTS ... (log in $AVR_BUILD/step62_avrada_rts_make.log)"
make -d build_rts >& ../step62_avrada_rts_make.log
check_return_code
display "install AVR-Ada RTS ... (log in $AVR_BUILD/step68_avrada_rts_install.log)"
make install_rts >& ../step68_avrada_rts_install.log
check_return_code
fi
if test "x$build_avrada" = "xyes" ; then
#########################################################################
header "Building AVR-Ada libraries"
cd $AVR_BUILD/$FILE_AVRADA
display "build AVR-Ada libs ... (log in $AVR_BUILD/step14_avrada_libs.log)"
make build_libs >& ../step14_avrada_libs.log
check_return_code
make install_libs >& ../step14_avrada_libs_inst.log
check_return_code
fi
cd ..
#########################################################################
header "Build end"
display
display "Build logs are located in $AVR_BUILD"
display "Programs are in the $PREFIX hierarchy"
display "You may remove $AVR_BUILD directory"
#---------------------------------------------------------------------------
# eof
#---------------------------------------------------------------------------