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