summaryrefslogtreecommitdiffhomepage
path: root/subr
diff options
context:
space:
mode:
Diffstat (limited to 'subr')
-rw-r--r--subr/build.subr140
-rw-r--r--subr/pkg.subr145
-rw-r--r--subr/rtl.subr102
-rw-r--r--subr/strip.subr19
-rw-r--r--subr/tarballs.subr108
5 files changed, 514 insertions, 0 deletions
diff --git a/subr/build.subr b/subr/build.subr
new file mode 100644
index 00000000..98bd4555
--- /dev/null
+++ b/subr/build.subr
@@ -0,0 +1,140 @@
+#
+# . ./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;
+};
+
+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
diff --git a/subr/pkg.subr b/subr/pkg.subr
new file mode 100644
index 00000000..2e0e36ae
--- /dev/null
+++ b/subr/pkg.subr
@@ -0,0 +1,145 @@
+#
+# . ./build.vars and set -o errexit -o noglob are assumed.
+# See warning at the top of build.vars.
+#
+
+# N.B. URLs ($1) may contain `?' or '&' characters.
+fetch() {
+ _f_url="${1}"; _f_sha256sum_src="${2}";
+ _f_url_dst="${DLCACHEDIR}/$(basename "${_f_url}")";
+ if [ -e ${_f_url_dst}.fetched ]; then
+ unset _f_url _f_sha256sum_src _f_url_dst;
+ return 0;
+ else
+ wget ${WGET_ARGS} -c -O ${_f_url_dst} "${_f_url}";
+ fi;
+ if [ -n "${_f_sha256sum_src}" ]; then
+ set -- $(openssl dgst -sha256 ${_f_url_dst}); shift $((${#}-1));
+ if [ "${_f_sha256sum_dst:=${1}}" != "${_f_sha256sum_src}" ]; then
+ log_msg failexit "Error: hash mismatch for URL \`${_f_url}' (is: ${_f_sha256sum_dst}, should be: ${_f_sha256sum_src}.)";
+ fi;
+ fi;
+ touch ${_f_url_dst}.fetched;
+ unset _f_url _f_url_dst _f_sha256sum_src _f_sha256sum_dst;
+};
+
+fetch_git() {
+ _fg_subdir="${1}"; _fg_url="${2}"; _fg_branch="${3}";
+ if [ -e "${DLCACHEDIR}/${_fg_subdir}" ]; then
+ cd ${DLCACHEDIR}/${_fg_subdir} &&\
+ git pull origin ${_fg_branch:-main} && cd ${OLDPWD};
+ else
+ git clone ${_fg_url} ${DLCACHEDIR}/${_fg_subdir};
+ if [ -n "${_fg_branch}" -a \
+ \( -z "${_fg_branch#main}" \) -a \
+ \( -z "${_fg_branch#master}" \) ]; then
+ cd ${DLCACHEDIR}/${_fg_subdir} &&\
+ git checkout -b ${_fg_branch} && cd ${OLDPWD};
+ fi;
+ fi;
+ secure_rm ${_fg_subdir};
+ cp -pr ${DLCACHEDIR}/${_fg_subdir} .;
+};
+
+is_build_script_done() {
+ if match_list "${ARG_RESTART}" , ${BUILD_PACKAGE_LC}; then
+ if [ -n "${ARG_RESTART_AT}" ] \
+ && [ "${ARG_RESTART_AT}" != "${1}" ]; then
+ return 0; # Skip
+ else
+ return 1; # Build
+ fi;
+ elif [ -f ${WORKDIR}/.${2:-${BUILD_PACKAGE_LC}}.${1} ]; then
+ return 0; # Skip
+ else
+ return 1; # Build
+ fi;
+};
+
+log_env_vars() {
+ log_msg info "Variables for this ${1:-build}:"; shift;
+ while [ ${_lev_nvar:=0} -lt ${#} ]; do
+ _lev_arg="$(eval echo \${${_lev_nvar}})";
+ _lev_arg="${_lev_arg%%=*}";
+ if [ ${#_lev_arg} -gt ${_lev_arg_len_max:=0} ]; then
+ _lev_arg_len_max=${#_lev_arg};
+ fi; : $((_lev_nvar+=1));
+ done; unset _lev_nvar _lev_arg;
+ while [ ${#} -gt 0 ]; do
+ log_msg info "$(printf \
+ "%${_lev_arg_len_max}.${_lev_arg_len_max}s=%s" \
+ "${1%%=*}" "$(get_var_unsafe ${1#*=})")";
+ shift;
+ done; unset _lev_arg_len_max;
+};
+
+parse_with_pkg_name() {
+ PKG_NAME=${1}; shift;
+ _pwpn_pkg_name_uc=$(echo ${PKG_NAME} | tr a-z A-Z);
+ if [ -z "$(get_var_unsafe PKG_${_pwpn_pkg_name_uc}_URL)" ]; then
+ unset _pwpn_pkg_name_uc;
+ log_msg failexit "Error: package \`${PKG_NAME}' missing in build.vars.";
+ else
+ for _pwpn_vname in ${PKG_BUILD_VARS}; do
+ if [ -n "$(get_var_unsafe DEFAULT_${_pwpn_vname})" ]; then
+ export "PKG_${_pwpn_vname}=$(get_var_unsafe DEFAULT_${_pwpn_vname})";
+ fi;
+ if [ -n "$(get_var_unsafe ${BUILD_TARGET}_${_pwpn_vname})" ]; then
+ export "PKG_${_pwpn_vname}=$(get_var_unsafe ${BUILD_TARGET}_${_pwpn_vname})";
+ fi;
+ if [ "${BUILD}" = "debug" ] \
+ && [ -n "$(get_var_unsafe PKG_${_pwpn_pkg_name_uc}_${_pwpn_vname}_DEBUG)" ]; then
+ export "PKG_${_pwpn_vname}=$(get_var_unsafe PKG_${_pwpn_pkg_name_uc}_${_pwpn_vname}_DEBUG)";
+ elif [ "${BUILD}" = "release" ] \
+ && [ -n "$(get_var_unsafe PKG_${_pwpn_pkg_name_uc}_${_pwpn_vname}_RELEASE)" ]; then
+ export "PKG_${_pwpn_vname}=$(get_var_unsafe PKG_${_pwpn_pkg_name_uc}_${_pwpn_vname}_RELEASE)";
+ elif [ -n "$(get_var_unsafe PKG_${_pwpn_pkg_name_uc}_${_pwpn_vname})" ]; then
+ export "PKG_${_pwpn_vname}=$(get_var_unsafe PKG_${_pwpn_pkg_name_uc}_${_pwpn_vname})";
+ fi;
+ done; unset _pwpn_vname;
+ fi;
+ [ -z "${PKG_FNAME}" ] && PKG_FNAME=${PKG_URL##*/};
+ [ -z "${PKG_SUBDIR}" ] && PKG_SUBDIR=${PKG_FNAME%%.tar*};
+ [ -n "${PKG_ENV_VARS_EXTRA}" ] && set_env_vars_with_sep : "${PKG_ENV_VARS_EXTRA}";
+ for _pwpn_env_var in $(export); do
+ if [ "${_pwpn_env_var#PKG_}" != "${_pwpn_env_var}" ]; then
+ _pwpn_env_vars="${_pwpn_env_vars:+${_pwpn_env_vars} }${_pwpn_env_var%%=*}";
+ fi;
+ done;
+ if [ -n "${_pwpn_env_vars}" ]; then
+ log_env_vars "build" ${_pwpn_env_vars};
+ fi; unset _pwpn_pkg_name_uc _pwpn_env_var _pwpn_env_vars;
+};
+
+run_cmd_unsplit() {
+ _rcu_cmd=${1}; shift;
+ while [ ${#} -gt 0 ]; do
+ [ -n "${1}" ] &&\
+ _rcu_cmdline="${_rcu_cmdline:+${_rcu_cmdline}:}${1}";
+ shift;
+ done;
+ push_IFS :; ${_rcu_cmd} ${_rcu_cmdline}; _rcu_rc=$?; pop_IFS;
+ unset _rcu_cmd _rcu_cmdline; return ${_rcu_rc};
+};
+
+set_build_script_done() {
+ _sbsd_script_fname=${BUILD_PACKAGE_LC};
+ _sbsd_done_fname=${WORKDIR}/.${_sbsd_script_fname};
+ while [ $# -ge 1 ]; do
+ if [ "${1#-}" != "${1}" ]; then
+ secure_rm ${_sbsd_done_fname}.${1#-};
+ else
+ touch ${_sbsd_done_fname}.${1};
+ log_msg info "Finished build step ${1} of \`${_sbsd_script_fname}'.";
+ fi; shift;
+ done; unset _sbsd_script_fname _sbsd_done_fname;
+};
+
+set_env_vars_with_sep() {
+ _sevws_sep=${1}; shift; push_IFS ${_sevws_sep}; set -- ${1};
+ while [ ${#} -gt 0 ]; do
+ export "${1}"; shift;
+ done; unset _sevws_sep; pop_IFS;
+};
+
+# vim:filetype=sh
diff --git a/subr/rtl.subr b/subr/rtl.subr
new file mode 100644
index 00000000..5d1dd97a
--- /dev/null
+++ b/subr/rtl.subr
@@ -0,0 +1,102 @@
+#
+# . ./build.vars and set -o errexit -o noglob are assumed.
+# See warning at the top of build.vars.
+#
+
+date() { command date +"${1:-${TIMESTAMP_FMT}}"; };
+get_var_unsafe() { eval echo \${${1}}; };
+set_var_unsafe() { eval ${1}=\"${2}\"; };
+push_IFS() { _pI_IFS="${IFS}"; IFS="${1}"; };
+pop_IFS() { IFS="${_pI_IFS}"; unset _pI_IFS; };
+set_build_dir() { PKG_BUILD_DIR=${1}-${2}-${TARGET}; };
+split() { push_IFS "${1}"; set -- ${2}; pop_IFS; echo "${*}"; };
+test_cmd() { command -v "${1}" >/dev/null; };
+unsplit() { push_IFS "${1}"; shift; set -- "${@}"; echo "${*}"; pop_IFS; };
+
+get_vars_unsafe() {
+ while [ ${#} -gt 0 ]; do
+ _gvu_vval="$(eval echo \${${1}})";
+ [ -z "${_gvu_vval}" ] || _gvu_vval_="${_gvu_vval}";
+ shift;
+ done; echo "${_gvu_vval_}";
+ unset _gvu_vval _gvu_vval_;
+};
+
+log_msg() {
+ _lm_lvl=${1}; shift;
+ case ${_lm_lvl} in
+ failexit) printf "\033[0m\033[${LOG_MSG_FAIL_COLOUR}m"; ;;
+ fail) printf "\033[0m\033[${LOG_MSG_FAIL_COLOUR}m"; ;;
+ info) printf "\033[0m\033[${LOG_MSG_INFO_COLOUR}m"; ;;
+ succ) printf "\033[0m\033[${LOG_MSG_SUCC_COLOUR}m"; ;;
+ warn) printf "\033[0m\033[${LOG_MSG_WARN_COLOUR}m"; ;;
+ esac;
+ if [ $# -gt 1 ]; then
+ printf "==> %s %s %s\033[0m\n" "$(date "${TIMESTAMP_FMT}")" "${1}" "$*";
+ else
+ printf "==> %s %s\033[0m\n" "$(date "${TIMESTAMP_FMT}")" "${1}";
+ fi; [ ${_lm_lvl} = failexit ] && exit 1 || unset _lm_lvl;
+};
+
+insecure_mkdir() {
+ while [ ${#} -gt 0 ]; do
+ if [ -z "${1}" ]; then
+ return 1;
+ elif [ ! -e "${1}" ]; then
+ [ "${ARG_VERBOSE:-0}" -eq 1 ] &&\
+ log_msg warn "Making directory \`${1}'.";
+ mkdir -p -- "${1}";
+ fi; shift;
+ done;
+};
+
+match_list() {
+ _ml_cmp="${3}"; push_IFS "${2}"; set -- ${1}; pop_IFS;
+ while [ ${#} -gt 0 ]; do
+ if [ "${1}" = "${_ml_cmp}" ]; then
+ unset _ml_cmp; return 0;
+ fi; shift;
+ done; unset _ml_cmp; return 1;
+};
+
+secure_cd() {
+ if [ \( -z "${1}" \) -o \( ! -e "${1}" \) ]; then
+ return 1;
+ else
+ (cd "${1}"; [ "${PWD#${PREFIX_ROOT}}" = "${PWD}" ] &&\
+ return 1 || return 0);
+ if [ ${?} -eq 0 ]; then
+ [ "${ARG_VERBOSE:-0}" -eq 1 ] &&\
+ log_msg warn "Changing working directory to \`${1}'.";
+ cd -- "${1}";
+ else
+ log_msg failexit "secure_cd() called with pathname \`${1}' not below \${PREFIX_ROOT} (${PREFIX_ROOT}). This is a bug.";
+ fi;
+ fi;
+};
+
+secure_rm() {
+ while [ ${#} -gt 0 ]; do
+ if [ -z "${1}" ]; then
+ return 1;
+ elif [ -e "${1}" ]; then
+ if [ -d "${1}" ]; then
+ _sr_pname_check="${1}";
+ else
+ _sr_pname_check="$(dirname "${1}")";
+ fi;
+ (cd "${_sr_pname_check}"; [ "${PWD#${PREFIX_ROOT}}" = "${PWD}" ] &&\
+ return 1 || return 0);
+ if [ ${?} -eq 0 ]; then
+ unset _sr_pname_check;
+ [ "${ARG_VERBOSE:-0}" -eq 1 ] &&\
+ log_msg warn "Removing directory or file \`${1}'.";
+ rm -rf -- "${1}";
+ else
+ log_msg failexit "secure_rm() called with pathname \`${1}' not below \${PREFIX_ROOT} (${PREFIX_ROOT}). This is a bug.";
+ fi;
+ fi; shift;
+ done;
+};
+
+# vim:filetype=sh
diff --git a/subr/strip.subr b/subr/strip.subr
new file mode 100644
index 00000000..c4e17a3e
--- /dev/null
+++ b/subr/strip.subr
@@ -0,0 +1,19 @@
+#
+# . ./build.vars and set -o errexit -o noglob are assumed.
+#
+
+do_strip() {
+ if [ ${BUILD_SCRIPT_RC:-0} -eq 0 ]\
+ && [ "${BUILD}" = release ]; then
+ for __ in $(find ${PREFIX_NATIVE}/bin -perm -0100 \( -type f -or -type l \)); do
+ if objdump -sj .debug_info >/dev/null 2>&1; then
+ if [ ${ARG_VERBOSE:-0} -eq 1 ]; then
+ echo ${PKG_TARGET}-strip ${__};
+ fi;
+ set +o errexit; ${PKG_TARGET}-strip ${__}; set -o errexit;
+ fi;
+ done;
+ fi;
+};
+
+# vim:filetype=sh
diff --git a/subr/tarballs.subr b/subr/tarballs.subr
new file mode 100644
index 00000000..7bde6642
--- /dev/null
+++ b/subr/tarballs.subr
@@ -0,0 +1,108 @@
+#
+# . ./build.vars and set -o errexit -o noglob are assumed.
+#
+
+do_tarball_dist() {
+ TARBALL_FNAME=${TARBALL_FNAME_PREFIX}${BUILD_USER}@${BUILD_HNAME}-${BUILD_DATE_START}.tar.${TARBALL_SUFFIX};
+ secure_rm ${PREFIX_BASENAME}/lib.bak;
+ insecure_mkdir ${PREFIX_BASENAME}/lib.bak;
+ tar -C ${PREFIX_BASENAME}/lib -cpf - . | tar -C ${PREFIX_BASENAME}/lib.bak -xpf -;
+ log_msg info "Backed up ${PREFIX_BASENAME}/lib.";
+ for __ in $(find native/lib \( -iname \*.so -or -iname \*.so.\* \) \
+ -type l); do
+ ___="native/lib/$(readlink -- ${__})";
+ if [ -f "${___}" ]; then
+ secure_rm ${__}; ln -f -- "${___}" "${__}";
+ fi;
+ done;
+ log_msg info "Converted symbolic links in ${PREFIX_BASENAME}/lib to hard links.";
+
+ tar -cpf - $(find . -maxdepth 2 -mindepth 1 -type d \
+ -not -path ./native -not -path ./native/lib.bak \
+ -not -path ./tmp -not -path ./tmp/\*) \
+ etc/midipix_shortcut.vbs etc/midipix.sh etc/README |\
+ ${TARBALL_COMPRESS_CMD} ${TARBALL_COMPRESS_ARGS} -c > ${TARBALL_FNAME};
+ log_msg info "Finished building binary distribution tarball.";
+ if [ -x "$(which gpg 2>/dev/null)" -a -n "${TARBALL_SIGN_GPG_KEY}" ] &&\
+ gpg --list-keys "${TARBALL_SIGN_GPG_KEY}" >/dev/null 2>&1; then
+ gpg --armor --passphrase-file /dev/null \
+ --local-user "${TARBALL_SIGN_GPG_KEY}" --sign ${TARBALL_FNAME};
+ log_msg info "Signed binary distribution tarball.";
+ fi;
+ secure_rm ${PREFIX_BASENAME}/lib; mv -- ${PREFIX_BASENAME}/lib.bak ${PREFIX_BASENAME}/lib;
+ log_msg info "Restored ${PREFIX_BASENAME}/lib.";
+};
+
+do_tarball_toolchain() {
+ TARBALL_CROSS_FNAME=${TARBALL_CROSS_FNAME_PREFIX}${BUILD_USER}@${BUILD_HNAME}-${BUILD_DATE_START}.tar.${TARBALL_SUFFIX};
+ tar -cpf - bin include lib lib64 libexec share ${PKG_TARGET} |\
+ ${TARBALL_COMPRESS_CMD} ${TARBALL_COMPRESS_ARGS} -c > ${TARBALL_CROSS_FNAME};
+ log_msg info "Finished building toolchain tarball.";
+ if [ -x "$(which gpg 2>/dev/null)" -a -n "${TARBALL_CROSS_SIGN_GPG_KEY}" ] &&\
+ gpg --list-keys "${TARBALL_CROSS_SIGN_GPG_KEY}" >/dev/null 2>&1; then
+ gpg --armor --passphrase-file /dev/null \
+ --local-user "${TARBALL_CROSS_SIGN_GPG_KEY}" --sign ${TARBALL_CROSS_FNAME};
+ log_msg info "Signed toolchain tarball.";
+ fi;
+};
+
+do_tarball_minipix() {
+ TARBALL_MINIPIX_FNAME=${TARBALL_MINIPIX_FNAME_PREFIX}${BUILD_USER}@${BUILD_HNAME}-${BUILD_DATE_START}.tar.${TARBALL_SUFFIX};
+ tar -cpf - minipix \
+ etc/midipix_shortcut.vbs etc/midipix.sh etc/README |\
+ ${TARBALL_COMPRESS_CMD} ${TARBALL_COMPRESS_ARGS} -c > ${TARBALL_MINIPIX_FNAME};
+ log_msg info "Finished building binary Minipix distribution tarball.";
+ if [ -x "$(which gpg 2>/dev/null)" -a -n "${TARBALL_MINIPIX_SIGN_GPG_KEY}" ] &&\
+ gpg --list-keys "${TARBALL_MINIPIX_SIGN_GPG_KEY}" >/dev/null 2>&1; then
+ gpg --armor --passphrase-file /dev/null \
+ --local-user "${TARBALL_MINIPIX_SIGN_GPG_KEY}" --sign ${TARBALL_MINIPIX_FNAME};
+ log_msg info "Signed binary Minipix distribution tarball.";
+ fi;
+};
+
+do_tarball_src() {
+ TARBALL_SRC_FNAME=${TARBALL_SRC_FNAME_PREFIX}${BUILD_USER}@${BUILD_HNAME}-${BUILD_DATE_START}.tar.${TARBALL_SUFFIX};
+ log_msg info "Building source tarball...";
+ tar -cpf - $(find tmp -mindepth 2 -maxdepth 2 \
+ -not -path tmp/.\* \
+ -not -path tmp/ntctty/.git \
+ -not -path tmp/psxscl/.git \
+ -not -path tmp/ptycon/.git) |\
+ ${TARBALL_COMPRESS_CMD} ${TARBALL_COMPRESS_ARGS} -c > ${TARBALL_SRC_FNAME};
+ log_msg info "Finished building source tarball.";
+ if [ -x "$(which gpg 2>/dev/null)" -a -n "${TARBALL_SRC_SIGN_GPG_KEY}" ] &&\
+ gpg --list-keys "${TARBALL_SRC_SIGN_GPG_KEY}" >/dev/null 2>&1; then
+ gpg --armor --passphrase-file /dev/null \
+ --local-user "${TARBALL_SRC_SIGN_GPG_KEY}" --sign ${TARBALL_SRC_FNAME};
+ log_msg info "Signed source tarball.";
+ fi;
+};
+
+do_tarballs() {
+ if [ ${BUILD_SCRIPT_RC:-0} -eq 0 ]\
+ && [ ${ARG_TARBALL:-0} -eq 1 ]; then
+ log_msg info "Building distribution tarballs...";
+ case ${TARBALL_SUFFIX} in
+ bz2) if [ -n "$(which pbzip2 2>/dev/null)" ]; then
+ TARBALL_COMPRESS_CMD="pbzip2";
+ else
+ TARBALL_COMPRESS_CMD="bzip2";
+ fi; ;;
+ gz) if [ -n "$(which pigz 2>/dev/null)" ]; then
+ TARBALL_COMPRESS_CMD="pigz";
+ else
+ TARBALL_COMPRESS_CMD="gzip";
+ fi; ;;
+ xz) TARBALL_COMPRESS_CMD="xz";
+ TARBALL_COMPRESS_ARGS="-T0"; ;;
+ *) log_msg failexit "Unknown tarball suffix \`.${TARBALL_SUFFIX}'.";
+ esac;
+ cd ${PREFIX}; PREFIX_BASENAME=${PREFIX_NATIVE##*/};
+ do_tarball_dist; do_tarball_toolchain; do_tarball_minipix;
+ if [ "${BUILD}" = "debug" ]; then
+ do_tarball_src;
+ fi;
+ fi;
+};
+
+# vim:filetype=sh