Skip to content

Commit 9c444c4

Browse files
committed
Changes to make incremental builds a little faster
utility scripts to build portions of the toolchain seperately.
1 parent 3b75962 commit 9c444c4

File tree

4 files changed

+109
-43
lines changed

4 files changed

+109
-43
lines changed

build-avrlibc3.sh

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
# Build Binutils ONLY
3+
export BUILD_LINUX=1
4+
export BUILD_WIN32=1
5+
export BUILD_WIN64=1
6+
7+
export BUILD_BINUTILS=0
8+
export BUILD_GCC=0
9+
export BUILD_LIBC=1
10+
11+
./build.sh

build-binutils.sh

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
# Build Binutils ONLY
3+
export BUILD_LINUX=1
4+
export BUILD_WIN32=1
5+
export BUILD_WIN64=1
6+
7+
export BUILD_BINUTILS=1
8+
export BUILD_GCC=0
9+
export BUILD_LIBC=0
10+
11+
./build.sh

build-gcc.sh

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
# Build Binutils ONLY
3+
export BUILD_LINUX=1
4+
export BUILD_WIN32=1
5+
export BUILD_WIN64=1
6+
7+
export BUILD_BINUTILS=0
8+
export BUILD_GCC=1
9+
export BUILD_LIBC=0
10+
11+
./build.sh

build.sh

100644100755
+76-43
Original file line numberDiff line numberDiff line change
@@ -3,66 +3,86 @@
33
# http://www.nongnu.org/avr-libc/user-manual/install_tools.html
44

55
# For optimum compile time this should generally be set to the number of CPU cores your machine has
6-
JOBCOUNT=8
6+
# Do it automatically, can over-ride from command line.
7+
if [ -z ${JOBCOUNT+x} ]; then
8+
CORES=$(getconf _NPROCESSORS_ONLN)
9+
JOBCOUNT=$CORES
10+
fi
711

812
# Build Linux toolchain
913
# A Linux AVR-GCC toolchain is required to build a Windows toolchain
1014
# If the Linux toolchain has already been built then you can set this to 0
11-
BUILD_LINUX=1
15+
if [ -z ${BUILD_LINUX+x} ]; then
16+
BUILD_LINUX=1
17+
fi
1218

1319
# Build 32 bit Windows toolchain
14-
BUILD_WIN32=0
20+
if [ -z ${BUILD_WIN32+x} ]; then
21+
BUILD_WIN32=1
22+
fi
1523

1624
# Build 64 bit Windows toolchain
17-
BUILD_WIN64=0
25+
if [ -z ${BUILD_WIN64+x} ]; then
26+
BUILD_WIN64=1
27+
fi
1828

1929
# Build Binutils? Can be set on command line.
20-
if [ -z ${BUILD_BINUTILS+x} ]; then
21-
BUILD_BINUTILS=0
30+
if [ -z ${BUILD_BINUTILS+x} ]; then
31+
BUILD_BINUTILS=1
2232
fi
2333

2434
# Build AVR-GCC? Can be set on command line.
25-
if [ -z ${BUILD_GCC+x} ]; then
26-
BUILD_GCC=0
35+
if [ -z ${BUILD_GCC+x} ]; then
36+
BUILD_GCC=1
2737
fi
2838

2939
# Build AVR-LibC? Can be set on command line.
30-
if [ -z ${BUILD_LIBC+x} ]; then
31-
BUILD_LIBC=1
40+
if [ -z ${BUILD_LIBC+x} ]; then
41+
BUILD_LIBC=1
3242
fi
3343

3444
# Output locations for built toolchains
35-
PREFIX_LINUX=/opt/AVR/linux
36-
PREFIX_WIN32=/omgwtfbbq/win32
37-
PREFIX_WIN64=/omgwtfbbq/win64
38-
PREFIX_LIBC=/opt/AVR/libc
45+
if [ -z ${PREFIX+x} ]; then
46+
PREFIX=/opt/AVR
47+
fi
48+
49+
PREFIX_LINUX="$PREFIX"/avr-gcc-linux
50+
PREFIX_WIN32="$PREFIX"/avr-gcc-win32
51+
PREFIX_WIN64="$PREFIX"/avr-gcc-win64
52+
PREFIX_LIBC="$PREFIX"/avr-libc3
3953

4054
# Install packages
41-
if hash apt-get 2>/dev/null; then
42-
# This works for Debian 8 and Ubuntu 16.04
43-
apt-get install wget make gcc g++ bzip2
44-
elif hash yum 2>/dev/null; then
45-
# This works for CentOS 7
46-
yum install wget
47-
rpm -q epel-release-7-6.noarch >/dev/null
48-
if [ $? -ne 0 ]; then
49-
# EPEL is for the MinGW stuff
50-
rm -f epel-release-7-6.noarch.rpm
51-
wget https://www.mirrorservice.org/sites/dl.fedoraproject.org/pub/epel//7/x86_64/e/epel-release-7-6.noarch.rpm
52-
rpm -Uvh epel-release-7-6.noarch.rpm
55+
if [ "$EUID" -eq 0 ]; then
56+
echo "Running as root, so trying to install dependant packages."
57+
if hash apt-get 2>/dev/null; then
58+
# This works for Debian 8 and Ubuntu 16.04
59+
apt-get install wget make gcc g++ bzip2 mingw-w64
60+
elif hash yum 2>/dev/null; then
61+
# This works for CentOS 7
62+
yum install wget
63+
rpm -q epel-release-7-6.noarch >/dev/null
64+
if [ $? -ne 0 ]; then
65+
# EPEL is for the MinGW stuff
66+
rm -f epel-release-7-6.noarch.rpm
67+
wget https://www.mirrorservice.org/sites/dl.fedoraproject.org/pub/epel//7/x86_64/e/epel-release-7-6.noarch.rpm
68+
rpm -Uvh epel-release-7-6.noarch.rpm
69+
fi
70+
yum install make mingw64-gcc mingw64-gcc-c++ mingw32-gcc mingw32-gcc-c++ gcc gcc-c++ bzip2
71+
elif hash pacman 2>/dev/null; then
72+
# This works for Arch
73+
pacman -S --needed wget make mingw-w64-binutils mingw-w64-gcc mingw-w64-crt mingw-w64-headers mingw-w64-winpthreads gcc bzip2
5374
fi
54-
yum install make mingw64-gcc mingw64-gcc-c++ mingw32-gcc mingw32-gcc-c++ gcc gcc-c++ bzip2
55-
elif hash pacman 2>/dev/null; then
56-
# This works for Arch
57-
pacman -S --needed wget make mingw-w64-binutils mingw-w64-gcc mingw-w64-crt mingw-w64-headers mingw-w64-winpthreads gcc bzip2
75+
76+
echo "We will not build while running as root, run as standard user to build."
77+
exit 1
5878
fi
5979

6080
# Stop on errors
6181
set -e
6282

6383
NAME_BINUTILS="binutils-2.32"
6484
NAME_GCC="gcc-9.1.0"
65-
NAME_LIBC="avr-libc.git"
85+
NAME_LIBC="avr-libc3.git"
6686

6787
HOST_WIN32="i686-w64-mingw32"
6888
HOST_WIN64="x86_64-w64-mingw32"
@@ -95,18 +115,23 @@ makeDir()
95115
}
96116

97117
echo "Clearing output directories..."
98-
[ $BUILD_LINUX -eq 1 ] && makeDir "$PREFIX_LINUX"
99-
[ $BUILD_WIN32 -eq 1 ] && makeDir "$PREFIX_WIN32"
100-
[ $BUILD_WIN64 -eq 1 ] && makeDir "$PREFIX_WIN64"
118+
[ $BUILD_LINUX -eq 1 ] && [ $BUILD_BINUTILS -eq 1 ] && makeDir "$PREFIX_LINUX"
119+
[ $BUILD_WIN32 -eq 1 ] && [ $BUILD_BINUTILS -eq 1 ] && makeDir "$PREFIX_WIN32"
120+
[ $BUILD_WIN64 -eq 1 ] && [ $BUILD_BINUTILS -eq 1 ] && makeDir "$PREFIX_WIN64"
101121
[ $BUILD_LIBC -eq 1 ] && makeDir "$PREFIX_LIBC"
102122

103-
PATH="$PATH":"$PREFIX_LINUX"/bin
123+
PATH="$PREFIX_LINUX"/bin:"$PATH"
104124
export PATH
105125

106126
CC=""
107127
export CC
108128

109129
echo "Downloading sources..."
130+
131+
# Create a temp directory for downloading and building in, to not polute base directory
132+
makeDir buildtemp
133+
cd buildtemp
134+
110135
if [ $BUILD_BINUTILS -eq 1 ]; then
111136
rm -f $NAME_BINUTILS.tar.xz
112137
rm -rf $NAME_BINUTILS/
@@ -121,7 +146,7 @@ fi
121146

122147
if [ $BUILD_LIBC -eq 1 ]; then
123148
rm -rf $NAME_LIBC/
124-
if [ "$NAME_LIBC" = "avr-libc.git" ]; then
149+
if [ "$NAME_LIBC" = "avr-libc3.git" ]; then
125150
git clone https://github.com/stevenj/avr-libc3.git "$NAME_LIBC"
126151
echo "Preparing"
127152
cd $NAME_LIBC
@@ -148,11 +173,20 @@ if [ $BUILD_BINUTILS -eq 1 ]; then
148173
tar xf $NAME_BINUTILS.tar.xz
149174
mkdir -p $NAME_BINUTILS/obj-avr
150175
cd $NAME_BINUTILS/obj-avr
151-
[ $BUILD_LINUX -eq 1 ] && confMake "$PREFIX_LINUX" "$OPTS_BINUTILS"
152-
[ $BUILD_WIN32 -eq 1 ] && confMake "$PREFIX_WIN32" "$OPTS_BINUTILS" --host=$HOST_WIN32 --build=`../config.guess`
153-
[ $BUILD_WIN64 -eq 1 ] && confMake "$PREFIX_WIN64" "$OPTS_BINUTILS" --host=$HOST_WIN64 --build=`../config.guess`
176+
if [ $BUILD_LINUX -eq 1 ]; then
177+
echo "********** BUILDING LINUX BINUTILS *************"
178+
confMake "$PREFIX_LINUX" "$OPTS_BINUTILS"
179+
fi
180+
if [ $BUILD_WIN32 -eq 1 ]; then
181+
echo "********** BUILDING WIN32 BINUTILS *************"
182+
confMake "$PREFIX_WIN32" "$OPTS_BINUTILS" --host=$HOST_WIN32 --build=`../config.guess`
183+
fi
184+
if [ $BUILD_WIN64 -eq 1 ]; then
185+
echo "********** BUILDING WIN64 BINUTILS *************"
186+
confMake "$PREFIX_WIN64" "$OPTS_BINUTILS" --host=$HOST_WIN64 --build=`../config.guess`
187+
fi
154188
cd ../../
155-
fi
189+
fi
156190

157191
# Make AVR-GCC
158192
if [ $BUILD_GCC -eq 1 ]; then
@@ -168,12 +202,12 @@ if [ $BUILD_GCC -eq 1 ]; then
168202
[ $BUILD_WIN32 -eq 1 ] && confMake "$PREFIX_WIN32" "$OPTS_GCC" --host=$HOST_WIN32 --build=`../config.guess`
169203
[ $BUILD_WIN64 -eq 1 ] && confMake "$PREFIX_WIN64" "$OPTS_GCC" --host=$HOST_WIN64 --build=`../config.guess`
170204
cd ../../
171-
fi
205+
fi
172206

173207
# Make AVR-LibC
174208
if [ $BUILD_LIBC -eq 1 ]; then
175209
echo "Making AVR-LibC..."
176-
if [ "$NAME_LIBC" != "avr-libc.git" ]; then
210+
if [ "$NAME_LIBC" != "avr-libc3.git" ]; then
177211
echo "Extracting..."
178212
bunzip2 -c $NAME_LIBC.tar.bz2 | tar xf -
179213
fi
@@ -190,4 +224,3 @@ echo ""
190224
echo "Done in $TIME_RUN seconds"
191225

192226
exit 0
193-

0 commit comments

Comments
 (0)