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 8a27f9
# Copyright (c) 2019 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 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 8a27f9
pkgtoolp_shell() {
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 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 f243be
pkgtoolp_env() {
Lucio Andrés Illanes Albornoz f243be
	local _rc=0; _status="";
Lucio Andrés Illanes Albornoz f243be
	if [ ! -e "${BUILD_WORKDIR}/${PKG_NAME}.dump" ]; then
Lucio Andrés Illanes Albornoz f243be
		rtl_log_msg fail "Warning: failed to locate environment dump for package \`${PKG_NAME}' in \`${BUILD_WORKDIR}'.";
Lucio Andrés Illanes Albornoz f243be
		rtl_log_msg info "Rebuilding package \`${PKG_NAME}' w/ --dump-in build...";
Lucio Andrés Illanes Albornoz f243be
		(export	ARCH BUILD						\
Lucio Andrés Illanes Albornoz f243be
			BUILD_DLCACHEDIR BUILD_WORKDIR				\
Lucio Andrés Illanes Albornoz f243be
			PREFIX PREFIX_CROSS PREFIX_MINGW32 PREFIX_MINIPIX	\
Lucio Andrés Illanes Albornoz f243be
			PREFIX_NATIVE PREFIX_ROOT PREFIX_RPM;
Lucio Andrés Illanes Albornoz f243be
		./build.sh -a "${ARCH}" -b "${BUILD}" --dump-in build -P -r "${PKG_NAME}" -v);
Lucio Andrés Illanes Albornoz f243be
		if [ ! -e "${BUILD_WORKDIR}/${PKG_NAME}.dump" ]; then
Lucio Andrés Illanes Albornoz f243be
			_rc=1; _status="Error: failed to locate environment dump for package \`${PKG_NAME}' in \`${BUILD_WORKDIR}'.";
Lucio Andrés Illanes Albornoz f243be
		fi;
Lucio Andrés Illanes Albornoz f243be
	else
Lucio Andrés Illanes Albornoz f243be
		_rc=0;
Lucio Andrés Illanes Albornoz f243be
	fi;
Lucio Andrés Illanes Albornoz f243be
	if [ "${_rc:-0}" -eq 0 ]\
Lucio Andrés Illanes Albornoz f243be
	&& ! . "${BUILD_WORKDIR}/${PKG_NAME}.dump"; then
Lucio Andrés Illanes Albornoz f243be
		_rc=1; _status="Error: failed to source environment dump for package \`${PKG_NAME}' from \`${BUILD_WORKDIR}'.";
Lucio Andrés Illanes Albornoz f243be
	fi; return "${_rc}";
Lucio Andrés Illanes Albornoz f243be
};
Lucio Andrés Illanes Albornoz f243be
	
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 f243be
	elif ! pkgtoolp_env; then
Lucio Andrés Illanes Albornoz f243be
		rtl_log_msg failexit "${_status}";
Lucio Andrés Illanes Albornoz 8a27f9
	elif ! rtl_fileop cd "${PKG_BUILD_DIR}"; then
Lucio Andrés Illanes Albornoz 8a27f9
		rtl_log_msg failexit "Error: failed to change working directory to \`${PKG_BUILD_DIR}'.";
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 8a27f9
	else	pkgtoolp_shell;
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