Conan_Kudo / build / midipix_build

Forked from build/midipix_build 4 years ago
Clone

Blame subr/build.subr

Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
#
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
# . ./build.vars and set -o errexit -o noglob are assumed.
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
# See warning at the top of build.vars.
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
#
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
check_cpuinfo() {
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
	if [ -z "${BUILD_CPUS}" ]	\
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
	&& [ -e /proc/cpuinfo ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
		BUILD_CPUS=$(awk '/^processor/{cpus++} END{print cpus}' /proc/cpuinfo);
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
	fi;
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
};
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
clear_env() {
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
	for __ in $(export | sed -e 's/^export //' -e 's/=.*$//'); do
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
		if ! match_list "${CLEAR_ENV_VARS_EXCEPT}" " " "${__}"; then
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
			unset "${__}";
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
		fi;
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
	done;
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
};
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
check_paths() {
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
	for __ in ${CHECK_PATH_VARS}; do
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
		if [ -z "${___:=$(get_var_unsafe "${__}")}" ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
			log_msg failexit "Error: variable \`${__}' is empty or unset.";
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
		elif [ "${___#* *}" != "${___}" ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
			log_msg failexit "Error: variable \`${__}' contains one or more whitespace characters.";
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
		fi;
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
	done;
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
	for __ in ${CHECK_PREREQ_CMDS} $(eval echo ${CHECK_PREREQ_FILES_DYNAMIC}) ${CHECK_PREREQ_FILES}; do
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
		if [ "${__#/}" != "${__}" ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
			if [ ! -e "${__}" ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
				log_msg fail "Error: missing prerequisite file \`${__}'.";
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
				__exit=1;
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
			fi;
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
		else
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
			if ! test_cmd "${__}"; then
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
				log_msg fail "Error: missing prerequisite command \`${__}'.";
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
				__exit=1;
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
			fi;
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
		fi;
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
	done;
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
	for __ in ${CHECK_PREREQ_PERL_MODULES}; do
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
		if ! perl -M"${__}" -e "" 2>/dev/null; then
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
			log_msg fail "Error: missing prerequisite Perl module \`${__}'.";
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
			__exit=1;
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
		fi;
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
	done;
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
	if [ ${__exit:-0} = 1 ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
		exit 1;
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
	elif [ -n "${__exit}" ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
		unset __exit;
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
	fi;
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
};
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
clean_prefix() {
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
	if [ ${ARG_CLEAN:-0} -eq 1 ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
		log_msg info "-c specified, cleaning prefix...";
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
		for __ in ${CLEAR_PREFIX_DIRS}; do
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
			if [ -e ${PREFIX}/${__} ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
				secure_rm ${PREFIX}/${__};
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
			fi;
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
		done;
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
	fi;
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
};
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
Lucio Andrés Illanes Albornoz (arab, vxp) 5ee71e
copy_etc() {
Lucio Andrés Illanes Albornoz (arab, vxp) 38dd78
	tar -C etc -cpf - midipix.sh README midipix_shortcut.vbs	|\
Lucio Andrés Illanes Albornoz (arab, vxp) 5ee71e
	tar -C ${PREFIX} -xpf -;
Lucio Andrés Illanes Albornoz (arab, vxp) 5ee71e
	chmod +x ${PREFIX}/midipix.sh;
Lucio Andrés Illanes Albornoz (arab, vxp) 5ee71e
};
Lucio Andrés Illanes Albornoz (arab, vxp) 5ee71e
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
create_dirs() {
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
	insecure_mkdir ${PREFIX} ${PREFIX_NATIVE} ${PREFIX_CROSS} ${PREFIX_TARGET}/lib ${DLCACHEDIR} ${WORKDIR};
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
	for __ in ${PREFIX}/usr ${PREFIX_NATIVE}/usr; do
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
		if [ ! -L "${__}" ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
			secure_rm "${__}"; ln -sf -- . "${__}";
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
		fi;
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
	done;
Lucio Andrés Illanes Albornoz (arab, vxp) a04c8b
	if [ ! -L ${PREFIX_NATIVE}/man ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) a04c8b
		secure_rm ${PREFIX_NATIVE}/man;
Lucio Andrés Illanes Albornoz (arab, vxp) a04c8b
		ln -sf share/man ${PREFIX_NATIVE}/man;
Lucio Andrés Illanes Albornoz (arab, vxp) a04c8b
	fi;
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
	insecure_mkdir ${PREFIX_MINIPIX}/bin;
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
	for __ in lib libexec share; do
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
		if [ ! -e ${PREFIX_MINIPIX}/${__} ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
			ln -sf bin ${PREFIX_MINIPIX}/${__};
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
		fi;
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
	done;
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
};
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
fini_build_progress_file() {
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
	if [ -f "${BUILD_STATUS_IN_PROGRESS_FNAME}" ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
		secure_rm ${BUILD_STATUS_IN_PROGRESS_FNAME};
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
	fi;
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
};
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
fini_build_vars() {
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
	: $((BUILD_TIMES_SECS=$(command date +%s)-${BUILD_TIMES_SECS}));
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
	: $((BUILD_TIMES_HOURS=${BUILD_TIMES_SECS}/3600));
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
	: $((BUILD_TIMES_MINUTES=(${BUILD_TIMES_SECS}%3600)/60));
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
	: $((BUILD_TIMES_SECS=(${BUILD_TIMES_SECS}%3600)%60));
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
};
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
init_build_log() {
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
	if [ -e ${BUILD_LOG_FNAME} ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
		mv -- ${BUILD_LOG_FNAME} ${BUILD_LOG_LAST_FNAME};
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
	fi;
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
};
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
init_build_progress_file() {
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
	touch ${BUILD_STATUS_IN_PROGRESS_FNAME};
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
};
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
init_build_vars() {
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
	BUILD_DATE_START="$(date %Y-%m-%d-%H-%M-%S)";
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
	BUILD_NFINI=${BUILD_NSKIP:=${BUILD_NFAIL:=${BUILD_NBUILT:=0}}};
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
	BUILD_TIMES_SECS=$(command date +%s);
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
};
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
source_scripts() {
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
	set -- ${BUILD_PACKAGE_LC%.*} ${BUILD_PACKAGE_LC#*.};
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
	for SCRIPT_SOURCE in vars/${BUILD_PACKAGE_LC}.vars ${BUILD_SCRIPT_FNAME}; do
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
		if [ -f ${MIDIPIX_BUILD_PWD}/${SCRIPT_SOURCE} ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
			if [ ${ARG_DRYRUN:-0} -eq 1 ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
				echo . ${MIDIPIX_BUILD_PWD}/${SCRIPT_SOURCE};
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
			else
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
				. ${MIDIPIX_BUILD_PWD}/${SCRIPT_SOURCE};
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
			fi;
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
		fi;
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
	done;
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
};
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
source_vars() {
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
	for __ in ${HOME}/midipix_build.vars ../midipix_build.vars ./vars/build.vars; do
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
		[ -e ${__} ] && . ${__};
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
	done;
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
};
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
subst_tgts() {
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
	while [ ${#} -ge 1 ]; do
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
	case "${1}" in
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
	devroot)
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
		echo ${DEVROOT_PACKAGES}; ;;
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
	world)	echo ${WORLD_PACKAGES}; ;;
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
	*)	echo ${1}; ;;
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
	esac; shift;
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
	done;
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
};
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
# vim:filetype=sh