Lucio Andrés Illanes Albornoz 8a27f9
#!/bin/sh
0f9be6
# Copyright (c) 2020, 2021 LucĂ­a Andrea Illanes Albornoz <lucia@luciaillanes.de>
Lucio Andrés Illanes Albornoz 8a27f9
#
Lucio Andrés Illanes Albornoz 8a27f9
Lucio Andrés Illanes Albornoz 60fba6
pkgtoolp_info() {
Lucio Andrés Illanes Albornoz 1dd6a3
	local	_pkg_name="${1}" _group_name="" _pkg_name_uc="$(rtl_toupper "${1}")" _fname="" _pkg_names=""\
Lucio Andrés Illanes Albornoz 1dd6a3
		_rc=0 EX_PKG_BUILD_GROUPS="" EX_PKG_DISABLED="" EX_PKG_FINISHED="" EX_PKG_NAMES=""; _status="";
Lucio Andrés Illanes Albornoz e493dc
Lucio Andrés Illanes Albornoz b6a9a1
	if ! ex_pkg_load_groups; then
Lucio Andrés Illanes Albornoz b6a9a1
		_rc=1; _status="Error: failed to load build groups.";
Lucio Andrés Illanes Albornoz b6a9a1
	elif ! _group_name="$(ex_pkg_find_package "${EX_PKG_BUILD_GROUPS}" "${_pkg_name}")"; then
Lucio Andrés Illanes Albornoz b6a9a1
		_rc=1; _status="Error: unknown package \`${_pkg_name}'.";
Lucio Andrés Illanes Albornoz 60fba6
	elif ! _pkg_names="$(ex_pkg_get_packages "${_group_name}")"; then
Lucio Andrés Illanes Albornoz b6a9a1
		_rc=1; _status="Error: failed to expand package list of build group \`${_group_name}'.";
Lucio Andrés Illanes Albornoz b6a9a1
	elif ! ex_pkg_env "${DEFAULT_BUILD_STEPS}" "${DEFAULT_BUILD_VARS}"\
Lucio Andrés Illanes Albornoz b6a9a1
			"${_group_name}" 1 "${_pkg_name}" "" "${BUILD_WORKDIR}"; then
Lucio Andrés Illanes Albornoz b6a9a1
		_rc=1; _status="Error: failed to set package environment for \`${_pkg_name}'.";
Lucio Andrés Illanes Albornoz 1dd6a3
	else	_pkg_version="$(rtl_get_var_unsafe -u "PKG_"${_pkg_name}"_VERSION")";
Lucio Andrés Illanes Albornoz b1d432
		rtl_log_env_vars "verbose" "package" $(rtl_get_vars_fast "^PKG_${_pkg_name_uc}");
Lucio Andrés Illanes Albornoz e493dc
		rtl_log_msg "info" "${MSG_pkgtool_build_group}" "${_group_name}";
Lucio Andrés Illanes Albornoz e1d469
		if [ -z "${PKG_DEPENDS:-}" ]; then
Lucio Andrés Illanes Albornoz e493dc
			rtl_log_msg "info" "${MSG_pkgtool_pkg_no_deps}" "${_pkg_name}";
Lucio Andrés Illanes Albornoz e493dc
		else	rtl_log_msg "info" "${MSG_pkgtool_pkg_direct_deps}" "${_pkg_name}" "${PKG_DEPENDS}";
Lucio Andrés Illanes Albornoz b6a9a1
			if ! ex_pkg_unfold_depends 1 1 "${_group_name}" "${_pkg_names}" "${_pkg_name}" 0; then
Lucio Andrés Illanes Albornoz e493dc
				rtl_log_msg "warning" "${MSG_pkgtool_pkg_deps_fail}" "${_pkg_name}";
Lucio Andrés Illanes Albornoz b6a9a1
			else	EX_PKG_NAMES="$(rtl_lfilter "${EX_PKG_NAMES}" "${_pkg_name}")";
Lucio Andrés Illanes Albornoz 60fba6
				if [ -n "${EX_PKG_NAMES}" ]; then
Lucio Andrés Illanes Albornoz e493dc
					rtl_log_msg "info" "${MSG_pkgtool_pkg_deps_full}"\
Lucio Andrés Illanes Albornoz b6a9a1
							"${_pkg_name}" "$(rtl_lsort "${EX_PKG_NAMES}")";
Lucio Andrés Illanes Albornoz 60fba6
				fi;
Lucio Andrés Illanes Albornoz 60fba6
				if [ -n "${EX_PKG_DISABLED}" ]; then
Lucio Andrés Illanes Albornoz e493dc
					rtl_log_msg "info" "${MSG_pkgtool_pkg_deps_full_disabled}"\
Lucio Andrés Illanes Albornoz b6a9a1
							"${_pkg_name}" "$(rtl_lsort "${EX_PKG_DISABLED}")";
Lucio Andrés Illanes Albornoz 60fba6
				fi;
Lucio Andrés Illanes Albornoz 60fba6
			fi;
Lucio Andrés Illanes Albornoz 60fba6
		fi;
Lucio Andrés Illanes Albornoz 1dd6a3
		set +o noglob;
Lucio Andrés Illanes Albornoz 1dd6a3
		for _fname in	\
Lucio Andrés Illanes Albornoz 1dd6a3
				"vars/${_pkg_name}.vars"								\
Lucio Andrés Illanes Albornoz 1dd6a3
				"patches/${_pkg_name}/"*.patch								\
Lucio Andrés Illanes Albornoz 1dd6a3
				"patches/${_pkg_name}${_pkg_version:+-${_pkg_version}}.local.patch"			\
Lucio Andrés Illanes Albornoz 1dd6a3
				"patches/${_pkg_name}${_pkg_version:+-${_pkg_version}}.local@${BUILD_HNAME}.patch"	\
Lucio Andrés Illanes Albornoz 1dd6a3
				"patches/${_pkg_name}${_pkg_version:+-${_pkg_version}}_pre.local.patch"			\
Lucio Andrés Illanes Albornoz 1dd6a3
				"patches/${_pkg_name}${_pkg_version:+-${_pkg_version}}_pre.local@${BUILD_HNAME}.patch"	\
Lucio Andrés Illanes Albornoz 1dd6a3
				"${BUILD_WORKDIR}/chainport/patches/${_pkg_name%%_*}/${_pkg_name%%_*}-${_pkg_version}.midipix.patch"; do
Lucio Andrés Illanes Albornoz 1dd6a3
			if [ -e "${_fname}" ]; then
Lucio Andrés Illanes Albornoz 1dd6a3
				sha256sum "${_fname}";
Lucio Andrés Illanes Albornoz 1dd6a3
			fi;
Lucio Andrés Illanes Albornoz 1dd6a3
		done;
Lucio Andrés Illanes Albornoz 1dd6a3
		set -o noglob;
Lucio Andrés Illanes Albornoz b6a9a1
	fi; return "${_rc}";
Lucio Andrés Illanes Albornoz 60fba6
};
Lucio Andrés Illanes Albornoz 60fba6
Lucio Andrés Illanes Albornoz b63b9b
pkgtoolp_mirror() {
Lucio Andrés Illanes Albornoz 22d139
	local	_mirror_dname="${1}" _mirror_dname_git="${2}" _group_name="" _pkg_name="" _pkg_parent="" _rc=0;
Lucio Andrés Illanes Albornoz 368962
Lucio Andrés Illanes Albornoz 22d139
	umask 022;
Lucio Andrés Illanes Albornoz 0e2bbe
	_mirror_dname="$(rtl_subst "${_mirror_dname}" "~" "${HOME}")";
Lucio Andrés Illanes Albornoz 0e2bbe
	_mirror_dname_git="$(rtl_subst "${_mirror_dname_git}" "~" "${HOME}")";
Lucio Andrés Illanes Albornoz b63b9b
	if ! ex_pkg_load_groups; then
Lucio Andrés Illanes Albornoz b63b9b
		_rc=1; _status="Error: failed to load build groups.";
Lucio Andrés Illanes Albornoz 22d139
	elif [ -n "${_mirror_dname}" ]\
Lucio Andrés Illanes Albornoz 22d139
	&& ! rtl_fileop mkdir "${_mirror_dname}"; then
Lucio Andrés Illanes Albornoz 368962
		_rc=1; _status="Error: failed to create \`${_mirror_dname}'.";
Lucio Andrés Illanes Albornoz 22d139
	elif [ -n "${_mirror_dname_git}" ]\
Lucio Andrés Illanes Albornoz 22d139
	&& ! rtl_fileop mkdir "${_mirror_dname_git}"; then
Lucio Andrés Illanes Albornoz 368962
		_rc=1; _status="Error: failed to create \`${_mirror_dname_git}'.";
Lucio Andrés Illanes Albornoz b63b9b
	else	for _group_name in ${EX_PKG_BUILD_GROUPS}; do
Lucio Andrés Illanes Albornoz b63b9b
			for _pkg_name in $(ex_pkg_get_packages "${_group_name}"); do
Lucio Andrés Illanes Albornoz b63b9b
				_pkg_parent="$(rtl_get_var_unsafe -u "PKG_${_pkg_name}_INHERIT_FROM")";
Lucio Andrés Illanes Albornoz 368962
				if ! pkgtoolp_mirror_fetch						\
Lucio Andrés Illanes Albornoz 368962
						"${_mirror_dname}" "${_mirror_dname_git}" "${_pkg_name}"\
Lucio Andrés Illanes Albornoz 368962
						"${_pkg_parent:-${_pkg_name}}"; then
Lucio Andrés Illanes Albornoz 368962
					_rc=1; _status="Warning: failed to mirror one or more packages.";
Lucio Andrés Illanes Albornoz 368962
				fi;
Lucio Andrés Illanes Albornoz b63b9b
			done;
Lucio Andrés Illanes Albornoz b63b9b
		done;
Lucio Andrés Illanes Albornoz b63b9b
	fi; return "${_rc}";
Lucio Andrés Illanes Albornoz b63b9b
};
Lucio Andrés Illanes Albornoz b63b9b
Lucio Andrés Illanes Albornoz b63b9b
pkgtoolp_mirror_fetch() {
Lucio Andrés Illanes Albornoz 368962
	local	_mirror_dname="${1}" _mirror_dname_git="${2}" _pkg_name="${3}" _pkg_name_real="${4}"\
Lucio Andrés Illanes Albornoz 2c5ce2
		_fname="" _pkg_disabled=0 _pkg_fname="" _pkg_sha256sum="" _pkg_url="" _pkg_urls_git=""\
Lucio Andrés Illanes Albornoz 2c5ce2
		_rc=0;
Lucio Andrés Illanes Albornoz 368962
Lucio Andrés Illanes Albornoz a50e83
	if _pkg_disabled="$(rtl_get_var_unsafe -u "PKG_${_pkg_name_real}_DISABLED")"\
Lucio Andrés Illanes Albornoz a50e83
	&& [ "${_pkg_disabled:-0}" -eq 1 ]; then
Lucio Andrés Illanes Albornoz e493dc
		rtl_log_msg "verbose" "${MSG_pkgtool_pkg_disabled}" "${_pkg_name}" "${_pkg_name_real}";
Lucio Andrés Illanes Albornoz 368962
	else	if _pkg_url="$(rtl_get_var_unsafe -u "PKG_${_pkg_name_real}_URL")"\
Lucio Andrés Illanes Albornoz a50e83
		&& _pkg_sha256sum="$(rtl_get_var_unsafe -u "PKG_${_pkg_name_real}_SHA256SUM")"; then
Lucio Andrés Illanes Albornoz 22d139
			if [ -z "${_mirror_dname}" ]; then
Lucio Andrés Illanes Albornoz e493dc
				_rc=0; rtl_log_msg "verbose" "${MSG_pkgtool_pkg_skip_archive_mirror}" "${_pkg_name}";
Lucio Andrés Illanes Albornoz 22d139
			elif [ "${_pkg_name}" != "${_pkg_name_real}" ]; then
Lucio Andrés Illanes Albornoz e493dc
				rtl_log_msg "info" "${MSG_pkgtool_pkg_archive_mirroring_parent}" "${_pkg_name}" "${_pkg_name_real}" "${_pkg_url}";
Lucio Andrés Illanes Albornoz 368962
				if ! rtl_fileop ln_symbolic "${_pkg_name_real}" "${_mirror_dname}/${_pkg_name}"; then
Lucio Andrés Illanes Albornoz e493dc
					_rc=1; rtl_log_msg "warning" "${MSG_pkgtool_pkg_link_fail}"\
Lucio Andrés Illanes Albornoz 368962
							"${_mirror_dname}/${_pkg_name}" "${_pkg_name}" "${_pkg_name_real}";
Lucio Andrés Illanes Albornoz 368962
				fi;
Lucio Andrés Illanes Albornoz a50e83
			else
Lucio Andrés Illanes Albornoz fe3fd1
				if ! _pkg_fname="$(rtl_get_var_unsafe -u "PKG_${_pkg_name_real}_FNAME")"; then
Lucio Andrés Illanes Albornoz fe3fd1
					_pkg_fname="${_pkg_url##*/}";
Lucio Andrés Illanes Albornoz fe3fd1
				fi;
Lucio Andrés Illanes Albornoz e493dc
				rtl_log_msg "info" "${MSG_pkgtool_pkg_archive_mirroring}" "${_pkg_name}" "${_pkg_url}";
Lucio Andrés Illanes Albornoz 368962
				if ! rtl_fileop mkdir "${_mirror_dname}/${_pkg_name}"\
Lucio Andrés Illanes Albornoz fe3fd1
				|| ! rtl_fetch_url_wget "${_pkg_url}" "${_pkg_sha256sum}" "${_mirror_dname}/${_pkg_name}" "${_pkg_fname}" "${_pkg_name_real}" ""; then
Lucio Andrés Illanes Albornoz e493dc
					_rc=1; rtl_log_msg "warning" "${MSG_pkgtool_pkg_mirror_fail}" "${_pkg_name}";
Lucio Andrés Illanes Albornoz 5daef9
				else
Lucio Andrés Illanes Albornoz 2c5ce2
					pkg_fetch_download_clean_dlcache "${_mirror_dname}" "${_pkg_name}" "${_pkg_fname}" "${_pkg_urls_git}";
Lucio Andrés Illanes Albornoz 368962
				fi;
Lucio Andrés Illanes Albornoz a50e83
			fi;
Lucio Andrés Illanes Albornoz 2c5ce2
		fi;
Lucio Andrés Illanes Albornoz 2c5ce2
		if _pkg_urls_git="$(rtl_get_var_unsafe -u "PKG_${_pkg_name_real}_URLS_GIT")"; then
Lucio Andrés Illanes Albornoz 22d139
			if [ -z "${_mirror_dname_git}" ]; then
Lucio Andrés Illanes Albornoz e493dc
				_rc=0; rtl_log_msg "verbose" "${MSG_pkgtool_pkg_skip_git_mirror}" "${_pkg_name}";
Lucio Andrés Illanes Albornoz 22d139
			elif [ "$(rtl_get_var_unsafe -u "PKG_${_pkg_name_real}_MIRRORS_GIT")" = "skip" ]; then
Lucio Andrés Illanes Albornoz e493dc
				_rc=0; rtl_log_msg "verbose" "${MSG_pkgtool_pkg_skip_git_mirror_disabled}" "${_pkg_name}";
Lucio Andrés Illanes Albornoz 23caa1
			elif [ "${_pkg_name}" != "${_pkg_name_real}" ]; then
Lucio Andrés Illanes Albornoz e493dc
				rtl_log_msg "info" "${MSG_pkgtool_pkg_git_mirroring_parent}" "${_pkg_name}" "${_pkg_name_real}" "${_pkg_urls_git}";
Lucio Andrés Illanes Albornoz 368962
				if ! rtl_fileop ln_symbolic "${_pkg_name_real}" "${_mirror_dname_git}/${_pkg_name}"; then
Lucio Andrés Illanes Albornoz e493dc
					_rc=1; rtl_log_msg "warning" "${MSG_pkgtool_pkg_link_fail}"\
Lucio Andrés Illanes Albornoz 368962
							"${_mirror_dname_git}/${_pkg_name}" "${_pkg_name}" "${_pkg_name_real}";
Lucio Andrés Illanes Albornoz 368962
				fi;
Lucio Andrés Illanes Albornoz a50e83
			else
Lucio Andrés Illanes Albornoz e493dc
				rtl_log_msg "info" "${MSG_pkgtool_pkg_git_mirroring}" "${_pkg_name}" "${_pkg_urls_git}";
Lucio Andrés Illanes Albornoz 368962
				if ! rtl_fileop mkdir "${_mirror_dname_git}/${_pkg_name}"\
Lucio Andrés Illanes Albornoz 2c5ce2
				|| ! rtl_fetch_mirror_urls_git "${DEFAULT_GIT_ARGS}" "${_mirror_dname_git}/${_pkg_name}" ${_pkg_urls_git}; then
Lucio Andrés Illanes Albornoz e493dc
					_rc=1; rtl_log_msg "warning" "${MSG_pkgtool_pkg_mirror_fail}" "${_pkg_name}";
Lucio Andrés Illanes Albornoz 2c5ce2
				else
Lucio Andrés Illanes Albornoz 2c5ce2
					pkg_fetch_download_clean_dlcache "${_mirror_dname_git}" "${_pkg_name}" "${_pkg_fname}" "${_pkg_urls_git}";
Lucio Andrés Illanes Albornoz 368962
				fi;
Lucio Andrés Illanes Albornoz a50e83
			fi;
Lucio Andrés Illanes Albornoz 2c5ce2
		fi;
Lucio Andrés Illanes Albornoz 2c5ce2
		if [ -z "${_pkg_url}" ]\
Lucio Andrés Illanes Albornoz 2c5ce2
		&& [ -z "${_pkg_sha256sum}" ]\
Lucio Andrés Illanes Albornoz 2c5ce2
		&& [ -z "${_pkg_urls_git}" ]; then
Lucio Andrés Illanes Albornoz e493dc
			_rc=0; rtl_log_msg "verbose" "${MSG_pkgtool_pkg_skip_no_urls}" "${_pkg_name}";
Lucio Andrés Illanes Albornoz b63b9b
		fi;
Lucio Andrés Illanes Albornoz 368962
	fi; return "${_rc}";
Lucio Andrés Illanes Albornoz b63b9b
};
Lucio Andrés Illanes Albornoz b63b9b
Lucio Andrés Illanes Albornoz 8a27f9
pkgtoolp_restart_at() {
Lucio Andrés Illanes Albornoz b6a9a1
	local _pkg_name="${1}" _rc=0; _status="";
Lucio Andrés Illanes Albornoz e493dc
Lucio Andrés Illanes Albornoz b6a9a1
	if ! ex_pkg_load_dump "${_pkg_name}" "${BUILD_WORKDIR}"; then
Lucio Andrés Illanes Albornoz b6a9a1
		_rc=1; _status="${_status}";
Lucio Andrés Illanes Albornoz b6a9a1
	else	case "${ARG_RESTART_AT}" in
Lucio Andrés Illanes Albornoz b6a9a1
		ALL)	if ! "${MIDIPIX_BUILD_PWD}/build.sh" -P -r "${_pkg_name}" -v; then
Lucio Andrés Illanes Albornoz b6a9a1
				_rc=1; _status="Error: failed to run command line ${MIDIPIX_BUILD_PWD}/build.sh -P -r ${_pkg_name} -v";
Lucio Andrés Illanes Albornoz b6a9a1
			fi; ;;
Lucio Andrés Illanes Albornoz b6a9a1
		*)	if ! "${MIDIPIX_BUILD_PWD}/build.sh" -P -r "${_pkg_name}:${ARG_RESTART_AT}" -v; then
Lucio Andrés Illanes Albornoz b6a9a1
				_rc=1; _status="Error: failed to run command line ${MIDIPIX_BUILD_PWD}/build.sh -P -r ${_pkg_name}:${ARG_RESTART_AT} -v";
Lucio Andrés Illanes Albornoz b6a9a1
			fi; ;;
Lucio Andrés Illanes Albornoz b6a9a1
		esac;
Lucio Andrés Illanes Albornoz b6a9a1
	fi; return "${_rc}";
Lucio Andrés Illanes Albornoz 8a27f9
};
Lucio Andrés Illanes Albornoz 8a27f9
Lucio Andrés Illanes Albornoz 60fba6
pkgtoolp_rdepends() {
Lucio Andrés Illanes Albornoz 57b30d
	local	_pkg_name="${1}" _group_name="" _pkg_depends="" _pkg_name_rdepend="" _pkg_names=""\
Lucio Andrés Illanes Albornoz 57b30d
		_pkg_rdepends="" _rc=0 EX_PKG_BUILD_GROUPS="" EX_PKG_DISABLED="" EX_PKG_RDEPENDS_DIRECT=""; _status="";
Lucio Andrés Illanes Albornoz e493dc
Lucio Andrés Illanes Albornoz b6a9a1
	if ! ex_pkg_load_groups; then
Lucio Andrés Illanes Albornoz b6a9a1
		_rc=1; _status="Error: failed to load build groups.";
Lucio Andrés Illanes Albornoz b6a9a1
	elif ! _group_name="$(ex_pkg_find_package "${EX_PKG_BUILD_GROUPS}" "${_pkg_name}")"; then
Lucio Andrés Illanes Albornoz b6a9a1
		_rc=1; _status="Error: unknown package \`${_pkg_name}'.";
Lucio Andrés Illanes Albornoz 60fba6
	elif ! _pkg_names="$(ex_pkg_get_packages "${_group_name}")"; then
Lucio Andrés Illanes Albornoz b6a9a1
		_rc=1; _status="Error: failed to expand package list of build group \`${_group_name}'.";
Lucio Andrés Illanes Albornoz 57b30d
	elif ! ex_pkg_unfold_rdepends_direct "${_group_name}" "${_pkg_names}" "${_pkg_name}"; then
Lucio Andrés Illanes Albornoz b6a9a1
		_rc=1; _status="Error: failed to unfold reverse dependency-expanded package name list for \`${_pkg_name}'.";
Lucio Andrés Illanes Albornoz 57b30d
	elif [ -z "${EX_PKG_DISABLED}" ] && [ -z "${EX_PKG_RDEPENDS_DIRECT}" ]; then
Lucio Andrés Illanes Albornoz e493dc
		rtl_log_msg "info" "${MSG_pkgtool_pkg_deps_rev_none}" "${_pkg_name}";
Lucio Andrés Illanes Albornoz 57b30d
	else	for _pkg_name_rdepend in $(rtl_lsort "${EX_PKG_RDEPENDS_DIRECT}"); do
Lucio Andrés Illanes Albornoz 57b30d
			_pkg_rdepends="$(rtl_lconcat "${_pkg_rdepends}" "${_pkg_name_rdepend}")";
Lucio Andrés Illanes Albornoz 57b30d
			if _pkg_depends="$(rtl_lunfold_depends 'PKG_${_name}_DEPENDS' $(rtl_get_var_unsafe -u "PKG_"${_pkg_name}"_DEPENDS"))"\
Lucio Andrés Illanes Albornoz 57b30d
			&& [ -n "${_pkg_depends}" ]; then
Lucio Andrés Illanes Albornoz 57b30d
				_pkg_rdepends="$(rtl_lconcat "${_pkg_rdepends}" "?[33m${_pkg_depends}?[93m")";
Lucio Andrés Illanes Albornoz 57b30d
			fi;
Lucio Andrés Illanes Albornoz 57b30d
		done;
Lucio Andrés Illanes Albornoz 57b30d
		if [ -n "${_pkg_rdepends}" ]; then
Lucio Andrés Illanes Albornoz e493dc
			rtl_log_msg "info" "${MSG_pkgtool_pkgs_deps_rev}" "${_pkg_name}" "${_pkg_rdepends}";
Lucio Andrés Illanes Albornoz 60fba6
		fi;
Lucio Andrés Illanes Albornoz 60fba6
		if [ -n "${EX_PKG_DISABLED}" ]; then
Lucio Andrés Illanes Albornoz e493dc
			rtl_log_msg "info" "${MSG_pkgtool_pkgs_deps_rev_disabled}" "${_pkg_name}" "$(rtl_lsort "${EX_PKG_DISABLED}")";
Lucio Andrés Illanes Albornoz 60fba6
		fi;
Lucio Andrés Illanes Albornoz b6a9a1
	fi; return "${_rc}";
Lucio Andrés Illanes Albornoz 60fba6
};
Lucio Andrés Illanes Albornoz 60fba6
Lucio Andrés Illanes Albornoz 8a27f9
pkgtoolp_shell() {
Lucio Andrés Illanes Albornoz b6a9a1
	local _pkg_name="${1}" _rc=0; _status="";
Lucio Andrés Illanes Albornoz e493dc
Lucio Andrés Illanes Albornoz b6a9a1
	if ! ex_pkg_load_dump "${_pkg_name}" "${BUILD_WORKDIR}"; then
Lucio Andrés Illanes Albornoz b6a9a1
		_rc=1; _status="${_status}";
Lucio Andrés Illanes Albornoz b1d432
	else	rtl_log_env_vars "verbose" "package" $(rtl_get_vars_fast "^PKG_");
Lucio Andrés Illanes Albornoz e493dc
		rtl_log_msg "info" "${MSG_pkgtool_shell_env1}" "${SHELL}" "${PKG_BUILD_DIR}";
Lucio Andrés Illanes Albornoz e493dc
		rtl_log_msg "info" "${MSG_pkgtool_shell_env2}" "${_pkg_name}";
Lucio Andrés Illanes Albornoz e493dc
		rtl_log_msg "info" "${MSG_pkgtool_shell_env3}" "${_pkg_name}";
Lucio Andrés Illanes Albornoz e493dc
		rtl_log_msg "info" "${MSG_pkgtool_shell_env4}" "${_pkg_name}";
Lucio Andrés Illanes Albornoz cd416f
		export	ARCH BUILD_KIND						\
Lucio Andrés Illanes Albornoz b6a9a1
			BUILD_DLCACHEDIR BUILD_WORKDIR				\
Lucio Andrés Illanes Albornoz b6a9a1
			MAKE="make LIBTOOL=${PKG_LIBTOOL:-slibtool}"		\
Lucio Andrés Illanes Albornoz b6a9a1
			MIDIPIX_BUILD_PWD					\
Lucio Andrés Illanes Albornoz b6a9a1
			PKG_NAME						\
Lucio Andrés Illanes Albornoz b6a9a1
			PREFIX PREFIX_CROSS PREFIX_MINGW32 PREFIX_MINIPIX	\
Lucio Andrés Illanes Albornoz b6a9a1
			PREFIX_NATIVE PREFIX_ROOT PREFIX_RPM;
Lucio Andrés Illanes Albornoz b6a9a1
		D="${MIDIPIX_BUILD_PWD}/${0##*/} --update-diff"			\
Lucio Andrés Illanes Albornoz b6a9a1
		R="${MIDIPIX_BUILD_PWD}/${0##*/} --restart-at ALL"		\
Lucio Andrés Illanes Albornoz b6a9a1
		RS="${MIDIPIX_BUILD_PWD}/${0##*/} --restart-at "		\
Lucio Andrés Illanes Albornoz b6a9a1
		"${SHELL}";
Lucio Andrés Illanes Albornoz b6a9a1
	fi; return "${_rc}";
Lucio Andrés Illanes Albornoz 8a27f9
};
Lucio Andrés Illanes Albornoz 8a27f9
Lucio Andrés Illanes Albornoz 60fba6
pkgtoolp_tarball() {
Lucio Andrés Illanes Albornoz b6a9a1
	local	_pkg_name="${1}" _date="" _group_name="" _hname="" _pkg_name_full=""\
Lucio Andrés Illanes Albornoz b6a9a1
		_pkg_version="" _rc=0 _tarball_fname="" EX_PKG_BUILD_GROUPS=""; _status="";
Lucio Andrés Illanes Albornoz e493dc
Lucio Andrés Illanes Albornoz b6a9a1
	if ! ex_pkg_load_groups; then
Lucio Andrés Illanes Albornoz b6a9a1
		_rc=1; _status="Error: failed to load build groups.";
Lucio Andrés Illanes Albornoz b6a9a1
	elif ! _group_name="$(ex_pkg_find_package "${EX_PKG_BUILD_GROUPS}" "${_pkg_name}")"; then
Lucio Andrés Illanes Albornoz b6a9a1
		_rc=1; _status="Error: unknown package \`${_pkg_name}'.";
Lucio Andrés Illanes Albornoz 60fba6
	elif ! ex_pkg_env "${DEFAULT_BUILD_STEPS}" "${DEFAULT_BUILD_VARS}"	\
Lucio Andrés Illanes Albornoz b6a9a1
			"${_group_name}" 0 "${_pkg_name}" "" "${BUILD_WORKDIR}"; then
Lucio Andrés Illanes Albornoz b6a9a1
		_rc=1; _status="Error: failed to set package environment for \`${_pkg_name}'.";
Lucio Andrés Illanes Albornoz 60fba6
	elif ! _date="$(date +%Y%m%d_%H%M%S)"; then
Lucio Andrés Illanes Albornoz b6a9a1
		_rc=1; _status="Error: failed to call date(1).";
Lucio Andrés Illanes Albornoz 60fba6
	elif ! _hname="$(hostname -f)"; then
Lucio Andrés Illanes Albornoz b6a9a1
		_rc=1; _status="Error: failed to call hostname(1).";
Lucio Andrés Illanes Albornoz 60fba6
	else	if [ -n "${PKG_VERSION}" ]; then
Lucio Andrés Illanes Albornoz b6a9a1
			_pkg_name_full="${_pkg_name}-${PKG_VERSION}";
Lucio Andrés Illanes Albornoz 60fba6
		else
Lucio Andrés Illanes Albornoz b6a9a1
			_pkg_name_full="${_pkg_name}";
Lucio Andrés Illanes Albornoz 60fba6
		fi;
Lucio Andrés Illanes Albornoz 60fba6
		_tarball_fname="${_pkg_name_full}@${_hname}-${_date}.tbz2";
Lucio Andrés Illanes Albornoz e493dc
		rtl_log_msg "info" "${MSG_pkgtool_tarball_creating}" "${PKG_BASE_DIR}" "${_pkg_name}";
Lucio Andrés Illanes Albornoz 60fba6
		if ! tar -C "${BUILD_WORKDIR}" -cpf -				\
Lucio Andrés Illanes Albornoz 60fba6
				"${PKG_BASE_DIR#${BUILD_WORKDIR%/}/}"		\
Lucio Andrés Illanes Albornoz b6a9a1
				"${_pkg_name}_stderrout.log"			|\
Lucio Andrés Illanes Albornoz 60fba6
					bzip2 -c -9 - > "${_tarball_fname}"; then
Lucio Andrés Illanes Albornoz b6a9a1
			_rc=1; _status="Error: failed to create compressed tarball of \`${PKG_BASE_DIR}' and \`${_pkg_name}_stderrout.log'.";
Lucio Andrés Illanes Albornoz 60fba6
		else
Lucio Andrés Illanes Albornoz e493dc
			rtl_log_msg "info" "${MSG_pkgtool_tarball_created}" "${PKG_BASE_DIR}" "${_pkg_name}";
Lucio Andrés Illanes Albornoz 60fba6
		fi;
Lucio Andrés Illanes Albornoz b6a9a1
	fi; return "${_rc}";
Lucio Andrés Illanes Albornoz 60fba6
};
Lucio Andrés Illanes Albornoz 60fba6
Lucio Andrés Illanes Albornoz 8a27f9
pkgtoolp_update_diff() {
Lucio Andrés Illanes Albornoz b6a9a1
	local	_pkg_name="${1}" _diff_fname_dst="" _diff_fname_src="" _fname=""\
Lucio Andrés Illanes Albornoz b6a9a1
		_fname_base="" _rc=0; _status="";
Lucio Andrés Illanes Albornoz e493dc
Lucio Andrés Illanes Albornoz b6a9a1
	if ! ex_pkg_load_dump "${_pkg_name}" "${BUILD_WORKDIR}"; then
Lucio Andrés Illanes Albornoz b6a9a1
		_rc=1; _status="${_status}";
Lucio Andrés Illanes Albornoz b6a9a1
	else	if [ -n "${PKG_VERSION}" ]; then
Lucio Andrés Illanes Albornoz b6a9a1
			_diff_fname_dst="${_pkg_name}-${PKG_VERSION}.local.patch";
Lucio Andrés Illanes Albornoz b6a9a1
		else
Lucio Andrés Illanes Albornoz b6a9a1
			_diff_fname_dst="${_pkg_name}.local.patch";
Lucio Andrés Illanes Albornoz 8a27f9
		fi;
Lucio Andrés Illanes Albornoz b6a9a1
		if ! _diff_fname_src="$(mktemp)"; then
Lucio Andrés Illanes Albornoz b6a9a1
			_rc=1; _status="Error: failed to create temporary target diff(1) file.";
Lucio Andrés Illanes Albornoz b6a9a1
		else	trap "rm -f \"${_diff_fname_src}\" >/dev/null 2>&1" EXIT HUP INT TERM USR1 USR2;
Lucio Andrés Illanes Albornoz b6a9a1
			(cd "${PKG_BASE_DIR}" && printf "" > "${_diff_fname_src}";
Lucio Andrés Illanes Albornoz b6a9a1
			 for _fname in $(find "${PKG_SUBDIR}" -iname \*.orig); do
Lucio Andrés Illanes Albornoz b6a9a1
				_fname_base="${_fname##*/}"; _fname_base="${_fname_base%.orig}";
Lucio Andrés Illanes Albornoz b6a9a1
				case "${_fname_base}" in
Lucio Andrés Illanes Albornoz b6a9a1
				config.sub)
Lucio Andrés Illanes Albornoz b6a9a1
					continue; ;;
Lucio Andrés Illanes Albornoz b6a9a1
				*)	diff -u "${_fname}" "${_fname%.orig}" >> "${_diff_fname_src}"; ;;
Lucio Andrés Illanes Albornoz b6a9a1
				esac;
Lucio Andrés Illanes Albornoz b6a9a1
			done);
Lucio Andrés Illanes Albornoz b6a9a1
			if [ "${?}" -ne 0 ]; then
Lucio Andrés Illanes Albornoz b6a9a1
				_rc=1; _status="Error: failed to create diff(1).";
Lucio Andrés Illanes Albornoz b6a9a1
			elif ! rtl_fileop mv "${_diff_fname_src}" "${MIDIPIX_BUILD_PWD}/patches/${_diff_fname_dst}"; then
Lucio Andrés Illanes Albornoz b6a9a1
				_rc=1; _status="Error: failed to rename diff(1) to \`${MIDIPIX_BUILD_PWD}/patches/${_diff_fname_dst}'.";
Lucio Andrés Illanes Albornoz b6a9a1
			else	trap - EXIT HUP INT TERM USR1 USR2;
Lucio Andrés Illanes Albornoz e493dc
				rtl_log_msg "info" "${MSG_pkgtool_updated_patches}" "${MIDIPIX_BUILD_PWD}" "${_diff_fname_dst}";
Lucio Andrés Illanes Albornoz b6a9a1
			fi;
Lucio Andrés Illanes Albornoz b6a9a1
		fi;
Lucio Andrés Illanes Albornoz b6a9a1
	fi; return "${_rc}";
Lucio Andrés Illanes Albornoz 8a27f9
};
Lucio Andrés Illanes Albornoz 8a27f9
Lucio Andrés Illanes Albornoz 8a27f9
pkgtool() {
Lucio Andrés Illanes Albornoz cd416f
	local _rc=0 _status="" BUILD_GROUPS="" ARCH BUILD_KIND BUILD_WORKDIR PKGTOOL_PKGNAME PREFIX;
Lucio Andrés Illanes Albornoz e493dc
Lucio Andrés Illanes Albornoz b6a9a1
	if ! . "${0%/*}/subr/pkgtool_init.subr"; then
Lucio Andrés Illanes Albornoz b6a9a1
		_rc=1; printf "Error: failed to source \`${0%/*}/subr/pkgtool_init.subr'." >&2;
Lucio Andrés Illanes Albornoz b6a9a1
	elif ! pkgtool_init "${@}"; then
Lucio Andrés Illanes Albornoz b6a9a1
		_rc=1; _status="${_status}";
Lucio Andrés Illanes Albornoz b6a9a1
	else	case "1" in
Lucio Andrés Illanes Albornoz b6a9a1
		"${ARG_INFO:-0}")		pkgtoolp_info "${PKGTOOL_PKG_NAME}"; ;;
Lucio Andrés Illanes Albornoz 22d139
		"${ARG_MIRROR:-0}")		pkgtoolp_mirror "${ARG_MIRROR_DNAME}" "${ARG_MIRROR_DNAME_GIT}"; ;;
Lucio Andrés Illanes Albornoz b6a9a1
		"${ARG_RDEPENDS:-0}")		pkgtoolp_rdepends "${PKGTOOL_PKG_NAME}"; ;;
Lucio Andrés Illanes Albornoz b6a9a1
		"${ARG_RESTART_AT:+1}")		pkgtoolp_restart_at "${PKGTOOL_PKG_NAME}"; ;;
Lucio Andrés Illanes Albornoz b6a9a1
		"${ARG_SHELL:-0}")		pkgtoolp_shell "${PKGTOOL_PKG_NAME}"; ;;
Lucio Andrés Illanes Albornoz b6a9a1
		"${ARG_TARBALL:-0}")		pkgtoolp_tarball "${PKGTOOL_PKG_NAME}"; ;;
Lucio Andrés Illanes Albornoz b6a9a1
		"${ARG_UPDATE_DIFF:-0}")	pkgtoolp_update_diff "${PKGTOOL_PKG_NAME}"; ;;
Lucio Andrés Illanes Albornoz b6a9a1
		esac; _rc="${?}";
Lucio Andrés Illanes Albornoz b6a9a1
	fi;
Lucio Andrés Illanes Albornoz b6a9a1
	if [ "${_rc}" -ne 0 ]; then
Lucio Andrés Illanes Albornoz dc07ba
		rtl_log_msg "fatalexit" "0;${_status}";
Lucio Andrés Illanes Albornoz b6a9a1
	elif [ -n "${_status}" ]; then
Lucio Andrés Illanes Albornoz dc07ba
		rtl_log_msg "info" "0;${_status}";
Lucio Andrés Illanes Albornoz 8a27f9
	fi;
Lucio Andrés Illanes Albornoz 8a27f9
};
Lucio Andrés Illanes Albornoz 8a27f9
Lucio Andrés Illanes Albornoz e493dc
set +o errexit -o noglob -o nounset; pkgtool "${@}";
Lucio Andrés Illanes Albornoz 8a27f9
Lucio Andrés Illanes Albornoz 8a27f9
# vim:filetype=sh textwidth=0