Skip to content

Commit

Permalink
Merge pull request #3171 from MilhouseVH/le90_buildsystem_source_pack…
Browse files Browse the repository at this point in the history
…ages-with-drop

buildsystem: centralise package sourcing
  • Loading branch information
CvH committed Dec 29, 2018
2 parents f091d71 + 710d431 commit a98586b
Show file tree
Hide file tree
Showing 47 changed files with 829 additions and 845 deletions.
141 changes: 121 additions & 20 deletions config/functions
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,6 @@ die() {
exit "${2:-1}"
}

# p1: name of potential function to execute if it exists
# return 0 if function executed, 1 if not, die if error
pkg_call() {
[ -n "${PKG_NAME}" ] || die "$(print_color CLR_ERROR "FAILURE: Cannot call ${1} package function when package is not known!")"

if [ "$(type -t ${1})" = "function" ]; then
${1} || die "$(print_color CLR_ERROR "FAILURE: ${1} for package ${PKG_NAME} did not succeed!")"
else
return 1
fi
}

# p1: name of potential function to execute if it exists
# return 0 if function executed or not, or die if error
pkg_call_optional() {
pkg_call ${1} || return 0
}

# return 0 if $2 in space-separated list $1, otherwise return 1
listcontains() {
if [ -n "$1" -a -n "$2" ]; then
Expand Down Expand Up @@ -687,8 +669,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
Expand Down Expand Up @@ -811,6 +792,126 @@ find_dir_path() {
find_path -d "$1" "$2"
}

# p1: name of potential function to execute if it exists
# return 0 if function executed, 1 if not, die if error
pkg_call() {
[ -n "${PKG_NAME}" ] || die "$(print_color CLR_ERROR "FAILURE: Cannot call ${1} package function when package is not known!")"

if [ "$(type -t ${1})" = "function" ]; then
${1} || die "$(print_color CLR_ERROR "FAILURE: ${1} for package ${PKG_NAME} did not succeed!")"
else
return 1
fi
}

# p1: name of potential function to execute if it exists
# return 0 if function executed or not, or die if error
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}"

PKG_SHORTDESC="${PKG_SHORTDESC:-${PKG_NAME} (autogenerated)}"
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() {
Expand Down
8 changes: 8 additions & 0 deletions config/options
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,11 @@ check_config

. config/graphic
. config/path $1

## package processing

# If the package caches are unset, then populate them
init_package_cache

# set package metadata
source_package "${1}"
103 changes: 17 additions & 86 deletions config/path
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# SPDX-License-Identifier: GPL-2.0-or-later
# Copyright (C) 2018-present Team LibreELEC (https://libreelec.tv)

set -e

# setup initial directorys (relative to root)
Expand Down Expand Up @@ -59,79 +62,6 @@ INSTALL_INIT=$BUILD/image/initramfs/root-image
MAKE="$TOOLCHAIN/bin/make"
MAKEINSTALL="$TOOLCHAIN/bin/make -j1 DESTDIR=$SYSROOT_PREFIX install"

unset LD_LIBRARY_PATH

# Don't use BUILD_WITH_DEBUG in "gloabl" 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

# If the package caches are unset, then populate them
init_package_cache

# set package metadata
reset_pkg_vars "$1"

[ -n "$1" ] && PKG_DIR="$(get_pkg_directory $1)"

if [ -n "$PKG_DIR" -a -r $PKG_DIR/package.mk ]; then
unset -f configure_package
. $PKG_DIR/package.mk
[ -z "$PKG_SHORTDESC" ] && PKG_SHORTDESC="$PKG_NAME (autogenerated)"
[ -z "$PKG_LONGDESC" ] && PKG_LONGDESC="$PKG_NAME (autogenerated)"
fi

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"
exit 1
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}"

build_with_debug && BUILD_WITH_DEBUG="yes" || BUILD_WITH_DEBUG="no"

XORG_PATH_DRI=/usr/lib/dri
XORG_PATH_XKB=/usr/share/X11/xkb
XORG_PATH_XKB_OUTPUT=/var/lib/xkb
Expand All @@ -151,22 +81,23 @@ fi

VERSION_SUFFIX=$TARGET_ARCH

SILENT_OUT=3
VERBOSE_OUT=4
if [ "$VERBOSE" = yes ]; then
exec 3>&1
exec 4>&2
else
exec 3>&2
exec 4>/dev/null
fi
BUILD_INDENT_SIZE=4
# redirect formatted output
if [ -z "${SILENT_OUT}" -a -z "${VERBOSE_OUT}" ]; then
export BUILD_INDENT_SIZE=4
export SILENT_OUT=3
export VERBOSE_OUT=4

# If sourcing a package, configure any package variables dependent on variables we have set
if [ -n "$PKG_DIR" -a -r $PKG_DIR/package.mk ]; then
pkg_call_optional configure_package
if [ "$VERBOSE" = yes ]; then
exec 3>&1
exec 4>&2
else
exec 3>&2
exec 4>/dev/null
fi
fi

unset LD_LIBRARY_PATH

# multilib? nah
unset CONFIG_SITE

Expand Down
9 changes: 5 additions & 4 deletions packages/addons/addon-depends/chrome-depends/icu/package.mk
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,16 @@ PKG_ICU_OPTS="--disable-extras \
--disable-tests \
--disable-tools"


PKG_CONFIGURE_OPTS_HOST="--enable-static \
--disable-shared \
$PKG_ICU_OPTS"

PKG_CONFIGURE_OPTS_TARGET="--with-cross-build=$PKG_BUILD/.$HOST_NAME \
$PKG_ICU_OPTS"
configure_package() {
PKG_CONFIGURE_OPTS_TARGET="--with-cross-build=$PKG_BUILD/.$HOST_NAME \
$PKG_ICU_OPTS"

PKG_CONFIGURE_SCRIPT="source/configure"
PKG_CONFIGURE_SCRIPT="${PKG_BUILD}/source/configure"
}

post_makeinstall_target() {
rm -rf $INSTALL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ PKG_URL="http://ftp.de.debian.org/debian/pool/main/o/opencaster/opencaster_${PKG
PKG_DEPENDS_TARGET="toolchain"
PKG_LONGDESC="A free and open source MPEG2 transport stream data generator and packet manipulator."

PKG_MAKE_OPTS_TARGET="CC=$CC"
pre_configure_target() {
PKG_MAKE_OPTS_TARGET="CC=$CC"
}

pre_makeinstall_target() {
mkdir -p $PKG_BUILD/.install_pkg
Expand Down
6 changes: 4 additions & 2 deletions packages/addons/addon-depends/protobuf/package.mk
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ PKG_DEPENDS_HOST="toolchain zlib:host"
PKG_DEPENDS_TARGET="toolchain zlib protobuf:host"
PKG_LONGDESC="Protocol Buffers for Google's data interchange format."

PKG_CMAKE_SCRIPT="$PKG_BUILD/cmake/CMakeLists.txt"

PKG_CMAKE_OPTS_HOST="-DCMAKE_NO_SYSTEM_FROM_IMPORTED=1 \
-DBUILD_SHARED_LIBS=0 \
-Dprotobuf_BUILD_TESTS=0 \
Expand All @@ -21,6 +19,10 @@ PKG_CMAKE_OPTS_HOST="-DCMAKE_NO_SYSTEM_FROM_IMPORTED=1 \

PKG_CMAKE_OPTS_TARGET="$PKG_CMAKE_OPTS_HOST"

configure_package() {
PKG_CMAKE_SCRIPT="$PKG_BUILD/cmake/CMakeLists.txt"
}

post_makeinstall_target() {
rm -rf $INSTALL/usr/bin

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ PKG_URL="$SOURCEFORGE_SRC/keytouch/getscancodes-${PKG_VERSION}.tar.gz"
PKG_DEPENDS_TARGET="toolchain"
PKG_LONGDESC="Shows the scancode of the pressed or released key."

PKG_MAKE_OPTS_TARGET="CC=$CC"
pre_configure_target() {
PKG_MAKE_OPTS_TARGET="CC=$CC"
}

makeinstall_target() {
: # nop
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ PKG_URL="https://github.com/groeck/lm-sensors/archive/${PKG_VERSION}.tar.gz"
PKG_DEPENDS_TARGET="toolchain"
PKG_LONGDESC="Provides user-space support for the hardware monitoring drivers."

PKG_MAKE_OPTS_TARGET="PREFIX=/usr CC=$CC AR=$AR"
PKG_MAKEINSTALL_OPTS_TARGET="PREFIX=/usr"

pre_make_target() {
PKG_MAKE_OPTS_TARGET="PREFIX=/usr CC=$CC AR=$AR"

export CFLAGS="$TARGET_CFLAGS"
export CPPFLAGS="$TARGET_CPPFLAGS"
}
Expand Down
4 changes: 3 additions & 1 deletion packages/addons/service/net-snmp/package.mk
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ PKG_IS_ADDON="yes"
PKG_ADDON_NAME="Net-SNMP"
PKG_ADDON_TYPE="xbmc.service"

PKG_CONFIGURE_OPTS_TARGET="--with-defaults \
configure_package() {
PKG_CONFIGURE_OPTS_TARGET="--with-defaults \
--disable-applications \
--disable-manuals \
--disable-debugging \
Expand All @@ -40,6 +41,7 @@ PKG_CONFIGURE_OPTS_TARGET="--with-defaults \
--libdir=/storage/.kodi/addons/${PKG_ADDON_ID}/lib \
--disable-embedded-perl \
--with-sysroot=$SYSROOT_PREFIX"
}

make_target() {
make
Expand Down
Loading

0 comments on commit a98586b

Please sign in to comment.