9 GNU_MIRROR
=https
://mirrors.kernel.org
/gnu
10 # Get absolute path, will spawn a subshell then exit so our pwd is retained
11 SCRIPTROOT
=$
(cd "$(dirname $0)" && pwd)
12 PATCHES
=$SCRIPTROOT/patches
/
14 # Cause errors in pipes to return failure when necessary
18 echo "doit: error during build"
19 if [ "$QUIET" = "1" ]; then
20 echo "doit: dumping last 50 lines of build log..."
21 echo "doit: see $OUTDIR/build.log for the full details"
22 tail -50 $OUTDIR/build.log
32 echo " -a <arch list> architectures to build"
33 echo " example: -a 'arm' or -a 'arm i386 x86_64' for multiple"
34 echo " -c use compilation cache (ccache must be installed)"
35 echo " -f fetch source releases from upstream"
36 echo " -h|-? display this help message"
37 echo " -j<#> use <#> parallel workers to build"
38 echo " -o <dir> output directory"
39 echo " -q make the build quieter"
40 echo " -s strip the binaries"
46 if [ "$QUIET" = "1" ]; then
47 "$@" >> $OUTDIR/build.log
2>&1
49 "$@" 2>&1 |
tee -a $OUTDIR/build.log
53 function extract-tool
()
55 #echo "extract-tool " $1 $2 $3 $4
57 TARFILE
=${1}-${2}.
tar$3
61 if [ -f ${TARGETDIR}/.extracted
]; then
62 log
echo "$TARFILE already extracted into $TARGETDIR, skipping"
65 if [ ! -f $ARCHIVES/$TARFILE ]; then
66 log
echo "error, missing $TARFILE"
70 echo "checking $TARFILE integrity"
71 if [ "$(shasum -a 256 -b "$ARCHIVES/$TARFILE" | cut -f1 -d' ')" != "$HASH" ]; then
72 log
echo "$TARFILE failed integrity check"
76 echo extracting
$TARFILE
79 tar xf
$ARCHIVES/$TARFILE ||
exit 1
81 if [ -n "$PATCH" ]; then
83 log
patch -d $TARGETDIR -p1 < "$PATCH" ||
exit 1
86 touch $TARGETDIR/.extracted ||
exit 1
91 if [ "$OS" = "Linux" ]; then
92 COUNT
=`grep processor /proc/cpuinfo | wc -l`
93 PARALLEL
=-j`expr $COUNT + $COUNT`
95 if [ "$OS" = "Darwin" ]; then
96 PARALLEL
=-j`sysctl -n hw.ncpu`
97 export CXXFLAGS
="-fbracket-depth=1024 -O2"
99 if [ "$OS" = "FreeBSD" ]; then
100 PARALLEL
=-j`sysctl -n hw.ncpu`
101 export CXXFLAGS
="-fbracket-depth=1024 -O2"
105 if [ "$HOSTARCH" = "amd64" ]; then
109 if [ $# == "0" ]; then
113 while getopts a
:cfhj
:o
:qs? arg
116 a
) ARCHES
=$OPTARG ;;
118 j
) PARALLEL
="-j$OPTARG" ;;
120 o
) OUTDIR
=$OPTARG ;;
125 * ) echo "unrecognized option '$arg'" ; exit 1 ;;
130 if [ -z "$ARCHES" ]; then
131 echo need to specify architectures to build
136 if [ -z "$OUTDIR" ]; then
139 ARCHIVES
=$OUTDIR/archives
141 if [ -z $
(which makeinfo
) ]; then
142 echo makeinfo not found. On debian
/ubuntu this is provided by the texinfo package.
149 if [ "$CCACHE" = "1" ]; then
150 export CC
="ccache $CC"
151 export CXX
="ccache $CXX"
155 log
echo "ARCHES='$ARCHES' PARALLEL='$PARALLEL' FETCH='$FETCH' CCACHE='$CCACHE'"
156 # load GCCVER and BINVER
159 if [ "$FETCH" = "1" ]; then
160 if [ ! -f $ARCHIVES/binutils-
$BINVER.
tar.bz2
]; then
161 echo fetching binutils-
$BINVER
162 log wget
-P $ARCHIVES -N $GNU_MIRROR/binutils
/binutils-
$BINVER.
tar.bz2
164 if [ ! -f $ARCHIVES/gcc-
$GCCVER.
tar.bz2
]; then
165 echo fetching gcc-
$GCCVER
166 log wget
-P $ARCHIVES -N $GNU_MIRROR/gcc
/gcc-
$GCCVER/gcc-
$GCCVER.
tar.xz
168 if [ ! -f $ARCHIVES/gdb-
$GDBVER.
tar.xz
]; then
169 echo fetching gdb-
$GDBVER
170 log wget
-P $ARCHIVES -N $GNU_MIRROR/gdb
/gdb-
$GDBVER.
tar.xz
172 if [ ! -f $ARCHIVES/mpfr-
$MPFRVER.
tar.bz2
]; then
173 echo fetching mpfr-
$MPFRVER
174 log wget
-P $ARCHIVES -N $GNU_MIRROR/mpfr
/mpfr-
$MPFRVER.
tar.bz2
176 if [ ! -f $ARCHIVES/mpc-
$MPCVER.
tar.gz
]; then
177 echo fetching mpc-
$MPCVER
178 log wget
-P $ARCHIVES -N $GNU_MIRROR/mpc
/mpc-
$MPCVER.
tar.gz
180 if [ ! -f $ARCHIVES/gmp-
$GMPVER.
tar.bz2
]; then
181 echo fetching gmp-
$GMPVER
182 log wget
-P $ARCHIVES -N $GNU_MIRROR/gmp
/gmp-
$GMPVER.
tar.bz2
186 if [ ! -f $OUTDIR/.extracted-stamp
]; then
187 extract-tool binutils
$BINVER .bz2
$BINHASH
188 extract-tool gcc
$GCCVER .xz
$GCCHASH $PATCHES/gcc-patch.txt
189 extract-tool gdb
$GDBVER .xz
$GDBHASH $PATCHES/gdb-patch.txt
190 extract-tool gmp
$GMPVER .bz2
$GMPHASH
191 extract-tool mpc
$MPCVER .gz
$MPCHASH
192 extract-tool mpfr
$MPFRVER .bz2
$MPFRHASH
193 touch $OUTDIR/.extracted-stamp
196 # link the last three libs into gcc
197 pushd $OUTDIR/gcc-
$GCCVER
198 ln -sf ..
/gmp-
$GMPVER gmp
199 ln -sf ..
/mpc-
$MPCVER mpc
200 ln -sf ..
/mpfr-
$MPFRVER mpfr
203 for ARCH
in $ARCHES; do
204 echo building
for arch
\"$ARCH\"
205 if [ "$ARCH" == "arm" ]; then
211 INSTALLPATH
=$OUTDIR/$TARGET-$GCCVER-$OS-$HOSTARCH
212 BINBUILDPATH
=$OUTDIR/build-binutils-
$BINVER-$ARCH-$OS-$HOSTARCH
213 GCCBUILDPATH
=$OUTDIR/build-gcc-
$GCCVER-$ARCH-$OS-$HOSTARCH
214 GDBBUILDPATH
=$OUTDIR/build-gdb-
$GDBVER-$ARCH-$OS-$HOSTARCH
215 export PATH
=$INSTALLPATH/bin
:$PATH
218 if [ ! -f $BINBUILDPATH/built.txt
]; then
219 echo building binutils
220 mkdir
-p $BINBUILDPATH
222 log ..
/binutils-
$BINVER/configure
--target=$TARGET --prefix=$INSTALLPATH --disable-werror
230 if [ ! -f $GCCBUILDPATH/built.txt
]; then
233 if [ $ARCH == "arm" ]; then
234 ARCH_OPTIONS
="--with-cpu=arm926ej-s --with-fpu=vfp"
237 mkdir
-p $GCCBUILDPATH
239 log ..
/gcc-
$GCCVER/configure
--target=$TARGET --prefix=$INSTALLPATH --enable-languages=c
,c
++ $ARCH_OPTIONS --disable-werror
240 log
$MAKE all-gcc
$PARALLEL
241 log
$MAKE all-target-libgcc
$PARALLEL
242 log
$MAKE install-gcc
243 log
$MAKE install-target-libgcc
248 if [ ! -f $GDBBUILDPATH/built.txt
]; then
250 aarch64-elf
) EXTRA_TARGETS
="--enable-targets=arm-eabi" ;;
251 *) EXTRA_TARGETS
="" ;;
255 mkdir
-p $GDBBUILDPATH
257 log ..
/gdb-
$GDBVER/configure
--target=$TARGET --prefix=$INSTALLPATH --disable-werror $EXTRA_TARGETS
264 # Optionally strip the binaries
265 if [ "${STRIP}" = "1" ]; then
266 find "${INSTALLPATH}/bin" -type f
-exec strip
{} \
;
267 for filename
in $
(find "${INSTALLPATH}/libexec" -type f
); do
268 (file "${filename}" |
grep -q ELF
) && strip
"${filename}"