Conan_Kudo / build / midipix_build

Forked from build/midipix_build 4 years ago
Clone

Blame build.subr

lalbornoz 340f4c
TIMESTAMP_FMT="${TIMESTAMP_FMT:-"%Y/%m/%d %H:%M:%S"}";
lalbornoz 340f4c
Lucio Andrés Illanes Albornoz (arab, vxp) f5eeee
check_prereqs() {
Lucio Andrés Illanes Albornoz (arab, vxp) f5eeee
	for _cmd in "$@"; do
Lucio Andrés Illanes Albornoz (arab, vxp) f5eeee
		if ! command -v "${_cmd}" >/dev/null; then
Lucio Andrés Illanes Albornoz (arab, vxp) f5eeee
			echo "Error: missing prerequisite command \`${_cmd}" >&2;
Lucio Andrés Illanes Albornoz (arab, vxp) f5eeee
			exit 1;
Lucio Andrés Illanes Albornoz (arab, vxp) f5eeee
		fi;
Lucio Andrés Illanes Albornoz (arab, vxp) f5eeee
	done; unset _cmd;
Lucio Andrés Illanes Albornoz (arab, vxp) f5eeee
};
Lucio Andrés Illanes Albornoz (arab, vxp) f5eeee
lalbornoz 340f4c
date() {
lalbornoz 340f4c
	command date +"${TIMESTAMP_FMT}";
lalbornoz 340f4c
};
lalbornoz 340f4c
lalbornoz 340f4c
fetch() {
lalbornoz 340f4c
	wget --no-check-certificate -N "${@}";
lalbornoz 340f4c
};
lalbornoz 340f4c
lalbornoz 340f4c
fetch_git() {
Lucio Andrés Illanes Albornoz (arab, vxp) f5eeee
	if [ -d "${1}" ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) f5eeee
		(cd "${1}" && git pull origin main);
lalbornoz 340f4c
	else
Lucio Andrés Illanes Albornoz (arab, vxp) f5eeee
		git clone "${2}" "${1}";
lalbornoz 340f4c
	fi;
lalbornoz 340f4c
};
lalbornoz 340f4c
lalbornoz 340f4c
is_build_script_done() {
Lucio Andrés Illanes Albornoz (arab, vxp) f5eeee
	_script_fname="${SCRIPT_FNAME##*/}";
Lucio Andrés Illanes Albornoz (arab, vxp) f5eeee
	if [ -f "${WORKDIR}/.${_script_fname%.build}.${1}" ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) f5eeee
		unset script_fname;
Lucio Andrés Illanes Albornoz (arab, vxp) f5eeee
		return 0;
Lucio Andrés Illanes Albornoz (arab, vxp) f5eeee
	else
Lucio Andrés Illanes Albornoz (arab, vxp) f5eeee
		unset script_fname;
Lucio Andrés Illanes Albornoz (arab, vxp) f5eeee
		return 1;
Lucio Andrés Illanes Albornoz (arab, vxp) f5eeee
	fi;
lalbornoz 340f4c
};
lalbornoz 340f4c
set_build_script_done() {
Lucio Andrés Illanes Albornoz (arab, vxp) f5eeee
	_script_fname="${SCRIPT_FNAME##*/}";
lalbornoz 340f4c
	_done_fname="${WORKDIR}/.${_script_fname%.build}";
lalbornoz 340f4c
	while [ $# -ge 1 ]; do
lalbornoz 340f4c
		if [ "x${1#-}" != "x${1}" ]; then
lalbornoz 340f4c
			rm -f "${_done_fname}.${1#-}";
lalbornoz 340f4c
		else
Lucio Andrés Illanes Albornoz (arab, vxp) f5eeee
			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
lalbornoz 340f4c
log_msg() {
Lucio Andrés Illanes Albornoz (arab, vxp) f5eeee
	_lvl="${1}"; shift;
lalbornoz 340f4c
	case "${_lvl}" in
lalbornoz 340f4c
		fail) printf "\033[91m"; ;;
lalbornoz 340f4c
		info) printf "\033[97m"; ;;
lalbornoz 340f4c
		succ) printf "\033[92m"; ;;
lalbornoz 340f4c
	esac;
lalbornoz 340f4c
	if [ $# -gt 1 ]; then
lalbornoz 340f4c
		printf "==> %s %s %s\033[0m\n" "$(date +"${TIMESTAMP_FMT}")" "${1}" "$*";
lalbornoz 340f4c
	else
lalbornoz 340f4c
		printf "==> %s %s\033[0m\n" "$(date +"${TIMESTAMP_FMT}")" "${1}";
lalbornoz 340f4c
	fi;
Lucio Andrés Illanes Albornoz (arab, vxp) f5eeee
	unset _lvl;
lalbornoz 340f4c
};
lalbornoz 340f4c
lalbornoz 340f4c
parse_with_pkg_name() {
Lucio Andrés Illanes Albornoz (arab, vxp) f5eeee
	_pkg_name="${1}"; shift;
lalbornoz 340f4c
	while [ $# -ge 0 ]; do
lalbornoz 340f4c
		_pkg_url="${1}"; _envvs="${2}"; _pkg_fname="${_pkg_url##*/}";
lalbornoz 340f4c
		if [ "x${_pkg_fname%%-*}" = "x${_pkg_name}" ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) f5eeee
			_IFS="${IFS}"; IFS=:;
Lucio Andrés Illanes Albornoz (arab, vxp) f5eeee
			for _envv in ${_envvs}; do
lalbornoz 340f4c
				export ${_envv};
Lucio Andrés Illanes Albornoz (arab, vxp) f5eeee
			done; IFS="${_IFS}";
lalbornoz 340f4c
			_pkg_subdir="${_pkg_fname%%.tar*}";
Lucio Andrés Illanes Albornoz (arab, vxp) f5eeee
			unset _envvs _envv;
lalbornoz 340f4c
			return;
lalbornoz 340f4c
		fi; shift 2;
Lucio Andrés Illanes Albornoz (arab, vxp) f5eeee
	done;
Lucio Andrés Illanes Albornoz (arab, vxp) f5eeee
	unset _pkg_name _pkg_url _envvs _pkg_fname _envv _IFS _pkg_subdir;
lalbornoz 340f4c
};
lalbornoz 340f4c
lalbornoz 340f4c
rm_if_exists() {
lalbornoz 340f4c
	while [ $# -gt 1 ]; do [ "x${1%[a-z]}" = "x-" ] &&\
Lucio Andrés Illanes Albornoz (arab, vxp) f5eeee
		eval _${1#-}flag=1; shift; done;
Lucio Andrés Illanes Albornoz (arab, vxp) f5eeee
	_dir="${1}";
Lucio Andrés Illanes Albornoz (arab, vxp) f5eeee
	if [ -d "${1}" ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) f5eeee
		rm -rf "${1}" || return 1;
lalbornoz 340f4c
	fi;
lalbornoz 340f4c
	if [ ${_mflag:-0} -eq 1 ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) f5eeee
		unset _mflag; mkdir "${1}" || return 2;
lalbornoz 340f4c
	fi;
lalbornoz 340f4c
	if [ ${_cflag:-0} -eq 1 ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) f5eeee
		unset _cflag; cd "${1}" || return 3;
lalbornoz 340f4c
	fi;
lalbornoz 340f4c
};
lalbornoz 340f4c
lalbornoz 340f4c
run_configure_with_extra_args() {
Lucio Andrés Illanes Albornoz (arab, vxp) f5eeee
	_IFS="${IFS}"; IFS=","; _script="${1}"; _extra_args="${2}";
Lucio Andrés Illanes Albornoz (arab, vxp) f5eeee
	shift 2; "${_script}" "${@}" ${_extra_args}; IFS="${_IFS}";
Lucio Andrés Illanes Albornoz (arab, vxp) f5eeee
	unset _script _extra_args;
lalbornoz 340f4c
};
lalbornoz 340f4c
lalbornoz 340f4c
set_build_dir() {
lalbornoz 340f4c
	export _build_dir="${1}-build-${2}";
lalbornoz 340f4c
};
lalbornoz 340f4c
lalbornoz 340f4c
set_env_vars() {
Lucio Andrés Illanes Albornoz (arab, vxp) f5eeee
	_val="${1}"; shift;
lalbornoz 340f4c
	while [ $# -ge 1 ]; do
lalbornoz 340f4c
		export "${1}=${_val}"; shift;
Lucio Andrés Illanes Albornoz (arab, vxp) f5eeee
	done; unset _val;
lalbornoz 340f4c
};
lalbornoz 340f4c
lalbornoz 340f4c
split() {
Lucio Andrés Illanes Albornoz (arab, vxp) f5eeee
	_IFS="${IFS}"; IFS="${1}"; set -- ${2};
Lucio Andrés Illanes Albornoz (arab, vxp) f5eeee
	IFS="${_IFS}"; echo "${*}"; unset _IFS;
lalbornoz 340f4c
};
lalbornoz 340f4c
lalbornoz 340f4c
# vim:filetype=sh