buildgcc: solidify and remove boilerplate code

- don't capture build_$package in a subshell by piping it
- move HOSTCFLAGS to build_GMP
- only create a build directory if a build happens
- automatically collect packages to build

Change-Id: Ic5a9f3f222faecd3381b413e5f25dff87262a855
Signed-off-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
Reviewed-on: http://review.coreboot.org/10475
Reviewed-by: Alexander Couzens <lynxis@fe80.eu>
Tested-by: build bot (Jenkins)
This commit is contained in:
Stefan Reinauer 2015-06-09 11:47:28 -07:00
parent 93b4745d93
commit 1c70e052aa
1 changed files with 33 additions and 38 deletions

View File

@ -235,29 +235,37 @@ unpack_and_patch() {
) )
} }
wait_for_build() { fn_exists()
# $1: directory in which log file and failure marker are stored {
cat > "$1/crossgcc-build.log" type $1 2>/dev/null | grep -q 'is a function'
test -r "$1/.failed" && printf "${RED}failed${NC}. Check $1/crossgcc-build.log.\n" || \
printf "${green}ok${NC}\n"
test -r "$1/.failed" && exit 1
true
} }
build() { build() {
package=$1 package=$1
version="$(eval echo \$$package"_VERSION")" version="$(eval echo \$$package"_VERSION")"
fn_exists build_$package || return
mkdir -p ${BUILDDIRPREFIX}-$package
[[ "$PACKAGES" == *$package* ]] && \ [[ "$PACKAGES" == *$package* ]] && \
if [ -f ${BUILDDIRPREFIX}-$package/.success ]; then if [ -f ${BUILDDIRPREFIX}-$package/.success ]; then
printf "Skipping $package as it is already built\n" printf "Skipping $package as it is already built\n"
else else
printf "Building $package $version ... " printf "Building $package $version ... "
( DIR=$PWD
cd ${BUILDDIRPREFIX}-$package cd ${BUILDDIRPREFIX}-$package
rm -f .failed rm -f .failed
build_${package} build_${package} > build.log 2>&1
cd $DIR/${BUILDDIRPREFIX}-$package
if [ ! -f .failed ]; then touch .success; fi if [ ! -f .failed ]; then touch .success; fi
) 2>&1 | wait_for_build "${BUILDDIRPREFIX}-$package" || exit 1 cd ..
if [ -r "${BUILDDIRPREFIX}-$package/.failed" ]; then
printf "${RED}failed${NC}. Check ${BUILDDIRPREFIX}-$package/build.log.\n"
exit 1
fi
printf "${green}ok${NC}\n"
fi fi
} }
@ -322,6 +330,11 @@ build_GMP() {
$MAKE install DESTDIR=$DESTDIR || touch .failed $MAKE install DESTDIR=$DESTDIR || touch .failed
normalize_dirs normalize_dirs
# Now set CFLAGS to match GMP CFLAGS but strip out -pedantic
# as GCC 4.6.x fails if it's there.
export HOSTCFLAGS=$(grep __GMP_CFLAGS $DESTDIR$TARGETDIR/include/gmp.h |cut -d\" -f2 |\
sed s,-pedantic,,)
} }
build_MPFR() { build_MPFR() {
@ -538,11 +551,11 @@ if [ $SKIPGDB -eq 1 ]; then
SKIPPYTHON=1 SKIPPYTHON=1
fi fi
else else
PACKAGES="$PACKAGES GDB"
fi
if [ $SKIPPYTHON -eq 0 ]; then if [ $SKIPPYTHON -eq 0 ]; then
PACKAGES="$PACKAGES EXPAT PYTHON" PACKAGES="$PACKAGES EXPAT PYTHON"
fi fi
PACKAGES="$PACKAGES GDB"
fi
# coreboot does not like the GOLD linker # coreboot does not like the GOLD linker
# USE_GOLD="--enable-gold" # USE_GOLD="--enable-gold"
@ -558,7 +571,7 @@ printf "Downloaded tar balls ... ${green}ok${NC}\n"
printf "Unpacking and patching ... \n" printf "Unpacking and patching ... \n"
for P in $PACKAGES; do for P in $PACKAGES; do
unpack_and_patch $P unpack_and_patch $P || exit 1
done done
printf "Unpacked and patched ... ${green}ok${NC}\n" printf "Unpacked and patched ... ${green}ok${NC}\n"
@ -591,30 +604,12 @@ if [ "$USECCACHE" = 1 ]; then
CC="ccache $CC" CC="ccache $CC"
fi fi
for package in $PACKAGES; do
mkdir -p ${BUILDDIRPREFIX}-$package
done
mkdir -p $DESTDIR$TARGETDIR/bin mkdir -p $DESTDIR$TARGETDIR/bin
export PATH=$DESTDIR$TARGETDIR/bin:$PATH export PATH=$DESTDIR$TARGETDIR/bin:$PATH
build GMP for package in $PACKAGES; do
build $package
# Now set CFLAGS to match GMP CFLAGS but strip out -pedantic done
# as GCC 4.6.x fails if it's there.
HOSTCFLAGS=$(grep __GMP_CFLAGS $DESTDIR$TARGETDIR/include/gmp.h |cut -d\" -f2 |\
sed s,-pedantic,,)
build MPFR
build MPC
build LIBELF
build BINUTILS
build GCC
build EXPAT
build PYTHON
build GDB
build IASL
build LLVM
# Adding git information of current tree to target directory # Adding git information of current tree to target directory
# for reproducibility # for reproducibility