lalbornoz 340f4c
#!/bin/sh
lalbornoz 340f4c
lalbornoz 340f4c
{
Lucio Andrés Illanes Albornoz (arab, vxp) f9c386
#clear_env_with_except HOME PATH SHELL TERM USER;
lalbornoz 340f4c
unset AR ARFLAGS CC CFLAGS CXX CXXFLAGS LD LDFLAGS;
lalbornoz 340f4c
. ./build.vars; . ./build.subr;
Lucio Andrés Illanes Albornoz (arab, vxp) d30b8f
check_path_vars PREFIX PREFIX_NATIVE WORKDIR;
Lucio Andrés Illanes Albornoz (arab, vxp) 680d83
check_prereqs git make openssl sed sort tar tr wget;
Lucio Andrés Illanes Albornoz (arab, vxp) 0dae87
set_env_vars "" LANG LANGUAGE LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES LC_PAPER LC_NAME LC_ADDRESS \
Lucio Andrés Illanes Albornoz (arab, vxp) 0dae87
LC_TELEPHONE LC_MEASUREMENT LC_IDENTIFICATION LC_ALL;
Lucio Andrés Illanes Albornoz (arab, vxp) d30b8f
log_msg info "Build started by ${BUILD_USER:=${USER}}@${BUILD_HNAME:=$(hostname)} at ${BUILD_DATE:=$(date %Y-%m-%d-%H-%M-%S)}.";
lalbornoz 340f4c
#trap
Lucio Andrés Illanes Albornoz (arab, vxp) 29df05
(set -o errexit; mkdir -p ${PREFIX} ${WORKDIR});
Lucio Andrés Illanes Albornoz (arab, vxp) 96b309
BUILD_NFINI=${BUILD_NSKIP:=${BUILD_NFAIL:=${BUILD_NBUILT:=0}}};
Lucio Andrés Illanes Albornoz (arab, vxp) 75a203
for BUILD_LVL in 0 1 2 3; do
lalbornoz 340f4c
	for BUILD_SCRIPT_FNAME in ${BUILD_LVL}[0-9][0-9].*.build; do
lalbornoz 340f4c
		if [ -n "${DEBUG_SCRIPT}" ]\
lalbornoz 340f4c
		&& [ "x${DEBUG_SCRIPT}" != "x${BUILD_SCRIPT_FNAME}" ]; then
lalbornoz 340f4c
			continue;
Lucio Andrés Illanes Albornoz (arab, vxp) 29df05
		elif [ ! -f ${BUILD_SCRIPT_FNAME} ]; then
lalbornoz 340f4c
			continue;
lalbornoz 340f4c
		else
Lucio Andrés Illanes Albornoz (arab, vxp) 96b309
			unset BUILD_SCRIPT_RC; : $((BUILD_NBUILT+=1));
lalbornoz 340f4c
			log_msg info "Invoking build script \`${BUILD_SCRIPT_FNAME}'";
Lucio Andrés Illanes Albornoz (arab, vxp) 29df05
			(set -o errexit -- $(split . ${BUILD_SCRIPT_FNAME%.build});	\
Lucio Andrés Illanes Albornoz (arab, vxp) 29df05
			 SCRIPT_FNAME=${BUILD_SCRIPT_FNAME}; _pwd=$(pwd);		\
Lucio Andrés Illanes Albornoz (arab, vxp) d30b8f
			 export CFLAGS="$(eval echo \${CFLAGS_LVL${BUILD_LVL}})";	\
Lucio Andrés Illanes Albornoz (arab, vxp) f9c386
			 export PREFIX_LVL="$(eval echo \${PREFIX_LVL${BUILD_LVL}})";	\
Lucio Andrés Illanes Albornoz (arab, vxp) 29df05
			 cd ${WORKDIR}; . ${_pwd}/build.subr;				\
Lucio Andrés Illanes Albornoz (arab, vxp) 75a203
			 [ -f ${_pwd}/${SCRIPT_FNAME%.build}.vars ] &&			\
Lucio Andrés Illanes Albornoz (arab, vxp) 75a203
			 	. ${_pwd}/${SCRIPT_FNAME%.build}.vars;			\
Lucio Andrés Illanes Albornoz (arab, vxp) 29df05
			 . ${_pwd}/${BUILD_SCRIPT_FNAME});
lalbornoz 340f4c
			case ${BUILD_SCRIPT_RC:=${?}} in
lalbornoz 340f4c
			0) log_msg succ "Finished build script \`${BUILD_SCRIPT_FNAME}'.";
lalbornoz 340f4c
				: $((BUILD_NFINI+=1)); continue; ;;
lalbornoz 340f4c
			212) log_msg info "Skipped build script \`${BUILD_SCRIPT_FNAME}' (already built.)";
lalbornoz 340f4c
				: $((BUILD_NSKIP+=1)); BUILD_SCRIPT_RC=0; continue; ;;
lalbornoz 340f4c
			*) log_msg fail "Build failed in build script \`${BUILD_SCRIPT_FNAME}' (last return code ${BUILD_SCRIPT_RC}.).";
lalbornoz 340f4c
				: $((BUILD_NFAIL+=1)); break; ;;
lalbornoz 340f4c
			esac;
lalbornoz 340f4c
		fi;
lalbornoz 340f4c
	done;
lalbornoz 340f4c
	if [ ${BUILD_SCRIPT_RC:-0} != 0 ]; then
lalbornoz 340f4c
		break;
lalbornoz 340f4c
	fi;
lalbornoz 340f4c
done;
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) d30b8f
if [ $(( ${BUILD_NFINI} + ${BUILD_NSKIP} )) -ge 0 ]\
Lucio Andrés Illanes Albornoz (arab, vxp) d30b8f
&& [ ${BUILD_NFAIL} -eq 0 ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) d30b8f
	log_msg info "Building distribution tarball.";
Lucio Andrés Illanes Albornoz (arab, vxp) d30b8f
	(cd ${PREFIX};
Lucio Andrés Illanes Albornoz (arab, vxp) d30b8f
	DISTRIB_FNAME=midipix.${BUILD_USER}@${BUILD_HNAME}-${BUILD_DATE}.tar.bz2;
Lucio Andrés Illanes Albornoz (arab, vxp) d30b8f
	rm_if_exists -m ${PREFIX_NATIVE##*/}/lib.bak; rm_if_exists ${DISTRIB_FNAME};
Lucio Andrés Illanes Albornoz (arab, vxp) d30b8f
	tar -C ${PREFIX_NATIVE##*/}/lib -cpf - . |\
Lucio Andrés Illanes Albornoz (arab, vxp) d30b8f
	tar -C ${PREFIX_NATIVE##*/}/lib.bak -xpf -;
Lucio Andrés Illanes Albornoz (arab, vxp) d30b8f
	(cd native/lib &&
Lucio Andrés Illanes Albornoz (arab, vxp) d30b8f
	 find . -maxdepth 1 -type l				\
Lucio Andrés Illanes Albornoz (arab, vxp) d30b8f
		-exec sh -c 'dest=$(readlink -- "$0") && rm -- "$0" && ln -- "$dest" "$0"' {} \;);
Lucio Andrés Illanes Albornoz (arab, vxp) d30b8f
	wait;
Lucio Andrés Illanes Albornoz (arab, vxp) d30b8f
	find .	-maxdepth 2 -type d				\
Lucio Andrés Illanes Albornoz (arab, vxp) d30b8f
		-not -path .					\
Lucio Andrés Illanes Albornoz (arab, vxp) d30b8f
		-not -path ./${WORKDIR##*/}			\
Lucio Andrés Illanes Albornoz (arab, vxp) d30b8f
		-not -path ./${WORKDIR##*/}/\*			\
Lucio Andrés Illanes Albornoz (arab, vxp) d30b8f
		-not -path ./${PREFIX_NATIVE##*/}		\
Lucio Andrés Illanes Albornoz (arab, vxp) d30b8f
		-not -path ./${PREFIX_NATIVE##*/}/lib.bak	|\
Lucio Andrés Illanes Albornoz (arab, vxp) d30b8f
	tar -T - -cpf - | bzip2 -9c - > ${DISTRIB_FNAME}
Lucio Andrés Illanes Albornoz (arab, vxp) d30b8f
	rm -rf ${PREFIX_NATIVE##*/}/lib;
Lucio Andrés Illanes Albornoz (arab, vxp) 96b309
	mv ${PREFIX_NATIVE##*/}/lib.bak ${PREFIX_NATIVE##*/}/lib); wait;
Lucio Andrés Illanes Albornoz (arab, vxp) d30b8f
fi;
lalbornoz 340f4c
exit ${BUILD_SCRIPT_RC};
lalbornoz 340f4c
} 2>&1 | tee build.log;
lalbornoz 340f4c
lalbornoz 340f4c
# vim:filetype=sh