Conan_Kudo / build / midipix_build

Forked from build/midipix_build 4 years ago
Clone

Blame build.subr

Lucio Andrés Illanes Albornoz (arab, vxp) 6e940c
#
Lucio Andrés Illanes Albornoz (arab, vxp) 31dc75
# . ./build.vars and set -o errexit are assumed.
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
# See warning at the top of build.vars.
Lucio Andrés Illanes Albornoz (arab, vxp) 6e940c
#
Lucio Andrés Illanes Albornoz (arab, vxp) 6e940c
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
date() { command date +"${1:-${TIMESTAMP_FMT}}"; };
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
fetch_git() { [ -d ${1} ] && (cd ${1} && git pull origin main) || git clone ${3} ${2} ${1}; };
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
get_basename() { set -- $(get_name_without_slash ${1}); echo "${1##*/}"; };
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
get_var() { eval echo \${${1}}; }; # XXX
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
set_var() { eval ${1}=\"${2}\"; }; # XXX
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
get_name_without_slash() { while [ "x${1%/}" != "x${1}" ]; do set -- ${1%/}; done; echo ${1}; };
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
get_postfix_lrg() { echo "${1##*${2}}"; };
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
get_prefix_lrg() { echo "${1%%${2}*}"; };
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
get_postfix() { echo "${1#*${2}}"; };
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
get_prefix() { echo "${1%${2}*}"; };
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
match_any() { [ "x${1#*${2}*}" != "x${1}" ]; };
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
match_start() { [ "x${1#${2}}" != "x${1}" ]; };
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
push_IFS() { _IFS="${IFS}"; IFS="${1}"; };
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
pop_IFS() { IFS="${_IFS}"; unset _IFS; };
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
set_build_dir() { BUILD_DIR=${1}-${2}-${TARGET}; };
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
split() { push_IFS "${1}"; set -- ${2}; pop_IFS; echo "${*}"; };
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
unsplit() { push_IFS "${1}"; shift; set -- "${@}"; echo "${*}"; pop_IFS; };
lalbornoz 340f4c
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
rm_if_exists() {
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
	set_flag_vars_from_args "$@"; shift ${_nshift:-0};
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
	[ -d ${1} ] && rm -rf ${1}; [ -f ${1} ] && rm -f ${1};
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
	[ ${_arg_m:-0} -eq 1 ] && mkdir ${1};
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
	[ ${_arg_c:-0} -eq 1 ] && cd ${1};
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
	unset_flag_vars_from_args;
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
};
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
set_flag_vars_from_args() {
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
	unset _flag_vars _nshift;
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
	while [ ${#} -gt 1 ]; do
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
		if [ "x${1%[a-z]}" = "x-" ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
			set_var _arg_${1#-} 1;
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
			_flag_vars="${_flag_vars:+${_flag_vars} }_arg_${1#-}";
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
			: $((_nshift+=1));
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
		fi; shift;
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
	done;
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
};
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
unset_flag_vars_from_args() {
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
	set -- ${_flag_vars}; while [ ${#} -gt 0 ]; do
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
		unset ${1}; shift; done; unset _flag_vars _nshift;
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
};
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
set_env_vars() {
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
	_val_new="${1}"; shift;
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
	while [ ${#} -gt 1 ]; do
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
		[ -z "${_val_new}" ] && unset ${1} ||\
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
			export "${1}=${_val_new}"; shift;
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
	done; unset _val_new;
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
};
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
# Download GNU bash-style patch sets into ${2}-patches-extra and
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
# apply them to ${2} in the correct order.
Lucio Andrés Illanes Albornoz (arab, vxp) f9c386
apply_patches() {
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
	(rm_if_exists -m -c ${2}-patches-extra;
Lucio Andrés Illanes Albornoz (arab, vxp) f9c386
	wget -c -nd -np -r -R \*.htm\* -R \*.sig ${1};
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
	for _patch_fname in		\
Lucio Andrés Illanes Albornoz (arab, vxp) f9c386
			$(find . -type f -not -iname \*.sig | sort); do
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
		patch -b -d ../${2} -p0	\
Lucio Andrés Illanes Albornoz (arab, vxp) f9c386
			< ${_patch_fname};
Lucio Andrés Illanes Albornoz (arab, vxp) f9c386
	done; unset _patch_fname);
Lucio Andrés Illanes Albornoz (arab, vxp) f9c386
};
Lucio Andrés Illanes Albornoz (arab, vxp) f9c386
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
# Check whether all supplied arguments contain non-empty valid values.
Lucio Andrés Illanes Albornoz (arab, vxp) d30b8f
check_path_vars() {
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
	while [ ${#} -gt 0 ]; do
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
		unset _val;
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
		if [ -z "${_val:=$(get_var "${1}")}" ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
			log_msg failexit "Error: variable \`${1}' is empty or unset.";
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
		elif match_any "${_val}" " "; then
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
			log_msg failexit "Error: variable \`${1}' contains one or more whitespace characters.";
Lucio Andrés Illanes Albornoz (arab, vxp) d30b8f
		else
Lucio Andrés Illanes Albornoz (arab, vxp) d30b8f
			shift;
Lucio Andrés Illanes Albornoz (arab, vxp) d30b8f
		fi;
Lucio Andrés Illanes Albornoz (arab, vxp) d30b8f
	done; unset _val;
Lucio Andrés Illanes Albornoz (arab, vxp) d30b8f
};
Lucio Andrés Illanes Albornoz (arab, vxp) d30b8f
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
# Check whether all supplied command names resolve.
Lucio Andrés Illanes Albornoz (arab, vxp) f5eeee
check_prereqs() {
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
	while [ ${#} -gt 0 ]; do
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
		if ! command -v ${1} >/dev/null; then
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
			log_msg failexit "Error: missing prerequisite command \`${1}'.";
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
		fi; shift;
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
	done;
Lucio Andrés Illanes Albornoz (arab, vxp) f5eeee
};
Lucio Andrés Illanes Albornoz (arab, vxp) f5eeee
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
# Clear the environment by unsetting each exported variable except
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
# for those named by the caller. 
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
clear_env_with_except() {
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
	_vfilter="${*}"; _unset_cmds="$(mktemp -q)";
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
	export | while read _vspec; do
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
		set -- ${_vspec}; shift;
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
		if ! match_list "${_vfilter}" " "	\
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
				$(get_prefix_lrg ${1} =); then
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
			echo unset $(get_prefix_lrg ${1} =) >> ${_unset_cmds};
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
		fi;
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
	done; . "${_unset_cmds}"; rm -f "${_unset_cmds}" 2>/dev/null;
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
	unset _vfilter _vspec;
lalbornoz 340f4c
};
lalbornoz 340f4c
lalbornoz 340f4c
fetch() {
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
	wget ${WGET_ARGS} ${1};
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
	if [ ${#} -eq 2 ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
		set -- $(get_basename ${1}) "$(compare_hash $(get_basename ${1}) ${2})" ${2};
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
		if [ -n "${2}" ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
			log_msg failexit "Error: hash mismatch for URL \`${1}' (is: ${2}, should be: ${3}.)";
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
		fi;
lalbornoz 340f4c
	fi;
lalbornoz 340f4c
};
lalbornoz 340f4c
Lucio Andrés Illanes Albornoz (arab, vxp) 6e940c
compare_hash() {
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
	# Push the output of dgst(1SSL) and the caller-supplied hash
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
	# value to compare the former with on the pseudo-stack and
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
	# shift off# all but the last two positional parameters.
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
	# This corresponds to the hash output and caller-supplied
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
	# hash values.
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
	set -- $(openssl dgst -sha256 ${1}) ${2}; shift $((${#}-2));
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
	[ "x${1}" = "x${2}" ] || echo "${1}";
Lucio Andrés Illanes Albornoz (arab, vxp) 6e940c
};
Lucio Andrés Illanes Albornoz (arab, vxp) f9c386
compare_hash_manifest() {
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
	while [ ${#} -gt 0 ]; do
Lucio Andrés Illanes Albornoz (arab, vxp) f9c386
		if ! compare_hash ${1} ${2}; then
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
			log_msg failexit "Error: hash mismatch for patch file \`${1}'.";
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
		fi; shift;
Lucio Andrés Illanes Albornoz (arab, vxp) f9c386
	done; return 0;
Lucio Andrés Illanes Albornoz (arab, vxp) f9c386
};
Lucio Andrés Illanes Albornoz (arab, vxp) 6e940c
lalbornoz 340f4c
is_build_script_done() {
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
	if [ -n "${ARG_BUILD_STEPS}" ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
		if [ "${ARG_BUILD_STEPS}" = "finish" ]\
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
		|| [ -z "${ARG_BUILD_STEPS#ALL}" ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
			return 1;	# Build
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
		elif ! match_list ${ARG_BUILD_STEPS} , ${1}; then
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
			return 0;	# Skip
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
		else
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
			return 1;	# Build
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
		fi;
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
	elif [ -f ${WORKDIR}/.${2:-$(get_basename ${SCRIPT_FNAME%.build})}.${1} ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
		return 0;		# Skip
Lucio Andrés Illanes Albornoz (arab, vxp) f5eeee
	else
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
		return 1;		# Build
Lucio Andrés Illanes Albornoz (arab, vxp) f5eeee
	fi;
lalbornoz 340f4c
};
lalbornoz 340f4c
set_build_script_done() {
Lucio Andrés Illanes Albornoz (arab, vxp) 6e940c
	_script_fname=${SCRIPT_FNAME##*/};
Lucio Andrés Illanes Albornoz (arab, vxp) 6e940c
	_done_fname=${WORKDIR}/.${_script_fname%.build};
lalbornoz 340f4c
	while [ $# -ge 1 ]; do
lalbornoz 340f4c
		if [ "x${1#-}" != "x${1}" ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 6e940c
			rm -f ${_done_fname}.${1#-};
lalbornoz 340f4c
		else
Lucio Andrés Illanes Albornoz (arab, vxp) 6e940c
			touch ${_done_fname}.${1};
lalbornoz 340f4c
			log_msg info "Finished build step ${1} of build script \`${_script_fname}'.";
lalbornoz 340f4c
		fi; shift;
lalbornoz 340f4c
	done;
Lucio Andrés Illanes Albornoz (arab, vxp) f5eeee
	unset _script_fname _done_fname;
lalbornoz 340f4c
};
lalbornoz 340f4c
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
log_env_vars() {
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
	log_msg info "Variables for this build:";
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
	while [ ${_nvar:=0} -lt ${#} ]; do
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
		_arg="$(eval echo \${${_nvar}})"; _arg="${_arg%%=*}";
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
		if [ ${#_arg} -gt ${_arg_len_max:=0} ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
			_arg_len_max=${#_arg};
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
		fi; : $((_nvar+=1));
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
	done; unset _nvar _arg;
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
	while [ ${#} -gt 0 ]; do
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
		log_msg info "$(printf				\
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
			"%${_arg_len_max}.${_arg_len_max}s=%s"	\
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
			"${1%%=*}" "$(get_var ${1#*=})")";
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
		shift;
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
	done; unset _arg_len_max;
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
};
lalbornoz 340f4c
log_msg() {
Lucio Andrés Illanes Albornoz (arab, vxp) 6e940c
	_lvl=${1}; shift;
Lucio Andrés Illanes Albornoz (arab, vxp) 6e940c
	case ${_lvl} in
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
		failexit) printf "\033[${LOG_MSG_FAIL_COLOUR}m"; ;;
Lucio Andrés Illanes Albornoz (arab, vxp) 31dc75
		fail) printf "\033[${LOG_MSG_FAIL_COLOUR}m"; ;;
Lucio Andrés Illanes Albornoz (arab, vxp) 31dc75
		info) printf "\033[${LOG_MSG_INFO_COLOUR}m"; ;;
Lucio Andrés Illanes Albornoz (arab, vxp) 31dc75
		succ) printf "\033[${LOG_MSG_SUCC_COLOUR}m"; ;;
lalbornoz 340f4c
	esac;
lalbornoz 340f4c
	if [ $# -gt 1 ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) d30b8f
		printf "==> %s %s %s\033[0m\n" "$(date "${TIMESTAMP_FMT}")" "${1}" "$*";
lalbornoz 340f4c
	else
Lucio Andrés Illanes Albornoz (arab, vxp) d30b8f
		printf "==> %s %s\033[0m\n" "$(date "${TIMESTAMP_FMT}")" "${1}";
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
	fi; [ ${_lvl} = failexit ] && exit 1 || unset _lvl;
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
};
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
match_list() {
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
	_cmp="${3}"; push_IFS "${2}"; set -- ${1}; pop_IFS;
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
	while [ ${#} -gt 0 ]; do
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
		if [ "x${1}" = "x${_cmp}" ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
			unset _cmp; return 0;
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
		fi; shift;
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
	done; unset _cmp; return 1;
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
};
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
parse_args_into_vars() {
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
	_arg0="${1}"; _args_valid="${2}"; shift 2;
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
	while [ $# -gt 0 ]; do
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
		case "${1}" in
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
		--*)	_aname="${1#--}";
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
			if ! match_list "${_args_valid}" , "${_aname%%=*}"; then
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
				log_msg failexit "Unknown parameter --${_aname%%=*} specified.";
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
			elif match_start "${_aname}" "*="; then
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
				_aval="$(get_postfix "${_aname}" =)";
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
				_aname="$(get_prefix_lrg "${_aname}" =)";
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
			else
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
				_aval=1;
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
			fi;
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
			set_var $(echo arg_${_aname} | tr a-z- A-Z_) "${_aval}";
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
			shift; ;;
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
		*=*)	set_var "$(get_prefix_lrg "${1}" =)"\
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
				"$(get_postfix "${1}" =)"; shift; ;;
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
		*)	log_msg failexit "Invalid or unknown command line argument \`${1}'."; ;;
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
		esac;
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
	done; unset _arg0 _args_valid _aname _aval;
lalbornoz 340f4c
};
lalbornoz 340f4c
lalbornoz 340f4c
parse_with_pkg_name() {
Lucio Andrés Illanes Albornoz (arab, vxp) 75a203
	PKG_NAME=${1}; shift;
lalbornoz 340f4c
	while [ $# -ge 0 ]; do
Lucio Andrés Illanes Albornoz (arab, vxp) 75a203
		if [ "x${PKG_NAME}" = "x${1}" ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 75a203
			_pkg_NAME=$(echo "${PKG_NAME}" | tr a-z A-Z);
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
			for _vname in ${PKG_VARS}; do
Lucio Andrés Illanes Albornoz (arab, vxp) d30b8f
				_vNAME=$(echo "${_vname}" | tr a-z A-Z);
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
				if [ -n "${_vval:=$(get_var PKG_${_pkg_NAME}_${_vNAME})}" ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 96b309
					export PKG_${_vNAME}="${_vval}";
Lucio Andrés Illanes Albornoz (arab, vxp) d30b8f
					if [ "x${_vname#[A-Z]}" != "x${_vname}" ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) d30b8f
						export ${_vname}="${_vval}";
Lucio Andrés Illanes Albornoz (arab, vxp) d30b8f
					fi;
Lucio Andrés Illanes Albornoz (arab, vxp) 96b309
				else
Lucio Andrés Illanes Albornoz (arab, vxp) 96b309
					unset PKG_${_vNAME};
Lucio Andrés Illanes Albornoz (arab, vxp) d30b8f
				fi; unset _vval;
Lucio Andrés Illanes Albornoz (arab, vxp) d30b8f
			done; unset _pkg_NAME _vname _vNAME;
Lucio Andrés Illanes Albornoz (arab, vxp) 96b309
			if [ -z "${PKG_URL}" ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 96b309
				return 1;
Lucio Andrés Illanes Albornoz (arab, vxp) 96b309
			else
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
				[ -z "${PKG_FNAME}" ] && PKG_FNAME=${PKG_URL##*/};
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
				[ -z "${PKG_SUBDIR}" ] && PKG_SUBDIR=${PKG_FNAME%%.tar*};
Lucio Andrés Illanes Albornoz (arab, vxp) 96b309
				return 0;
Lucio Andrés Illanes Albornoz (arab, vxp) 96b309
			fi;
Lucio Andrés Illanes Albornoz (arab, vxp) c49754
		fi; shift;
Lucio Andrés Illanes Albornoz (arab, vxp) c49754
	done; return 1;
lalbornoz 340f4c
};
lalbornoz 340f4c
lalbornoz 340f4c
# vim:filetype=sh