[coreboot-gerrit] New patch to review for coreboot: 84f438f buildgcc: WIP
Stefan Reinauer (stefan.reinauer@coreboot.org)
gerrit at coreboot.org
Tue Jun 9 11:31:27 CEST 2015
Stefan Reinauer (stefan.reinauer at coreboot.org) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/10475
-gerrit
commit 84f438fb78da440663f427281b44a7c3abd61649
Author: Stefan Reinauer <stefan.reinauer at coreboot.org>
Date: Tue Jun 9 02:25:12 2015 -0700
buildgcc: WIP
- start unifying coding style: `` -> $( .. ), if test -> if [ ]
- don't capture build_$package in a subshell by piping it
- fail build when a patch doesn't apply
- move HOSTCFLAGS to build_GMP
- don't call autoconf, upstream is fixed (this was causing trouble
for some people)
- gdb-${GDB_VERSION} -> ${GDB_DIR}
- only create a build directory if a build happens
- automatically collect packages to build
Change-Id: Ic5a9f3f222faecd3381b413e5f25dff87262a855
Signed-off-by: Stefan Reinauer <stefan.reinauer at coreboot.org>
---
util/crossgcc/buildgcc | 169 ++++++++++++++++++++++---------------------------
1 file changed, 75 insertions(+), 94 deletions(-)
diff --git a/util/crossgcc/buildgcc b/util/crossgcc/buildgcc
index 1c1f6a5..dd16e83 100755
--- a/util/crossgcc/buildgcc
+++ b/util/crossgcc/buildgcc
@@ -20,13 +20,13 @@
# Foundation, Inc.
#
-cd `dirname $0`
+cd $(dirname $0)
CROSSGCC_DATE="June 4th, 2015"
CROSSGCC_VERSION="1.29"
# default settings
-TARGETDIR=`pwd`/xgcc
+TARGETDIR=$(pwd)/xgcc
TARGETARCH=i386-elf
DESTDIR=
@@ -96,7 +96,7 @@ cyan='\033[0;36m'
CYAN='\033[1;36m'
NC='\033[0m' # No Color
-UNAME=`uname`
+UNAME=$(uname)
normalize_dirs()
{
@@ -121,9 +121,9 @@ searchtool()
search="$2"
fi
for i in "$1" "g$1" "gnu$1"; do
- if test -x "`which $i 2>/dev/null`"; then
- if test `cat /dev/null | $i --version 2>&1 |grep -c "$search"` \
- -gt 0; then
+ if [ -x "$(which $i 2>/dev/null)" ]; then
+ if [ "$(cat /dev/null | $i --version 2>&1 | grep -c "$search")" \
+ -gt 0 ]; then
echo $i
return
fi
@@ -133,28 +133,28 @@ searchtool()
# patch and tar also work.
if [ $UNAME = "Darwin" -o $UNAME = "FreeBSD" -o $UNAME = "NetBSD" -o $UNAME = "OpenBSD" ]; then
if [ "$1" = "patch" -o "$1" = "tar" ]; then
- if test -x "`which $1 2>/dev/null`"; then
+ if [ -x "$(which $1 2>/dev/null)" ]; then
echo $1
return
fi
fi
fi
- if [ "`echo $1 | cut -b -3`" = "sha" ]; then
+ if [ "$(echo $1 | cut -b -3)" = "sha" ]; then
if [ $UNAME = "FreeBSD" ]; then
- if test -x "`which sha1 2>/dev/null`"; then
+ if [ -x "$(which sha1 2>/dev/null)" ]; then
echo sha1
return
fi
fi
if [ $UNAME = "NetBSD" ]; then
- if test -x "`which cksum 2>/dev/null`"; then
- echo cksum -a `echo $1 | sed -e 's,sum,,'`
+ if [ -x "$(which cksum 2>/dev/null)" ]; then
+ echo cksum -a $(echo $1 | sed -e 's,sum,,')
return
fi
fi
if [ $UNAME = "Darwin" ]; then
- if test -x "`which openssl 2>/dev/null`"; then
- echo openssl `echo $1 | sed -e 's,sum,,'`
+ if [ -x "$(which openssl 2>/dev/null)" ]; then
+ echo openssl $(echo $1 | sed -e 's,sum,,')
return
fi
fi
@@ -164,12 +164,12 @@ searchtool()
false
}
-TAR=`searchtool tar` || exit $?
-PATCH=`searchtool patch` || exit $?
-MAKE=`searchtool make` || exit $?
-CMAKE=`searchtool cmake "cmake"` || exit $?
-SHA1SUM=`searchtool sha1sum`
-SHA512SUM=`searchtool sha512sum`
+TAR=$(searchtool tar) || exit $?
+PATCH=$(searchtool patch) || exit $?
+MAKE=$(searchtool make) || exit $?
+CMAKE=$(searchtool cmake "cmake") || exit $?
+SHA1SUM=$(searchtool sha1sum)
+SHA512SUM=$(searchtool sha512sum)
CHECKSUM=$SHA1SUM
searchtool m4 > /dev/null
@@ -184,12 +184,15 @@ download() {
package=$1
archive="$(eval echo \$$package"_ARCHIVE")"
- FILE=`basename $archive`
+ FILE=$(basename $archive)
printf " * $FILE "
test -f tarballs/$FILE && \
- (test -z "$CHECKSUM" || \
- test "`cat sum/$FILE.cksum 2>/dev/null | sed -e 's,.*\([0-9a-f]\{40\}\).*,\1,'`" = "`$CHECKSUM tarballs/$FILE 2>/dev/null | sed -e 's,.*\([0-9a-f]\{40\}\).*,\1,'`" ) && \
+ ( test -z "$CHECKSUM" || \
+ test "$(cat sum/$FILE.cksum 2>/dev/null | \
+ sed -e 's,.*\([0-9a-f]\{40\}\).*,\1,')" = \
+ "$($CHECKSUM tarballs/$FILE 2>/dev/null | \
+ sed -e 's,.*\([0-9a-f]\{40\}\).*,\1,')" ) && \
printf "(cached)" || (
printf "(downloading)"
rm -f tarballs/$FILE
@@ -200,9 +203,10 @@ download() {
(test -z "$CHECKSUM" || $CHECKSUM tarballs/$FILE > sum/$FILE.cksum ) && \
printf "(checksum created. ${RED}Note. Please upload sum/$FILE.cksum if the corresponding archive is upgraded.${NC})"
)
- test -f tarballs/$FILE || \
+ if [ ! -f tarballs/$FILE ]; then
printf "\n${RED}Failed to download $FILE.${NC}\n"
- test -f tarballs/$FILE || exit 1
+ exit 1
+ fi
printf "\n"
}
@@ -211,47 +215,57 @@ unpack_and_patch() {
archive="$(eval echo \$$package"_ARCHIVE")"
dir="$(eval echo \$$package"_DIR")"
test -d ${dir} && test -f ${dir}/.unpack_success || (
- printf " * `basename $archive`\n"
+ printf " * $(basename $archive)\n"
FLAGS=zxf
- suffix=`echo $archive | sed 's,.*\.,,'`
+ suffix=$(echo $archive | sed 's,.*\.,,')
test "$suffix" = "gz" && FLAGS=zxf
test "$suffix" = "bz2" && FLAGS=jxf
test "$suffix" = "xz" && FLAGS="--xz -xf"
test "$suffix" = "lzma" && FLAGS="--lzma -xf"
- $TAR $FLAGS tarballs/`basename $archive`
+ $TAR $FLAGS tarballs/$(basename $archive)
for patch in patches/${dir}_*.patch; do
test -r $patch || continue
- printf " o `basename $patch`\n"
- $PATCH -s -N -p0 < `echo $patch` || \
+ printf " o $(basename $patch)\n"
+ $PATCH -s -N -p0 < $(echo $patch) || {
printf "\n${RED}Failed $patch.${NC}\n"
+ exit 1
+ }
done
touch ${dir}/.unpack_success
)
}
-wait_for_build() {
- # $1: directory in which log file and failure marker are stored
- cat > "$1/crossgcc-build.log"
- 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
+fn_exists()
+{
+ type $1 2>/dev/null | grep -q 'is a function'
}
build() {
package=$1
version="$(eval echo \$$package"_VERSION")"
+
+ fn_exists build_$package || return
+
+ mkdir -p ${BUILDDIRPREFIX}-$package
+
[[ "$PACKAGES" == *$package* ]] && \
if [ -f ${BUILDDIRPREFIX}-$package/.success ]; then
printf "Skipping $package as it is already built\n"
else
printf "Building $package $version ... "
- (
- cd ${BUILDDIRPREFIX}-$package
- rm -f .failed
- build_${package}
- if [ ! -f .failed ]; then touch .success; fi
- ) 2>&1 | wait_for_build "${BUILDDIRPREFIX}-$package" || exit 1
+ DIR=$PWD
+ cd ${BUILDDIRPREFIX}-$package
+ rm -f .failed
+ build_${package} > build.log 2>&1
+ cd $DIR/${BUILDDIRPREFIX}-$package
+ if [ ! -f .failed ]; then touch .success; fi
+ 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
}
@@ -316,6 +330,11 @@ build_GMP() {
$MAKE install DESTDIR=$DESTDIR || touch .failed
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() {
@@ -357,13 +376,7 @@ build_LIBELF() {
}
build_BINUTILS() {
- # What a pain: binutils don't come with configure
- # script anymore. Create it:
- cd ../binutils-${BINUTILS_VERSION}/
- autoconf
- cd -
# Now build binutils
- rm -f .failed
CC="$CC" ../binutils-${BINUTILS_VERSION}/configure --prefix=$TARGETDIR \
--target=${TARGETARCH} --disable-werror --disable-nls \
$USE_GOLD CFLAGS="$HOSTCFLAGS" || touch .failed
@@ -373,22 +386,8 @@ build_BINUTILS() {
build_GCC() {
- # Even worse than binutils: GCC does not come with configure
- # script anymore, but also enforces an obsolete autoconf version
- # to create it. This is a poster child of how autotools help make
- # software portable.
- cd ../gcc-${GCC_VERSION}
- sed '/dnl Ensure exactly this Autoconf version is used/d' \
- config/override.m4 > config/override.m4.new
- autoconf_version=`autoconf -V | grep "autoconf" | tr ' ' '\n' | tail -1`
- sed "s/${GCC_AUTOCONF_VERSION}/${autoconf_version}/g" \
- config/override.m4.new > config/override.m4
- autoconf
- cd -
-
- # Now, finally, we can build gcc:
- # GCC does not honour HOSTCFLAGS at all. CFLAGS are used for
- # both target and host object files. This is pretty misdesigned.
+ # GCC does not honor HOSTCFLAGS at all. CFLAGS are used for
+ # both target and host object files.
# There's a work-around called CFLAGS_FOR_BUILD and CFLAGS_FOR_TARGET
# but it does not seem to work properly. At least the host library
# libiberty is not compiled with CFLAGS_FOR_BUILD.
@@ -406,7 +405,7 @@ build_GCC() {
$MAKE $JOBS CFLAGS_FOR_BUILD="$HOSTCFLAGS" all-gcc || touch .failed
$MAKE install-gcc DESTDIR=$DESTDIR || touch .failed
- if [ "`echo $TARGETARCH | grep -c -- -mingw32`" -eq 0 ]; then
+ if [ "$(echo $TARGETARCH | grep -c -- -mingw32)" -eq 0 ]; then
$MAKE $JOBS CFLAGS_FOR_BUILD="$HOSTCFLAGS" all-target-libgcc || touch .failed
$MAKE install-target-libgcc DESTDIR=$DESTDIR || touch .failed
fi
@@ -438,7 +437,7 @@ build_GDB() {
LDFLAGS="-Wl,-rpath,\$\$ORIGIN/../lib/ -L$DESTDIR$TARGETDIR/lib \
-lpthread $LIBDL -lutil" \
CC="$CC" CFLAGS="$HOSTCFLAGS -I$DESTDIR$TARGETDIR/include" \
- ../gdb-${GDB_VERSION}/configure --prefix=$TARGETDIR \
+ ../${GDB_DIR}/configure --prefix=$TARGETDIR \
--target=${TARGETARCH} --disable-werror --disable-nls
$MAKE $JOBS || touch .failed
$MAKE install DESTDIR=$DESTDIR || touch .failed
@@ -480,14 +479,14 @@ export PATH=$PATH:.
getopt - > /dev/null 2>/dev/null || gcc -o getopt getopt.c
# parse parameters.. try to find out whether we're running GNU getopt
-getoptbrand="`getopt -V | sed -e '1!d' -e 's,^\(......\).*,\1,'`"
+getoptbrand="$(getopt -V | sed -e '1!d' -e 's,^\(......\).*,\1,')"
if [ "${getoptbrand}" = "getopt" ]; then
# Detected GNU getopt that supports long options.
- args=`getopt -l version,help,clean,directory:,platform:,jobs:,destdir:,savetemps,skip-gdb,ccache,clang Vhcd:p:j:D:tGyC -- "$@"`
+ args=$(getopt -l version,help,clean,directory:,platform:,jobs:,destdir:,savetemps,skip-gdb,ccache,clang Vhcd:p:j:D:tGyC -- "$@")
eval set "$args"
else
# Detected non-GNU getopt
- args=`getopt Vhcd:p:j:D:tGyC $*`
+ args=$(getopt Vhcd:p:j:D:tGyC $*)
set -- $args
fi
@@ -572,7 +571,7 @@ printf "Downloaded tar balls ... ${green}ok${NC}\n"
printf "Unpacking and patching ... \n"
for P in $PACKAGES; do
- unpack_and_patch $P
+ unpack_and_patch $P || exit 1
done
printf "Unpacked and patched ... ${green}ok${NC}\n"
@@ -586,7 +585,7 @@ if [ $UNAME = "Darwin" ]; then
# binaries in 10.6 (even if the kernel is 32bit)
# For some weird reason, 10.5 autodetects an ABI=64 though
# so we're setting the ABI explicitly here.
- if [ `sysctl -n hw.optional.x86_64 2>/dev/null` -eq 1 ] 2>/dev/null; then
+ if [ $(sysctl -n hw.optional.x86_64 2>/dev/null) -eq 1 ] 2>/dev/null; then
OPTIONS="ABI=64"
else
OPTIONS="ABI=32"
@@ -605,36 +604,18 @@ if [ "$USECCACHE" = 1 ]; then
CC="ccache $CC"
fi
-for package in $PACKAGES; do
- mkdir -p ${BUILDDIRPREFIX}-$package
-done
-
mkdir -p $DESTDIR$TARGETDIR/bin
export PATH=$DESTDIR$TARGETDIR/bin:$PATH
-build GMP
-
-# Now set CFLAGS to match GMP CFLAGS but strip out -pedantic
-# 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
+for package in $PACKAGES; do
+ build $package
+done
# Adding git information of current tree to target directory
# for reproducibility
-PROGNAME=`basename "$0"`
+PROGNAME=$(basename "$0")
rm -f "$DESTDIR$TARGETDIR/$PROGNAME".commit.*
-cp "$PROGNAME" $DESTDIR$TARGETDIR/"$PROGNAME.commit.`git describe`"
+cp "$PROGNAME" $DESTDIR$TARGETDIR/"$PROGNAME.commit.$(git describe)"
if [ $SAVETEMPS -eq 0 ]; then
cleanup
More information about the coreboot-gerrit
mailing list