Blame build.sh

lalbornoz 340f4c
#!/bin/sh
Lucio Andrés Illanes Albornoz (arab, vxp) 0724e5
# Copyright (c) 2016 Lucio Andrés Illanes Albornoz <l.illanes@gmx.de>
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
#
Lucio Andrés Illanes Albornoz (arab, vxp) 090fd4
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
bp_subst_tgts() {
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
	while [ ${#} -ge 1 ]; do
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
	case "${1}" in
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
	devroot)
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
		echo ${DEVROOT_PACKAGES}; ;;
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
	world)	echo ${WORLD_PACKAGES}; ;;
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
	*)	echo ${1}; ;;
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
	esac; shift;
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
	done;
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
};
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
Lucio Andrés Illanes Albornoz (arab, vxp) 820be1
#
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
# Clear the environment.
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
# Source subroutine scripts.
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
# Source the build variables file and its local overrides, if any.
Lucio Andrés Illanes Albornoz (arab, vxp) 820be1
# Process command line arguments.
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
for __ in subr/*.subr; do
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
	. ./${__};
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
done;
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
if [ -z "${BUILD_CPUS}" ]	\
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
&& [ -e /proc/cpuinfo ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
	BUILD_CPUS=$(awk '/^processor/{cpus++} END{print cpus}' /proc/cpuinfo);
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
fi;
Lucio Andrés Illanes Albornoz (arab, vxp) 090fd4
while [ ${#} -gt 0 ]; do
Lucio Andrés Illanes Albornoz (arab, vxp) 6e48a0
case ${1} in
Lucio Andrés Illanes Albornoz (arab, vxp) 6e313c
-c)	ARG_CLEAN=1; ;;
Lucio Andrés Illanes Albornoz (arab, vxp) 47c5cd
-C)	ARG_CHECK_UPDATES=1; ;;
Lucio Andrés Illanes Albornoz (arab, vxp) 6e313c
-n)	ARG_DRYRUN=1 ARG_VERBOSE=1; ;;
Lucio Andrés Illanes Albornoz (arab, vxp) 6e313c
-N)	ARG_OFFLINE=1; ;;
Lucio Andrés Illanes Albornoz (arab, vxp) a0561a
-i)	ARG_IGNORE_SHA256SUMS=1; ;;
Lucio Andrés Illanes Albornoz (arab, vxp) 6e313c
-t*)	ARG_TARBALL=1; [ "${1#-t.}" != "${1}" ] && TARBALL_SUFFIX=${1#-t.}; ;;
Lucio Andrés Illanes Albornoz (arab, vxp) 6e313c
-v)	ARG_VERBOSE=1; ;;
Lucio Andrés Illanes Albornoz (arab, vxp) 6e313c
-x)	ARG_XTRACE=1; set -o xtrace; ;;
Lucio Andrés Illanes Albornoz (arab, vxp) 6e313c
-a)	[ -z "${2}" ] && exec cat etc/build.usage || ARCH=${2}; shift; ;;
Lucio Andrés Illanes Albornoz (arab, vxp) 6e313c
-b)	[ -z "${2}" ] && exec cat etc/build.usage || BUILD=${2}; shift; ;;
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
-r)	if [ -z "${2}" ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 49ffbe
		exec cat build.usage;
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
	elif [ "${2%:*}" = "${2}" ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 6e313c
		ARG_RESTART=${2};
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
	else
Lucio Andrés Illanes Albornoz (arab, vxp) 6e313c
		ARG_RESTART=${2%:*}; ARG_RESTART_AT=${2#*:};
Lucio Andrés Illanes Albornoz (arab, vxp) a0561a
	fi;
Lucio Andrés Illanes Albornoz (arab, vxp) a0561a
	if [ -z "${ARG_RESTART_AT}" ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) a0561a
		ARG_RESTART_AT=ALL;
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
	fi; shift; ;;
Lucio Andrés Illanes Albornoz (arab, vxp) e5b9d8
host_toolchain|native_toolchain|runtime|lib_packages|leaf_packages|devroot|world)
Lucio Andrés Illanes Albornoz (arab, vxp) 6e313c
	BUILD_TARGETS_META="${BUILD_TARGETS_META:+${BUILD_TARGETS_META} }${1}"; ;;
Lucio Andrés Illanes Albornoz (arab, vxp) 820be1
*=*)	set_var_unsafe "${1%%=*}" "${1#*=}"; ;;
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
*)	exec cat etc/build.usage; ;;
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
esac; shift;
Lucio Andrés Illanes Albornoz (arab, vxp) 820be1
done;
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
#
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
# Source variables.
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
# Clear environment.
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
#
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
for __ in ${HOME}/midipix_build.vars ../midipix_build.vars ./vars/build.vars; do
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
	[ -e ${__} ] && . ${__};
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
done;
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
for __ in $(export | sed -e 's/^export //' -e 's/=.*$//'); do
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
	if ! match_list "${CLEAR_ENV_VARS_EXCEPT}" " " "${__}"; then
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
		unset "${__}";
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
	fi;
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
done;
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
if [ -z "${BUILD_TARGETS_META}" ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
	BUILD_TARGETS_META=world;
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
fi;
Lucio Andrés Illanes Albornoz (arab, vxp) e5b9d8
BUILD_TARGETS_META="invariants ${BUILD_TARGETS_META}";
Lucio Andrés Illanes Albornoz (arab, vxp) 820be1
Lucio Andrés Illanes Albornoz (arab, vxp) 820be1
#
Lucio Andrés Illanes Albornoz (arab, vxp) 820be1
# Check whether the pathnames in build.vars contain non-empty valid values.
Lucio Andrés Illanes Albornoz (arab, vxp) 820be1
# Check whether all prerequisite command names resolve.
Lucio Andrés Illanes Albornoz (arab, vxp) 820be1
# Check whether all prerequisite pathnames resolve.
Lucio Andrés Illanes Albornoz (arab, vxp) b66e01
# Check whether all prerequisite Perl modules exist.
Lucio Andrés Illanes Albornoz (arab, vxp) 820be1
# Clean ${PREFIX} if requested.
Lucio Andrés Illanes Albornoz (arab, vxp) 820be1
# Create directory hierarchy and usr -> . symlinks.
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
for __ in ${CHECK_PATH_VARS}; do
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
	if [ -z "${___:=$(get_var_unsafe "${__}")}" ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
		log_msg failexit "Error: variable \`${__}' is empty or unset.";
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
	elif [ "${___#* *}" != "${___}" ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
		log_msg failexit "Error: variable \`${__}' contains one or more whitespace characters.";
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
	fi;
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
done;
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
for __ in ${CHECK_PREREQ_CMDS} $(eval echo ${CHECK_PREREQ_FILES_DYNAMIC}) ${CHECK_PREREQ_FILES}; do
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
	if [ "${__#/}" != "${__}" ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
		if [ ! -e "${__}" ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
			log_msg fail "Error: missing prerequisite file \`${__}'.";
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
			__exit=1;
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
		fi;
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
	else
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
		if ! test_cmd "${__}"; then
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
			log_msg fail "Error: missing prerequisite command \`${__}'.";
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
			__exit=1;
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
		fi;
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
	fi;
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
done;
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
for __ in ${CHECK_PREREQ_PERL_MODULES}; do
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
	if ! perl -M"${__}" -e "" 2>/dev/null; then
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
		log_msg fail "Error: missing prerequisite Perl module \`${__}'.";
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
		__exit=1;
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
	fi;
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
done;
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
if [ ${__exit:-0} = 1 ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
	exit 1;
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
elif [ -n "${__exit}" ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
	unset __exit;
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
fi;
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
if [ ${ARG_CLEAN:-0} -eq 1 ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
	log_msg info "-c specified, cleaning prefix...";
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
	for __ in ${CLEAR_PREFIX_DIRS}; do
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
		if [ -e ${PREFIX}/${__} ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
			secure_rm ${PREFIX}/${__};
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
		fi;
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
	done;
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
fi;
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
insecure_mkdir ${PREFIX} ${PREFIX}/x86_64-w64-mingw32 ${PREFIX_NATIVE} ${PREFIX_CROSS} ${PREFIX_TARGET}/lib ${DLCACHEDIR} ${WORKDIR};
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
for __ in ${PREFIX}/usr ${PREFIX_NATIVE}/usr; do
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
	if [ ! -L "${__}" ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
		secure_rm "${__}"; ln -sf -- . "${__}";
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
	fi;
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
done;
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
if [ ! -L ${PREFIX}/x86_64-w64-mingw32/mingw ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
	secure_rm ${PREFIX}/x86_64-w64-mingw32/mingw;
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
	ln -sf . ${PREFIX}/x86_64-w64-mingw32/mingw;
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
fi;
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
if [ ! -d ${PREFIX}/x86_64-w64-mingw32/mingw/include ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
	secure_rm ${PREFIX}/x86_64-w64-mingw32/mingw/include;
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
	insecure_mkdir ${PREFIX}/x86_64-w64-mingw32/mingw/include;
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
fi;
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
if [ ! -L ${PREFIX}/man ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
	secure_rm ${PREFIX}/man;
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
	ln -sf share/man ${PREFIX}/man;
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
fi;
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
if [ ! -L ${PREFIX_NATIVE}/man ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
	secure_rm ${PREFIX_NATIVE}/man;
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
	ln -sf share/man ${PREFIX_NATIVE}/man;
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
fi;
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
insecure_mkdir ${PREFIX_MINIPIX}/bin;
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
for __ in lib libexec share; do
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
	if [ ! -e ${PREFIX_MINIPIX}/${__} ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
		ln -sf bin ${PREFIX_MINIPIX}/${__};
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
	fi;
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
done;
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
if [ -e ${BUILD_LOG_FNAME} ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
	mv -- ${BUILD_LOG_FNAME} ${BUILD_LOG_LAST_FNAME};
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
fi;
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
touch ${BUILD_STATUS_IN_PROGRESS_FNAME};
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
{(
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
BUILD_DATE_START="$(date %Y-%m-%d-%H-%M-%S)";
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
BUILD_NFINI=${BUILD_NSKIP:=${BUILD_NFAIL:=${BUILD_NBUILT:=0}}};
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
BUILD_TIMES_SECS=$(command date +%s);
Lucio Andrés Illanes Albornoz (arab, vxp) 44046a
if [ ${ARG_CHECK_UPDATES:-0} -eq 0 ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 0bb2fe
	log_msg info "Build started by ${BUILD_USER:=${USER}}@${BUILD_HNAME:=$(hostname)} at ${BUILD_DATE_START}.";
Lucio Andrés Illanes Albornoz (arab, vxp) 44046a
	log_env_vars "build (global)" ${LOG_ENV_VARS};
Lucio Andrés Illanes Albornoz (arab, vxp) 0bb2fe
else
Lucio Andrés Illanes Albornoz (arab, vxp) 0bb2fe
	log_msg info "Version check run started by ${BUILD_USER:=${USER}}@${BUILD_HNAME:=$(hostname)} at ${BUILD_DATE_START}.";
Lucio Andrés Illanes Albornoz (arab, vxp) 44046a
fi;
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
for BUILD_TARGET_LC in $(bp_subst_tgts ${BUILD_TARGETS_META}); do
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
	BUILD_TARGET=$(echo ${BUILD_TARGET_LC} | tr a-z A-Z);
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
	for BUILD_PACKAGE_LC in $(get_var_unsafe ${BUILD_TARGET}_PACKAGES); do
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
		BUILD_PACKAGE=$(echo ${BUILD_PACKAGE_LC} | tr a-z A-Z);
Lucio Andrés Illanes Albornoz (arab, vxp) e5b9d8
		if [ "${BUILD_TARGET}" != "INVARIANTS" ]\
Lucio Andrés Illanes Albornoz (arab, vxp) e5b9d8
		&& [ -n "${ARG_RESTART}" ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) ea7997
			if [ "${ARG_RESTART}" != "ALL" ] &&\
Lucio Andrés Illanes Albornoz (arab, vxp) ea7997
			! match_list ${ARG_RESTART} , ${BUILD_PACKAGE_LC}; then
Lucio Andrés Illanes Albornoz (arab, vxp) 02175d
				log_msg vnfo "Skipped \`${BUILD_PACKAGE_LC}' (-r specified.)";
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
				: $((BUILD_NSKIP+=1)); BUILD_SCRIPT_RC=0; continue;
Lucio Andrés Illanes Albornoz (arab, vxp) 820be1
			fi;
Lucio Andrés Illanes Albornoz (arab, vxp) 47c5cd
		fi;
Lucio Andrés Illanes Albornoz (arab, vxp) 47c5cd
		if [ ${ARG_CHECK_UPDATES:-0} -eq 1 ]\
Lucio Andrés Illanes Albornoz (arab, vxp) 47c5cd
		&& [ "${BUILD_PACKAGE#*.*}" = "${BUILD_PACKAGE}" ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 47c5cd
			if [ ${ARG_DRYRUN:-0} -eq 1 ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 154865
				echo mode_check_pkg_updates "${BUILD_PACKAGE_LC}"		\
Lucio Andrés Illanes Albornoz (arab, vxp) 47c5cd
					"$(get_var_unsafe PKG_${BUILD_PACKAGE}_VERSION)"	\
Lucio Andrés Illanes Albornoz (arab, vxp) 47c5cd
					"$(get_var_unsafe PKG_${BUILD_PACKAGE}_URL)"		\
Lucio Andrés Illanes Albornoz (arab, vxp) 47c5cd
					"$(get_var_unsafe PKG_${BUILD_PACKAGE}_URL_TYPE)";
Lucio Andrés Illanes Albornoz (arab, vxp) 47c5cd
			else
Lucio Andrés Illanes Albornoz (arab, vxp) 154865
				mode_check_pkg_updates "${BUILD_PACKAGE_LC}"			\
Lucio Andrés Illanes Albornoz (arab, vxp) 47c5cd
					"$(get_var_unsafe PKG_${BUILD_PACKAGE}_VERSION)"	\
Lucio Andrés Illanes Albornoz (arab, vxp) 47c5cd
					"$(get_var_unsafe PKG_${BUILD_PACKAGE}_URL)"		\
Lucio Andrés Illanes Albornoz (arab, vxp) 47c5cd
					"$(get_var_unsafe PKG_${BUILD_PACKAGE}_URL_TYPE)";
Lucio Andrés Illanes Albornoz (arab, vxp) 47c5cd
			fi;
Lucio Andrés Illanes Albornoz (arab, vxp) 47c5cd
			continue;
Lucio Andrés Illanes Albornoz (arab, vxp) 47c5cd
		fi;
Lucio Andrés Illanes Albornoz (arab, vxp) e5b9d8
		if [ "${BUILD_TARGET}" != "INVARIANTS" ]\
Lucio Andrés Illanes Albornoz (arab, vxp) e5b9d8
		&& [ -z "${ARG_RESTART}" ]\
Lucio Andrés Illanes Albornoz (arab, vxp) 413df3
		&& is_build_script_done finish "${BUILD_PACKAGE_LC}"; then
Lucio Andrés Illanes Albornoz (arab, vxp) 02175d
			log_msg vnfo "Skipped \`${BUILD_PACKAGE_LC}' (already built.)";
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
			: $((BUILD_NSKIP+=1)); BUILD_SCRIPT_RC=0; continue;
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
		fi;
Lucio Andrés Illanes Albornoz (arab, vxp) 570129
		if [ -n "${ARG_RESTART}" ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 570129
			log_msg vnfo "Forcing package \`${BUILD_PACKAGE_LC}'.";
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
		fi;
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
		(set -o errexit -o noglob;
Lucio Andrés Illanes Albornoz (arab, vxp) 570129
		MIDIPIX_BUILD_PWD=$(pwd);
Lucio Andrés Illanes Albornoz (arab, vxp) 570129
		PKG_BUILD=${BUILD};
Lucio Andrés Illanes Albornoz (arab, vxp) 570129
		PKG_PREFIX=$(get_vars_unsafe ${BUILD_TARGET}_PREFIX PKG_${BUILD_PACKAGE%%.*}_PREFIX);				
Lucio Andrés Illanes Albornoz (arab, vxp) 570129
		PKG_TARGET=${TARGET};
Lucio Andrés Illanes Albornoz (arab, vxp) 570129
		cd ${WORKDIR};
Lucio Andrés Illanes Albornoz (arab, vxp) 570129
		for SCRIPT_SOURCE in vars/${BUILD_PACKAGE_LC%.*}.vars; do
Lucio Andrés Illanes Albornoz (arab, vxp) 570129
			if [ -f ${MIDIPIX_BUILD_PWD}/${SCRIPT_SOURCE} ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 570129
				if [ ${ARG_DRYRUN:-0} -eq 1 ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 570129
					echo . ${MIDIPIX_BUILD_PWD}/${SCRIPT_SOURCE};
Lucio Andrés Illanes Albornoz (arab, vxp) 570129
				else
Lucio Andrés Illanes Albornoz (arab, vxp) 570129
					. ${MIDIPIX_BUILD_PWD}/${SCRIPT_SOURCE};
Lucio Andrés Illanes Albornoz (arab, vxp) 570129
				fi;
Lucio Andrés Illanes Albornoz (arab, vxp) 570129
			fi;
Lucio Andrés Illanes Albornoz (arab, vxp) 570129
		done;
Lucio Andrés Illanes Albornoz (arab, vxp) 570129
		parse_with_pkg_name ${BUILD_PACKAGE_LC%.*};
Lucio Andrés Illanes Albornoz (arab, vxp) 570129
		for __ in all disabled fetch extract build_dir patch_pre autoconf patch setup	\
Lucio Andrés Illanes Albornoz (arab, vxp) 570129
				configure clean build install; do
Lucio Andrés Illanes Albornoz (arab, vxp) 570129
			case ${__} in
Lucio Andrés Illanes Albornoz (arab, vxp) 570129
			all)
Lucio Andrés Illanes Albornoz (arab, vxp) 570129
				if test_cmd pkg_${PKG_NAME}_all; then
Lucio Andrés Illanes Albornoz (arab, vxp) 570129
					pkg_${PKG_NAME}_all; exit 0;
Lucio Andrés Illanes Albornoz (arab, vxp) 570129
				fi;
Lucio Andrés Illanes Albornoz (arab, vxp) 570129
				;;
Lucio Andrés Illanes Albornoz (arab, vxp) 570129
			disabled|build_dir|setup)
Lucio Andrés Illanes Albornoz (arab, vxp) 570129
				pkg_${__};
Lucio Andrés Illanes Albornoz (arab, vxp) 570129
				;;
Lucio Andrés Illanes Albornoz (arab, vxp) 570129
			*)	if ! is_build_script_done ${__}; then
Lucio Andrés Illanes Albornoz (arab, vxp) 570129
					if test_cmd pkg_${PKG_NAME}_${__}; then
Lucio Andrés Illanes Albornoz (arab, vxp) 570129
						pkg_${PKG_NAME}_${__};
Lucio Andrés Illanes Albornoz (arab, vxp) 570129
					else
Lucio Andrés Illanes Albornoz (arab, vxp) 570129
						pkg_${__};
Lucio Andrés Illanes Albornoz (arab, vxp) 570129
					fi;
Lucio Andrés Illanes Albornoz (arab, vxp) 570129
				fi;
Lucio Andrés Illanes Albornoz (arab, vxp) 570129
				;;
Lucio Andrés Illanes Albornoz (arab, vxp) 570129
			esac;
Lucio Andrés Illanes Albornoz (arab, vxp) 570129
		done;
Lucio Andrés Illanes Albornoz (arab, vxp) 570129
		set_build_script_done finish;
Lucio Andrés Illanes Albornoz (arab, vxp) 570129
		);
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
		BUILD_SCRIPT_RC=${?}; case ${BUILD_SCRIPT_RC} in
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
		0) log_msg succ "Finished \`${BUILD_PACKAGE_LC}' build.";
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
			: $((BUILD_NFINI+=1)); continue; ;;
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
		*) log_msg fail "Build failed in \`${BUILD_PACKAGE_LC}' (last return code ${BUILD_SCRIPT_RC}.).";
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
			: $((BUILD_NFAIL+=1)); break; ;;
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
		esac;
lalbornoz 340f4c
	done;
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
	if [ ${BUILD_SCRIPT_RC:-0} -ne 0 ]; then
lalbornoz 340f4c
		break;
lalbornoz 340f4c
	fi;
lalbornoz 340f4c
done;
Lucio Andrés Illanes Albornoz (arab, vxp) 154865
for __ in copy_etc strip tarballs; do
Lucio Andrés Illanes Albornoz (arab, vxp) 154865
	post_${__};
Lucio Andrés Illanes Albornoz (arab, vxp) 154865
done;
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
: $((BUILD_TIMES_SECS=$(command date +%s)-${BUILD_TIMES_SECS}));
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
: $((BUILD_TIMES_HOURS=${BUILD_TIMES_SECS}/3600));
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
: $((BUILD_TIMES_MINUTES=(${BUILD_TIMES_SECS}%3600)/60));
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
: $((BUILD_TIMES_SECS=(${BUILD_TIMES_SECS}%3600)%60));
Lucio Andrés Illanes Albornoz (arab, vxp) 96b309
log_msg info "${BUILD_NFINI} finished, ${BUILD_NSKIP} skipped, and ${BUILD_NFAIL} failed builds in ${BUILD_NBUILT} build script(s).";
Lucio Andrés Illanes Albornoz (arab, vxp) 820be1
log_msg info "Build time: ${BUILD_TIMES_HOURS} hour(s), ${BUILD_TIMES_MINUTES} minute(s), and ${BUILD_TIMES_SECS} second(s).";
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
if [ -f "${BUILD_STATUS_IN_PROGRESS_FNAME}" ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
	secure_rm ${BUILD_STATUS_IN_PROGRESS_FNAME};
Lucio Andrés Illanes Albornoz (arab, vxp) ce047e
fi;
Lucio Andrés Illanes Albornoz (arab, vxp) 820be1
exit ${BUILD_SCRIPT_RC})} 2>&1 | tee ${BUILD_LOG_FNAME} &
Lucio Andrés Illanes Albornoz (arab, vxp) e2a4f2
TEE_PID=${!};
Lucio Andrés Illanes Albornoz (arab, vxp) e2a4f2
trap "rm -f ${BUILD_STATUS_IN_PROGRESS_FNAME};	\
Lucio Andrés Illanes Albornoz (arab, vxp) e2a4f2
	log_msg fail \"Build aborted.\";	\
Lucio Andrés Illanes Albornoz (arab, vxp) e2a4f2
	echo kill ${TEE_PID};			\
Lucio Andrés Illanes Albornoz (arab, vxp) e2a4f2
	kill ${TEE_PID}" HUP INT TERM USR1 USR2;
Lucio Andrés Illanes Albornoz (arab, vxp) e2a4f2
wait;
lalbornoz 340f4c
lalbornoz 340f4c
# vim:filetype=sh