Lucio Andrés Illanes Albornoz c6d6e0
#
Lucio Andrés Illanes Albornoz e1d469
# set +o errexit -o noglob -o nounset 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 3e5303
	local	_foundfl=0 _group="" _pkg_names_unknown="" _rc=0	\
Lucio Andrés Illanes Albornoz 1dd016
		EX_PKG_BUILD_GROUPS EX_PKG_BUILD_GROUPS_NOAUTO; _status="";
Lucio Andrés Illanes Albornoz 1dd016
Lucio Andrés Illanes Albornoz 370e98
	case "${ARG_FETCH_FORCE}" in
Lucio Andrés Illanes Albornoz 370e98
	ipv4)	DEFAULT_GIT_ARGS="$(rtl_lconcat "-4" "${DEFAULT_GIT_ARGS}")";
Lucio Andrés Illanes Albornoz 370e98
		DEFAULT_WGET_ARGS="$(rtl_lconcat "-4" "${DEFAULT_WGET_ARGS}")"; ;;
Lucio Andrés Illanes Albornoz 370e98
	ipv6)	DEFAULT_GIT_ARGS="$(rtl_lconcat "-6" "${DEFAULT_GIT_ARGS}")";
Lucio Andrés Illanes Albornoz 370e98
		DEFAULT_WGET_ARGS="$(rtl_lconcat "-6" "${DEFAULT_WGET_ARGS}")"; ;;
Lucio Andrés Illanes Albornoz 370e98
	esac;
Lucio Andrés Illanes Albornoz 3e5303
	if [ "${BUILD_HNAME:+1}" != 1 ]\
Lucio Andrés Illanes Albornoz 9b5d49
	&& ! BUILD_HNAME="$(hostname)"; then
Lucio Andrés Illanes Albornoz 9b5d49
		_rc=1; _status="Error: failed to obtain hostname.";
Lucio Andrés Illanes Albornoz 9b5d49
	elif [ "${ARG_DUMP_ON_ABORT:-0}" -eq 1 ]\
Lucio Andrés Illanes Albornoz 3e5303
	&&   [ "${ARG_RELAXED:-0}" -eq 1 ]; then
Lucio Andrés Illanes Albornoz b6a9a1
		_rc=1; _status="Error: --dump-on-abort excludes -R.";
Lucio Andrés Illanes Albornoz b6a9a1
	elif [ "${ARG_AS_NEEDED:-0}" -eq 1 ]\
Lucio Andrés Illanes Albornoz 3e5303
	&&   [ -e "${PREFIX}/build.gitref" ]\
Lucio Andrés Illanes Albornoz 3e5303
	&&   [ "$(git rev-parse HEAD)" = "$(cat "${PREFIX}/build.gitref")" ]; then
Lucio Andrés Illanes Albornoz b6a9a1
		_rc=0; _status="Git repository has not changed since last build and --as-needed was specified.";
Lucio Andrés Illanes Albornoz 3e5303
	elif ! ex_pkg_process_restart_spec \$ARG_RESTART \$ARG_RESTART_AT \$ARG_RESTART_RECURSIVE; then
Lucio Andrés Illanes Albornoz 370e98
		_rc=1; _status="Error: failed to process -r specification: ${_status}.";
Lucio Andrés Illanes Albornoz 370e98
	elif ! ex_pkg_load_groups; then
Lucio Andrés Illanes Albornoz 370e98
		_rc=1; _status="Error: failed to load build groups.";
Lucio Andrés Illanes Albornoz 370e98
	else	if ! rtl_lmatch "${ARG_DIST:-}" "rpm" ","\
Lucio Andrés Illanes Albornoz 3e5303
		&& [ "${ARG_DUMP_IN:+1}" != 1 ]\
Lucio Andrés Illanes Albornoz 370e98
		&& [ "${ARG_DUMP_ON_ABORT:-0}" -eq 0 ]; then
Lucio Andrés Illanes Albornoz 370e98
			EX_PKG_BUILD_GROUPS="$(rtl_lfilter "${EX_PKG_BUILD_GROUPS}" "host_deps_rpm")";
Lucio Andrés Illanes Albornoz 370e98
		fi;
Lucio Andrés Illanes Albornoz 3e5303
		if [ "${BUILD_GROUPS:+1}" != 1 ]; then
Lucio Andrés Illanes Albornoz 370e98
			BUILD_GROUPS="${EX_PKG_BUILD_GROUPS}";
Lucio Andrés Illanes Albornoz 370e98
		else	_foundfl=0; for _group in ${BUILD_GROUPS}; do
Lucio Andrés Illanes Albornoz 370e98
				if rtl_lmatch "${EX_PKG_BUILD_GROUPS}" "${_group}"; then
Lucio Andrés Illanes Albornoz 370e98
					_foundfl=1; break;
Lucio Andrés Illanes Albornoz e1d469
				fi;
Lucio Andrés Illanes Albornoz 370e98
			done;
Lucio Andrés Illanes Albornoz 370e98
			if [ "${_foundfl}" -eq 0 ]; then
Lucio Andrés Illanes Albornoz 370e98
				_foundfl=0; for _group in ${BUILD_GROUPS}; do
Lucio Andrés Illanes Albornoz 370e98
					if rtl_lmatch "${EX_PKG_BUILD_GROUPS}" "${_group}"; then
Lucio Andrés Illanes Albornoz 370e98
						_rc=1; _status="Error: unknown build group \`${_group}'."; break;
Lucio Andrés Illanes Albornoz b6a9a1
					fi;
Lucio Andrés Illanes Albornoz 370e98
				done;
Lucio Andrés Illanes Albornoz 370e98
			fi;
Lucio Andrés Illanes Albornoz 370e98
		fi;
Lucio Andrés Illanes Albornoz 370e98
		if [ "${_rc:-0}" -eq 0 ]; then
Lucio Andrés Illanes Albornoz 3e5303
			if [ "${ARG_DIST:+1}" = 1 ]; then
Lucio Andrés Illanes Albornoz 370e98
				BUILD_GROUPS="$(rtl_lconcat "$(rtl_lfilter "${BUILD_GROUPS}" "dist")" "dist")";
Lucio Andrés Illanes Albornoz 370e98
			fi;
Lucio Andrés Illanes Albornoz 3e5303
			if [ "${ARG_RESTART:+1}" = 1 ]\
Lucio Andrés Illanes Albornoz 3e5303
			&& ! rtl_lmatch "${ARG_RESTART}" "ALL LAST"; then
Lucio Andrés Illanes Albornoz 370e98
				for _pkg_name in ${ARG_RESTART}; do
Lucio Andrés Illanes Albornoz 370e98
					if ! ex_pkg_find_package "${BUILD_GROUPS}" "${_pkg_name}" >/dev/null; then
Lucio Andrés Illanes Albornoz 370e98
						_pkg_names_unknown="$(rtl_lconcat "${_pkg_names_unknown}" "${_pkg_name}")";
Lucio Andrés Illanes Albornoz b6a9a1
					fi;
Lucio Andrés Illanes Albornoz 370e98
				done;
Lucio Andrés Illanes Albornoz 370e98
				case "$(rtl_llength "${_pkg_names_unknown}")" in
Lucio Andrés Illanes Albornoz 370e98
				0)	;;
Lucio Andrés Illanes Albornoz 370e98
				1)	_rc=1; _status="Error: unknown package \`${_pkg_names_unknown}'."; ;;
Lucio Andrés Illanes Albornoz 370e98
				*)	_rc=1; _status="Error: unknown packages: $(rtl_subst "${_pkg_names_unknown}" " " ", ")"; ;;
Lucio Andrés Illanes Albornoz 370e98
				esac;
Lucio Andrés Illanes Albornoz b6a9a1
			fi;
Lucio Andrés Illanes Albornoz c3bcd7
		fi;
Lucio Andrés Illanes Albornoz b6a9a1
	fi; 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 3e5303
Lucio Andrés Illanes Albornoz b6a9a1
	if ! cd "${0%/*}"; then
Lucio Andrés Illanes Albornoz b6a9a1
		printf "Error: failed to change working directory to \`${0%/*}'." >&2; exit 1;
Lucio Andrés Illanes Albornoz b6a9a1
	elif ! umask 022; then
Lucio Andrés Illanes Albornoz b6a9a1
		printf "Error: failed to set umask(2).\n" >&2; exit 1;
Lucio Andrés Illanes Albornoz b6a9a1
	elif ! BUILD_USER="$(id -nu)"; then
Lucio Andrés Illanes Albornoz 11ef38
		printf "Error: failed to obtain username." >&2; exit 1;
Lucio Andrés Illanes Albornoz 612534
	else	for _fname in $(find subr.rtl -name *.subr) $(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 b6a9a1
		done;
Lucio Andrés Illanes Albornoz b6a9a1
	fi; 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 0d1c4f
	local _log_last_fname="" _log_last_num=1 _rc=0; _status=""
Lucio Andrés Illanes Albornoz 3e5303
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 98c928
	else	export TMP="${BUILD_WORKDIR}" TMPDIR="${BUILD_WORKDIR}";
Lucio Andrés Illanes Albornoz 98c928
		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 0d1c4f
			while [ -e "${DEFAULT_BUILD_LOG_FNAME}.${_log_last_num}" ]; do
Lucio Andrés Illanes Albornoz 0d1c4f
				: $((_log_last_num+=1));
Lucio Andrés Illanes Albornoz 0d1c4f
			done;
Lucio Andrés Illanes Albornoz 0d1c4f
			_log_last_fname="${DEFAULT_BUILD_LOG_FNAME}.${_log_last_num}";
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 b6a9a1
		rtl_fileop touch "${DEFAULT_BUILD_LOG_FNAME}"; rtl_log_set_fname "${DEFAULT_BUILD_LOG_FNAME}";
Lucio Andrés Illanes Albornoz c6d6e0
		if rtl_lmatch "${ARG_CLEAN_BUILDS}" "prefix" ","; then
Lucio Andrés Illanes Albornoz 0a3032
			trap "rm -f \"${DEFAULT_BUILD_STATUS_IN_PROGRESS_FNAME}\" 2>/dev/null; rtl_log_msg fatalexit \"Build aborted.\"" HUP INT TERM USR1 USR2;
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 144d63
			trap - HUP INT TERM USR1 USR2;
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 30cdf7
	local _arg="" _level="" _opt="" _rc=0 _shiftfl=0 _verbose=0 OPTIND=0; _status="";
Lucio Andrés Illanes Albornoz 30cdf7
Lucio Andrés Illanes Albornoz a6970c
	: ${ARCH:="nt64"}; : ${BUILD_KIND:="debug"};
Lucio Andrés Illanes Albornoz dd8dfb
	ARG_AS_NEEDED=0; ARG_CLEAN_BUILDS=""; ARG_DEBUG_MINIPIX=0; ARG_DIST=""; ARG_DUMP_IN="";
Lucio Andrés Illanes Albornoz 370e98
	ARG_DUMP_ON_ABORT=0; ARG_FETCH_FORCE=""; ARG_PARALLEL=1; ARG_RELAXED=0; ARG_RESET_PKG=0;
Lucio Andrés Illanes Albornoz 30cdf7
	ARG_RESTART=""; ARG_RESTART_AT=""; ARG_RESTART_RECURSIVE=""; ARG_VERBOSE_LEVELS="";
Lucio Andrés Illanes Albornoz 30cdf7
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 171651
		--help)
Lucio Andrés Illanes Albornoz 171651
			if [ -t 1 ]; then
Lucio Andrés Illanes Albornoz 171651
				cat etc/build.usage;
Lucio Andrés Illanes Albornoz 171651
			else
Lucio Andrés Illanes Albornoz 171651
				sed 's/?\[[0-9]\+m//g' etc/build.usage;
Lucio Andrés Illanes Albornoz 171651
			fi; exit 0; ;;
Lucio Andrés Illanes Albornoz 370e98
		--reset-state)	ARG_RESET_PKG=1; _shiftfl=1; ;;
Lucio Andrés Illanes Albornoz c3bcd7
		-v*)		_opt="${1#-}"; while [ -n "${_opt}" ]; do
Lucio Andrés Illanes Albornoz 30cdf7
					: $((_verbose+=1)); _opt="${_opt#?}";
Lucio Andrés Illanes Albornoz c3bcd7
				done; _shiftfl=1; ;;
Lucio Andrés Illanes Albornoz 75bb81
		# {{{ --roar
Lucio Andrés Illanes Albornoz 75bb81
		--roar)		printf "%s\n" '
Lucio Andrés Illanes Albornoz 75bb81
?[49;37m                ?[41;97m     ?[49;37m            ?[0m
Lucio Andrés Illanes Albornoz 75bb81
?[49;37m             ?[41;97m           ?[49;37m         ?[0m
Lucio Andrés Illanes Albornoz 75bb81
?[103;31m%.?[49;37m          ?[41;33m ?[103;33m/\?[41;31m  ?[41;97m     ?[103;33m/\?[41;97m ?[49;97m   ROAR!?[0m
Lucio Andrés Illanes Albornoz 75bb81
?[103;31m`%%.?[49;37m        ?[41;33m ?[41;31m  ?[103;31m  ?[103;33m"""?[103;31m ?[103;30m ?[41;30m   ?[49;97m  /?[49;37m     ?[0m
Lucio Andrés Illanes Albornoz 75bb81
?[49;37m ?[103;31m`%%?[49;37m        ?[41;97m ?[103;97m   ?[103;32mo?[103;97m ?[103;30m_?[103;97m ?[103;32mo?[103;97m   ?[41;31m ?[49;97m /?[49;37m      ?[0m
Lucio Andrés Illanes Albornoz 75bb81
?[49;37m ?[103;30m//?[49;37m        ?[103;30m;?[41;33m  ?[103;31m ?[103;33m(__?[103;30mY?[103;33m__)?[103;30m ?[41;31m ?[41;97m ?[49;37m        ?[0m
Lucio Andrés Illanes Albornoz 75bb81
?[103;30m((?[49;37m        ?[103;30m/?[103;33m ?[103;97m  ?[41;97m  ?[103;33m`\_/?[41;30m ?[41;97m  ?[49;37m          ?[0m
Lucio Andrés Illanes Albornoz 75bb81
?[49;37m ?[103;30m\\?[49;37m     ?[103;30m.'\''  ?[103;97m  ?[103;31m  ?[41;31m     ?[49;37m            ?[0m
Lucio Andrés Illanes Albornoz 75bb81
?[49;37m  ?[103;30m\\?[49;37m   ?[103;30m/?[103;97m         ?[41;97m   ?[49;37m             ?[0m
Lucio Andrés Illanes Albornoz 75bb81
?[49;37m   ?[103;30m\\/   ?[103;97m ?[103;30m\?[103;97m    ?[103;30m|?[103;33m ?[103;30m|?[49;37m               ?[0m
Lucio Andrés Illanes Albornoz 75bb81
?[49;37m    ?[103;30m\?[103;33m      ?[103;30m)___|?[103;33m ?[103;30m|?[49;37m               ?[0m
Lucio Andrés Illanes Albornoz 75bb81
?[49;37m   ?[103;30m(_____/__)))))))?[49;37m              ?[0m'; exit 0; ;;
Lucio Andrés Illanes Albornoz 75bb81
		# }}}
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 30cdf7
		elif getopts a:b:C:D:F:hp:Pr:RxV: _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 a6970c
			b)	BUILD_KIND="${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 157d4b
			F)	ARG_FETCH_FORCE="${OPTARG}"; ;;
Lucio Andrés Illanes Albornoz 171651
			h)
Lucio Andrés Illanes Albornoz 171651
				if [ -t 1 ]; then
Lucio Andrés Illanes Albornoz 171651
					cat etc/build.usage.short;
Lucio Andrés Illanes Albornoz 171651
				else
Lucio Andrés Illanes Albornoz 171651
					sed 's/?\[[0-9]\+m//g' etc/build.usage.short;
Lucio Andrés Illanes Albornoz 171651
				fi; exit 0; ;;
Lucio Andrés Illanes Albornoz 8f50a3
			p)	ARG_PARALLEL="${OPTARG}"; ;;
Lucio Andrés Illanes Albornoz 73f6c6
			P)	ARG_PARALLEL="auto";
Lucio Andrés Illanes Albornoz 73f6c6
				if [ -n "${2:-}" ]\
Lucio Andrés Illanes Albornoz 73f6c6
				&& rtl_isnumber "${2}"; then
Lucio Andrés Illanes Albornoz 73f6c6
					_rc=1; _status="Error: maximum parallelisation job count is set with the \`-p jobs' option."; break
Lucio Andrés Illanes Albornoz 73f6c6
				fi; ;;
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 30cdf7
			x)	ARG_VERBOSE_LEVELS="${ARG_VERBOSE_LEVELS:+${ARG_VERBOSE_LEVELS},}xtrace"; ;;
Lucio Andrés Illanes Albornoz 30cdf7
			V)	ARG_VERBOSE_LEVELS="${OPTARG}"; ;;
Lucio Andrés Illanes Albornoz 370e98
			*)	cat etc/build.usage.short; exit 1; ;;
Lucio Andrés Illanes Albornoz 8f50a3
			esac; shift $((${OPTIND}-1)); OPTIND=1;
Lucio Andrés Illanes Albornoz 286c43
		else	if rtl_match "${1}" "=*"; then
Lucio Andrés Illanes Albornoz b6a9a1
				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 a7ecdc
			[!a-zA-Z]*)	_rc=1; _status="Error: build group names must start with [a-zA-Z] (in argument \`${_arg}'.)"; ;;
Lucio Andrés Illanes Albornoz a7ecdc
			*[!_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 b6a9a1
			esac; shift;
Lucio Andrés Illanes Albornoz 286c43
		fi;
Lucio Andrés Illanes Albornoz 286c43
	done;
Lucio Andrés Illanes Albornoz 286c43
	if [ "${_rc:-0}" -eq 0 ]; then
Lucio Andrés Illanes Albornoz 286c43
		case "${ARG_PARALLEL}" in
Lucio Andrés Illanes Albornoz 286c43
		auto)	if ! ARG_PARALLEL="$(rtl_get_cpu_count)"; then
Lucio Andrés Illanes Albornoz 286c43
				_rc=1; _status="Error: failed to get CPU count.";
Lucio Andrés Illanes Albornoz 286c43
			else
Lucio Andrés Illanes Albornoz 286c43
				ARG_PARALLEL=$((${ARG_PARALLEL}/2));
Lucio Andrés Illanes Albornoz 286c43
			fi; ;;
Lucio Andrés Illanes Albornoz 286c43
		"")	ARG_PARALLEL=1; ;;
Lucio Andrés Illanes Albornoz 286c43
		*)	if ! rtl_isnumber "${ARG_PARALLEL}"; then
Lucio Andrés Illanes Albornoz 286c43
				_rc=1; _status="Error: invalid jobs count \`${ARG_PARALLEL}'.";
Lucio Andrés Illanes Albornoz 286c43
			fi; ;;
Lucio Andrés Illanes Albornoz 286c43
		esac;
Lucio Andrés Illanes Albornoz e1d469
		if [ "${_rc:-0}" -eq 0 ]; then
Lucio Andrés Illanes Albornoz 286c43
			DEFAULT_BUILD_CPUS="${ARG_PARALLEL}";
Lucio Andrés Illanes Albornoz 30cdf7
			case "${_verbose:-0}" in
Lucio Andrés Illanes Albornoz 30cdf7
			0)	;;
Lucio Andrés Illanes Albornoz 30cdf7
			1)	ARG_VERBOSE_LEVELS="${ARG_VERBOSE_LEVELS:+${ARG_VERBOSE_LEVELS},}notice"; ;;
Lucio Andrés Illanes Albornoz 30cdf7
			2)	ARG_VERBOSE_LEVELS="${ARG_VERBOSE_LEVELS:+${ARG_VERBOSE_LEVELS},}verbose"; ;;
Lucio Andrés Illanes Albornoz 30cdf7
			*)	_rc=1; _status="Error: invalid verbosity level (max. -vv)"; ;;
Lucio Andrés Illanes Albornoz e1d469
			esac;
Lucio Andrés Illanes Albornoz 30cdf7
			rtl_log_set_lvl 0;
Lucio Andrés Illanes Albornoz 30cdf7
			for _level in $(rtl_llift "${ARG_VERBOSE_LEVELS}" "," " "); do
Lucio Andrés Illanes Albornoz 30cdf7
				case "${_level}" in
Lucio Andrés Illanes Albornoz 30cdf7
				notice)		rtl_log_set_lvl 1; ;;
Lucio Andrés Illanes Albornoz 30cdf7
				verbose)	rtl_log_set_lvl 2; ;;
Lucio Andrés Illanes Albornoz 30cdf7
				build|install|xtrace)
Lucio Andrés Illanes Albornoz 77458d
						rtl_log_set_lvl 1; ;;
Lucio Andrés Illanes Albornoz 77458d
				fileops)	rtl_log_set_lvl 1; rtl_fileop_set_log 1; ;;
Lucio Andrés Illanes Albornoz 30cdf7
				*)		_rc=1; _status="Error: invalid verbosity level \`${_level}'"; ;;
Lucio Andrés Illanes Albornoz 30cdf7
				esac;
Lucio Andrés Illanes Albornoz 30cdf7
			done;
Lucio Andrés Illanes Albornoz e1d469
		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 9d2842
buildp_init_prereqs() {
Lucio Andrés Illanes Albornoz 3e5303
	if ! rtl_check_prereqs ${DEFAULT_PREREQS}; then
Lucio Andrés Illanes Albornoz 11ef38
		printf "%s\n" "${_status}" >&2; exit 1;
Lucio Andrés Illanes Albornoz a778c2
	elif ! awk -V 2>/dev/null | grep -q "^GNU Awk "; then
Lucio Andrés Illanes Albornoz a778c2
		printf "Error: awk(1) in \$PATH must be GNU Awk." >&2; exit 1;
Lucio Andrés Illanes Albornoz 3e5303
	elif ! (FNAME="$(mktemp)" && { trap "rm -f \"\${FNAME}\"" EXIT;	\
Lucio Andrés Illanes Albornoz 0d1c4f
			sed -i'' -e '' "${FNAME}" >/dev/null 2>&1; }); then
Lucio Andrés Illanes Albornoz 11ef38
		printf "Error: sed(1) in \${PATH} does not support the \`-i' option.\n" >&2; exit 1;
Lucio Andrés Illanes Albornoz 9d2842
	fi;
Lucio Andrés Illanes Albornoz 9d2842
};
Lucio Andrés Illanes Albornoz 9d2842
Lucio Andrés Illanes Albornoz c3bcd7
build_init() {
Lucio Andrés Illanes Albornoz b6a9a1
	local _rc=0; _status="";
Lucio Andrés Illanes Albornoz 11ef38
	if ! buildp_init_env			\
Lucio Andrés Illanes Albornoz 11ef38
	|| ! buildp_init_getopts "${@}"		\
Lucio Andrés Illanes Albornoz 11ef38
	|| ! ex_pkg_load_vars			\
Lucio Andrés Illanes Albornoz 3e5303
	|| ! buildp_init_prereqs		\
Lucio Andrés Illanes Albornoz 11ef38
	|| ! buildp_init_args			\
Lucio Andrés Illanes Albornoz c6d6e0
	|| ! buildp_init_files; then
Lucio Andrés Illanes Albornoz b6a9a1
		_rc=1; _status="${_status}";
Lucio Andrés Illanes Albornoz b6a9a1
	fi; return "${_rc}";
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