midipix / build / midipix_build

Forked from build/midipix_build 4 years ago
Clone

Blame pkgtool.sh

Lucio Andrés Illanes Albornoz 8a27f9
#!/bin/sh
Lucio Andrés Illanes Albornoz 60fba6
# Copyright (c) 2020 Lucio Andrés Illanes Albornoz <lucio@lucioillanes.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 60fba6
	local	_group_name="" _pkg_name_uc="$(rtl_toupper "${PKG_NAME}")" _pkg_names=""	\
Lucio Andrés Illanes Albornoz 60fba6
		EX_PKG_DISABLED=""; EX_PKG_FINISHED=""; EX_PKG_NAMES="";
Lucio Andrés Illanes Albornoz 60fba6
	if ! _group_name="$(ex_pkg_find_package "${BUILD_GROUPS}" "${PKG_NAME}")"; then
Lucio Andrés Illanes Albornoz 60fba6
		rtl_log_msg failexit "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 60fba6
		rtl_log_msg failexit "Error: failed to expand package list of build group \`${_group_name}'.";
Lucio Andrés Illanes Albornoz 60fba6
	elif ! ex_pkg_env "${DEFAULT_BUILD_STEPS}" "${DEFAULT_BUILD_VARS}"	\
Lucio Andrés Illanes Albornoz 60fba6
			"${_group_name}" 1 "${PKG_NAME}" "" "${BUILD_WORKDIR}"; then
Lucio Andrés Illanes Albornoz 60fba6
		rtl_log_msg failexit "Error: failed to set package environment for \`${PKG_NAME}'.";
Lucio Andrés Illanes Albornoz 60fba6
	else	rtl_log_env_vars "package" $(set | awk -F= '/^PKG_'"${_pkg_name_uc}"'_/{print $1}' | sort);
Lucio Andrés Illanes Albornoz 60fba6
		if [ -z "${PKG_DEPENDS}" ]; then
Lucio Andrés Illanes Albornoz 60fba6
			rtl_log_msg info "Package \`${PKG_NAME}' has no dependencies.";
Lucio Andrés Illanes Albornoz 60fba6
		else	rtl_log_msg info "Direct dependencies of \`${PKG_NAME}': ${PKG_DEPENDS}";
Lucio Andrés Illanes Albornoz 60fba6
			if ! ex_pkg_unfold_depends "${_group_name}" "${_pkg_names}" "${PKG_NAME}" 2 0; then
Lucio Andrés Illanes Albornoz 60fba6
				rtl_log_msg warn "Warning: failed to unfold dependency-expanded package name list for \`${PKG_NAME}'.";
Lucio Andrés Illanes Albornoz 60fba6
			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 60fba6
					rtl_log_msg info "Full dependencies of \`${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 60fba6
					rtl_log_msg info "Full dependencies of \`${PKG_NAME}' (disabled packages:) $(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 60fba6
	fi;
Lucio Andrés Illanes Albornoz 60fba6
};
Lucio Andrés Illanes Albornoz 60fba6
Lucio Andrés Illanes Albornoz 8a27f9
pkgtoolp_restart_at() {
Lucio Andrés Illanes Albornoz 8a27f9
	case "${ARG_RESTART_AT}" in
Lucio Andrés Illanes Albornoz 8a27f9
	ALL)	"${MIDIPIX_BUILD_PWD}/build.sh" -P -r "${PKG_NAME}" -v; ;;
Lucio Andrés Illanes Albornoz 8a27f9
	*)	"${MIDIPIX_BUILD_PWD}/build.sh" -P -r "${PKG_NAME}:${ARG_RESTART_AT}" -v; ;;
Lucio Andrés Illanes Albornoz 8a27f9
	esac;
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 60fba6
	local _group_name="" _pkg_names="" EX_PKG_DISABLED=""; EX_PKG_FINISHED=""; EX_PKG_NAMES="";
Lucio Andrés Illanes Albornoz 60fba6
	if ! _group_name="$(ex_pkg_find_package "${BUILD_GROUPS}" "${PKG_NAME}")"; then
Lucio Andrés Illanes Albornoz 60fba6
		rtl_log_msg failexit "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 60fba6
		rtl_log_msg failexit "Error: failed to expand package list of build group \`${_group_name}'.";
Lucio Andrés Illanes Albornoz 60fba6
	elif ! ex_pkg_unfold_rdepends "${_group_name}" "${_pkg_names}" "${PKG_NAME}" 0; then
Lucio Andrés Illanes Albornoz 60fba6
		rtl_log_msg failexit "Error: failed to unfold reverse dependency-expanded package name list for \`${PKG_NAME}'.";
Lucio Andrés Illanes Albornoz 60fba6
	elif [ -z "${EX_PKG_NAMES}" ] && [ -z "${EX_PKG_DISABLED}" ]; then
Lucio Andrés Illanes Albornoz 60fba6
		rtl_log_msg info "Package \`${PKG_NAME}' has no reverse dependencies.";
Lucio Andrés Illanes Albornoz 60fba6
	else	if [ -n "${EX_PKG_NAMES}" ]; then
Lucio Andrés Illanes Albornoz 60fba6
			rtl_log_msg info "Reverse dependencies of \`${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 60fba6
			rtl_log_msg info "Reverse dependencies of \`${PKG_NAME}' (disabled packages:) $(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
};
Lucio Andrés Illanes Albornoz 60fba6
Lucio Andrés Illanes Albornoz 8a27f9
pkgtoolp_shell() {
Lucio Andrés Illanes Albornoz 60fba6
	rtl_log_env_vars "build" $(set | awk -F= '/^PKG_/{print $1}' | sort);
Lucio Andrés Illanes Albornoz 8a27f9
	rtl_log_msg info "Launching shell \`${SHELL}' within package environment and \`${PKG_BUILD_DIR}'.";
Lucio Andrés Illanes Albornoz 8a27f9
	rtl_log_msg info "Run \$R to rebuild \`${PKG_NAME}'.";
Lucio Andrés Illanes Albornoz 8a27f9
	rtl_log_msg info "Run \$RS <step> to restart the specified build step of \`${PKG_NAME}'";
Lucio Andrés Illanes Albornoz 8a27f9
	rtl_log_msg info "Run \$D to automatically regenerate the patch for \`${PKG_NAME}'.";
Lucio Andrés Illanes Albornoz 8a27f9
	export	ARCH BUILD							\
Lucio Andrés Illanes Albornoz 8a27f9
		BUILD_DLCACHEDIR BUILD_WORKDIR					\
Lucio Andrés Illanes Albornoz 8a27f9
		MAKE="make LIBTOOL=${PKG_LIBTOOL:-slibtool}"			\
Lucio Andrés Illanes Albornoz 8a27f9
		MIDIPIX_BUILD_PWD						\
Lucio Andrés Illanes Albornoz 8a27f9
		PKG_NAME							\
Lucio Andrés Illanes Albornoz 8a27f9
		PREFIX PREFIX_CROSS PREFIX_MINGW32 PREFIX_MINIPIX		\
Lucio Andrés Illanes Albornoz 8a27f9
		PREFIX_NATIVE PREFIX_ROOT PREFIX_RPM;
Lucio Andrés Illanes Albornoz 8a27f9
	D="${MIDIPIX_BUILD_PWD}/${0##*/} --update-diff"				\
Lucio Andrés Illanes Albornoz 8a27f9
	R="${MIDIPIX_BUILD_PWD}/${0##*/} --restart-at ALL"			\
Lucio Andrés Illanes Albornoz 8a27f9
	RS="${MIDIPIX_BUILD_PWD}/${0##*/} --restart-at "			\
Lucio Andrés Illanes Albornoz 8a27f9
	"${SHELL}";
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 60fba6
	local _date="" _group_name="" _hname="" _pkg_name_full="" _pkg_version="" _tarball_fname="";
Lucio Andrés Illanes Albornoz 60fba6
	if ! _group_name="$(ex_pkg_find_package "${BUILD_GROUPS}" "${PKG_NAME}")"; then
Lucio Andrés Illanes Albornoz 60fba6
		rtl_log_msg failexit "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 60fba6
			"${_group_name}" "${PKG_NAME}" "" "${BUILD_WORKDIR}"; then
Lucio Andrés Illanes Albornoz 60fba6
		rtl_log_msg failexit "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 60fba6
		rtl_log_msg failexit "Error: failed to call date(1).";
Lucio Andrés Illanes Albornoz 60fba6
	elif ! _hname="$(hostname -f)"; then
Lucio Andrés Illanes Albornoz 60fba6
		rtl_log_msg failexit "Error: failed to call hostname(1).";
Lucio Andrés Illanes Albornoz 60fba6
	else	if [ -n "${PKG_VERSION}" ]; then
Lucio Andrés Illanes Albornoz 60fba6
			_pkg_name_full="${PKG_NAME}-${PKG_VERSION}";
Lucio Andrés Illanes Albornoz 60fba6
		else
Lucio Andrés Illanes Albornoz 60fba6
			_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 60fba6
		rtl_log_msg info "Creating compressed tarball of \`${PKG_BASE_DIR}' and \`${PKG_NAME}_stderrout.log'...";
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 60fba6
				"${PKG_NAME}_stderrout.log"			|\
Lucio Andrés Illanes Albornoz 60fba6
					bzip2 -c -9 - > "${_tarball_fname}"; then
Lucio Andrés Illanes Albornoz 60fba6
			rtl_log_msg failexit "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 60fba6
			rtl_log_msg info "Created compressed tarball of \`${PKG_BASE_DIR}' and \`${PKG_NAME}_stderrout.log'.";
Lucio Andrés Illanes Albornoz 60fba6
		fi;
Lucio Andrés Illanes Albornoz 60fba6
	fi;
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 8a27f9
	local _diff_fname_dst="" _diff_fname_src="" _fname="" _fname_base="";
Lucio Andrés Illanes Albornoz 8a27f9
	if [ -n "${PKG_VERSION}" ]; then
Lucio Andrés Illanes Albornoz 8a27f9
		_diff_fname_dst="${PKG_NAME}-${PKG_VERSION}.local.patch";
Lucio Andrés Illanes Albornoz 8a27f9
	else
Lucio Andrés Illanes Albornoz 8a27f9
		_diff_fname_dst="${PKG_NAME}.local.patch";
Lucio Andrés Illanes Albornoz 8a27f9
	fi;
Lucio Andrés Illanes Albornoz 8a27f9
	if ! _diff_fname_src="$(mktemp)"; then
Lucio Andrés Illanes Albornoz 8a27f9
		rtl_log_msg failexit "Error: failed to create temporary target diff(1) file.";
Lucio Andrés Illanes Albornoz 8a27f9
	else	trap "rm -f \"${_diff_fname_src}\" >/dev/null 2>&1" EXIT HUP INT TERM USR1 USR2;
Lucio Andrés Illanes Albornoz 8a27f9
		(cd "${PKG_BASE_DIR}" && printf "" > "${_diff_fname_src}";
Lucio Andrés Illanes Albornoz 8a27f9
		 for _fname in $(find "${PKG_SUBDIR}" -iname \*.orig); do
Lucio Andrés Illanes Albornoz 8a27f9
			_fname_base="${_fname##*/}"; _fname_base="${_fname_base%.orig}";
Lucio Andrés Illanes Albornoz 8a27f9
			case "${_fname_base}" in
Lucio Andrés Illanes Albornoz 8a27f9
			config.sub)
Lucio Andrés Illanes Albornoz 8a27f9
				continue; ;;
Lucio Andrés Illanes Albornoz 8a27f9
			*)	diff -u "${_fname}" "${_fname%.orig}" >> "${_diff_fname_src}"; ;;
Lucio Andrés Illanes Albornoz 8a27f9
			esac;
Lucio Andrés Illanes Albornoz 8a27f9
		done);
Lucio Andrés Illanes Albornoz 8a27f9
		if [ "${?}" -ne 0 ]; then
Lucio Andrés Illanes Albornoz 8a27f9
			rtl_log_msg failexit "Error: failed to create diff(1).";
Lucio Andrés Illanes Albornoz 8a27f9
		elif ! rtl_fileop mv "${_diff_fname_src}" "${MIDIPIX_BUILD_PWD}/patches/${_diff_fname_dst}"; then
Lucio Andrés Illanes Albornoz 8a27f9
			rtl_log_msg failexit "Error: failed to rename diff(1) to \`${MIDIPIX_BUILD_PWD}/patches/${_diff_fname_dst}'.";
Lucio Andrés Illanes Albornoz 8a27f9
		else	trap - EXIT HUP INT TERM USR1 USR2;
Lucio Andrés Illanes Albornoz 8a27f9
			rtl_log_msg info "Updated \`${MIDIPIX_BUILD_PWD}/patches/${_diff_fname_dst}'.";
Lucio Andrés Illanes Albornoz 8a27f9
		fi;
Lucio Andrés Illanes Albornoz 8a27f9
	fi;
Lucio Andrés Illanes Albornoz 8a27f9
};
Lucio Andrés Illanes Albornoz 8a27f9
Lucio Andrés Illanes Albornoz 8a27f9
pkgtool() {
Lucio Andrés Illanes Albornoz f243be
	local _status="";
Lucio Andrés Illanes Albornoz 8a27f9
	if ! cd "$(dirname "${0}")"\
Lucio Andrés Illanes Albornoz 8a27f9
	|| ! . ./subr/pkgtool_init.subr\
Lucio Andrés Illanes Albornoz 8a27f9
	|| ! pkgtool_init "${@}"; then
Lucio Andrés Illanes Albornoz 8a27f9
		printf "Error: failed to setup environment.\n"; exit 1;
Lucio Andrés Illanes Albornoz 8a27f9
	elif [ -n "${ARG_RESTART_AT}" ]; then
Lucio Andrés Illanes Albornoz 8a27f9
		pkgtoolp_restart_at;
Lucio Andrés Illanes Albornoz 8a27f9
	elif [ "${ARG_UPDATE_DIFF:-0}" -eq 1 ]; then
Lucio Andrés Illanes Albornoz 8a27f9
		pkgtoolp_update_diff;
Lucio Andrés Illanes Albornoz 60fba6
	elif [ "${ARG_INFO:-0}" -eq 1 ]; then
Lucio Andrés Illanes Albornoz 60fba6
		pkgtoolp_info;
Lucio Andrés Illanes Albornoz 60fba6
	elif [ "${ARG_RDEPENDS:-0}" -eq 1 ]; then
Lucio Andrés Illanes Albornoz 60fba6
		pkgtoolp_rdepends;
Lucio Andrés Illanes Albornoz 60fba6
	elif [ "${ARG_SHELL:-0}" -eq 1 ]; then
Lucio Andrés Illanes Albornoz 60fba6
		pkgtoolp_shell;
Lucio Andrés Illanes Albornoz 60fba6
	elif [ "${ARG_TARBALL:-0}" -eq 1 ]; then
Lucio Andrés Illanes Albornoz 60fba6
		pkgtoolp_tarball;
Lucio Andrés Illanes Albornoz 8a27f9
	fi;
Lucio Andrés Illanes Albornoz 8a27f9
};
Lucio Andrés Illanes Albornoz 8a27f9
Lucio Andrés Illanes Albornoz 8a27f9
set +o errexit -o noglob; pkgtool "${@}";
Lucio Andrés Illanes Albornoz 8a27f9
Lucio Andrés Illanes Albornoz 8a27f9
# vim:filetype=sh textwidth=0