lalbornoz 340f4c
#!/bin/sh
Lucio Andrés Illanes Albornoz (arab, vxp) a39ccb
# Copyright (c) 2016, 2017 Lucio Andrés Illanes Albornoz <lucio@lucioillanes.de>
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
#
Lucio Andrés Illanes Albornoz (arab, vxp) 090fd4
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
buildp_dispatch() {
Lucio Andrés Illanes Albornoz (arab, vxp) 1dfec6
	local _msg="${1}" _pkg_name="${2}" _tgt_name="${3}"					\
Lucio Andrés Illanes Albornoz 907bd3
		_build_tgt_meta="" _build_tgt_lc="" _build_tgt_pkg_names="" _build_tgt_uc="";
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
	case "${_msg}" in
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
	# Top-level
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
	start_build)	shift; build_args "${@}"; build_init; build_checks;
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
			ex_rtl_log_set_vnfo_lvl "${ARG_VERBOSE:-0}";
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
			ex_rtl_log_msg info "Build started by ${BUILD_USER:=${USER}}@${BUILD_HNAME:=$(hostname)} at ${BUILD_DATE_START}.";
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
			ex_rtl_log_env_vars "build (global)" ${DEFAULT_LOG_ENV_VARS};
Lucio Andrés Illanes Albornoz (arab, vxp) 95a70a
			if [ -n "${ARG_RESTART}" ]\
Lucio Andrés Illanes Albornoz (arab, vxp) 95a70a
			&& [ "${ARG_RESTART}" != ALL ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 02c235
				_build_tgt_pkg_names="";
Lucio Andrés Illanes Albornoz (arab, vxp) 02c235
				for _build_tgt_lc in ${BUILD_TARGETS:-${TARGETS_DEFAULT}}; do
Lucio Andrés Illanes Albornoz (arab, vxp) 64e589
					if [ "${_build_tgt_lc}" = "host_tools_rpm" ]		\
Lucio Andrés Illanes Albornoz (arab, vxp) 64e589
					&& [ "${ARG_RPM:-0}" -eq 0 ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 64e589
						continue;
Lucio Andrés Illanes Albornoz (arab, vxp) 64e589
					fi;
Lucio Andrés Illanes Albornoz (arab, vxp) 02c235
					_build_tgt_uc="$(ex_rtl_toupper "${_build_tgt_lc}")";
Lucio Andrés Illanes Albornoz (arab, vxp) 02c235
					_build_tgt_pkg_names="${_build_tgt_pkg_names:+${_build_tgt_pkg_names} }$(ex_rtl_get_var_unsafe ${_build_tgt_uc}_PACKAGES)";
Lucio Andrés Illanes Albornoz (arab, vxp) 02c235
				done;
Lucio Andrés Illanes Albornoz (arab, vxp) 02c235
				_build_tgt_pkg_names="$(ex_rtl_lfilter_not "${ARG_RESTART}" "${_build_tgt_pkg_names}")";
Lucio Andrés Illanes Albornoz (arab, vxp) 02c235
				if [ -n "${_build_tgt_pkg_names}" ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 02c235
					ex_rtl_log_msg failexit "Error: package(s) \`${_build_tgt_pkg_names}' unknown.";
Lucio Andrés Illanes Albornoz (arab, vxp) 02c235
				fi;
Lucio Andrés Illanes Albornoz (arab, vxp) 02c235
			fi;
Lucio Andrés Illanes Albornoz (arab, vxp) ed83f9
			for _build_tgt_lc in ${BUILD_TARGETS:-${TARGETS_DEFAULT}}; do
Lucio Andrés Illanes Albornoz (arab, vxp) 64e589
				if [ "${_build_tgt_lc}" = "host_tools_rpm" ]			\
Lucio Andrés Illanes Albornoz (arab, vxp) c4aea7
				&& [ "${ARG_RPM:-0}" -eq 0 ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 64e589
					continue;
Lucio Andrés Illanes Albornoz (arab, vxp) 64e589
				fi;
Lucio Andrés Illanes Albornoz (arab, vxp) 1dfec6
				ex_pkg_dispatch "${_build_tgt_lc}"				\
Lucio Andrés Illanes Albornoz (arab, vxp) 1dfec6
						"${ARG_RESTART}" "${ARG_RESTART_AT}"		\
Lucio Andrés Illanes Albornoz (arab, vxp) 1dfec6
						buildp_dispatch;
Lucio Andrés Illanes Albornoz (arab, vxp) 1dfec6
				if [ ${?} -ne 0 ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 1dfec6
					break;
Lucio Andrés Illanes Albornoz (arab, vxp) 1dfec6
				fi;
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
			done;
Lucio Andrés Illanes Albornoz (arab, vxp) 6c6c71
			if ! ex_pkg_dispatch "invariants" "ALL" "ALL" buildp_dispatch; then
Lucio Andrés Illanes Albornoz (arab, vxp) 6c6c71
				break;
Lucio Andrés Illanes Albornoz (arab, vxp) 6c6c71
			fi;
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
			buildp_dispatch finish_build; ;;
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
	finish_build)	build_fini;
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
			ex_rtl_log_msg info "${BUILD_NFINI} finished, ${BUILD_NSKIP} skipped, and ${BUILD_NFAIL} failed builds in ${BUILD_NBUILT} build script(s).";
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
			ex_rtl_log_msg info "Build time: ${BUILD_TIMES_HOURS} hour(s), ${BUILD_TIMES_MINUTES} minute(s), and ${BUILD_TIMES_SECS} second(s).";
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
			if [ -n "${BUILD_PKGS_FAILED}" ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 0b72c8
				ex_rtl_log_msg failexit "Build script failure(s) in: ${BUILD_PKGS_FAILED}.";
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
			fi; ;;
Lucio Andrés Illanes Albornoz (arab, vxp) fc9417
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
	# Target build
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
	start_target)	ex_rtl_log_msg inf2 "Starting \`${_tgt_name}' build target..."; ;;
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
	finish_target)	ex_rtl_log_msg suc2 "Finished \`${_tgt_name}' build target."; ;;
Lucio Andrés Illanes Albornoz (arab, vxp) fc9417
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
	# Package build
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
	start_pkg)	ex_rtl_log_msg info "Starting \`${_pkg_name}' build..."; ;;
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
	finish_pkg)	: $((BUILD_NFINI+=1));
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
			if [ "${ARG_VERBOSE:-0}" -ge 2 ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
				cat "${BUILD_WORKDIR}/${_pkg_name}_stderrout.log";
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
			fi;
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
			ex_rtl_log_msg succ "Finished \`${_pkg_name}' build."; ;;
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
	fail_pkg)	: $((BUILD_NFAIL+=1));
Lucio Andrés Illanes Albornoz (arab, vxp) b3d07b
			BUILD_PKGS_FAILED="${BUILD_PKGS_FAILED:+${BUILD_PKGS_FAILED} }${_pkg_name}";
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
			if [ "${ARG_RELAXED:-0}" -eq 1 ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
				ex_rtl_log_msg fail "Build failed in \`${_pkg_name}', check \`${BUILD_WORKDIR}/${_pkg_name}_stderrout.log' for details.";
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
			else
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
				ex_rtl_log_msg fail "${BUILD_WORKDIR}/${_pkg_name}_stderrout.log:";
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
				cat "${BUILD_WORKDIR}/${_pkg_name}_stderrout.log";
Lucio Andrés Illanes Albornoz (arab, vxp) 30ae14
				ex_rtl_log_msg fail "Build failed in \`${_pkg_name}'.";
Lucio Andrés Illanes Albornoz (arab, vxp) 71818e
				if [ "${ARG_PARALLEL:-0}" -eq 1 ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 71818e
					ex_rtl_log_msg fail "Terminating pending builds...";
Lucio Andrés Illanes Albornoz (arab, vxp) 71818e
					pkill -P "${$}";
Lucio Andrés Illanes Albornoz (arab, vxp) 71818e
				fi;
Lucio Andrés Illanes Albornoz (arab, vxp) 30ae14
				exit 1;
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
			fi; ;;
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
	disabled_pkg)	ex_rtl_log_msg vnfo "Skipping disabled package \`${_pkg_name}.'"; ;;
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
	skipped_pkg)	ex_rtl_log_msg vnfo "Skipping finished package \`${_pkg_name}.'"; ;;
Lucio Andrés Illanes Albornoz (arab, vxp) 5c1ec1
	step_pkg)	ex_rtl_log_msg vucc "Finished build step ${4} of package \`${_pkg_name}'."; ;;
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
	# Child process
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
	exec_finish)	;;
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
	exec_missing)	ex_rtl_log_msg failexit "Error: package \`${_pkg_name}' missing in build.vars."; ;;
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
	exec_start)	if [ "${PKG_NO_LOG_VARS:-0}" -eq 0 ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
				ex_rtl_log_env_vars "build"		\
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
					$(set | awk -F= '/^PKG_/{print $1}' | sort);
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
			fi;
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
			if [ "${ARG_DEBUG_MINIPIX:-0}" -eq 1 ]\
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
			&& [ "${_tgt_name}" = "dist_minipix" ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
				PKG_BUILD_STEPS="$(ex_rtl_lfilter_not	\
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
					"${PKG_BUILD_STEPS}" "strip")";
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
			elif [ "${BUILD}" = release ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
				PKG_BUILD_STEPS="$(ex_rtl_lfilter_not	\
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
					"${PKG_BUILD_STEPS}" "strip")";
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
			fi;
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
			if [ "${ARG_OFFLINE:-0}" -eq 1 ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
				PKG_BUILD_STEPS="$(ex_rtl_lfilter_not	\
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
					"${PKG_BUILD_STEPS}" "fetch_git fetch_wget")";
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
			fi;
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
			if [ "${ARG_XTRACE:-0}" -eq 1 ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
				set -o xtrace;
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
			fi; ;;
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
	exec_step)	ex_rtl_log_msg info "Finished build step ${4} of package \`${_pkg_name}'."; ;;
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
	esac; return 0;
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
};
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
for __ in $(find subr -name *.subr); do
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
	. "${__}"; done; buildp_dispatch start_build "${@}";
lalbornoz 340f4c
lalbornoz 340f4c
# vim:filetype=sh