midipix / build / midipix_build

Forked from build/midipix_build 4 years ago
Clone
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_check.sh midipix.sh README midipix_shortcut.vbs	|\
	tar -C ${PREFIX} -xpf -;
	chmod +x ${PREFIX}/midipix.sh;
};

create_dirs() {
	insecure_mkdir ${PREFIX} ${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;
	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_scripts() {
	set -- ${BUILD_PACKAGE_LC%.*} ${BUILD_PACKAGE_LC#*.};
	for SCRIPT_SOURCE in vars/${BUILD_PACKAGE_LC}.vars ${BUILD_SCRIPT_FNAME}; do
		if [ -f ${MIDIPIX_BUILD_PWD}/${SCRIPT_SOURCE} ]; then
			if [ ${ARG_DRYRUN:-0} -eq 1 ]; then
				echo . ${MIDIPIX_BUILD_PWD}/${SCRIPT_SOURCE};
			else
				. ${MIDIPIX_BUILD_PWD}/${SCRIPT_SOURCE};
			fi;
		fi;
	done;
};

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