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) 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) bd43d0
			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() {
lalbornoz 340f4c
	command date +"${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
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) 6e940c
	_pkg_name=${1}; shift;
lalbornoz 340f4c
	while [ $# -ge 0 ]; do
Lucio Andrés Illanes Albornoz (arab, vxp) c49754
		if [ "x${_pkg_name}" = "x${1}" ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) c49754
			_pkg_NAME=$(echo "${_pkg_name}" | tr a-z A-Z);
Lucio Andrés Illanes Albornoz (arab, vxp) c49754
			eval	_pkg_configure_extra_args=\"\${PKG_${_pkg_NAME}_CONFIGURE_EXTRA_ARGS}\"\
Lucio Andrés Illanes Albornoz (arab, vxp) c49754
				_pkg_no_libtool_midipix=\${PKG_${_pkg_NAME}_NO_LIBTOOL_MIDIPIX}\
Lucio Andrés Illanes Albornoz (arab, vxp) c49754
				_pkg_prefix=\${PKG_${_pkg_NAME}_PREFIX}\
Lucio Andrés Illanes Albornoz (arab, vxp) c49754
				_pkg_prefix_extra=\${PKG_${_pkg_NAME}_PREFIX_EXTRA}\
Lucio Andrés Illanes Albornoz (arab, vxp) c49754
				_pkg_sha256sum=\${PKG_${_pkg_NAME}_SHA256SUM}\
Lucio Andrés Illanes Albornoz (arab, vxp) c49754
				_pkg_url=\${PKG_${_pkg_NAME}_URL}\
Lucio Andrés Illanes Albornoz (arab, vxp) c49754
				_pkg_version=\${PKG_${_pkg_NAME}_VERSION}\
Lucio Andrés Illanes Albornoz (arab, vxp) c49754
				_pkg_CC=\${PKG_${_pkg_NAME}_CC}\
Lucio Andrés Illanes Albornoz (arab, vxp) c49754
				_pkg_CFLAGS=\${PKG_${_pkg_NAME}_CFLAGS}\
Lucio Andrés Illanes Albornoz (arab, vxp) c49754
				_pkg_DESTDIR=\${PKG_${_pkg_NAME}_DESTDIR};
Lucio Andrés Illanes Albornoz (arab, vxp) c49754
			_pkg_fname=${_pkg_url##*/};
Lucio Andrés Illanes Albornoz (arab, vxp) 6e940c
			_pkg_subdir=${_pkg_fname%%.tar*};
Lucio Andrés Illanes Albornoz (arab, vxp) c49754
			return 0;
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) c49754
	_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