Blob Blame History Raw
#
# . ./build.vars and set -o errexit -o noglob are assumed.
# See warning at the top of build.vars.
#

check_cpuinfo() {
	if [ -z "${BUILD_CPUS}" ]	\
	&& [ -e /proc/cpuinfo ]; then
		BUILD_CPUS=$(awk '/^processor/{cpus++} END{print cpus}' /proc/cpuinfo);
	fi;
};

clear_env() {
	for __ in $(export | sed -e 's/^export //' -e 's/=.*$//'); do
		if ! match_list "${CLEAR_ENV_VARS_EXCEPT}" " " "${__}"; then
			unset "${__}";
		fi;
	done;
};

check_paths() {
	for __ in ${CHECK_PATH_VARS}; do
		if [ -z "${___:=$(get_var_unsafe "${__}")}" ]; then
			log_msg failexit "Error: variable \`${__}' is empty or unset.";
		elif [ "${___#* *}" != "${___}" ]; then
			log_msg failexit "Error: variable \`${__}' contains one or more whitespace characters.";
		fi;
	done;
	for __ in ${CHECK_PREREQ_CMDS} $(eval echo ${CHECK_PREREQ_FILES_DYNAMIC}) ${CHECK_PREREQ_FILES}; do
		if [ "${__#/}" != "${__}" ]; then
			if [ ! -e "${__}" ]; then
				log_msg fail "Error: missing prerequisite file \`${__}'.";
				__exit=1;
			fi;
		else
			if ! test_cmd "${__}"; then
				log_msg fail "Error: missing prerequisite command \`${__}'.";
				__exit=1;
			fi;
		fi;
	done;
	for __ in ${CHECK_PREREQ_PERL_MODULES}; do
		if ! perl -M"${__}" -e "" 2>/dev/null; then
			log_msg fail "Error: missing prerequisite Perl module \`${__}'.";
			__exit=1;
		fi;
	done;
	if [ ${__exit:-0} = 1 ]; then
		exit 1;
	elif [ -n "${__exit}" ]; then
		unset __exit;
	fi;
};

clean_prefix() {
	if [ ${ARG_CLEAN:-0} -eq 1 ]; then
		log_msg info "-c specified, cleaning prefix...";
		for __ in ${CLEAR_PREFIX_DIRS}; do
			if [ -e ${PREFIX}/${__} ]; then
				secure_rm ${PREFIX}/${__};
			fi;
		done;
	fi;
};

copy_etc() {
	tar -C etc -cpf - midipix.sh README midipix_shortcut.vbs	|\
	tar -C ${PREFIX} -xpf -;
	chmod +x ${PREFIX}/midipix.sh;
};

create_dirs() {
	insecure_mkdir ${PREFIX} ${PREFIX}/x86_64-w64-mingw32 ${PREFIX_NATIVE} ${PREFIX_CROSS} ${PREFIX_TARGET}/lib ${DLCACHEDIR} ${WORKDIR};
	for __ in ${PREFIX}/usr ${PREFIX_NATIVE}/usr; do
		if [ ! -L "${__}" ]; then
			secure_rm "${__}"; ln -sf -- . "${__}";
		fi;
	done;
	if [ ! -L ${PREFIX}/x86_64-w64-mingw32/mingw ]; then
		secure_rm ${PREFIX}/x86_64-w64-mingw32/mingw;
		ln -sf . ${PREFIX}/x86_64-w64-mingw32/mingw;
	fi;
	if [ ! -d ${PREFIX}/x86_64-w64-mingw32/mingw/include ]; then
		secure_rm ${PREFIX}/x86_64-w64-mingw32/mingw/include;
		insecure_mkdir ${PREFIX}/x86_64-w64-mingw32/mingw/include;
	fi;
	if [ ! -L ${PREFIX}/man ]; then
		secure_rm ${PREFIX}/man;
		ln -sf share/man ${PREFIX}/man;
	fi;
	if [ ! -L ${PREFIX_NATIVE}/man ]; then
		secure_rm ${PREFIX_NATIVE}/man;
		ln -sf share/man ${PREFIX_NATIVE}/man;
	fi;
	insecure_mkdir ${PREFIX_MINIPIX}/bin;
	for __ in lib libexec share; do
		if [ ! -e ${PREFIX_MINIPIX}/${__} ]; then
			ln -sf bin ${PREFIX_MINIPIX}/${__};
		fi;
	done;
};

fini_build_progress_file() {
	if [ -f "${BUILD_STATUS_IN_PROGRESS_FNAME}" ]; then
		secure_rm ${BUILD_STATUS_IN_PROGRESS_FNAME};
	fi;
};

fini_build_vars() {
	: $((BUILD_TIMES_SECS=$(command date +%s)-${BUILD_TIMES_SECS}));
	: $((BUILD_TIMES_HOURS=${BUILD_TIMES_SECS}/3600));
	: $((BUILD_TIMES_MINUTES=(${BUILD_TIMES_SECS}%3600)/60));
	: $((BUILD_TIMES_SECS=(${BUILD_TIMES_SECS}%3600)%60));
};

init_build_log() {
	if [ -e ${BUILD_LOG_FNAME} ]; then
		mv -- ${BUILD_LOG_FNAME} ${BUILD_LOG_LAST_FNAME};
	fi;
};

init_build_progress_file() {
	touch ${BUILD_STATUS_IN_PROGRESS_FNAME};
};

init_build_vars() {
	BUILD_DATE_START="$(date %Y-%m-%d-%H-%M-%S)";
	BUILD_NFINI=${BUILD_NSKIP:=${BUILD_NFAIL:=${BUILD_NBUILT:=0}}};
	BUILD_TIMES_SECS=$(command date +%s);
};

source_vars() {
	for __ in ${HOME}/midipix_build.vars ../midipix_build.vars ./vars/build.vars; do
		[ -e ${__} ] && . ${__};
	done;
};

subst_tgts() {
	while [ ${#} -ge 1 ]; do
	case "${1}" in
	devroot)
		echo ${DEVROOT_PACKAGES}; ;;
	world)	echo ${WORLD_PACKAGES}; ;;
	*)	echo ${1}; ;;
	esac; shift;
	done;
};

# vim:filetype=sh