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) ec19f0
	local _msg="${1}" _pkg_name="${2}" _tgt_name="${3}"						\
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
		_build_tgt_meta _build_tgt_lc;
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) ec19f0
			for _build_tgt_meta in ${BUILD_TARGETS_META:-world}; do
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
				for _build_tgt_lc in $(ex_rtl_get_var_unsafe				\
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
						"$(ex_rtl_toupper "${_build_tgt_meta}")_TARGET"); do
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
					if ! ex_pkg_dispatch "${_build_tgt_lc}"				\
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
							"${ARG_RESTART}" "${ARG_RESTART_AT}"		\
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
							buildp_dispatch; then
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
						break;
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
					fi;
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
				done;
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
			done;
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) ec19f0
				ex_rtl_log_msg info "Build script failure(s) in: ${BUILD_PKGS_FAILED}.";
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
				exit 1;
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) 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
				BUILD_PKGS_FAILED="${BUILD_PKGS_FAILED:+${BUILD_PKGS_FAILED} }${_pkg_name}";
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) ec19f0
				ex_rtl_log_msg fail "Build failed in \`${_pkg_name}'.";
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
				return 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) ec19f0
	step_pkg)	ex_rtl_log_msg vnfo "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) 92aaa1
			if [ -z "${ARG_TARBALL}" ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
				case "${_pkg_name}" in
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
				dist_digest)	PKG_BUILD_STEPS=""; ;;
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
				dist_tarballs)	PKG_BUILD_STEPS=""; ;;
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
				esac;
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