scripts/build: general cleanup

Add copyright
Convert to config/functions/die()
Make use of bash default value mechanic
Combine some if tests
Get PKG_BUILD quoted
Replace `` with $()

Signed-off-by: Ian Leonard <antonlacon@gmail.com>
This commit is contained in:
Ian Leonard 2018-11-02 22:24:35 +00:00
parent eeb3f94648
commit acca8326ce

View File

@ -2,11 +2,12 @@
# SPDX-License-Identifier: GPL-2.0-or-later # SPDX-License-Identifier: GPL-2.0-or-later
# Copyright (C) 2009-2016 Stephan Raue (stephan@openelec.tv) # Copyright (C) 2009-2016 Stephan Raue (stephan@openelec.tv)
# Copyright (C) 2018-present Team LibreELEC (https://libreelec.tv)
. config/options $1 . config/options $1
if [ "$1" = "--all" ]; then if [ "$1" = "--all" ]; then
if [ ! -z "$2" ]; then if [ -n "$2" ]; then
for build_dir in $(ls -1d ${ROOT}/build.*); do for build_dir in $(ls -1d ${ROOT}/build.*); do
load_build_config ${build_dir} && ./scripts/build $2 load_build_config ${build_dir} && ./scripts/build $2
done done
@ -15,13 +16,11 @@ if [ "$1" = "--all" ]; then
fi fi
if [ -z "$1" ]; then if [ -z "$1" ]; then
echo "usage: $0 package_name[:<host|target|init|bootstrap>]" die "usage: $0 package_name[:<host|target|init|bootstrap>]"
exit 1
fi fi
if [ ! -f $PKG_DIR/package.mk ]; then if [ ! -f $PKG_DIR/package.mk ]; then
printf "$(print_color CLR_ERROR "$1: no package.mk file found")\n" die "$(print_color CLR_ERROR "$1: no package.mk file found")"
exit 1
fi fi
# set defaults # set defaults
@ -36,7 +35,7 @@ else
PACKAGE_NAME=$1 PACKAGE_NAME=$1
TARGET= TARGET=
fi fi
[ -z "$TARGET" ] && TARGET="target" TARGET="${TARGET:-target}"
if [ -n "$PKG_ARCH" ]; then if [ -n "$PKG_ARCH" ]; then
listcontains "$PKG_ARCH" "!$TARGET_ARCH" && exit 0 listcontains "$PKG_ARCH" "!$TARGET_ARCH" && exit 0
@ -53,15 +52,11 @@ $SCRIPTS/unpack $PACKAGE_NAME
if [ -f $STAMP ] ; then if [ -f $STAMP ] ; then
. $STAMP . $STAMP
PKG_DEEPHASH=$(calculate_stamp) PKG_DEEPHASH=$(calculate_stamp)
if [ ! "$PKG_DEEPHASH" = "$STAMP_PKG_DEEPHASH" ] ; then if [ ! "$PKG_DEEPHASH" = "$STAMP_PKG_DEEPHASH" ]; then
rm -f $STAMP rm -f $STAMP
fi elif [ ! "$BUILD_WITH_DEBUG" = "$STAMP_BUILD_WITH_DEBUG" ]; then
if [ ! "$BUILD_WITH_DEBUG" = "$STAMP_BUILD_WITH_DEBUG" ]; then
rm -f $STAMP rm -f $STAMP
fi elif [ "$1" = "u-boot" -a ! "$UBOOT_SYSTEM" = "$STAMP_UBOOT_SYSTEM" ]; then
if [ "$1" = "u-boot" -a ! "$UBOOT_SYSTEM" = "$STAMP_UBOOT_SYSTEM" ]; then
rm -f $STAMP rm -f $STAMP
fi fi
fi fi
@ -232,32 +227,26 @@ fi
# configure other variables # configure other variables
if [ "$TARGET" = "target" ]; then if [ "$TARGET" = "target" ]; then
INSTALL=$PKG_BUILD/.install_pkg INSTALL="$PKG_BUILD/.install_pkg"
elif [ "$TARGET" = "init" ]; then elif [ "$TARGET" = "init" ]; then
INSTALL=$PKG_BUILD/.install_init INSTALL="$PKG_BUILD/.install_init"
fi fi
# clean up # clear previous image files
if [ ! -z "$INSTALL" ] ; then if [ -n "$INSTALL" -a -d "$INSTALL" ]; then
if [ -d "$INSTALL" ] ; then rm -rf "$INSTALL"
rm -rf $INSTALL
fi
fi fi
# setup configure script # setup configure scripts
if [ -z "$PKG_CONFIGURE_SCRIPT" ]; then if [ -z "$PKG_CONFIGURE_SCRIPT" ]; then
PKG_CONFIGURE_SCRIPT="$PKG_BUILD/configure" PKG_CONFIGURE_SCRIPT="$PKG_BUILD/configure"
else else
PKG_CONFIGURE_SCRIPT="$PKG_BUILD/$PKG_CONFIGURE_SCRIPT" PKG_CONFIGURE_SCRIPT="$PKG_BUILD/$PKG_CONFIGURE_SCRIPT"
fi fi
if [ -z "$PKG_CMAKE_SCRIPT" ]; then PKG_CMAKE_SCRIPT="${PKG_CMAKE_SCRIPT:-$PKG_BUILD/CMakeLists.txt}"
PKG_CMAKE_SCRIPT="$PKG_BUILD/CMakeLists.txt"
fi
if [ -z "$PKG_MESON_SCRIPT" ]; then PKG_MESON_SCRIPT="${PKG_MESON_SCRIPT:-$PKG_BUILD/meson.build}"
PKG_MESON_SCRIPT="$PKG_BUILD/meson.build"
fi
# auto detect toolchain # auto detect toolchain
_auto_toolchain="" _auto_toolchain=""
@ -268,17 +257,15 @@ if [ -z "$PKG_TOOLCHAIN" -o "$PKG_TOOLCHAIN" = "auto" ]; then
PKG_TOOLCHAIN="cmake" PKG_TOOLCHAIN="cmake"
elif [ -f "$PKG_CONFIGURE_SCRIPT" ]; then elif [ -f "$PKG_CONFIGURE_SCRIPT" ]; then
PKG_TOOLCHAIN="configure" PKG_TOOLCHAIN="configure"
elif [ -f $PKG_BUILD/Makefile ]; then elif [ -f "$PKG_BUILD/Makefile" ]; then
PKG_TOOLCHAIN="make" PKG_TOOLCHAIN="make"
else else
echo "Not possible to detect toolchain automatically. Add PKG_TOOLCHAIN= to package.mk" die "Not possible to detect toolchain automatically. Add PKG_TOOLCHAIN= to package.mk"
exit 1
fi fi
_auto_toolchain=" (auto-detect)" _auto_toolchain=" (auto-detect)"
fi fi
if ! listcontains "meson cmake cmake-make configure ninja make autotools manual" "$PKG_TOOLCHAIN"; then if ! listcontains "meson cmake cmake-make configure ninja make autotools manual" "$PKG_TOOLCHAIN"; then
printf "$(print_color bold-red "ERROR:") unknown toolchain $PKG_TOOLCHAIN" die "$(print_color bold-red "ERROR:") unknown toolchain $PKG_TOOLCHAIN"
exit 1
fi fi
printf "%${BUILD_INDENT}c $(print_color CLR_TOOLCHAIN "TOOLCHAIN") $PKG_TOOLCHAIN${_auto_toolchain}\n" ' '>&$SILENT_OUT printf "%${BUILD_INDENT}c $(print_color CLR_TOOLCHAIN "TOOLCHAIN") $PKG_TOOLCHAIN${_auto_toolchain}\n" ' '>&$SILENT_OUT
@ -293,11 +280,11 @@ if [ "$(type -t pre_build_$TARGET)" = "function" ]; then
fi fi
# ensure $PKG_BUILD is there. (installer? PKG_URL="") # ensure $PKG_BUILD is there. (installer? PKG_URL="")
if [ ! -d $PKG_BUILD ] ; then if [ ! -d "$PKG_BUILD" ] ; then
mkdir -p $PKG_BUILD 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 case "$TARGET" in
@ -306,9 +293,9 @@ if [ -f "$PKG_CONFIGURE_SCRIPT" -o -f "$PKG_CMAKE_SCRIPT" -o -f "$PKG_MESON_SCRI
"init") PKG_REAL_BUILD="$PKG_BUILD/.$TARGET_NAME-$TARGET" ;; "init") PKG_REAL_BUILD="$PKG_BUILD/.$TARGET_NAME-$TARGET" ;;
"bootstrap") PKG_REAL_BUILD="$PKG_BUILD/.$HOST_NAME-$TARGET" ;; "bootstrap") PKG_REAL_BUILD="$PKG_BUILD/.$HOST_NAME-$TARGET" ;;
esac esac
mkdir -p $PKG_REAL_BUILD mkdir -p "$PKG_REAL_BUILD"
cd $PKG_REAL_BUILD cd "$PKG_REAL_BUILD"
MESON_CONF="$PKG_REAL_BUILD/meson.conf" MESON_CONF="$PKG_REAL_BUILD/meson.conf"
fi fi
@ -494,7 +481,7 @@ if [ "$(type -t post_makeinstall_$TARGET)" = "function" ]; then
fi fi
if [ "$TARGET" = "target" -o "$TARGET" = "init" ]; then if [ "$TARGET" = "target" -o "$TARGET" = "init" ]; then
if [ -d $INSTALL ] ; then if [ -d $INSTALL ]; then
rm -rf $INSTALL/{usr/,}include rm -rf $INSTALL/{usr/,}include
rm -rf $INSTALL/{usr/,}lib/cmake rm -rf $INSTALL/{usr/,}lib/cmake
rm -rf $INSTALL/{usr/,}lib/pkgconfig rm -rf $INSTALL/{usr/,}lib/pkgconfig
@ -520,26 +507,26 @@ if [ "$TARGET" = "target" -o "$TARGET" = "init" ]; then
find $INSTALL -type d -exec rmdir -p {} \; 2>/dev/null || : find $INSTALL -type d -exec rmdir -p {} \; 2>/dev/null || :
if [ ! "${BUILD_WITH_DEBUG}" = "yes" ]; then if [ ! "${BUILD_WITH_DEBUG}" = "yes" ]; then
$STRIP `find $INSTALL \ $STRIP $(find $INSTALL \
-type f -name "*.so*" \ -type f -name "*.so*" \
! -name "ld-*.so" \ ! -name "ld-*.so" \
! -name "libc-*.so" \ ! -name "libc-*.so" \
! -name "libpthread-*.so" \ ! -name "libpthread-*.so" \
! -name "libthread_db-*so" \ ! -name "libthread_db-*so" \
2>/dev/null` 2>/dev/null || : 2>/dev/null) 2>/dev/null || :
if [ "$TARGET" = "init" ]; then if [ "$TARGET" = "init" ]; then
$STRIP `find $INSTALL -type f -name "*.so*" 2>/dev/null` 2>/dev/null || : $STRIP $(find $INSTALL -type f -name "*.so*" 2>/dev/null) 2>/dev/null || :
fi fi
$STRIP `find $INSTALL/bin $INSTALL/usr/bin $INSTALL/sbin $INSTALL/usr/sbin \ $STRIP $(find $INSTALL/bin $INSTALL/usr/bin $INSTALL/sbin $INSTALL/usr/sbin \
-type f -executable 2>/dev/null` 2>/dev/null || : -type f -executable 2>/dev/null) 2>/dev/null || :
fi fi
fi fi
fi fi
cd $ROOT cd $ROOT
for i in `find $SYSROOT_PREFIX/usr/lib/ -name "*.la" 2>/dev/null`; do \ for i in $(find $SYSROOT_PREFIX/usr/lib/ -name "*.la" 2>/dev/null); do
$SED "s:\(['= ]\)/usr:\\1$SYSROOT_PREFIX/usr:g" $i; \ sed -e "s:\(['= ]\)/usr:\\1$SYSROOT_PREFIX/usr:g" -i $i
done done
PKG_DEEPHASH=$(calculate_stamp) PKG_DEEPHASH=$(calculate_stamp)