config/functions: add helpers for sourcing packages

This commit is contained in:
MilhouseVH 2018-12-18 03:43:28 +00:00
parent 442b489c99
commit 8996ca654f

View File

@ -661,8 +661,7 @@ do_autoreconf() {
get_pkg_variable() {
if [ -n "$1" -a -n "$2" ] ; then
if [ "$1" != "$PKG_NAME" ]; then
cd $ROOT
. config/options $1 &>/dev/null
source_package "${1}"
fi
echo "${!2}"
fi
@ -803,6 +802,108 @@ pkg_call_optional() {
pkg_call ${1} || return 0
}
unset_functions() {
local target
unset -f configure_package
unset -f pre_unpack unpack post_unpack
unset -f pre_patch post_patch
for target in target host init bootstrap; do
unset -f pre_build_${target}
unset -f pre_configure_${target} configure_${target} post_configure_${target}
unset -f pre_make_${target} make_${target} post_make_${target}
unset -f pre_makeinstall_${target} makeinstall_${target} post_makeinstall_${target}
done
unset -f pre_install post_install
unset -f addon
}
# p1: name of package to be sourced
source_package() {
local opwd="${PWD}"
# Don't use BUILD_WITH_DEBUG in "global" package.mk - instead, call the function
# build_with_debug() directly as the function depends on various package.mk
# variables that will be in the process of being configured. Once package.mk is
# fully sourced we can set this variable and use it in situations where we know the
# package has already been sourced.
unset BUILD_WITH_DEBUG
reset_pkg_vars
unset_functions
if [ -n "${1}" ]; then
PKG_DIR="$(get_pkg_directory ${1})"
[ -n "$PKG_DIR" -a -r $PKG_DIR/package.mk ] || die "FAILURE: unable to source package - ${1}/package.mk does not exist"
cd "${ROOT}"
. ${PKG_DIR}/package.mk || die "FAILURE: an error occurred while sourcing ${PKG_DIR}/package.mk"
cd "${opwd}"
[ -z "$PKG_SHORTDESC" ] && PKG_SHORTDESC="$PKG_NAME (autogenerated)"
[ -z "$PKG_LONGDESC" ] && PKG_LONGDESC="$PKG_NAME (autogenerated)"
if [ "$PKG_IS_ADDON" = "yes" -o "$PKG_IS_ADDON" = "embedded" ] ; then
[ -z $PKG_SECTION ] && PKG_ADDON_ID="$PKG_NAME" || PKG_ADDON_ID="${PKG_SECTION//\//.}.$PKG_NAME"
[ "$PKG_ADDON_IS_STANDALONE" != "yes" ] && PKG_NEED_UNPACK="${PKG_NEED_UNPACK} $(get_pkg_directory $MEDIACENTER)"
fi
# Automatically set PKG_SOURCE_NAME unless it is already defined.
# PKG_SOURCE_NAME will be automatically set to a name based on
# the $PKG_NAME-$PKG_VERSION convention.
#
# Any $PKG_URL that references more than a single url will abort
# the build as these are no longer supported - use mkpkg instead.
if [ -n "$PKG_URL" -a -z "$PKG_SOURCE_NAME" ]; then
if [[ $PKG_URL =~ .*\ .* ]]; then
echo "Error - packages with multiple urls are no longer supported, use mkpkg."
echo "$PKG_URL"
die
fi
if [[ ${PKG_URL} =~ .git$ || ${PKG_URL} =~ ^git:// ]]; then
PKG_SOURCE_NAME=${PKG_NAME}-${PKG_VERSION}
elif [[ ${PKG_URL} =~ ^file:// ]]; then
PKG_SOURCE_NAME=${PKG_URL#file://}
# if no specific PKG_TAR_COPY_OPTS then default to excluding .git and .svn as they can be huge
[ -z "${PKG_TAR_COPY_OPTS+x}" ] && PKG_TAR_COPY_OPTS="--exclude=.git --exclude=.svn"
else
PKG_SOURCE_NAME="${PKG_URL##*/}"
case $PKG_SOURCE_NAME in
${PKG_NAME}-${PKG_VERSION}.*)
PKG_SOURCE_NAME=$PKG_SOURCE_NAME
;;
*.tar | *.tbz | *.tgz | *.txz | *.7z | *.zip)
PKG_SOURCE_NAME=${PKG_NAME}-${PKG_VERSION}.${PKG_SOURCE_NAME##*\.}
;;
*.tar.bz2 | *.tar.gz | *.tar.xz)
PKG_SOURCE_NAME=${PKG_NAME}-${PKG_VERSION}.tar.${PKG_SOURCE_NAME##*\.}
;;
*.diff | *.patch | *.diff.bz2 | *.patch.bz2 | patch-*.bz2 | *.diff.gz | *.patch.gz | patch-*.gz)
PKG_SOURCE_NAME=$PKG_SOURCE_NAME
;;
*)
PKG_SOURCE_NAME=${PKG_NAME}-${PKG_VERSION}.${PKG_SOURCE_NAME##*\.}
;;
esac
fi
fi
PKG_BUILD="$BUILD/${PKG_NAME}-${PKG_VERSION}"
fi
build_with_debug && BUILD_WITH_DEBUG="yes" || BUILD_WITH_DEBUG="no"
# Late variable binding - allow the package to now evaluate any variables
# that we may have initialised after sourcing the package, typically
# PKG_BUILD etc.
[ -n "${PKG_NAME}" ] && pkg_call_optional configure_package || true
}
### KERNEL HELPERS ###
kernel_path() {