Blob Blame History Raw
#
# set +o errexit -o noglob is assumed.
#

#
# exp_pkg_env_defaults() - set package variable defaults for single named package
# @_build_steps_default:	list of default build steps
# @_pkg_name:			single package name
# @_workdir:			pathname to build-specific temporary directory
#
# Return:		zero (0) on success, non-zero (>0) on failure
#
exp_pkg_env_defaults() {
	local _build_steps_default="${1}" _pkg_name="${2}" _workdir="${3}";
	: ${PKG_NAME:="${_pkg_name}"};
	: ${MIDIPIX_BUILD_PWD:="$(pwd)"};
	: ${PKG_BASE_DIR:="${_workdir}/${_pkg_name}-${PKG_BUILD_TYPE}-${PKG_TARGET}"};
	: ${PKG_FNAME:="${PKG_URL##*/}"};
	: ${PKG_BUILD_STEPS:="$(rtl_lfilter "${_build_steps_default}" "${PKG_BUILD_STEPS_DISABLE}")"};
	if [ -z "${PKG_SUBDIR}" ]; then
		if [ -n "${PKG_URLS_GIT}" ]; then
			PKG_SUBDIR="${PKG_URLS_GIT%%=*}";
		else case "${PKG_FNAME}" in
		*.t*)	PKG_SUBDIR="${PKG_FNAME%%.t*}"; ;;
		*)	PKG_SUBDIR="${_pkg_name}"; ;;
		esac; fi;
	fi;
	if [ -z "${PKG_BUILD_DIR}" ]; then
		case "${PKG_IN_TREE:-0}" in
		0) PKG_BUILD_DIR="obj"; ;;
		1) PKG_BUILD_DIR="${PKG_SUBDIR}"; ;;
		esac;
	fi;
	PKG_BUILD_DIR="${PKG_BASE_DIR}/${PKG_BUILD_DIR}";
	PKG_CONFIGURE="${PKG_BASE_DIR}/${PKG_CONFIGURE:-${PKG_SUBDIR}/configure}";
	PKG_DESTDIR="${PKG_BASE_DIR}/${PKG_DESTDIR:-destdir}";
};

#
# exp_pkg_env_set() - set package variables for single named package
# @_build_vars_default:	list of default build variables
# @_group_name:		build group name
# @_pkg_name:		single package name
#
# Sets package variables from either defaults, defaults specific to build type,
# build group, package to inherit from if any, or package for a single named
# package, exports variables optionally named in ${PKG_ENV_VARS_EXTRA}, and
# clears the package variable namespace.
#
# Return:		zero (0) on success, non-zero (>0) on failure
#
exp_pkg_env_set() {
	local _build_vars_default="${1}" _group_name="${2}" _pkg_name="${3}" _var_prefixes="" _vars_set="" _vname="";
	rtl_set_vars _vars_set BUILD_TYPE "DEFAULT ${_group_name} PKG_${_pkg_name}";
	rtl_set_vars _vars_set INHERIT_FROM "PKG_${_pkg_name}";
	_var_prefixes="$(rtl_toupper "DEFAULT DEFAULT_${PKG_BUILD_TYPE} ${_group_name}")";
	for _vname in $(rtl_lfilter "${_build_vars_default}" BUILD_TYPE); do
		if [ -n "${PKG_INHERIT_FROM}" ]; then
			rtl_set_vars _vars_set "${_vname}"	\
				"$(rtl_lconcat "${_var_prefixes}" "$(rtl_toupper "PKG_${PKG_INHERIT_FROM} PKG_${_pkg_name}")")"
		else
			rtl_set_vars _vars_set "${_vname}"	\
				"$(rtl_lconcat "${_var_prefixes}" "$(rtl_toupper "PKG_${_pkg_name}")")";
		fi;
	done;
	rtl_push_IFS :; for _vname in ${PKG_ENV_VARS_EXTRA}; do
		export "${_vname}";
	done; rtl_pop_IFS;
	rtl_unset_vars $(rtl_lfilter			\
		"$(set | awk -F= '/^PKG_/{print $1}' | sort)"	\
		"${_vars_set}");
};

#
# ex_pkg_env() - set package variables for single named package
# @_build_steps_default:	list of default build steps
# @_build_vars_default:		list of default build variables
# @_group_name:			build group name
# @_pkg_name:			single package name
# @_restart_at:			optional comma-separated list of build steps at which to rebuild or ALL
# @_workdir:			pathname to build-specific temporary directory
#
# Return:		zero (0) on success, non-zero (>0) on failure
#
ex_pkg_env() {
	local	_build_steps_default="${1}" _build_vars_default="${2}" _group_name="${3}"	\
		_pkg_name="${4}" _restart_at="${5}" _workdir="${6}" _vname="";
	rtl_fileop source_opt "vars/${_pkg_name}.vars";
	if ! exp_pkg_env_set "${_build_vars_default}" "${_group_name}" "${_pkg_name}"\
	|| ! exp_pkg_env_defaults "${_build_steps_default}" "${_pkg_name}" "${_workdir}"; then
		return "${?}";
	fi;
};

#
# ex_pkg_state_set() - update build step status for single named package
# @_workdir:		pathname to temporary build directory
# @_pkg_name:		single package name
# @${@}:		list of build steps
#
# Return:		zero (0) on success, non-zero (>0) on failure
#
ex_pkg_state_set() {
	rtl_state_set "${_workdir}" "${@}";
};

#
# ex_pkg_state_test() - test build step status of single named package
# @_workdir:		pathname to temporary build directory
# @_pkg_name:		single package name
# @_build_step:		build step to test status of
# @_restart_at:		optional comma-separated list of build steps at which to rebuild or ALL
#
# Return:		zero (0) on success, non-zero (>0) on failure
#
ex_pkg_state_test() {
	rtl_state_test "${_workdir}" "${@}";
};

# vim:filetype=sh