#
# set -o errexit -o noglob are assumed.
#

pkg_invariants_zipdist_all() {
	local _dist_fname="" _pkg_name="" _pkglist_fname="${PREFIX}/pkglist.native";
	if ex_rtl_lmatch "${ARG_DIST}" , zipdist; then
		ex_rtl_log_msg info "Building deployable distribution ZIP archive...";
		for _pkg_name in $(cat "${_pkglist_fname}"); do
			if ! stat "${BUILD_WORKDIR}/${_pkg_name}-native-${DEFAULT_TARGET}" >/dev/null 2>&1; then
				ex_rtl_log_msg failexit "Error: missing package build directory for package \`${_pkg_name}'.";
			fi;
		done;
		_dist_fname="${DEFAULT_ZIPDIST_FNAME_PREFIX}${BUILD_USER}@${BUILD_HNAME}-${BUILD_DATE_START}.zip";
		"${BUILD_WORKDIR}/mpackage/mpackage.sh"		\
			--defroot=/dev/fs/c/midipix		\
			--flysyms				\
			--minroot="${PREFIX_MINIPIX}"		\
			--objroot="${BUILD_WORKDIR}"		\
			--pkgroot="${BUILD_WORKDIR}/pkgroot"	\
			--product=Midipix			\
			--subset="${_pkglist_fname}"		\
			--symbols				\
			--sysroot="${BUILD_WORKDIR}/sysroot"	\
			--target="${DEFAULT_TARGET}"		\
			--tmproot="${BUILD_WORKDIR}/tmproot"	\
			--zipfile="${PREFIX}/${_dist_fname}";
	fi;
};

# vim:filetype=sh