buildsystem: reduce cascaded if-blocks (stamp and virtual)

This commit is contained in:
Sascha Kuehndel (InuSasha) 2017-10-27 18:39:14 +02:00
parent 3cd7be6023
commit 68ea042161
No known key found for this signature in database
GPG Key ID: 15FED89617B88D1B

View File

@ -71,58 +71,61 @@ if [ -f $STAMP ] ; then
fi
fi
if [ ! -f $STAMP ]; then
rm -f $STAMP
if [ -f $STAMP ]; then
# already build, do nothing
exit 0
fi
rm -f $STAMP
setup_toolchain $TARGET
setup_toolchain $TARGET
# unset functions
unset -f pre_build_target
unset -f pre_configure_target
unset -f configure_target
unset -f post_configure_target
unset -f pre_make_target
unset -f make_target
unset -f post_make_target
unset -f pre_makeinstall_target
unset -f makeinstall_target
unset -f post_makeinstall_target
# unset functions
unset -f pre_build_target
unset -f pre_configure_target
unset -f configure_target
unset -f post_configure_target
unset -f pre_make_target
unset -f make_target
unset -f post_make_target
unset -f pre_makeinstall_target
unset -f makeinstall_target
unset -f post_makeinstall_target
unset -f pre_build_host
unset -f pre_configure_host
unset -f configure_host
unset -f post_configure_host
unset -f pre_make_host
unset -f make_host
unset -f post_make_host
unset -f pre_makeinstall_host
unset -f makeinstall_host
unset -f post_makeinstall_host
unset -f pre_build_host
unset -f pre_configure_host
unset -f configure_host
unset -f post_configure_host
unset -f pre_make_host
unset -f make_host
unset -f post_make_host
unset -f pre_makeinstall_host
unset -f makeinstall_host
unset -f post_makeinstall_host
unset -f pre_build_init
unset -f pre_configure_init
unset -f configure_init
unset -f post_configure_init
unset -f pre_make_init
unset -f make_init
unset -f post_make_init
unset -f pre_makeinstall_init
unset -f makeinstall_init
unset -f post_makeinstall_init
unset -f pre_build_init
unset -f pre_configure_init
unset -f configure_init
unset -f post_configure_init
unset -f pre_make_init
unset -f make_init
unset -f post_make_init
unset -f pre_makeinstall_init
unset -f makeinstall_init
unset -f post_makeinstall_init
unset -f pre_build_bootstrap
unset -f pre_configure_bootstrap
unset -f configure_bootstrap
unset -f post_configure_bootstrap
unset -f pre_make_bootstrap
unset -f make_bootstrap
unset -f post_make_bootstrap
unset -f pre_makeinstall_bootstrap
unset -f makeinstall_bootstrap
unset -f post_makeinstall_bootstrap
unset -f pre_build_bootstrap
unset -f pre_configure_bootstrap
unset -f configure_bootstrap
unset -f post_configure_bootstrap
unset -f pre_make_bootstrap
unset -f make_bootstrap
unset -f post_make_bootstrap
unset -f pre_makeinstall_bootstrap
unset -f makeinstall_bootstrap
unset -f post_makeinstall_bootstrap
# configure TARGET build defaults
TARGET_CONFIGURE_OPTS="--host=$TARGET_NAME \
# configure TARGET build defaults
TARGET_CONFIGURE_OPTS="--host=$TARGET_NAME \
--build=$HOST_NAME \
--prefix=/usr \
--bindir=/usr/bin \
@ -134,28 +137,28 @@ if [ ! -f $STAMP ]; then
--disable-static \
--enable-shared"
# cmake build defaults
if [ "$DEBUG" = "yes" ]; then
# cmake build defaults
if [ "$DEBUG" = "yes" ]; then
CMAKE_BUILD_TYPE="Debug"
else
else
CMAKE_BUILD_TYPE="MinSizeRel"
fi
fi
CMAKE_GENERATOR_NINJA="-GNinja \
CMAKE_GENERATOR_NINJA="-GNinja \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON"
TARGET_CMAKE_OPTS="-DCMAKE_TOOLCHAIN_FILE=$CMAKE_CONF \
TARGET_CMAKE_OPTS="-DCMAKE_TOOLCHAIN_FILE=$CMAKE_CONF \
-DCMAKE_INSTALL_PREFIX=/usr \
-DCMAKE_BUILD_TYPE=$CMAKE_BUILD_TYPE"
# meson build defaults
if [ "$DEBUG" = "yes" ]; then
# meson build defaults
if [ "$DEBUG" = "yes" ]; then
MESON_BUILD_TYPE="debug"
else
else
MESON_BUILD_TYPE="plain"
fi
fi
TARGET_MESON_OPTS="--prefix=/usr \
TARGET_MESON_OPTS="--prefix=/usr \
--bindir=/usr/bin \
--sbindir=/usr/sbin \
--sysconfdir=/etc \
@ -165,8 +168,8 @@ if [ ! -f $STAMP ]; then
--buildtype=$MESON_BUILD_TYPE \
--cross-file=$MESON_CONF"
# configure HOST build defaults
HOST_CONFIGURE_OPTS="--host=$HOST_NAME \
# configure HOST build defaults
HOST_CONFIGURE_OPTS="--host=$HOST_NAME \
--build=$HOST_NAME \
--prefix=$TOOLCHAIN \
--bindir=$TOOLCHAIN/bin \
@ -177,11 +180,11 @@ if [ ! -f $STAMP ]; then
--disable-static \
--enable-shared"
HOST_CMAKE_OPTS="$CMAKE_GENERATOR \
HOST_CMAKE_OPTS="$CMAKE_GENERATOR \
-DCMAKE_TOOLCHAIN_FILE=$CMAKE_CONF \
-DCMAKE_INSTALL_PREFIX=$TOOLCHAIN"
HOST_MESON_OPTS="--prefix=$TOOLCHAIN \
HOST_MESON_OPTS="--prefix=$TOOLCHAIN \
--bindir=$TOOLCHAIN/bin \
--sbindir=$TOOLCHAIN/sbin \
--sysconfdir=$TOOLCHAIN/etc \
@ -191,86 +194,81 @@ if [ ! -f $STAMP ]; then
--buildtype=plain \
--cross-file=$MESON_CONF"
# configure INIT build defaults
INIT_CONFIGURE_OPTS="$TARGET_CONFIGURE_OPTS"
INIT_CMAKE_OPTS="$TARGET_CMAKE_OPTS"
INIT_MESON_OPTS="$TARGET_MESON_OPTS"
# configure INIT build defaults
INIT_CONFIGURE_OPTS="$TARGET_CONFIGURE_OPTS"
INIT_CMAKE_OPTS="$TARGET_CMAKE_OPTS"
INIT_MESON_OPTS="$TARGET_MESON_OPTS"
# configure BOOTSTRAP build defaults
BOOTSTRAP_CONFIGURE_OPTS="$HOST_CONFIGURE_OPTS"
BOOTSTRAP_CMAKE_OPTS="$HOST_CMAKE_OPTS"
BOOTSTRAP_MESON_OPTS="$HOST_MESON_OPTS"
# configure BOOTSTRAP build defaults
BOOTSTRAP_CONFIGURE_OPTS="$HOST_CONFIGURE_OPTS"
BOOTSTRAP_CMAKE_OPTS="$HOST_CMAKE_OPTS"
BOOTSTRAP_MESON_OPTS="$HOST_MESON_OPTS"
# include buildfile
. $PKG_DIR/package.mk
# include buildfile
. $PKG_DIR/package.mk
if [ "$PKG_IS_KERNEL_PKG" = "yes" ]; then
if [ "$PKG_IS_KERNEL_PKG" = "yes" ]; then
if [ "$TARGET_KERNEL_ARCH" = "arm64" -a "$TARGET_ARCH" = "arm" ]; then
TARGET_PREFIX=$TOOLCHAIN/lib/gcc-linaro-aarch64-linux-gnu/bin/aarch64-linux-gnu-
fi
fi
fi
# build dependencies
case "$TARGET" in
"target")
for p in $PKG_DEPENDS_TARGET; do
# build dependencies
case "$TARGET" in
"target") _pkg_depends="$PKG_DEPENDS_TARGET";;
"host") _pkg_depends="$PKG_DEPENDS_HOST";;
"init") _pkg_depends="$PKG_DEPENDS_INIT";;
"bootstrap") _pkg_depends="$PKG_DEPENDS_BOOTSTRAP";;
esac
for p in $_pkg_depends; do
$SCRIPTS/build $p
done
;;
"host")
for p in $PKG_DEPENDS_HOST; do
$SCRIPTS/build $p
done
;;
"init")
for p in $PKG_DEPENDS_INIT; do
$SCRIPTS/build $p
done
;;
"bootstrap")
for p in $PKG_DEPENDS_BOOTSTRAP; do
$SCRIPTS/build $p
done
;;
esac
done
printf "%${BUILD_INDENT}c $(print_color CLR_BUILD "BUILD") $PACKAGE_NAME $(print_color CLR_TARGET "($TARGET)")\n" ' '>&$SILENT_OUT
export BUILD_INDENT=$((${BUILD_INDENT:-1}+$BUILD_INDENT_SIZE))
printf "%${BUILD_INDENT}c $(print_color CLR_BUILD "BUILD") $PACKAGE_NAME $(print_color CLR_TARGET "($TARGET)")\n" ' '>&$SILENT_OUT
export BUILD_INDENT=$((${BUILD_INDENT:-1}+$BUILD_INDENT_SIZE))
# virtual packages dont must be build, they only contains dependencies, so dont go further here
if [ ! "$PKG_SECTION" = "virtual" ]; then
# virtual packages dont must be build, they only contains dependencies, so dont go further here
if [ "$PKG_SECTION" = "virtual" ]; then
PKG_DEEPMD5=$(find $STAMP_DEPENDS -exec md5sum {} \; 2>/dev/null | sort | md5sum | cut -d" " -f1)
for i in PKG_NAME PKG_DEEPMD5; do
echo "STAMP_$i=\"${!i}\"" >> $STAMP
done
# configure other variables
if [ "$TARGET" = "target" ]; then
exit 0
fi
# configure other variables
if [ "$TARGET" = "target" ]; then
INSTALL=$PKG_BUILD/.install_pkg
elif [ "$TARGET" = "init" ]; then
elif [ "$TARGET" = "init" ]; then
INSTALL=$PKG_BUILD/.install_init
fi
fi
# clean up
if [ ! -z "$INSTALL" ] ; then
# clean up
if [ ! -z "$INSTALL" ] ; then
if [ -d "$INSTALL" ] ; then
rm -rf $INSTALL
fi
fi
fi
# setup configure script
if [ -z "$PKG_CONFIGURE_SCRIPT" ]; then
# setup configure script
if [ -z "$PKG_CONFIGURE_SCRIPT" ]; then
PKG_CONFIGURE_SCRIPT="$PKG_BUILD/configure"
else
else
PKG_CONFIGURE_SCRIPT="$PKG_BUILD/$PKG_CONFIGURE_SCRIPT"
fi
if [ -z "$PKG_CMAKE_SCRIPT" ]; then
fi
if [ -z "$PKG_CMAKE_SCRIPT" ]; then
PKG_CMAKE_SCRIPT="$PKG_BUILD/CMakeLists.txt"
fi
fi
if [ -z "$PKG_MESON_SCRIPT" ]; then
if [ -z "$PKG_MESON_SCRIPT" ]; then
PKG_MESON_SCRIPT="$PKG_BUILD/meson.build"
fi
fi
# auto detect toolchain
_auto_toolchain=""
if [ -z "$PKG_TOOLCHAIN" -o "$PKG_TOOLCHAIN" = "auto" ]; then
# auto detect toolchain
_auto_toolchain=""
if [ -z "$PKG_TOOLCHAIN" -o "$PKG_TOOLCHAIN" = "auto" ]; then
if [ -f "$PKG_MESON_SCRIPT" ]; then
PKG_TOOLCHAIN="meson"
elif [ -f "$PKG_CMAKE_SCRIPT" -a ! "$PKG_USE_CMAKE" = "no" ]; then
@ -284,30 +282,31 @@ if [ ! -f $STAMP ]; then
exit 1
fi
_auto_toolchain=" (auto-detect)"
fi
if ! listcontains "meson cmake cmake-make configure ninja make autotools manual" "$PKG_TOOLCHAIN"; then
fi
if ! listcontains "meson cmake cmake-make configure ninja make autotools manual" "$PKG_TOOLCHAIN"; then
printf "$(print_color bold-red "ERROR:") unknown toolchain $PKG_TOOLCHAIN"
exit 1
fi
printf "%${BUILD_INDENT}c $(print_color CLR_TOOLCHAIN "TOOLCHAIN") $PKG_TOOLCHAIN${_auto_toolchain}\n" ' '>&$SILENT_OUT
fi
printf "%${BUILD_INDENT}c $(print_color CLR_TOOLCHAIN "TOOLCHAIN") $PKG_TOOLCHAIN${_auto_toolchain}\n" ' '>&$SILENT_OUT
if [ "$PKG_TOOLCHAIN" = "autotools" ]; then
# make autoreconf
if [ "$PKG_TOOLCHAIN" = "autotools" ]; then
$SCRIPTS/autoreconf $PACKAGE_NAME
fi
fi
# include build template and build
if [ "$(type -t pre_build_$TARGET)" = "function" ]; then
# include build template and build
if [ "$(type -t pre_build_$TARGET)" = "function" ]; then
pre_build_$TARGET
fi
fi
# ensure $PKG_BUILD is there. (installer? PKG_URL="")
if [ ! -d $PKG_BUILD ] ; then
# ensure $PKG_BUILD is there. (installer? PKG_URL="")
if [ ! -d $PKG_BUILD ] ; then
mkdir -p $PKG_BUILD
fi
fi
cd $PKG_BUILD
cd $PKG_BUILD
if [ -f "$PKG_CONFIGURE_SCRIPT" -o -f "$PKG_CMAKE_SCRIPT" -o -f "$PKG_MESON_SCRIPT" ]; then
if [ -f "$PKG_CONFIGURE_SCRIPT" -o -f "$PKG_CMAKE_SCRIPT" -o -f "$PKG_MESON_SCRIPT" ]; then
case "$TARGET" in
"target")
mkdir -p .$TARGET_NAME
@ -326,15 +325,15 @@ if [ ! -f $STAMP ]; then
cd .$HOST_NAME-$TARGET
;;
esac
fi
fi
# configure
if [ "$(type -t pre_configure_$TARGET)" = "function" ]; then
# configure
if [ "$(type -t pre_configure_$TARGET)" = "function" ]; then
pre_configure_$TARGET
fi
if [ "$(type -t configure_$TARGET)" = "function" ]; then
fi
if [ "$(type -t configure_$TARGET)" = "function" ]; then
configure_$TARGET
else
else
case "$PKG_TOOLCHAIN:$TARGET" in
# meson builds
"meson:target")
@ -408,18 +407,18 @@ if [ ! -f $STAMP ]; then
$PKG_CONFIGURE_SCRIPT $BOOTSTRAP_CONFIGURE_OPTS $PKG_CONFIGURE_OPTS_BOOTSTRAP
;;
esac
fi
if [ "$(type -t post_configure_$TARGET)" = "function" ]; then
fi
if [ "$(type -t post_configure_$TARGET)" = "function" ]; then
post_configure_$TARGET
fi
fi
# make
if [ "$(type -t pre_make_$TARGET)" = "function" ]; then
# make
if [ "$(type -t pre_make_$TARGET)" = "function" ]; then
pre_make_$TARGET
fi
if [ "$(type -t make_$TARGET)" = "function" ]; then
fi
if [ "$(type -t make_$TARGET)" = "function" ]; then
make_$TARGET
else
else
case "$PKG_TOOLCHAIN:$TARGET" in
# ninja based builds
"meson:target"|"cmake:target"|"ninja:target")
@ -457,18 +456,18 @@ if [ ! -f $STAMP ]; then
make $PKG_MAKE_OPTS_BOOTSTRAP
;;
esac
fi
if [ "$(type -t post_make_$TARGET)" = "function" ]; then
fi
if [ "$(type -t post_make_$TARGET)" = "function" ]; then
post_make_$TARGET
fi
fi
# make install
if [ "$(type -t pre_makeinstall_$TARGET)" = "function" ]; then
# make install
if [ "$(type -t pre_makeinstall_$TARGET)" = "function" ]; then
pre_makeinstall_$TARGET
fi
if [ "$(type -t makeinstall_$TARGET)" = "function" ]; then
fi
if [ "$(type -t makeinstall_$TARGET)" = "function" ]; then
makeinstall_$TARGET
else
else
case "$PKG_TOOLCHAIN:$TARGET" in
# ninja based builds
"meson:target"|"cmake:target")
@ -500,12 +499,12 @@ if [ ! -f $STAMP ]; then
make install $PKG_MAKEINSTALL_OPTS_BOOTSTRAP
;;
esac
fi
if [ "$(type -t post_makeinstall_$TARGET)" = "function" ]; then
fi
if [ "$(type -t post_makeinstall_$TARGET)" = "function" ]; then
post_makeinstall_$TARGET
fi
fi
if [ "$TARGET" = "target" -o "$TARGET" = "init" ]; then
if [ "$TARGET" = "target" -o "$TARGET" = "init" ]; then
if [ -d $INSTALL ] ; then
rm -rf $INSTALL/{usr/,}include
rm -rf $INSTALL/{usr/,}lib/cmake
@ -546,21 +545,19 @@ if [ ! -f $STAMP ]; then
-type f -executable 2>/dev/null` 2>/dev/null || :
fi
fi
fi
cd $ROOT
fi # ! "$PKG_SECTION" = "virtual"
for i in `find $SYSROOT_PREFIX/usr/lib/ -name "*.la" 2>/dev/null`; do \
$SED "s:\(['= ]\)/usr:\\1$SYSROOT_PREFIX/usr:g" $i; \
done
PKG_DEEPMD5=$(find $STAMP_DEPENDS -exec md5sum {} \; 2>/dev/null | sort | md5sum | cut -d" " -f1)
for i in PKG_NAME PKG_DEEPMD5; do
echo "STAMP_$i=\"${!i}\"" >> $STAMP
done
if [ "$1" = "u-boot" ]; then
echo "STAMP_UBOOT_SYSTEM=\"${UBOOT_SYSTEM}\"" >> $STAMP
fi
fi
cd $ROOT
for i in `find $SYSROOT_PREFIX/usr/lib/ -name "*.la" 2>/dev/null`; do \
$SED "s:\(['= ]\)/usr:\\1$SYSROOT_PREFIX/usr:g" $i; \
done
PKG_DEEPMD5=$(find $STAMP_DEPENDS -exec md5sum {} \; 2>/dev/null | sort | md5sum | cut -d" " -f1)
for i in PKG_NAME PKG_DEEPMD5; do
echo "STAMP_$i=\"${!i}\"" >> $STAMP
done
if [ "$1" = "u-boot" ]; then
echo "STAMP_UBOOT_SYSTEM=\"${UBOOT_SYSTEM}\"" >> $STAMP
fi