[coreboot-gerrit] New patch to review for coreboot: util/crossgcc: Add ability to build host tools/libs
Nico Huber (nico.h@gmx.de)
gerrit at coreboot.org
Tue Jan 26 19:15:40 CET 2016
Nico Huber (nico.h at gmx.de) just uploaded a new patch set to gerrit, which you can find at https://review.coreboot.org/13471
-gerrit
commit 1d51805db1004df8ff123468090809681311e53d
Author: Nico Huber <nico.huber at secunet.com>
Date: Tue Jan 26 16:09:31 2016 +0100
util/crossgcc: Add ability to build host tools/libs
We currently mix builds of host tools and libraries with builds of our
target toolchain. To end this, add the option to prefix a package name
with `host-` to build it only once for the host. Details:
o Resulting files will be installed into xgcc-host/ instead of xgcc/.
o .success files moved into the destination dir. That way we can tell
that a package has been built even if the package build directory
was removed.
Change-Id: I52a7245714a040d11f6e1ac8bdbff8057bb7f0a1
Signed-off-by: Nico Huber <nico.huber at secunet.com>
---
util/crossgcc/buildgcc | 133 ++++++++++++++++++++++++++++++++-----------------
1 file changed, 87 insertions(+), 46 deletions(-)
diff --git a/util/crossgcc/buildgcc b/util/crossgcc/buildgcc
index 138558a..830f6c4 100755
--- a/util/crossgcc/buildgcc
+++ b/util/crossgcc/buildgcc
@@ -27,6 +27,7 @@ TARGETDIR=$(pwd)/xgcc
TARGETARCH=i386-elf
LANGUAGES=c
DESTDIR=
+CLEANHOST=0
SAVETEMPS=0
SKIPPYTHON=1
@@ -94,6 +95,38 @@ NC='\033[0m' # No Color
UNAME=$(uname | grep -iq cygwin && echo Cygwin || uname)
HALT_FOR_TOOLS=0
+package_name()
+{
+ echo $1 | sed -e 's/^host-//'
+}
+
+build_dir()
+{
+ if echo $1 | grep -q '^host-' >/dev/null 2>&1; then
+ echo build-$1
+ else
+ echo build-${TARGETARCH}-$2
+ fi
+}
+
+install_dir()
+{
+ if echo $1 | grep -q '^host-' >/dev/null 2>&1; then
+ echo $TARGETDIR-host
+ else
+ echo $TARGETDIR
+ fi
+}
+
+success_file()
+{
+ if echo $1 | grep -q '^host-' >/dev/null 2>&1; then
+ echo .$2.success
+ else
+ echo .$2-$TARGETARCH.success
+ fi
+}
+
normalize_dirs()
{
mkdir -p $DESTDIR$TARGETDIR/lib
@@ -200,7 +233,7 @@ download_showing_percentage() {
}
download() {
- package=$1
+ package=$(package_name $1)
archive="$(eval echo \$$package"_ARCHIVE")"
FILE=$(basename $archive)
@@ -225,7 +258,7 @@ download() {
}
unpack_and_patch() {
- package=$1
+ package=$(package_name $1)
archive="$(eval echo \$$package"_ARCHIVE")"
dir="$(eval echo \$$package"_DIR")"
test -d ${dir} && test -f ${dir}/.unpack_success || (
@@ -260,29 +293,31 @@ is_package_enabled()
}
build() {
- package=$1
+ pkgspec=$1
+ package=$(package_name $pkgspec)
fn_exists build_$package || return
version="$(eval echo \$$package"_VERSION")"
- BUILDDIR=build-${TARGETARCH}-$package
+ SUCCESS=$(success_file $pkgspec $package)
+ BUILDDIR=$(build_dir $pkgspec $package)
+ INSTALLDIR=$(install_dir $pkgspec)
mkdir -p ${BUILDDIR}
- is_package_enabled "$package" && \
- if [ -f ${BUILDDIR}/.success ]; then
- printf "Skipping $package as it is already built\n"
+ is_package_enabled "$pkgspec" && \
+ if [ -f ${INSTALLDIR}/${SUCCESS} ]; then
+ printf "Skipping $pkgspec as it is already built\n"
else
- printf "Building $package $version ... "
+ printf "Building $pkgspec $version ... "
DIR=$PWD
cd ${BUILDDIR}
rm -f .failed
- build_${package} > build.log 2>&1
- cd $DIR/${BUILDDIR}
- if [ ! -f .failed ]; then touch .success; fi
- cd ..
-
- if [ -r "${BUILDDIR}/.failed" ]; then
+ build_${package} $pkgspec $INSTALLDIR > build.log 2>&1
+ cd $DIR
+ if [ ! -f ${BUILDDIR}/.failed ]; then
+ touch ${INSTALLDIR}/${SUCCESS};
+ else
printf "${RED}failed${NC}. Check ${BUILDDIR}/build.log.\n"
exit 1
fi
@@ -293,9 +328,13 @@ build() {
cleanup()
{
printf "Cleaning up temporary files... "
- for package in $PACKAGES; do
- rm -rf build-${TARGETARCH}-$package $(eval echo \$$package"_DIR")
+ for pkgspec in $PACKAGES; do
+ package=$(package_name $pkgspec)
+ rm -rf $(build_dir $pkgspec $package) $(eval echo \$$package"_DIR")
done
+ if [ $CLEANHOST = 1 ]; then
+ rm -rf $DESTDIR$TARGETDIR-host
+ fi
rm -f getopt
printf "${green}ok${NC}\n"
}
@@ -310,6 +349,7 @@ myhelp()
printf " [-V|--version] print version number and exit\n"
printf " [-h|--help] print this help and exit\n"
printf " [-c|--clean] remove temporary files before build\n"
+ printf " [-r|--cleanhost] remove temporary files for host libs and tools\n"
printf " [-t|--savetemps] don't remove temporary files after build\n"
printf " [-y|--ccache] Use ccache when building cross compiler\n"
printf " [-j|--jobs <num>] run <num> jobs in parallel in make\n"
@@ -358,7 +398,7 @@ EOF
}
build_GMP() {
- CC="$CC" CFLAGS="-Os" ../${GMP_DIR}/configure --disable-shared --enable-fat --prefix=$TARGETDIR $OPTIONS \
+ CC="$CC" CFLAGS="-Os" ../${GMP_DIR}/configure --disable-shared --enable-fat --prefix=$2 $OPTIONS \
|| touch .failed
$MAKE $JOBS || touch .failed
$MAKE install DESTDIR=$DESTDIR || touch .failed
@@ -367,15 +407,15 @@ build_GMP() {
# 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 |\
+ export HOSTCFLAGS=$(grep __GMP_CFLAGS $DESTDIR$2/include/gmp.h |cut -d\" -f2 |\
sed s,-pedantic,,)
}
build_MPFR() {
test $UNAME = "Darwin" && CFLAGS="$CFLAGS -force_cpusubtype_ALL"
- CC="$CC" ../${MPFR_DIR}/configure --disable-shared --prefix=$TARGETDIR \
- --infodir=$TARGETDIR/info \
- --with-gmp=$DESTDIR$TARGETDIR CFLAGS="$HOSTCFLAGS" || \
+ CC="$CC" ../${MPFR_DIR}/configure --disable-shared --prefix=$2 \
+ --infodir=$2/info \
+ --with-gmp=$DESTDIR$2 CFLAGS="$HOSTCFLAGS" || \
touch .failed
$MAKE $JOBS || touch .failed
$MAKE install DESTDIR=$DESTDIR || touch .failed
@@ -384,14 +424,14 @@ build_MPFR() {
# work around build problem of libgmp.la
if [ "$DESTDIR" != "" ]; then
- perl -pi -e "s,$DESTDIR,," $DESTDIR$TARGETDIR/libgmp.la
+ perl -pi -e "s,$DESTDIR,," $DESTDIR$2/libgmp.la
fi
}
build_MPC() {
- CC="$CC" ../${MPC_DIR}/configure --disable-shared --prefix=$TARGETDIR \
- --infodir=$TARGETDIR/info --with-mpfr=$DESTDIR$TARGETDIR \
- --with-gmp=$DESTDIR$TARGETDIR CFLAGS="$HOSTCFLAGS" || \
+ CC="$CC" ../${MPC_DIR}/configure --disable-shared --prefix=$2 \
+ --infodir=$2/info --with-mpfr=$DESTDIR$2 \
+ --with-gmp=$DESTDIR$2 CFLAGS="$HOSTCFLAGS" || \
touch .failed
$MAKE $JOBS || touch .failed
$MAKE install DESTDIR=$DESTDIR || touch .failed
@@ -401,10 +441,10 @@ build_MPC() {
build_LIBELF() {
CC="$CC" CFLAGS="$HOSTCFLAGS" libelf_cv_elf_h_works=no \
- ../${LIBELF_DIR}/configure --disable-shared --prefix=$TARGETDIR \
- --infodir=$TARGETDIR/info CFLAGS="$HOSTCFLAGS" || touch .failed
+ ../${LIBELF_DIR}/configure --disable-shared --prefix=$2 \
+ --infodir=$2/info CFLAGS="$HOSTCFLAGS" || touch .failed
$MAKE $JOBS || touch .failed
- $MAKE install prefix=$DESTDIR$TARGETDIR || touch .failed
+ $MAKE install prefix=$DESTDIR$2 || touch .failed
normalize_dirs
}
@@ -413,7 +453,7 @@ build_BINUTILS() {
if [ $TARGETARCH == "x86_64-elf" ]; then
ADDITIONALTARGET=",i386-elf"
fi
- CC="$CC" ../binutils-${BINUTILS_VERSION}/configure --prefix=$TARGETDIR \
+ CC="$CC" ../binutils-${BINUTILS_VERSION}/configure --prefix=$2 \
--target=${TARGETARCH} --enable-targets=${TARGETARCH}${ADDITIONALTARGET} \
--disable-werror --disable-nls --enable-lto --enable-gold \
--enable-plugins --enable-multilibs CFLAGS="$HOSTCFLAGS" || touch .failed
@@ -430,14 +470,14 @@ build_GCC() {
# libiberty is not compiled with CFLAGS_FOR_BUILD.
CC="$CC" CFLAGS_FOR_TARGET="-O2" CFLAGS="$HOSTCFLAGS" \
CFLAGS_FOR_BUILD="$HOSTCFLAGS" ../gcc-${GCC_VERSION}/configure \
- --prefix=$TARGETDIR --libexecdir=$TARGETDIR/lib \
+ --prefix=$2 --libexecdir=$2/lib \
--target=${TARGETARCH} --disable-werror --disable-shared \
--enable-lto --enable-plugins --enable-gold --enable-ld=default \
--disable-libssp --disable-bootstrap --disable-nls \
--disable-libquadmath --without-headers \
${GCC_OPTIONS} --enable-languages="${LANGUAGES}" \
- --with-gmp=$DESTDIR$TARGETDIR --with-mpfr=$DESTDIR$TARGETDIR \
- --with-mpc=$DESTDIR$TARGETDIR --with-libelf=$DESTDIR$TARGETDIR \
+ --with-gmp=$DESTDIR$2-host --with-mpfr=$DESTDIR$2-host \
+ --with-mpc=$DESTDIR$2-host --with-libelf=$DESTDIR$2-host \
--with-pkgversion="coreboot toolchain v$CROSSGCC_VERSION $CROSSGCC_DATE" \
|| touch .failed
$MAKE $JOBS CFLAGS_FOR_BUILD="$HOSTCFLAGS" all-gcc || touch .failed
@@ -451,7 +491,7 @@ build_GCC() {
build_EXPAT() {
CC="$CC" CFLAGS="$HOSTCFLAGS" ../${EXPAT_DIR}/configure --disable-shared \
- --prefix=$TARGETDIR --target=${TARGETARCH} || touch .failed
+ --prefix=$2 --target=${TARGETARCH} || touch .failed
$MAKE || touch .failed
$MAKE install DESTDIR=$DESTDIR || touch .failed
@@ -459,7 +499,7 @@ build_EXPAT() {
}
build_PYTHON() {
- CC="$CC" CFLAGS="$HOSTCFLAGS" ../${PYTHON_DIR}/configure --prefix=$TARGETDIR \
+ CC="$CC" CFLAGS="$HOSTCFLAGS" ../${PYTHON_DIR}/configure --prefix=$2 \
--target=${TARGETARCH} || touch .failed
$MAKE $JOBS || touch .failed
$MAKE install DESTDIR=$DESTDIR || touch .failed
@@ -468,14 +508,14 @@ build_PYTHON() {
}
build_GDB() {
- export PYTHONHOME=$DESTDIR$TARGETDIR
+ export PYTHONHOME=$DESTDIR$2
if [ $(uname) != "FreeBSD" -a $(uname) != "NetBSD" ]; then
LIBDL="-ldl"
fi
- LDFLAGS="-Wl,-rpath,\$\$ORIGIN/../lib/ -L$DESTDIR$TARGETDIR/lib \
+ LDFLAGS="-Wl,-rpath,\$\$ORIGIN/../lib/ -L$DESTDIR$2/lib \
-lpthread $LIBDL -lutil" \
- CC="$CC" CFLAGS="$HOSTCFLAGS -I$DESTDIR$TARGETDIR/include" \
- ../${GDB_DIR}/configure --prefix=$TARGETDIR \
+ CC="$CC" CFLAGS="$HOSTCFLAGS -I$DESTDIR$2/include" \
+ ../${GDB_DIR}/configure --prefix=$2 \
--target=${TARGETARCH} --disable-werror --disable-nls
$MAKE $JOBS || touch .failed
$MAKE install DESTDIR=$DESTDIR || touch .failed
@@ -490,8 +530,8 @@ build_IASL() {
test $UNAME = "FreeBSD" && HOST="_FreeBSD"
test $UNAME = "Cygwin" && HOST="_CYGWIN"
HOST="$HOST" OPT_CFLAGS="-O -D_FORTIFY_SOURCE=2 -D COREBOOT_TOOLCHAIN_VERSION='\"coreboot toolchain v$CROSSGCC_VERSION $CROSSGCC_DATE\"' " CFLAGS="$CFLAGS" $MAKE CC="$CC" iasl || touch $RDIR/.failed
- rm -f $DESTDIR$TARGETDIR/bin/iasl || touch $RDIR/.failed
- cp bin/iasl $DESTDIR$TARGETDIR/bin || touch $RDIR/.failed
+ rm -f $DESTDIR$2/bin/iasl || touch $RDIR/.failed
+ cp bin/iasl $DESTDIR$2/bin || touch $RDIR/.failed
}
build_LLVM() {
@@ -501,18 +541,18 @@ build_LLVM() {
ln -sf $PWD/$CRT_DIR $LLVM_DIR/projects/compiler-rt
cd -
- $CMAKE -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX=$DESTDIR$TARGETDIR \
+ $CMAKE -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX=$DESTDIR$2 \
-DCLANG_VENDOR="coreboot toolchain v$CROSSGCC_VERSION $CROSSGCC_DATE - " \
-DCMAKE_BUILD_TYPE=Release ../$LLVM_DIR || touch .failed
$MAKE $JOBS || touch .failed
$MAKE install || touch .failed
- cp -a ../$CFE_DIR/tools/scan-build/* $DESTDIR$TARGETDIR/bin
- cp -a ../$CFE_DIR/tools/scan-view/* $DESTDIR$TARGETDIR/bin
+ cp -a ../$CFE_DIR/tools/scan-build/* $DESTDIR$2/bin
+ cp -a ../$CFE_DIR/tools/scan-view/* $DESTDIR$2/bin
# create symlinks to work around broken --print-librt-file-name
# when used with -target.
- cd $DESTDIR$TARGETDIR/lib/clang/${CLANG_VERSION}/lib
+ cd $DESTDIR$2/lib/clang/${CLANG_VERSION}/lib
for i in */libclang_rt.builtins*.a; do
ln -s $i .
done
@@ -562,6 +602,7 @@ while true ; do
-V|--version) shift; myversion; exit 0;;
-h|--help) shift; myhelp; exit 0;;
-c|--clean) shift; clean=1;;
+ -r|--cleanhost) shift; CLEANHOST=1;;
-t|--savetemps) shift; SAVETEMPS=1;;
-d|--directory) shift; TARGETDIR="$1"; shift;;
-p|--platform) shift; TARGETARCH="$1"; shift;;
@@ -702,8 +743,8 @@ fi
# Prepare target directory for building GCC
# (dependencies must be in the PATH)
-mkdir -p $DESTDIR$TARGETDIR/bin
-export PATH=$DESTDIR$TARGETDIR/bin:$PATH
+mkdir -p $DESTDIR$TARGETDIR-host/bin $DESTDIR$TARGETDIR/bin
+export PATH=$DESTDIR$TARGETDIR-host/bin:$DESTDIR$TARGETDIR/bin:$PATH
# Download, unpack, patch and build all packages
More information about the coreboot-gerrit
mailing list