|
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) |
1d0876 |
. ./build.subr;
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
0724e5 |
|
|
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) |
0724e5 |
-c) ARG_CLEAN=1; ;;
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
3243be |
-i) [ -z "${2}" ] && exec cat build.usage ||\
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
3243be |
insert_build_script_link "${2}"; exit $?; ;;
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
0724e5 |
-nd) ARG_NO_DOWNLOAD=1; ;;
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
d824e1 |
-pt) ARG_PEDANTIC=1; ;;
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
6e48a0 |
-r) [ -n "${ARG_RESTART_SCRIPT}" ] && exec cat build.usage;
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
9ba5d3 |
match_any "${2}" : \
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
9ba5d3 |
&& { ARG_RESTART_SCRIPT="${2%%:*}"; ARG_RESTART_SCRIPT_AT="${2##*:}"; } \
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
9ba5d3 |
|| { ARG_RESTART_SCRIPT="${2}"; ARG_RESTART_SCRIPT_AT=ALL; };
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
6e48a0 |
shift; ;;
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
afcefa |
-t*) [ ${ARG_TARBALL:-0} -eq 1 ] && exec cat build.usage || ARG_TARBALL=1;
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
afcefa |
[ "${1#-t.}" != "${1}" ] && TARBALL_SUFFIX=${1#-t.}; ;;
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
b94746 |
-x) set -o xtrace; ;;
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
b94746 |
-X) set -o xtrace; ARG_DEBUG_TARBALL=1; ;;
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
6e48a0 |
*=*) set_var_unsafe "$(get_prefix_lrg "${1}" =)" \
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
6e48a0 |
"$(get_postfix "${1}" =)"; ;;
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
6e48a0 |
*) exec cat build.usage; ;;
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
0724e5 |
esac; shift; done;
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
0724e5 |
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
963869 |
[ -f ${HOME}/midipix_build.vars ] && . ${HOME}/midipix_build.vars;
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
963869 |
[ -f ../midipix_build.vars ] && . ../midipix_build.vars;
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
0724e5 |
. ./build.vars;
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
3243be |
clear_env_with_except ${CLEAR_ENV_VARS_EXCEPT};
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
3243be |
check_path_vars ${CHECK_PATH_VARS}; check_prereqs ${CHECK_PREREQ_CMDS};
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
578dff |
if ! [ -d ${PREFIX} ]; then
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
578dff |
mkdir ${PREFIX};
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
578dff |
fi;
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
ffc940 |
{(
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
ffc940 |
update_build_status build_start; build_times_init; trap "clean_build_status abort; exit 1" HUP INT TERM USR1 USR2;
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
ffc940 |
log_msg info "Build started by ${BUILD_USER:=${USER}}@${BUILD_HNAME:=$(hostname)} at ${BUILD_DATE_START}.";
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
c288df |
log_env_vars "build (global)" ${LOG_ENV_VARS}; [ ${ARG_CLEAN:-0} -eq 1 ] && clean_prefix;
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
951620 |
mkdir -p ${PREFIX} ${PREFIX_NATIVE} ${PREFIX_TARGET} ${PREFIX_TARGET}/lib ${WORKDIR};
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
15af12 |
if [ -d ${PREFIX}/usr -o -f ${PREFIX}/usr -o -L ${PREFIX}/usr ]; then
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
15af12 |
rm -rf ${PREFIX}/usr;
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
15af12 |
fi;
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
15af12 |
ln -sf . ${PREFIX}/usr;
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
15af12 |
if [ -d ${PREFIX_NATIVE}/usr -o -f ${PREFIX_NATIVE}/usr -o -L ${PREFIX_NATIVE}/usr ]; then
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
15af12 |
rm -rf ${PREFIX_NATIVE}/usr;
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
15af12 |
fi;
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
15af12 |
ln -sf . ${PREFIX_NATIVE}/usr;
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
96b309 |
BUILD_NFINI=${BUILD_NSKIP:=${BUILD_NFAIL:=${BUILD_NBUILT:=0}}};
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
afcefa |
for BUILD_LVL in 0 1 2 3 ${ARG_TARBALL:+9}; do
|
|
lalbornoz |
340f4c |
for BUILD_SCRIPT_FNAME in ${BUILD_LVL}[0-9][0-9].*.build; do
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
6e48a0 |
if [ -n "${ARG_RESTART_SCRIPT}" ] \
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
6e48a0 |
&& [ "${ARG_RESTART_SCRIPT}" != "ALL" ] \
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
6e48a0 |
&& ! match_list "${ARG_RESTART_SCRIPT}" \
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
1d0876 |
, "${BUILD_SCRIPT_FNAME}"; then
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
1d0876 |
log_msg info "Skipped build script \`${BUILD_SCRIPT_FNAME}' (--build-scripts policy.)";
|
|
lalbornoz |
340f4c |
continue;
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
3243be |
elif [ ! -f "${BUILD_SCRIPT_FNAME}" ]; then
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
1d0876 |
log_msg info "Build script \`${BUILD_SCRIPT_FNAME}' non-existent or not a file.";
|
|
lalbornoz |
340f4c |
continue;
|
|
lalbornoz |
340f4c |
else
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
96b309 |
unset BUILD_SCRIPT_RC; : $((BUILD_NBUILT+=1));
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
9ba5d3 |
if [ "${ARG_RESTART_SCRIPT}" != ALL ]\
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
1d0876 |
&& is_build_script_done finish "${BUILD_SCRIPT_FNAME%.build}"; then
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
1d0876 |
log_msg info "Skipped build script \`${BUILD_SCRIPT_FNAME}' (already built.)";
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
1d0876 |
: $((BUILD_NSKIP+=1)); BUILD_SCRIPT_RC=0; continue;
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
1d0876 |
fi;
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
6e48a0 |
log_msg info "Invoking build script${ARG_RESTART_SCRIPT:+ (forcibly)} \`${BUILD_SCRIPT_FNAME}'${ARG_RESTART_SCRIPT_AT:+ at build step ${ARG_RESTART_SCRIPT_AT}}.";
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
1d0876 |
(set -o errexit -- $(split . ${BUILD_SCRIPT_FNAME%%.build*}); \
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
1d0876 |
SCRIPT_FNAME=${BUILD_SCRIPT_FNAME}; \
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
1d0876 |
SCRIPT_NAME=${SCRIPT_FNAME%%.build*}; \
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
f9c386 |
export PREFIX_LVL="$(eval echo \${PREFIX_LVL${BUILD_LVL}})"; \
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
3243be |
export PKG_TARGET=${TARGET}; \
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
92d6c5 |
export MIDIPIX_BUILD_PWD=$(pwd); cd ${WORKDIR}; \
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
1d0876 |
for SCRIPT_SOURCE in build.subr ${SCRIPT_NAME}.vars \
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
1d0876 |
${BUILD_SCRIPT_FNAME}; do \
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
92d6c5 |
[ -f ${MIDIPIX_BUILD_PWD}/${SCRIPT_SOURCE} ] && \
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
92d6c5 |
. ${MIDIPIX_BUILD_PWD}/${SCRIPT_SOURCE}; \
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
1d0876 |
done);
|
|
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 |
*) log_msg fail "Build failed in build script \`${BUILD_SCRIPT_FNAME}' (last return code ${BUILD_SCRIPT_RC}.).";
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
b94746 |
if [ ${ARG_DEBUG_TARBALL:-0} -eq 1 ]; then
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
b94746 |
log_msg info "-X specified, creating debug tarball.";
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
b94746 |
SCRIPT_NAME=${BUILD_SCRIPT_FNAME%%.build};
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
b94746 |
SCRIPT_NAME=${SCRIPT_NAME#*.};
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
b94746 |
SCRIPT_NAME=$(echo "${SCRIPT_NAME}" | tr a-z A-Z);
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
3243be |
if [ -z "${PKG_SUBDIR=$(get_var_unsafe PKG_${SCRIPT_NAME}_SUBDIR)}" ]; then
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
b94746 |
PKG_URL=$(get_var_unsafe PKG_${SCRIPT_NAME}_URL);
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
b94746 |
PKG_FNAME=${PKG_URL##*/};
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
b94746 |
PKG_SUBDIR=${PKG_FNAME%%.tar*};
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
b94746 |
fi;
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
4e7360 |
BUILD_DEBUG_TARBALL_FNAME=${PREFIX}/midipix-debug-${BUILD_USER}@${BUILD_HNAME}_$(date %Y-%m-%d-%H-%M-%S).tar.xz;
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
4e7360 |
tar -C ${PREFIX} -cJp \
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
4e7360 |
-f ${BUILD_DEBUG_TARBALL_FNAME} \
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
4e7360 |
build.log $(cd ${PREFIX} && \
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
4e7360 |
find ${WORKDIR#${PREFIX}/} \
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
4e7360 |
-mindepth 1 -maxdepth 1 \
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
4e7360 |
-type d -iname ${PKG_SUBDIR}-*);
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
b94746 |
log_msg info "Please upload ${BUILD_DEBUG_TARBALL_FNAME} and provide an URL to it in <irc://irc.freenode.net/midipix>.";
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
b94746 |
fi;
|
|
lalbornoz |
340f4c |
: $((BUILD_NFAIL+=1)); break; ;;
|
|
lalbornoz |
340f4c |
esac;
|
|
lalbornoz |
340f4c |
fi;
|
|
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) |
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) |
0724e5 |
build_times_get; 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) |
75cb84 |
update_build_status finish; clean_build_status;
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
95bf77 |
exit ${BUILD_SCRIPT_RC})} 2>&1 | tee ${PREFIX}/${BUILD_LOG_FNAME:=build-$(date ${TIMESTAMP_FMT_STATUS_FILES}).log} &
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
75cb84 |
trap "kill -INT $!" HUP INT TERM USR1 USR2; wait;
|
|
lalbornoz |
340f4c |
|
|
lalbornoz |
340f4c |
# vim:filetype=sh
|