Lucio Andrés Illanes Albornoz c6d6e0
#
Lucio Andrés Illanes Albornoz c6d6e0
# set +o errexit -o noglob is assumed.
Lucio Andrés Illanes Albornoz c6d6e0
#
Lucio Andrés Illanes Albornoz 6c3660
Lucio Andrés Illanes Albornoz c3bcd7
buildp_init_args() {
Lucio Andrés Illanes Albornoz ebda8b
	local _last_pkg=""; _status="";
Lucio Andrés Illanes Albornoz c3bcd7
	if [ "${ARG_AS_NEEDED:-0}" -eq 1 ]\
Lucio Andrés Illanes Albornoz c3bcd7
	&& [ -e "${PREFIX}/build.gitref" ]\
Lucio Andrés Illanes Albornoz c3bcd7
	&& [ "$(git rev-parse HEAD)" = "$(cat "${PREFIX}/build.gitref")" ]; then
Lucio Andrés Illanes Albornoz c3bcd7
		_status="Git repository has not changed since last build and --as-needed was specified.";
Lucio Andrés Illanes Albornoz c3bcd7
	fi;
Lucio Andrés Illanes Albornoz ebda8b
	if [ -n "${ARG_RESTART}" ]; then
Lucio Andrés Illanes Albornoz 7bed88
		if [ "${ARG_RESTART#\*\*\*}" != "${ARG_RESTART}" ]; then
Lucio Andrés Illanes Albornoz 7bed88
			ARG_RESTART="${ARG_RESTART#\*\*\*}"; ARG_RESTART_RECURSIVE=3;
Lucio Andrés Illanes Albornoz 7bed88
		elif [ "${ARG_RESTART#\*\*}" != "${ARG_RESTART}" ]; then
Lucio Andrés Illanes Albornoz ebda8b
			ARG_RESTART="${ARG_RESTART#\*\*}"; ARG_RESTART_RECURSIVE=2;
Lucio Andrés Illanes Albornoz ebda8b
		elif [ "${ARG_RESTART#\*}" != "${ARG_RESTART}" ]; then
Lucio Andrés Illanes Albornoz ebda8b
			ARG_RESTART="${ARG_RESTART#\*}"; ARG_RESTART_RECURSIVE=1;
Lucio Andrés Illanes Albornoz ebda8b
		fi;
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
	fi;
Lucio Andrés Illanes Albornoz c3bcd7
	case "${ARG_RESTART}" in
Lucio Andrés Illanes Albornoz c6d6e0
	ALL)	ARG_RESTART_AT=ALL; ARG_RESTART_RECURSIVE=2; ;;
Lucio Andrés Illanes Albornoz c6d6e0
	LAST)	ARG_RESTART_AT=ALL; ARG_RESTART_RECURSIVE=0; ;;
Lucio Andrés Illanes Albornoz c3bcd7
	"")	;;
Lucio Andrés Illanes Albornoz 974685
	*:*)	ARG_RESTART_AT="${ARG_RESTART#*:}"; ARG_RESTART="$(rtl_llift "${ARG_RESTART%%:*}" "," " ")"; ;;
Lucio Andrés Illanes Albornoz 974685
	*)	ARG_RESTART="$(rtl_llift "${ARG_RESTART}" "," " ")"; ARG_RESTART_AT=ALL; ;;
Lucio Andrés Illanes Albornoz c3bcd7
	esac;
Lucio Andrés Illanes Albornoz c3bcd7
	if [ "${ARG_RESTART}" = "LAST" ]; then
Lucio Andrés Illanes Albornoz c3bcd7
		if [ -n "${DEFAULT_BUILD_LAST_FAILED_PKG_FNAME}" ]\
Lucio Andrés Illanes Albornoz c3bcd7
		&& [ -e "${DEFAULT_BUILD_LAST_FAILED_PKG_FNAME}" ]; then
Lucio Andrés Illanes Albornoz c3bcd7
			_last_pkg="$(cat "${DEFAULT_BUILD_LAST_FAILED_PKG_FNAME}")";
Lucio Andrés Illanes Albornoz c6d6e0
			rtl_fileop rm "${DEFAULT_BUILD_LAST_FAILED_PKG_FNAME}";
Lucio Andrés Illanes Albornoz c6d6e0
			rtl_state_clear "${BUILD_WORKDIR}" "${_last_pkg}";
Lucio Andrés Illanes Albornoz c6d6e0
			ARG_RESTART="${_last_pkg}";
Lucio Andrés Illanes Albornoz c3bcd7
		fi;
Lucio Andrés Illanes Albornoz c3bcd7
	fi;
Lucio Andrés Illanes Albornoz c6d6e0
	rtl_log_set_vnfo_lvl "${ARG_VERBOSE:-0}";
Lucio Andrés Illanes Albornoz c6d6e0
	case "${ARG_FETCH_FORCE}" in
Lucio Andrés Illanes Albornoz c6d6e0
	ipv4)	DEFAULT_GIT_ARGS="$(rtl_lconcat "-4" "${DEFAULT_GIT_ARGS}")";
Lucio Andrés Illanes Albornoz c6d6e0
		DEFAULT_WGET_ARGS="$(rtl_lconcat "-4" "${DEFAULT_GIT_ARGS}")"; ;;
Lucio Andrés Illanes Albornoz c6d6e0
	ipv6)	DEFAULT_GIT_ARGS="$(rtl_lconcat "-6" "${DEFAULT_GIT_ARGS}")";
Lucio Andrés Illanes Albornoz c6d6e0
		DEFAULT_WGET_ARGS="$(rtl_lconcat "-6" "${DEFAULT_GIT_ARGS}")"; ;;
Lucio Andrés Illanes Albornoz c6d6e0
	esac;
Lucio Andrés Illanes Albornoz c3bcd7
	return 0;
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
};
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
Lucio Andrés Illanes Albornoz c6d6e0
buildp_init_defaults() {
Lucio Andrés Illanes Albornoz c6d6e0
	local _rc=0; _status="";
Lucio Andrés Illanes Albornoz c6d6e0
Lucio Andrés Illanes Albornoz c6d6e0
	# Command-line arguments
Lucio Andrés Illanes Albornoz 8a27f9
	: ${ARCH:="nt64"}; : ${BUILD:="debug"};
Lucio Andrés Illanes Albornoz f243be
	ARG_AS_NEEDED=0; ARG_CLEAN_BUILDS=""; ARG_DEBUG_MINIPIX=0; ARG_DUMP_IN="";
Lucio Andrés Illanes Albornoz f243be
	ARG_DUMP_ON_ABORT=0; ARG_DIST=""; ARG_FETCH_FORCE=0; ARG_PARALLEL=1; ARG_RELAXED=0;
Lucio Andrés Illanes Albornoz f243be
	ARG_RESTART=""; ARG_VERBOSE=0;
Lucio Andrés Illanes Albornoz c6d6e0
Lucio Andrés Illanes Albornoz c6d6e0
	# Build parameters & state
Lucio Andrés Illanes Albornoz 8a27f9
	BUILD_HNAME=""; BUILD_IS_PARENT=1; BUILD_GROUPS=""; BUILD_GROUPS_INHIBIT_DEPS=0;
Lucio Andrés Illanes Albornoz 8a27f9
	BUILD_TARGET=""; BUILD_USER=""; MIDIPIX_BUILD_PWD="";
Lucio Andrés Illanes Albornoz c6d6e0
Lucio Andrés Illanes Albornoz c6d6e0
	# Global defaults
Lucio Andrés Illanes Albornoz c6d6e0
	DEFAULT_BUILD_CPUS=1;
Lucio Andrés Illanes Albornoz c6d6e0
	DEFAULT_BUILD_LAST_FAILED_PKG_FNAME=""
Lucio Andrés Illanes Albornoz c6d6e0
	DEFAULT_BUILD_LOG_FNAME="";
Lucio Andrés Illanes Albornoz c6d6e0
	DEFAULT_BUILD_STATUS_IN_PROGRESS_FNAME="";
Lucio Andrés Illanes Albornoz c6d6e0
	DEFAULT_BUILD_STEPS="";
Lucio Andrés Illanes Albornoz c6d6e0
	DEFAULT_BUILD_VARS="";
Lucio Andrés Illanes Albornoz c6d6e0
	DEFAULT_CLEAR_PREFIX_PATHS="";
Lucio Andrés Illanes Albornoz c6d6e0
	DEFAULT_GIT_ARGS="";
Lucio Andrés Illanes Albornoz c6d6e0
	DEFAULT_GITROOT_HEAD="";
Lucio Andrés Illanes Albornoz c6d6e0
	DEFAULT_LOG_ENV_VARS="";
Lucio Andrés Illanes Albornoz c6d6e0
	DEFAULT_TARGET="";
Lucio Andrés Illanes Albornoz c6d6e0
	DEFAULT_WGET_ARGS="";
Lucio Andrés Illanes Albornoz c6d6e0
Lucio Andrés Illanes Albornoz c6d6e0
	return "${_rc}";
Lucio Andrés Illanes Albornoz c3bcd7
};
Lucio Andrés Illanes Albornoz c3bcd7
Lucio Andrés Illanes Albornoz c3bcd7
buildp_init_env() {
Lucio Andrés Illanes Albornoz 9d2842
	local _fname="" _rc=0; _status="";
Lucio Andrés Illanes Albornoz 8a27f9
	if ! umask 022; then
Lucio Andrés Illanes Albornoz 6d9a3c
		printf "Error: failed to setup environment.\n"; exit 1;
Lucio Andrés Illanes Albornoz 6d9a3c
	else	for _fname in $(find subr -name *.subr); do
Lucio Andrés Illanes Albornoz 6d9a3c
			if ! . "${_fname}"; then
Lucio Andrés Illanes Albornoz 6d9a3c
				printf "Error: failed to source \`%s'.\n" "${_fname}"; exit 1;
Lucio Andrés Illanes Albornoz 6d9a3c
			fi;
Lucio Andrés Illanes Albornoz 9d2842
		done; fi;
Lucio Andrés Illanes Albornoz c3bcd7
	return "${_rc}";
Lucio Andrés Illanes Albornoz c3bcd7
};
Lucio Andrés Illanes Albornoz c3bcd7
Lucio Andrés Illanes Albornoz c3bcd7
buildp_init_files() {
Lucio Andrés Illanes Albornoz c3bcd7
	local _log_last_fname="" _log_last_ts="" _rc=0; _status=""
Lucio Andrés Illanes Albornoz c6d6e0
	if ! rtl_fileop mkdir "${BUILD_DLCACHEDIR}" "${BUILD_WORKDIR}"\
Lucio Andrés Illanes Albornoz c6d6e0
	|| rtl_lmatch "${ARG_DIST}" "rpm" ","\
Lucio Andrés Illanes Albornoz c6d6e0
	&& ! rtl_fileop mkdir "${PREFIX_RPM}"; then
Lucio Andrés Illanes Albornoz c6d6e0
		_rc=1; _status="Error: cannot create build directories.";
Lucio Andrés Illanes Albornoz 2b85d0
	elif [ -e "${DEFAULT_BUILD_STATUS_IN_PROGRESS_FNAME}" ]; then
Lucio Andrés Illanes Albornoz c6d6e0
		_rc=1; _status="Error: another build targeting this architecture and build type is currently in progress.";
Lucio Andrés Illanes Albornoz c6d6e0
	elif ! rtl_clean_env "${DEFAULT_CLEAR_ENV_VARS_EXCEPT}"; then
Lucio Andrés Illanes Albornoz c6d6e0
		_rc=1; _status="Error: failed to clean environment.";
Lucio Andrés Illanes Albornoz c6d6e0
	elif ! rtl_check_path_vars "${DEFAULT_CHECK_PATH_VARS}"; then
Lucio Andrés Illanes Albornoz 8a27f9
		_rc=1; _status="${_status}";
Lucio Andrés Illanes Albornoz c3bcd7
	else
Lucio Andrés Illanes Albornoz c3bcd7
		touch "${DEFAULT_BUILD_STATUS_IN_PROGRESS_FNAME}";
Lucio Andrés Illanes Albornoz c3bcd7
		if [ -e "${DEFAULT_BUILD_LOG_FNAME}" ]; then
Lucio Andrés Illanes Albornoz c3bcd7
			_log_last_ts="$(stat -c %Y "${DEFAULT_BUILD_LOG_FNAME}")";
Lucio Andrés Illanes Albornoz c3bcd7
			_log_last_ts="$(awk 'BEGIN {printf(strftime("%Y-%m-%d-%H-%M-%S", '"${_log_last_ts}"'))}')";
Lucio Andrés Illanes Albornoz c3bcd7
			_log_last_fname="${DEFAULT_BUILD_LOG_FNAME}.${_log_last_ts}";
Lucio Andrés Illanes Albornoz c6d6e0
			rtl_fileop mv "${DEFAULT_BUILD_LOG_FNAME}" "${_log_last_fname}";
Lucio Andrés Illanes Albornoz c6d6e0
			rtl_fileop ln_symbolic "${_log_last_fname}" "${DEFAULT_BUILD_LOG_LAST_FNAME}";
Lucio Andrés Illanes Albornoz c6d6e0
		fi;
Lucio Andrés Illanes Albornoz c6d6e0
		rtl_fileop touch "${DEFAULT_BUILD_LOG_FNAME}";
Lucio Andrés Illanes Albornoz c6d6e0
		if rtl_lmatch "${ARG_CLEAN_BUILDS}" "prefix" ","; then
Lucio Andrés Illanes Albornoz c6d6e0
			rtl_log_msg info "-C prefix specified, cleaning prefix...";
Lucio Andrés Illanes Albornoz c6d6e0
			for _pname in ${DEFAULT_CLEAR_PREFIX_PATHS}; do
Lucio Andrés Illanes Albornoz c6d6e0
				if ! rtl_fileop rm "${PREFIX}/${_pname}"; then
Lucio Andrés Illanes Albornoz c6d6e0
					_rc=1; _status="Error: failed to remove \`${PREFIX}/${_pname}'."; break;
Lucio Andrés Illanes Albornoz c6d6e0
				fi;
Lucio Andrés Illanes Albornoz c6d6e0
			done;
Lucio Andrés Illanes Albornoz c3bcd7
		fi;
Lucio Andrés Illanes Albornoz c6d6e0
		export PATH="${PREFIX}/bin${PATH:+:${PATH}}";
Lucio Andrés Illanes Albornoz c3bcd7
	fi;
Lucio Andrés Illanes Albornoz c3bcd7
	return "${_rc}";
Lucio Andrés Illanes Albornoz c3bcd7
};
Lucio Andrés Illanes Albornoz c3bcd7
Lucio Andrés Illanes Albornoz c3bcd7
buildp_init_getopts() {
Lucio Andrés Illanes Albornoz 487c40
	local _arg="" _opt="" _rc=0 _shiftfl=0 OPTIND=0; _status="";
Lucio Andrés Illanes Albornoz c3bcd7
	while [ "${#}" -gt 0 ]; do
Lucio Andrés Illanes Albornoz c3bcd7
		case "${1}" in
Lucio Andrés Illanes Albornoz c3bcd7
		--as-needed)	ARG_AS_NEEDED=1; _shiftfl=1; ;;
Lucio Andrés Illanes Albornoz f243be
		--dump-in)	if [ "${#}" -ge 2 ]; then
Lucio Andrés Illanes Albornoz f243be
					ARG_DUMP_IN="${2}"; ARG_DUMP_ON_ABORT=1; _shiftfl=2;
Lucio Andrés Illanes Albornoz f243be
				else
Lucio Andrés Illanes Albornoz f243be
					_rc=1; _status="Error: missing argument to option --dump-in.";
Lucio Andrés Illanes Albornoz f243be
				fi; ;;
Lucio Andrés Illanes Albornoz 8a27f9
		--dump-on-abort)
Lucio Andrés Illanes Albornoz 8a27f9
				ARG_DUMP_ON_ABORT=1; _shiftfl=1; ;;
Lucio Andrés Illanes Albornoz c3bcd7
		--debug-minipx)	ARG_DEBUG_MINIPIX=1; _shiftfl=1; ;;
Lucio Andrés Illanes Albornoz c3bcd7
		-v*)		_opt="${1#-}"; while [ -n "${_opt}" ]; do
Lucio Andrés Illanes Albornoz c3bcd7
					: $((ARG_VERBOSE+=1)); _opt="${_opt#?}";
Lucio Andrés Illanes Albornoz c3bcd7
				done; _shiftfl=1; ;;
Lucio Andrés Illanes Albornoz c3bcd7
		*)		_shiftfl=0; ;;
Lucio Andrés Illanes Albornoz c3bcd7
		esac;
Lucio Andrés Illanes Albornoz f243be
		if [ "${_rc}" -ne 0 ]; then
Lucio Andrés Illanes Albornoz f243be
			break;
Lucio Andrés Illanes Albornoz f243be
		elif [ "${_shiftfl}" -gt 0 ]; then
Lucio Andrés Illanes Albornoz c3bcd7
			shift "${_shiftfl}"; continue;
Lucio Andrés Illanes Albornoz 8f50a3
		elif getopts a:b:C:D:Fhp:Pr:R _opt; then
Lucio Andrés Illanes Albornoz c3bcd7
			case "${_opt}" in
Lucio Andrés Illanes Albornoz c3bcd7
			a)	ARCH="${OPTARG}"; ;;
Lucio Andrés Illanes Albornoz c3bcd7
			b)	BUILD="${OPTARG}"; ;;
Lucio Andrés Illanes Albornoz c3bcd7
			C)	ARG_CLEAN_BUILDS="${OPTARG}"; ;;
Lucio Andrés Illanes Albornoz c3bcd7
			D)	ARG_DIST="${OPTARG}"; ;;
Lucio Andrés Illanes Albornoz c3bcd7
			F)	ARG_FETCH_FORCE=1; ;;
Lucio Andrés Illanes Albornoz c3bcd7
			h)	cat etc/build.usage; exit 0; ;;
Lucio Andrés Illanes Albornoz 8f50a3
			p)	ARG_PARALLEL="${OPTARG}"; ;;
Lucio Andrés Illanes Albornoz 8f50a3
			P)	ARG_PARALLEL="auto"; ;;
Lucio Andrés Illanes Albornoz c3bcd7
			r)	ARG_RESTART="${OPTARG}"; ;;
Lucio Andrés Illanes Albornoz c3bcd7
			R)	ARG_RELAXED=1; ;;
Lucio Andrés Illanes Albornoz c3bcd7
			*)	cat etc/build.usage; exit 1; ;;
Lucio Andrés Illanes Albornoz 8f50a3
			esac; shift $((${OPTIND}-1)); OPTIND=1;
Lucio Andrés Illanes Albornoz c3bcd7
		else
Lucio Andrés Illanes Albornoz c240c2
			break;
Lucio Andrés Illanes Albornoz c3bcd7
		fi;
Lucio Andrés Illanes Albornoz c3bcd7
	done;
Lucio Andrés Illanes Albornoz 8f50a3
	if [ "${_rc}" -eq 0 ]; then
Lucio Andrés Illanes Albornoz 5f8a15
		if [ "${ARG_DUMP_ON_ABORT:-0}" -eq 1 ]\
Lucio Andrés Illanes Albornoz 5f8a15
		&& [ "${ARG_RELAXED:-0}" -eq 1 ]; then
Lucio Andrés Illanes Albornoz 5f8a15
			_rc=1; _status="Error: --dump-on-abort excludes -R.";
Lucio Andrés Illanes Albornoz 5f8a15
		else	while [ ${#} -gt 0 ]; do
Lucio Andrés Illanes Albornoz 5f8a15
			if [ "${1#\*}" != "${1}" ]; then
Lucio Andrés Illanes Albornoz 5f8a15
				BUILD_GROUPS_INHIBIT_DEPS=1; _arg="${1#\*}";
Lucio Andrés Illanes Albornoz 5f8a15
			else
Lucio Andrés Illanes Albornoz 5f8a15
				_arg="${1}";
Lucio Andrés Illanes Albornoz 5f8a15
			fi;
Lucio Andrés Illanes Albornoz 5f8a15
			case "${_arg}" in
Lucio Andrés Illanes Albornoz 5f8a15
			*=*)		rtl_set_var_unsafe "${_arg%%=*}" "${_arg#*=}"; ;;
Lucio Andrés Illanes Albornoz 5f8a15
			[^a-zA-Z]*)	_rc=1; _status="Error: build group names must start with [a-zA-Z] (in argument \`${_arg}'.)"; ;;
Lucio Andrés Illanes Albornoz 5f8a15
			*[^_a-zA-Z]*)	_rc=1; _status="Error: build group names must not contain [^_a-zA-Z] (in argument \`${_arg}'.)"; ;;
Lucio Andrés Illanes Albornoz 5f8a15
			*)		BUILD_GROUPS="$(rtl_lconcat "${BUILD_GROUPS}" "${_arg}")"; ;;
Lucio Andrés Illanes Albornoz 5f8a15
			esac; shift; done;
Lucio Andrés Illanes Albornoz 487c40
		fi;
Lucio Andrés Illanes Albornoz 8f50a3
	fi;
Lucio Andrés Illanes Albornoz ae3ff0
	return "${_rc}";
Lucio Andrés Illanes Albornoz c3bcd7
};
Lucio Andrés Illanes Albornoz c3bcd7
Lucio Andrés Illanes Albornoz 487c40
buildp_init_groups() {
Lucio Andrés Illanes Albornoz 487c40
	local _default_build_groups="" _fname="" _group="" _groups="" _rc=0; _status="";
Lucio Andrés Illanes Albornoz 487c40
	for _fname in $(find ./groups -name *.group | sort); do
Lucio Andrés Illanes Albornoz 487c40
		rtl_fileop source_opt "${_fname}";
Lucio Andrés Illanes Albornoz 487c40
		if [ -n "${GROUP_TARGET}" ]; then
Lucio Andrés Illanes Albornoz 487c40
			_group="${GROUP_TARGET}"; unset GROUP_TARGET;
Lucio Andrés Illanes Albornoz 487c40
		else
Lucio Andrés Illanes Albornoz 487c40
			_group="${_fname##*/}"; _group="${_group%.group}"; _group="${_group#*.}";
Lucio Andrés Illanes Albornoz 487c40
		fi;
Lucio Andrés Illanes Albornoz 487c40
		if ! rtl_lmatch "${_groups}" "${_group}"; then
Lucio Andrés Illanes Albornoz 487c40
			_groups="$(rtl_lconcat "${_groups}" "${_group}")";
Lucio Andrés Illanes Albornoz 487c40
			if [ -n "${GROUP_AUTO}" ]; then
Lucio Andrés Illanes Albornoz 487c40
				if [ "${GROUP_AUTO:-0}" -ne 0 ]; then
Lucio Andrés Illanes Albornoz 487c40
					_default_build_groups="$(rtl_lconcat "${_default_build_groups}" "${_group}")";
Lucio Andrés Illanes Albornoz 487c40
				fi;
Lucio Andrés Illanes Albornoz 487c40
				unset GROUP_AUTO;
Lucio Andrés Illanes Albornoz 487c40
			else
Lucio Andrés Illanes Albornoz 487c40
				_default_build_groups="$(rtl_lconcat "${_default_build_groups}" "${_group}")";
Lucio Andrés Illanes Albornoz 487c40
			fi;
Lucio Andrés Illanes Albornoz 487c40
		fi;
Lucio Andrés Illanes Albornoz 487c40
	done;
Lucio Andrés Illanes Albornoz 487c40
	_default_build_groups="$(rtl_uniq "${_default_build_groups}")";
Lucio Andrés Illanes Albornoz 487c40
	if ! rtl_lmatch "${ARG_DIST}" "rpm" ","; then
Lucio Andrés Illanes Albornoz 487c40
		_default_build_groups="$(rtl_lfilter "${_default_build_groups}" "host_deps_rpm")";
Lucio Andrés Illanes Albornoz 487c40
	fi;
Lucio Andrés Illanes Albornoz 487c40
	if [ -z "${BUILD_GROUPS}" ]; then
Lucio Andrés Illanes Albornoz 487c40
		BUILD_GROUPS="${_default_build_groups}";
Lucio Andrés Illanes Albornoz 487c40
	fi;
Lucio Andrés Illanes Albornoz 487c40
	if [ -n "${ARG_DIST}" ]; then
Lucio Andrés Illanes Albornoz 487c40
		BUILD_GROUPS="$(rtl_lconcat "$(rtl_lfilter "${BUILD_GROUPS}" "dist")" "dist")";
Lucio Andrés Illanes Albornoz 487c40
	fi;
Lucio Andrés Illanes Albornoz 487c40
	for _group in ${BUILD_GROUPS}; do
Lucio Andrés Illanes Albornoz 487c40
		if ! rtl_lmatch "${_groups}" "${_group}"; then
Lucio Andrés Illanes Albornoz 487c40
			_rc=1; _status="Error: unknown build group \`${_group}'."; break;
Lucio Andrés Illanes Albornoz 487c40
		fi;
Lucio Andrés Illanes Albornoz 487c40
	done;
Lucio Andrés Illanes Albornoz 487c40
	return "${_rc}";
Lucio Andrés Illanes Albornoz 487c40
};
Lucio Andrés Illanes Albornoz 487c40
Lucio Andrés Illanes Albornoz 9d2842
buildp_init_prereqs() {
Lucio Andrés Illanes Albornoz 9d2842
	local _cmd="" _cmds_missing="" _rc=0; _status="";
Lucio Andrés Illanes Albornoz 9d2842
	for _cmd in	\
Lucio Andrés Illanes Albornoz 9d2842
			awk bunzip2 cat chmod cmake cp date find flock g++	\
Lucio Andrés Illanes Albornoz 9d2842
			gcc git grep gunzip gzip hostname install kill		\
Lucio Andrés Illanes Albornoz 9d2842
			ln lzip make mkdir mkfifo mv paste patch perl		\
Lucio Andrés Illanes Albornoz 9d2842
			pgrep pkill printf readlink rm sed seq sha256sum	\
Lucio Andrés Illanes Albornoz 9d2842
			sort stat tail tar test touch tr wget xz zip; do
Lucio Andrés Illanes Albornoz 9d2842
		if ! which "${_cmd}" >/dev/null 2>&1; then
Lucio Andrés Illanes Albornoz 9d2842
			_cmds_missing="${_cmds_missing:+${_cmds_missing} }${_cmd}";
Lucio Andrés Illanes Albornoz 9d2842
		fi;
Lucio Andrés Illanes Albornoz 9d2842
	done;
Lucio Andrés Illanes Albornoz 9d2842
	if [ -n "${_cmds_missing}" ]; then
Lucio Andrés Illanes Albornoz 9d2842
		_rc=1; _status="Error: missing prerequisite package(s): ${_cmds_missing}";
Lucio Andrés Illanes Albornoz 9d2842
	elif ! awk -V 2>/dev/null | grep -q "^GNU Awk "; then
Lucio Andrés Illanes Albornoz 9d2842
		_rc=1; _status="Error: awk(1) in \$PATH must be GNU Awk.";
Lucio Andrés Illanes Albornoz 9d2842
	elif ! sed --version 2>/dev/null | grep -q "^GNU sed "; then
Lucio Andrés Illanes Albornoz 9d2842
		_rc=1; _status="Error: sed(1) in \$PATH must be GNU sed.";
Lucio Andrés Illanes Albornoz 9d2842
	fi;
Lucio Andrés Illanes Albornoz 9d2842
	return "${_rc}";
Lucio Andrés Illanes Albornoz 9d2842
};
Lucio Andrés Illanes Albornoz 9d2842
Lucio Andrés Illanes Albornoz c3bcd7
buildp_init_vars() {
Lucio Andrés Illanes Albornoz 487c40
	local _rc=0; _status="";
Lucio Andrés Illanes Albornoz c6d6e0
	if ! rtl_lmatch "${ARCH}" "nt32 nt64"; then
Lucio Andrés Illanes Albornoz c6d6e0
		_rc=1; _status="Error: invalid architecture \`${ARCH}'.";
Lucio Andrés Illanes Albornoz c6d6e0
	elif ! rtl_lmatch "${BUILD}" "debug release"; then
Lucio Andrés Illanes Albornoz c6d6e0
		_rc=1; _status="Error: unknown build type \`${BUILD}'.";
Lucio Andrés Illanes Albornoz c6d6e0
	elif [ -n "${ARG_PARALLEL}" ] &&  [ "${ARG_PARALLEL}" != "auto" ]\
Lucio Andrés Illanes Albornoz c6d6e0
	&&   ! rtl_isnumber "${ARG_PARALLEL}"; then
Lucio Andrés Illanes Albornoz c6d6e0
		_rc=1; _status="Error: invalid jobs count \`${ARG_PARALLEL}'.";
Lucio Andrés Illanes Albornoz 487c40
	else	case "${ARCH}" in
Lucio Andrés Illanes Albornoz c6d6e0
		nt32)	DEFAULT_TARGET="i686-nt32-midipix"; ;;
Lucio Andrés Illanes Albornoz c6d6e0
		nt64)	DEFAULT_TARGET="x86_64-nt64-midipix"; ;;
Lucio Andrés Illanes Albornoz c6d6e0
		esac;
Lucio Andrés Illanes Albornoz c6d6e0
		if [ -e "/proc/cpuinfo" ]; then
Lucio Andrés Illanes Albornoz b6e66a
			DEFAULT_BUILD_CPUS="$(awk '/^processor/{cpus++} END{print cpus}' /proc/cpuinfo)";
Lucio Andrés Illanes Albornoz c6d6e0
			if [ "${ARG_PARALLEL}" = "auto" ]\
Lucio Andrés Illanes Albornoz c6d6e0
			&& [ "${DEFAULT_BUILD_CPUS}" -gt 1 ]; then
Lucio Andrés Illanes Albornoz c6d6e0
				ARG_PARALLEL=$((${DEFAULT_BUILD_CPUS}/2));
Lucio Andrés Illanes Albornoz c6d6e0
			fi;
Lucio Andrés Illanes Albornoz b6e66a
		fi;
Lucio Andrés Illanes Albornoz c6d6e0
		rtl_fileop source_opt							\
Lucio Andrés Illanes Albornoz c6d6e0
			"${HOME}/midipix_build.vars" "${HOME}/.midipix_build.vars"	\
Lucio Andrés Illanes Albornoz 1c6fee
			../midipix_build.vars ./midipix.env;
Lucio Andrés Illanes Albornoz c6d6e0
		if [ -z "${PREFIX}" ]; then
Lucio Andrés Illanes Albornoz c6d6e0
			_rc=1; _status="Error: \${PREFIX} empty or unset.";
Lucio Andrés Illanes Albornoz 487c40
		fi; fi;
Lucio Andrés Illanes Albornoz c3bcd7
	return "${_rc}";
Lucio Andrés Illanes Albornoz c3bcd7
};
Lucio Andrés Illanes Albornoz c3bcd7
Lucio Andrés Illanes Albornoz c3bcd7
build_init() {
Lucio Andrés Illanes Albornoz c6d6e0
	local _fname="" _rc=0 _status="";
Lucio Andrés Illanes Albornoz c6d6e0
	if ! buildp_init_env		\
Lucio Andrés Illanes Albornoz c6d6e0
	|| ! buildp_init_defaults	\
Lucio Andrés Illanes Albornoz c3bcd7
	|| ! buildp_init_getopts "${@}"	\
Lucio Andrés Illanes Albornoz 9d2842
	|| ! buildp_init_prereqs	\
Lucio Andrés Illanes Albornoz c3bcd7
	|| ! buildp_init_vars		\
Lucio Andrés Illanes Albornoz 487c40
	|| ! buildp_init_groups		\
Lucio Andrés Illanes Albornoz c3bcd7
	|| ! buildp_init_args		\
Lucio Andrés Illanes Albornoz c6d6e0
	|| ! buildp_init_files; then
Lucio Andrés Illanes Albornoz c6d6e0
		_rc="${?}"; rtl_log_msg fail "${_status}"; exit "${_rc}";
Lucio Andrés Illanes Albornoz c3bcd7
	elif [ -n "${_status}" ]; then
Lucio Andrés Illanes Albornoz c6d6e0
		rtl_log_msg info "${_status}"; exit 0;
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
	else
Lucio Andrés Illanes Albornoz c3bcd7
		return "${_rc}";
Lucio Andrés Illanes Albornoz ed4109
	fi;
Lucio Andrés Illanes Albornoz (arab, vxp) e2fea1
};
Lucio Andrés Illanes Albornoz (arab, vxp) e2fea1
Lucio Andrés Illanes Albornoz (arab, vxp) e2fea1
# vim:filetype=sh