Skip to content

Commit b26888f

Browse files
authored
Add files via upload
1 parent 8d51191 commit b26888f

File tree

1 file changed

+201
-0
lines changed

1 file changed

+201
-0
lines changed

build.sh

+201
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
1+
#!/bin/bash
2+
3+
# http://www.nongnu.org/avr-libc/user-manual/install_tools.html
4+
5+
# For optimum compile time this should generally be set to the number of CPU cores your machine has
6+
JOBCOUNT=8
7+
8+
# Build Linux toolchain
9+
# A Linux AVR-GCC toolchain is required to build a Windows toolchain
10+
# If the Linux toolchain has already been built then you can set this to 0
11+
BUILD_LINUX=1
12+
13+
# Build 32 bit Windows toolchain
14+
BUILD_WIN32=0
15+
16+
# Build 64 bit Windows toolchain
17+
BUILD_WIN64=0
18+
19+
# Build AVR-LibC
20+
BUILD_LIBC=1
21+
22+
# Output locations for built toolchains
23+
PREFIX_LINUX=/opt/AVR/linux
24+
PREFIX_WIN32=/omgwtfbbq/win32
25+
PREFIX_WIN64=/omgwtfbbq/win64
26+
PREFIX_LIBC=/opt/AVR/libc
27+
28+
# Install packages
29+
if hash apt-get 2>/dev/null; then
30+
# This works for Debian 8 and Ubuntu 16.04
31+
apt-get install wget make gcc g++ bzip2
32+
elif hash yum 2>/dev/null; then
33+
# This works for CentOS 7
34+
yum install wget
35+
rpm -q epel-release-7-6.noarch >/dev/null
36+
if [ $? -ne 0 ]; then
37+
# EPEL is for the MinGW stuff
38+
rm -f epel-release-7-6.noarch.rpm
39+
wget https://www.mirrorservice.org/sites/dl.fedoraproject.org/pub/epel//7/x86_64/e/epel-release-7-6.noarch.rpm
40+
rpm -Uvh epel-release-7-6.noarch.rpm
41+
fi
42+
yum install make mingw64-gcc mingw64-gcc-c++ mingw32-gcc mingw32-gcc-c++ gcc gcc-c++ bzip2
43+
elif hash pacman 2>/dev/null; then
44+
# This works for Arch
45+
pacman -S --needed wget make mingw-w64-binutils mingw-w64-gcc mingw-w64-crt mingw-w64-headers mingw-w64-winpthreads gcc bzip2
46+
fi
47+
48+
# Stop on errors
49+
set -e
50+
51+
NAME_BINUTILS="binutils-2.32"
52+
NAME_GCC="gcc-9.1.0"
53+
NAME_LIBC="avr-libc-SVN"
54+
55+
HOST_WIN32="i686-w64-mingw32"
56+
HOST_WIN64="x86_64-w64-mingw32"
57+
58+
OPTS_BINUTILS="
59+
--target=avr
60+
--disable-nls
61+
"
62+
63+
OPTS_GCC="
64+
--target=avr
65+
--enable-languages=c,c++
66+
--disable-nls
67+
--disable-libssp
68+
--disable-libada
69+
--with-dwarf2
70+
--disable-shared
71+
--enable-static
72+
--enable-mingw-wildcard
73+
"
74+
75+
OPTS_LIBC=""
76+
77+
TIME_START=$(date +%s)
78+
79+
makeDir()
80+
{
81+
rm -rf "$1/"
82+
mkdir -p "$1"
83+
}
84+
85+
fixGCCAVR()
86+
{
87+
# In GCC 7.1.0 there seems to be an issue with INT8_MAX and some other things being undefined in /gcc/config/avr/avr.c when building for Windows.
88+
# Adding '#include <stdint.h>' doesn't fix it, but manually defining the values does the trick.
89+
90+
echo "Fixing missing defines..."
91+
92+
DEFSFIX="
93+
#if (defined _WIN32 || defined __CYGWIN__)
94+
#define INT8_MIN (-128)
95+
#define INT16_MIN (-32768)
96+
#define INT8_MAX 127
97+
#define INT16_MAX 32767
98+
#define UINT8_MAX 0xff
99+
#define UINT16_MAX 0xffff
100+
#endif
101+
"
102+
103+
ORIGINAL=$(cat ../gcc/config/avr/avr.c)
104+
echo "$DEFSFIX" > ../gcc/config/avr/avr.c
105+
echo "$ORIGINAL" >> ../gcc/config/avr/avr.c
106+
}
107+
108+
echo "Clearing output directories..."
109+
[ $BUILD_LINUX -eq 1 ] && makeDir "$PREFIX_LINUX"
110+
[ $BUILD_WIN32 -eq 1 ] && makeDir "$PREFIX_WIN32"
111+
[ $BUILD_WIN64 -eq 1 ] && makeDir "$PREFIX_WIN64"
112+
[ $BUILD_LIBC -eq 1 ] && makeDir "$PREFIX_LIBC"
113+
114+
PATH="$PATH":"$PREFIX_LINUX"/bin
115+
export PATH
116+
117+
CC=""
118+
export CC
119+
120+
echo "Downloading sources..."
121+
rm -f $NAME_BINUTILS.tar.xz
122+
rm -rf $NAME_BINUTILS/
123+
wget ftp://ftp.mirrorservice.org/sites/ftp.gnu.org/gnu/binutils/$NAME_BINUTILS.tar.xz
124+
rm -f $NAME_GCC.tar.xz
125+
rm -rf $NAME_GCC/
126+
wget ftp://ftp.mirrorservice.org/sites/sourceware.org/pub/gcc/releases/$NAME_GCC/$NAME_GCC.tar.xz
127+
if [ $BUILD_LIBC -eq 1 ]; then
128+
rm -f $NAME_LIBC.tar.bz2
129+
rm -rf $NAME_LIBC/
130+
if [ "$NAME_LIBC" = "avr-libc-SVN" ]; then
131+
rm -f avrxmega3-v9.diff.bz2
132+
wget -O avrxmega3-v9.diff.bz2 https://savannah.nongnu.org/patch/download.php?file_id=45738
133+
svn co svn://svn.savannah.nongnu.org/avr-libc/trunk
134+
mv trunk/avr-libc $NAME_LIBC
135+
rm -rf trunk
136+
echo "Patching for XMEGA3 support"
137+
cat avrxmega3-v9.diff.bz2 | bzip2 -dc - | patch -d avr-libc-SVN -p0
138+
echo "Preparing"
139+
cd $NAME_LIBC
140+
./bootstrap
141+
cd ..
142+
else
143+
wget ftp://ftp.mirrorservice.org/sites/download.savannah.gnu.org/releases/avr-libc/$NAME_LIBC.tar.bz2
144+
fi
145+
fi
146+
147+
confMake()
148+
{
149+
../configure --prefix=$1 $2 $3 $4
150+
make -j $JOBCOUNT
151+
make install-strip
152+
rm -rf *
153+
}
154+
155+
# Make AVR-Binutils
156+
echo "Making Binutils..."
157+
echo "Extracting..."
158+
tar xf $NAME_BINUTILS.tar.xz
159+
mkdir -p $NAME_BINUTILS/obj-avr
160+
cd $NAME_BINUTILS/obj-avr
161+
[ $BUILD_LINUX -eq 1 ] && confMake "$PREFIX_LINUX" "$OPTS_BINUTILS"
162+
[ $BUILD_WIN32 -eq 1 ] && confMake "$PREFIX_WIN32" "$OPTS_BINUTILS" --host=$HOST_WIN32 --build=`../config.guess`
163+
[ $BUILD_WIN64 -eq 1 ] && confMake "$PREFIX_WIN64" "$OPTS_BINUTILS" --host=$HOST_WIN64 --build=`../config.guess`
164+
cd ../../
165+
166+
# Make AVR-GCC
167+
echo "Making GCC..."
168+
echo "Extracting..."
169+
tar xf $NAME_GCC.tar.xz
170+
mkdir -p $NAME_GCC/obj-avr
171+
cd $NAME_GCC
172+
chmod +x ./contrib/download_prerequisites
173+
./contrib/download_prerequisites
174+
cd obj-avr
175+
# fixGCCAVR
176+
[ $BUILD_LINUX -eq 1 ] && confMake "$PREFIX_LINUX" "$OPTS_GCC"
177+
[ $BUILD_WIN32 -eq 1 ] && confMake "$PREFIX_WIN32" "$OPTS_GCC" --host=$HOST_WIN32 --build=`../config.guess`
178+
[ $BUILD_WIN64 -eq 1 ] && confMake "$PREFIX_WIN64" "$OPTS_GCC" --host=$HOST_WIN64 --build=`../config.guess`
179+
cd ../../
180+
181+
# Make AVR-LibC
182+
if [ $BUILD_LIBC -eq 1 ]; then
183+
echo "Making AVR-LibC..."
184+
if [ "$NAME_LIBC" != "avr-libc-SVN" ]; then
185+
echo "Extracting..."
186+
bunzip2 -c $NAME_LIBC.tar.bz2 | tar xf -
187+
fi
188+
mkdir -p $NAME_LIBC/obj-avr
189+
cd $NAME_LIBC/obj-avr
190+
confMake "$PREFIX_LIBC" "$OPTS_LIBC" --host=avr --build=`../config.guess`
191+
cd ../../
192+
fi
193+
194+
TIME_END=$(date +%s)
195+
TIME_RUN=$(($TIME_END - $TIME_START))
196+
197+
echo ""
198+
echo "Done in $TIME_RUN seconds"
199+
200+
exit 0
201+

0 commit comments

Comments
 (0)