Lakka-LibreELEC/scripts/build
2017-10-14 14:34:56 -07:00

436 lines
16 KiB
Bash
Executable File

#!/bin/bash
################################################################################
# This file is part of OpenELEC - http://www.openelec.tv
# Copyright (C) 2009-2016 Stephan Raue (stephan@openelec.tv)
#
# OpenELEC is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# OpenELEC is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with OpenELEC. If not, see <http://www.gnu.org/licenses/>.
################################################################################
. config/options $1
if [ -z "$1" ]; then
echo "usage: $0 package_name[:<host|target|init|bootstrap>]"
exit 1
fi
if [ ! -f $PKG_DIR/package.mk ]; then
printf "$(print_color CLR_ERROR "$1: no package.mk file found")\n"
exit 1
fi
# set defaults
PKG_CONFIGURE_SCRIPT=""
PKG_MAKE_OPTS=""
PKG_MAKEINSTALL_OPTS=""
if [ "${1//:/}" != "${1}" ]; then
PACKAGE_NAME="${1%:*}"
TARGET="${1#*:}"
else
PACKAGE_NAME=$1
TARGET=
fi
[ -z "$TARGET" ] && TARGET="target"
if [ -n "$PKG_ARCH" -a ! "$PKG_ARCH" = "any" ]; then
echo "$PKG_ARCH" | grep -q "$TARGET_ARCH" || exit 0
echo "$PKG_ARCH" | grep -q "\-$TARGET_ARCH" && exit 0
fi
unset INSTALL
mkdir -p $STAMPS/$PACKAGE_NAME
STAMP=$STAMPS/$PACKAGE_NAME/build_$TARGET
$SCRIPTS/unpack $PACKAGE_NAME
STAMP_DEPENDS="$PKG_DIR $PKG_NEED_UNPACK $PROJECT_DIR/$PROJECT/patches/$PKG_NAME"
[ -n "$DEVICE" ] && STAMP_DEPENDS="$STAMP_DEPENDS $PROJECT_DIR/$PROJECT/devices/$DEVICE/patches/$PKG_NAME"
if [ -f $STAMP ] ; then
. $STAMP
PKG_DEEPMD5=$(find $STAMP_DEPENDS -exec md5sum {} \; 2>/dev/null | sort | md5sum | cut -d" " -f1)
if [ ! "$PKG_DEEPMD5" = "$STAMP_PKG_DEEPMD5" ] ; then
rm -f $STAMP
fi
fi
if [ ! -f $STAMP ]; then
rm -f $STAMP
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 -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_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 \
--build=$HOST_NAME \
--prefix=/usr \
--bindir=/usr/bin \
--sbindir=/usr/sbin \
--sysconfdir=/etc \
--libdir=/usr/lib \
--libexecdir=/usr/lib \
--localstatedir=/var \
--disable-static \
--enable-shared"
if [ "$DEBUG" = "yes" ]; then
CMAKE_BUILD_TYPE="Debug"
else
CMAKE_BUILD_TYPE="MinSizeRel"
fi
if [ "$PKG_USE_NINJA" = "no" ]; then
CMAKE_GENERATOR=""
else
CMAKE_GENERATOR="-GNinja \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON"
fi
TARGET_CMAKE_OPTS="$CMAKE_GENERATOR \
-DCMAKE_TOOLCHAIN_FILE=$CMAKE_CONF \
-DCMAKE_INSTALL_PREFIX=/usr \
-DCMAKE_BUILD_TYPE=$CMAKE_BUILD_TYPE"
# configure HOST build defaults
HOST_CONFIGURE_OPTS="--host=$HOST_NAME \
--build=$HOST_NAME \
--prefix=$TOOLCHAIN \
--bindir=$TOOLCHAIN/bin \
--sbindir=$TOOLCHAIN/sbin \
--sysconfdir=$TOOLCHAIN/etc \
--libexecdir=$TOOLCHAIN/lib \
--localstatedir=$TOOLCHAIN/var \
--disable-static \
--enable-shared"
HOST_CMAKE_OPTS="$CMAKE_GENERATOR \
-DCMAKE_TOOLCHAIN_FILE=$CMAKE_CONF \
-DCMAKE_INSTALL_PREFIX=$TOOLCHAIN"
# configure INIT build defaults
INIT_CONFIGURE_OPTS="$TARGET_CONFIGURE_OPTS"
INIT_CMAKE_OPTS="$TARGET_CMAKE_OPTS"
# configure BOOTSTRAP build defaults
BOOTSTRAP_CONFIGURE_OPTS="$HOST_CONFIGURE_OPTS"
BOOTSTRAP_CMAKE_OPTS="$HOST_CMAKE_OPTS"
# include buildfile
. $PKG_DIR/package.mk
if [ "$PKG_IS_KERNEL_PKG" = "yes" ]; then
if [ "$TARGET_KERNEL_ARCH" = "arm64" -a "$TARGET_ARCH" = "arm" ]; then
TARGET_PREFIX=$TOOLCHAIN/lib/gcc-linaro-aarch64-elf/bin/aarch64-elf-
fi
fi
if [ "$TARGET" = "target" ]; then
for p in $PKG_DEPENDS_TARGET; do
$SCRIPTS/build $p
done
elif [ "$TARGET" = "host" ]; then
for p in $PKG_DEPENDS_HOST; do
$SCRIPTS/build $p
done
elif [ "$TARGET" = "init" ]; then
for p in $PKG_DEPENDS_INIT; do
$SCRIPTS/build $p
done
elif [ "$TARGET" = "bootstrap" ]; then
for p in $PKG_DEPENDS_BOOTSTRAP; do
$SCRIPTS/build $p
done
fi
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))
if [ "$PKG_AUTORECONF" = yes ]; then
$SCRIPTS/autoreconf $PACKAGE_NAME
fi
# virtual packages dont must be build, they only contains dependencies, so dont go further here
if [ ! "$PKG_SECTION" = "virtual" ]; then
# configure other variables
if [ "$TARGET" = "target" ]; then
INSTALL=$PKG_BUILD/.install_pkg
elif [ "$TARGET" = "init" ]; then
INSTALL=$PKG_BUILD/.install_init
fi
# clean up
if [ ! -z "$INSTALL" ] ; then
if [ -d "$INSTALL" ] ; then
rm -rf $INSTALL
fi
fi
# setup configure script
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
# include build template and build
if [ "$(type -t pre_build_$TARGET)" = "function" ]; then
pre_build_$TARGET
fi
# ensure $PKG_BUILD is there. (installer? PKG_URL="")
if [ ! -d $PKG_BUILD ] ; then
mkdir -p $PKG_BUILD
fi
cd $PKG_BUILD
if [ "$TARGET" = "target" ]; then
if [ -f "$PKG_CONFIGURE_SCRIPT" -o -f "$PKG_CMAKE_SCRIPT" ]; then
mkdir -p .$TARGET_NAME
cd .$TARGET_NAME
fi
elif [ "$TARGET" = "host" ]; then
if [ -f "$PKG_CONFIGURE_SCRIPT" -o -f "$PKG_CMAKE_SCRIPT" ]; then
mkdir -p .$HOST_NAME
cd .$HOST_NAME
fi
elif [ "$TARGET" = "init" ]; then
if [ -f "$PKG_CONFIGURE_SCRIPT" -o -f "$PKG_CMAKE_SCRIPT" ]; then
mkdir -p .$TARGET_NAME-$TARGET
cd .$TARGET_NAME-$TARGET
fi
elif [ "$TARGET" = "bootstrap" ]; then
if [ -f "$PKG_CONFIGURE_SCRIPT" -o -f "$PKG_CMAKE_SCRIPT" ]; then
mkdir -p .$HOST_NAME-$TARGET
cd .$HOST_NAME-$TARGET
fi
fi
# configure
if [ "$(type -t pre_configure_$TARGET)" = "function" ]; then
pre_configure_$TARGET
fi
if [ "$(type -t configure_$TARGET)" = "function" ]; then
configure_$TARGET
elif [ -f "$PKG_CMAKE_SCRIPT" -a ! "$PKG_USE_CMAKE" = "no" ]; then
if [ "$TARGET" = "target" ]; then
echo "Executing (target): cmake $TARGET_CMAKE_OPTS $PKG_CMAKE_OPTS_TARGET $(dirname $PKG_CMAKE_SCRIPT)" | tr -s " "
cmake $TARGET_CMAKE_OPTS $PKG_CMAKE_OPTS_TARGET $(dirname $PKG_CMAKE_SCRIPT)
elif [ "$TARGET" = "host" ]; then
echo "Executing (host): cmake $HOST_CMAKE_OPTS $PKG_CMAKE_OPTS_HOST $(dirname $PKG_CMAKE_SCRIPT)" | tr -s " "
cmake $HOST_CMAKE_OPTS $PKG_CMAKE_OPTS_HOST $(dirname $PKG_CMAKE_SCRIPT)
elif [ "$TARGET" = "init" ]; then
echo "Executing (init): cmake $INIT_CMAKE_OPTS $PKG_CMAKE_OPTS_INIT $(dirname $PKG_CMAKE_SCRIPT)" | tr -s " "
cmake $INIT_CMAKE_OPTS $PKG_CMAKE_OPTS_INIT $(dirname $PKG_CMAKE_SCRIPT)
elif [ "$TARGET" = "bootstrap" ]; then
echo "Executing (bootstrap): cmake $BOOTSTRAP_CMAKE_OPTS $PKG_CMAKE_OPTS_BOOTSTRAP $(dirname $PKG_CMAKE_SCRIPT)" | tr -s " "
cmake $BOOTSTRAP_CMAKE_OPTS $PKG_CMAKE_OPTS_BOOTSTRAP $(dirname $PKG_CMAKE_SCRIPT)
fi
elif [ -f "$PKG_CONFIGURE_SCRIPT" ]; then
if [ "$TARGET" = "target" ]; then
echo "Executing (target): $PKG_CONFIGURE_SCRIPT $TARGET_CONFIGURE_OPTS $PKG_CONFIGURE_OPTS_TARGET" | tr -s " "
$PKG_CONFIGURE_SCRIPT $TARGET_CONFIGURE_OPTS $PKG_CONFIGURE_OPTS_TARGET
elif [ "$TARGET" = "host" ]; then
echo "Executing (host): $PKG_CONFIGURE_SCRIPT $HOST_CONFIGURE_OPTS $PKG_CONFIGURE_OPTS_HOST" | tr -s " "
$PKG_CONFIGURE_SCRIPT $HOST_CONFIGURE_OPTS $PKG_CONFIGURE_OPTS_HOST
elif [ "$TARGET" = "init" ]; then
echo "Executing (init): $PKG_CONFIGURE_SCRIPT $INIT_CONFIGURE_OPTS $PKG_CONFIGURE_OPTS_INIT" | tr -s " "
$PKG_CONFIGURE_SCRIPT $INIT_CONFIGURE_OPTS $PKG_CONFIGURE_OPTS_INIT
elif [ "$TARGET" = "bootstrap" ]; then
echo "Executing (bootstrap): $PKG_CONFIGURE_SCRIPT $BOOTSTRAP_CONFIGURE_OPTS $PKG_CONFIGURE_OPTS_BOOTSTRAP" | tr -s " "
$PKG_CONFIGURE_SCRIPT $BOOTSTRAP_CONFIGURE_OPTS $PKG_CONFIGURE_OPTS_BOOTSTRAP
fi
fi
if [ "$(type -t post_configure_$TARGET)" = "function" ]; then
post_configure_$TARGET
fi
# make
if [ "$(type -t pre_make_$TARGET)" = "function" ]; then
pre_make_$TARGET
fi
if [ "$(type -t make_$TARGET)" = "function" ]; then
make_$TARGET
elif [ -f "$PKG_CMAKE_SCRIPT" -a ! "$PKG_USE_CMAKE" = "no" -a ! "$PKG_USE_NINJA" = "no" ]; then
if [ "$TARGET" = "target" ]; then
echo "Executing (target): ninja $PKG_MAKE_OPTS_TARGET" | tr -s " "
ninja $PKG_MAKE_OPTS_TARGET
elif [ "$TARGET" = "host" ]; then
echo "Executing (host): ninja $PKG_MAKE_OPTS_HOST" | tr -s " "
ninja $PKG_MAKE_OPTS_HOST
elif [ "$TARGET" = "init" ]; then
echo "Executing (init): ninja $PKG_MAKE_OPTS_INIT" | tr -s " "
ninja $PKG_MAKE_OPTS_INIT
elif [ "$TARGET" = "bootstrap" ]; then
echo "Executing (bootstrap): ninja $PKG_MAKE_OPTS_BOOTSTRAP" | tr -s " "
ninja $PKG_MAKE_OPTS_BOOTSTRAP
fi
else
if [ "$TARGET" = "target" ]; then
echo "Executing (target): make $PKG_MAKE_OPTS_TARGET" | tr -s " "
make $PKG_MAKE_OPTS_TARGET
elif [ "$TARGET" = "host" ]; then
echo "Executing (host): make $PKG_MAKE_OPTS_HOST" | tr -s " "
make $PKG_MAKE_OPTS_HOST
elif [ "$TARGET" = "init" ]; then
echo "Executing (init): make $PKG_MAKE_OPTS_INIT" | tr -s " "
make $PKG_MAKE_OPTS_INIT
elif [ "$TARGET" = "bootstrap" ]; then
echo "Executing (bootstrap): make $PKG_MAKE_OPTS_BOOTSTRAP" | tr -s " "
make $PKG_MAKE_OPTS_BOOTSTRAP
fi
fi
if [ "$(type -t post_make_$TARGET)" = "function" ]; then
post_make_$TARGET
fi
# make install
if [ "$(type -t pre_makeinstall_$TARGET)" = "function" ]; then
pre_makeinstall_$TARGET
fi
if [ "$(type -t makeinstall_$TARGET)" = "function" ]; then
makeinstall_$TARGET
elif [ -f "$PKG_CMAKE_SCRIPT" -a ! "$PKG_USE_CMAKE" = "no" -a ! "$PKG_USE_NINJA" = "no" ]; then
if [ "$TARGET" = "target" ]; then
DESTDIR=$SYSROOT_PREFIX ninja install $PKG_MAKEINSTALL_OPTS_TARGET
DESTDIR=$INSTALL ninja install $PKG_MAKEINSTALL_OPTS_TARGET
elif [ "$TARGET" = "host" ]; then
ninja install $PKG_MAKEINSTALL_OPTS_HOST
elif [ "$TARGET" = "init" ]; then
DESTDIR=$INSTALL ninja install $PKG_MAKEINSTALL_OPTS_INIT
elif [ "$TARGET" = "bootstrap" ]; then
ninja install $PKG_MAKEINSTALL_OPTS_BOOTSTRAP
fi
else
if [ "$TARGET" = "target" ]; then
$MAKEINSTALL $PKG_MAKEINSTALL_OPTS_TARGET
make install DESTDIR=$INSTALL $PKG_MAKEINSTALL_OPTS_TARGET
elif [ "$TARGET" = "host" ]; then
make install $PKG_MAKEINSTALL_OPTS_HOST
elif [ "$TARGET" = "init" ]; then
make install DESTDIR=$INSTALL $PKG_MAKEINSTALL_OPTS_INIT
elif [ "$TARGET" = "bootstrap" ]; then
make install $PKG_MAKEINSTALL_OPTS_BOOTSTRAP
fi
fi
if [ "$(type -t post_makeinstall_$TARGET)" = "function" ]; then
post_makeinstall_$TARGET
fi
if [ "$TARGET" = "target" -o "$TARGET" = "init" ]; then
if [ -d $INSTALL ] ; then
rm -rf $INSTALL/{usr/,}include
rm -rf $INSTALL/{usr/,}lib/cmake
rm -rf $INSTALL/{usr/,}lib/pkgconfig
rm -rf $INSTALL/{usr/,}man
rm -rf $INSTALL/{usr/,}share/aclocal
rm -rf $INSTALL/{usr/,}share/bash-completion
rm -rf $INSTALL/{usr/,}share/doc
rm -rf $INSTALL/{usr/,}share/gtk-doc
rm -rf $INSTALL/{usr/,}share/info
rm -rf $INSTALL/{usr/,}share/locale
rm -rf $INSTALL/{usr/,}share/man
rm -rf $INSTALL/{usr/,}share/pkgconfig
rm -rf $INSTALL/{usr/,}share/zsh
rm -rf $INSTALL/{usr/,}var
find $INSTALL \( -name "*.orig" \
-o -name "*.rej" \
-o -name "*.a" \
-o -name "*.la" \
-o -name "*.o" \
-o -name "*.in" \
-o -name ".git*" \) \
-exec rm -f {} \; 2>/dev/null || :
find $INSTALL -type d -exec rmdir -p {} \; 2>/dev/null || :
if [ ! "$DEBUG" = yes ]; then
$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 || :
if [ "$TARGET" = "init" ]; then
$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 || :
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
fi