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) 6e940c
#
Lucio Andrés Illanes Albornoz (arab, vxp) 6e940c
lalbornoz 340f4c
TIMESTAMP_FMT="${TIMESTAMP_FMT:-"%Y/%m/%d %H:%M:%S"}";
lalbornoz 340f4c
Lucio Andrés Illanes Albornoz (arab, vxp) d30b8f
check_path_vars() {
Lucio Andrés Illanes Albornoz (arab, vxp) d30b8f
	while [ $# -gt 0 ]; do
Lucio Andrés Illanes Albornoz (arab, vxp) d30b8f
		if [ -z "${_val:=$(eval echo \${${1}})}" ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) d30b8f
			log_msg fail "Error: variable \`${1}' is empty or unset.";
Lucio Andrés Illanes Albornoz (arab, vxp) d30b8f
			exit 1;
Lucio Andrés Illanes Albornoz (arab, vxp) d30b8f
		elif [ "x${_val#* }" != "x${_val}" ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) d30b8f
			log_msg fail "Error: variable \`${1}' contains one or more whitespace characters.";
Lucio Andrés Illanes Albornoz (arab, vxp) d30b8f
			exit 1;
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) f5eeee
check_prereqs() {
Lucio Andrés Illanes Albornoz (arab, vxp) f5eeee
	for _cmd in "$@"; do
Lucio Andrés Illanes Albornoz (arab, vxp) 6e940c
		if ! command -v ${_cmd} >/dev/null; then
Lucio Andrés Illanes Albornoz (arab, vxp) d30b8f
			log_msg fail "Error: missing prerequisite command \`${_cmd}.";
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() {
Lucio Andrés Illanes Albornoz (arab, vxp) d30b8f
	command date +"${1:-${TIMESTAMP_FMT}}";
lalbornoz 340f4c
};
lalbornoz 340f4c
lalbornoz 340f4c
fetch() {
Lucio Andrés Illanes Albornoz (arab, vxp) 6e940c
	wget --no-check-certificate -N ${1};
Lucio Andrés Illanes Albornoz (arab, vxp) 6e940c
	if [ $# -eq 2 ] && ! compare_hash ${1##*/} ${2}; then
Lucio Andrés Illanes Albornoz (arab, vxp) 6e940c
		log_msg fail "Error: hash mismatch for URL \`${1##*/}'.";
Lucio Andrés Illanes Albornoz (arab, vxp) bd43d0
		exit 1;
Lucio Andrés Illanes Albornoz (arab, vxp) bd43d0
	fi;
lalbornoz 340f4c
};
lalbornoz 340f4c
lalbornoz 340f4c
fetch_git() {
Lucio Andrés Illanes Albornoz (arab, vxp) 6e940c
	if [ -d ${1} ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 6e940c
		(cd ${1} && git pull origin main);
lalbornoz 340f4c
	else
Lucio Andrés Illanes Albornoz (arab, vxp) 6e940c
		git clone ${2} ${1};
lalbornoz 340f4c
	fi;
lalbornoz 340f4c
};
lalbornoz 340f4c
Lucio Andrés Illanes Albornoz (arab, vxp) 6e940c
compare_hash() {
Lucio Andrés Illanes Albornoz (arab, vxp) 6e940c
	_hash_cmp=${2}; set -- $(openssl dgst -sha256 ${1});
Lucio Andrés Illanes Albornoz (arab, vxp) 6e940c
	shift $((${#}-1)); set -- ${1} ${_hash_cmp}; unset _hash_cmp;
Lucio Andrés Illanes Albornoz (arab, vxp) 6e940c
	[ "x${1}" = "x${2}" ];
Lucio Andrés Illanes Albornoz (arab, vxp) 6e940c
};
Lucio Andrés Illanes Albornoz (arab, vxp) 6e940c
lalbornoz 340f4c
is_build_script_done() {
Lucio Andrés Illanes Albornoz (arab, vxp) 6e940c
	_script_fname=${SCRIPT_FNAME##*/};
Lucio Andrés Illanes Albornoz (arab, vxp) 6e940c
	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) 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
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) 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}";
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) 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) d30b8f
			for _vname in							\
Lucio Andrés Illanes Albornoz (arab, vxp) d30b8f
					configure_extra_args no_libtool_midipix		\
Lucio Andrés Illanes Albornoz (arab, vxp) 680d83
					patches_extra prefix prefix_extra sha256sum	\
Lucio Andrés Illanes Albornoz (arab, vxp) 680d83
					url version					\
Lucio Andrés Illanes Albornoz (arab, vxp) d30b8f
					CC CFLAGS LDFLAGS DESTDIR; do
Lucio Andrés Illanes Albornoz (arab, vxp) d30b8f
				_vNAME=$(echo "${_vname}" | tr a-z A-Z);
Lucio Andrés Illanes Albornoz (arab, vxp) d30b8f
				if [ -n "${_vval:=$(eval echo \${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) 96b309
				PKG_FNAME=${PKG_URL##*/};
Lucio Andrés Illanes Albornoz (arab, vxp) 96b309
				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
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) 6e940c
	_dir=${1};
Lucio Andrés Illanes Albornoz (arab, vxp) 6e940c
	if [ -d ${1} ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 6e940c
		rm -rf ${1} || return 1;
lalbornoz 340f4c
	fi;
lalbornoz 340f4c
	if [ ${_mflag:-0} -eq 1 ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 6e940c
		unset _mflag; mkdir ${1} || return 2;
lalbornoz 340f4c
	fi;
lalbornoz 340f4c
	if [ ${_cflag:-0} -eq 1 ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 6e940c
		unset _cflag; cd ${1} || return 3;
lalbornoz 340f4c
	fi;
lalbornoz 340f4c
};
lalbornoz 340f4c
lalbornoz 340f4c
set_build_dir() {
Lucio Andrés Illanes Albornoz (arab, vxp) 96b309
	BUILD_DIR=${1}-${2}-${TARGET};
lalbornoz 340f4c
};
lalbornoz 340f4c
lalbornoz 340f4c
set_env_vars() {
Lucio Andrés Illanes Albornoz (arab, vxp) 6e940c
	_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