From c6d6e08feab839a9dc5792071fb803494cc51a69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucio=20Andr=C3=A9s=20Illanes=20Albornoz?= Date: Wed, 26 Feb 2020 21:54:12 +0000 Subject: General cleanup, pt. II. --- subr/build_init.subr | 290 ++++++++++++++++++------------------- subr/ex_pkg.subr | 75 ++++++++++ subr/ex_pkg_dispatch.subr | 294 +++++++++++++++++++++----------------- subr/ex_pkg_env.subr | 57 ++++---- subr/ex_pkg_exec.subr | 25 ++-- subr/ex_rtl.subr | 17 --- subr/ex_rtl_complex.subr | 114 --------------- subr/ex_rtl_fetch.subr | 92 ------------ subr/ex_rtl_fileop.subr | 111 -------------- subr/ex_rtl_install.subr | 47 ------ subr/ex_rtl_list.subr | 75 ---------- subr/ex_rtl_log.subr | 78 ---------- subr/ex_rtl_state.subr | 40 ------ subr/ex_rtl_string.subr | 83 ----------- subr/pkg_build.subr | 2 +- subr/pkg_clean.subr | 12 +- subr/pkg_configure.subr | 4 +- subr/pkg_configure_autotools.subr | 18 +-- subr/pkg_configure_patch.subr | 4 +- subr/pkg_configure_patch_pre.subr | 4 +- subr/pkg_fetch_download.subr | 4 +- subr/pkg_fetch_extract.subr | 6 +- subr/pkg_install.subr | 4 +- subr/pkg_install_files.subr | 4 +- subr/pkg_install_libs.subr | 18 +-- subr/pkg_install_make.subr | 2 +- subr/pkg_install_rpm.subr | 8 +- subr/pkg_install_subdirs.subr | 4 +- subr/rtl.subr | 17 +++ subr/rtl_complex.subr | 114 +++++++++++++++ subr/rtl_fetch.subr | 92 ++++++++++++ subr/rtl_fileop.subr | 111 ++++++++++++++ subr/rtl_install.subr | 47 ++++++ subr/rtl_list.subr | 75 ++++++++++ subr/rtl_log.subr | 78 ++++++++++ subr/rtl_state.subr | 40 ++++++ subr/rtl_string.subr | 93 ++++++++++++ 37 files changed, 1134 insertions(+), 1025 deletions(-) create mode 100644 subr/ex_pkg.subr delete mode 100644 subr/ex_rtl.subr delete mode 100644 subr/ex_rtl_complex.subr delete mode 100644 subr/ex_rtl_fetch.subr delete mode 100644 subr/ex_rtl_fileop.subr delete mode 100644 subr/ex_rtl_install.subr delete mode 100644 subr/ex_rtl_list.subr delete mode 100644 subr/ex_rtl_log.subr delete mode 100644 subr/ex_rtl_state.subr delete mode 100644 subr/ex_rtl_string.subr create mode 100644 subr/rtl.subr create mode 100644 subr/rtl_complex.subr create mode 100644 subr/rtl_fetch.subr create mode 100644 subr/rtl_fileop.subr create mode 100644 subr/rtl_install.subr create mode 100644 subr/rtl_list.subr create mode 100644 subr/rtl_log.subr create mode 100644 subr/rtl_state.subr create mode 100644 subr/rtl_string.subr (limited to 'subr') diff --git a/subr/build_init.subr b/subr/build_init.subr index a52ff5ff..a1c4f78d 100644 --- a/subr/build_init.subr +++ b/subr/build_init.subr @@ -1,14 +1,6 @@ -buildp_ast() { - local _param="${1}" _pids_killed=""; - rm -f "${DEFAULT_BUILD_STATUS_IN_PROGRESS_FNAME}"; - case "${_param}" in - abort) ex_rtl_log_msg failexit "Build aborted."; ;; - esac; - ex_rtl_kill_tree "${$}"; - if [ -n "${_pids_killed}" ]; then - ex_rtl_log_msg vnfo "Killed PIDs ${_pids_killed}"; - fi; -}; +# +# set +o errexit -o noglob is assumed. +# buildp_init_args() { local _last_pkg=""; _status=""; @@ -25,8 +17,8 @@ buildp_init_args() { fi; fi; case "${ARG_RESTART}" in - ALL) ARG_RESTART_AT=ALL; ;; - LAST) ARG_RESTART_AT=""; ;; + ALL) ARG_RESTART_AT=ALL; ARG_RESTART_RECURSIVE=2; ;; + LAST) ARG_RESTART_AT=ALL; ARG_RESTART_RECURSIVE=0; ;; "") ;; *:*) ARG_RESTART_AT="${ARG_RESTART#*:}"; ARG_RESTART="${ARG_RESTART%:*}"; ;; *) ARG_RESTART="$(echo "${ARG_RESTART}" | sed "s/,/ /g")"; ARG_RESTART_AT=ALL; ;; @@ -35,87 +27,116 @@ buildp_init_args() { if [ -n "${DEFAULT_BUILD_LAST_FAILED_PKG_FNAME}" ]\ && [ -e "${DEFAULT_BUILD_LAST_FAILED_PKG_FNAME}" ]; then _last_pkg="$(cat "${DEFAULT_BUILD_LAST_FAILED_PKG_FNAME}")"; - ex_rtl_fileop rm "${DEFAULT_BUILD_LAST_FAILED_PKG_FNAME}"; - ex_rtl_state_clear "${BUILD_WORKDIR}" "${_last_pkg}"; + rtl_fileop rm "${DEFAULT_BUILD_LAST_FAILED_PKG_FNAME}"; + rtl_state_clear "${BUILD_WORKDIR}" "${_last_pkg}"; + ARG_RESTART="${_last_pkg}"; fi; fi; - ex_rtl_log_set_vnfo_lvl "${ARG_VERBOSE:-0}"; - BUILD_DATE_START="$(ex_rtl_date %Y-%m-%d-%H-%M-%S)"; BUILD_IS_PARENT=1; - BUILD_NFAIL="${BUILD_NFINI:=${BUILD_NSKIP:=0}}"; - BUILD_PKGS_FAILED=""; BUILD_TIMES_SECS="$(ex_rtl_date %s)"; - if [ "${ARG_FETCH_FORCE}" = "ipv4" ]; then - DEFAULT_GIT_ARGS="-4${DEFAULT_GIT_ARGS:+ ${DEFAULT_GIT_ARGS}}"; - DEFAULT_WGET_ARGS="-4${DEFAULT_WGET_ARGS:+ ${DEFAULT_WGET_ARGS}}"; - elif [ "${ARG_FETCH_FORCE}" = "ipv6" ]; then - DEFAULT_GIT_ARGS="-6${DEFAULT_GIT_ARGS:+ ${DEFAULT_GIT_ARGS}}"; - DEFAULT_WGET_ARGS="-6${DEFAULT_WGET_ARGS:+ ${DEFAULT_WGET_ARGS}}"; - fi; + rtl_log_set_vnfo_lvl "${ARG_VERBOSE:-0}"; + case "${ARG_FETCH_FORCE}" in + ipv4) DEFAULT_GIT_ARGS="$(rtl_lconcat "-4" "${DEFAULT_GIT_ARGS}")"; + DEFAULT_WGET_ARGS="$(rtl_lconcat "-4" "${DEFAULT_GIT_ARGS}")"; ;; + ipv6) DEFAULT_GIT_ARGS="$(rtl_lconcat "-6" "${DEFAULT_GIT_ARGS}")"; + DEFAULT_WGET_ARGS="$(rtl_lconcat "-6" "${DEFAULT_GIT_ARGS}")"; ;; + esac; return 0; }; -buildp_init_clean_prefix() { - if ex_rtl_lmatch "${ARG_CLEAN_BUILDS}" "prefix" ","; then - ex_rtl_log_msg info "-C prefix specified, cleaning prefix..."; - for _pname in ${DEFAULT_CLEAR_PREFIX_PATHS}; do - ex_rtl_fileop rm "${PREFIX}/${_pname}"; - done; - fi; - return 0; +buildp_init_defaults() { + local _rc=0; _status=""; + + # Command-line arguments + ARCH="nt64"; BUILD="debug"; + ARG_AS_NEEDED=0; ARG_CLEAN_BUILDS=""; ARG_DEBUG_MINIPIX=0; ARG_DIST=""; + ARG_FETCH_FORCE=0; ARG_PARALLEL=1; ARG_RELAXED=0; ARG_RESTART=""; ARG_VERBOSE=0; + + # Build parameters & state + BUILD_DLCACHEDIR="";BUILD_HNAME=""; BUILD_IS_PARENT=1; BUILD_GROUPS=""; BUILD_TARGET=""; BUILD_USER=""; BUILD_WORKDIR=""; + MIDIPIX_BUILD_PWD=""; PREFIX=""; PREFIX_RPM=""; + + # Global defaults + DEFAULT_BUILD_CPUS=1; + DEFAULT_BUILD_LAST_FAILED_PKG_FNAME="" + DEFAULT_BUILD_LOG_FNAME=""; + DEFAULT_BUILD_STATUS_IN_PROGRESS_FNAME=""; + DEFAULT_BUILD_STEPS=""; + DEFAULT_BUILD_VARS=""; + DEFAULT_CLEAR_PREFIX_PATHS=""; + DEFAULT_GIT_ARGS=""; + DEFAULT_GITROOT_HEAD=""; + DEFAULT_LOG_ENV_VARS=""; + DEFAULT_TARGET=""; + DEFAULT_WGET_ARGS=""; + + return "${_rc}"; }; buildp_init_env() { - local _rc=0 _vname="" _vname_val=""; _status=""; - case "${ARG_PARALLEL}" in - auto) - if [ "${DEFAULT_BUILD_CPUS}" -gt 1 ]; then - ARG_PARALLEL=$((${DEFAULT_BUILD_CPUS}/2)); - else - ARG_PARALLEL="${DEFAULT_BUILD_CPUS}"; - fi; ;; - *[^0-9]*) - _rc=10; _status="Error: invalid jobs count \`${ARG_PARALLEL}'."; ;; - esac; - if [ "${_rc}" -eq 0 ]; then - ex_rtl_clean_env "${DEFAULT_CLEAR_ENV_VARS_EXCEPT}"; - if ex_rtl_check_path_vars "${DEFAULT_CHECK_PATH_VARS}"; then - export PATH="${PREFIX}/bin${PATH:+:${PATH}}"; - else - : $((_rc+=(11-1))); - fi; + local _cmd="" _cmds_missing="" _fname="" _rc=0; _status=""; + if ! cd "$(dirname "${0}")" || ! umask 022; then + _rc=1; _status="Error: failed to setup environment"; + else for _cmd in \ + awk bunzip2 cat chmod cmake cp date find flock g++ \ + gcc git grep gunzip gzip hostname install kill \ + ln lzip make mkdir mkfifo mv paste patch perl \ + pgrep pkill printf readlink rm sed seq sha256sum \ + sort stat tail tar test touch tr wget xz zip; do + if ! which "${_cmd}" >/dev/null 2>&1; then + _cmds_missing="$(rtl_lconcat "${_cmds_missing}" "${_cmd}")"; + fi; + done; + if [ -n "${_cmds_missing}" ]; then + _rc=1; _status="Error: missing prerequisite package(s): ${_cmds_missing}"; + elif ! awk -V 2>/dev/null | grep -q "^GNU Awk "; then + _rc=1; _status="Error: awk(1) in \$PATH must be GNU Awk."; + elif ! sed --version 2>/dev/null | grep -q "^GNU sed "; then + _rc=1; _status="Error: sed(1) in \$PATH must be GNU sed."; + else for _fname in $(find subr -name *.subr); do + if ! . "${_fname}"; then + _rc=1; _status="Error: failed to source \`${_fname}'."; break; + fi; + done; fi; fi; return "${_rc}"; }; -buildp_init_exec() { - _status="" - trap "buildp_ast abort" HUP INT TERM USR1 USR2; trap "buildp_ast exit" EXIT; umask 022; - return 0; -}; - buildp_init_files() { local _log_last_fname="" _log_last_ts="" _rc=0; _status="" - if ! ex_rtl_fileop mkdir "${BUILD_DLCACHEDIR}" "${BUILD_WORKDIR}"\ - || ex_rtl_lmatch "${ARG_DIST}" "rpm" ","\ - && ! ex_rtl_fileop mkdir "${PREFIX_RPM}"; then - _rc=13; _status="Error: cannot create build directories."; + if ! rtl_fileop mkdir "${BUILD_DLCACHEDIR}" "${BUILD_WORKDIR}"\ + || rtl_lmatch "${ARG_DIST}" "rpm" ","\ + && ! rtl_fileop mkdir "${PREFIX_RPM}"; then + _rc=1; _status="Error: cannot create build directories."; elif [ -e "${DEFAULT_BUILD_STATUS_IN_PROGRESS_FNAME}" ]; then - _rc=14; _status="Error: another build targeting this architecture and build type is currently in progress."; + _rc=1; _status="Error: another build targeting this architecture and build type is currently in progress."; + elif ! rtl_clean_env "${DEFAULT_CLEAR_ENV_VARS_EXCEPT}"; then + _rc=1; _status="Error: failed to clean environment."; + elif ! rtl_check_path_vars "${DEFAULT_CHECK_PATH_VARS}"; then + _rc=1; _status="Error: one or more variable containing pathname(s) contains whitespace character(s)."; else touch "${DEFAULT_BUILD_STATUS_IN_PROGRESS_FNAME}"; if [ -e "${DEFAULT_BUILD_LOG_FNAME}" ]; then _log_last_ts="$(stat -c %Y "${DEFAULT_BUILD_LOG_FNAME}")"; _log_last_ts="$(awk 'BEGIN {printf(strftime("%Y-%m-%d-%H-%M-%S", '"${_log_last_ts}"'))}')"; _log_last_fname="${DEFAULT_BUILD_LOG_FNAME}.${_log_last_ts}"; - ex_rtl_fileop mv "${DEFAULT_BUILD_LOG_FNAME}" "${_log_last_fname}"; - ex_rtl_fileop ln_symbolic "${_log_last_fname}" "${DEFAULT_BUILD_LOG_LAST_FNAME}"; + rtl_fileop mv "${DEFAULT_BUILD_LOG_FNAME}" "${_log_last_fname}"; + rtl_fileop ln_symbolic "${_log_last_fname}" "${DEFAULT_BUILD_LOG_LAST_FNAME}"; + fi; + rtl_fileop touch "${DEFAULT_BUILD_LOG_FNAME}"; + if rtl_lmatch "${ARG_CLEAN_BUILDS}" "prefix" ","; then + rtl_log_msg info "-C prefix specified, cleaning prefix..."; + for _pname in ${DEFAULT_CLEAR_PREFIX_PATHS}; do + if ! rtl_fileop rm "${PREFIX}/${_pname}"; then + _rc=1; _status="Error: failed to remove \`${PREFIX}/${_pname}'."; break; + fi; + done; fi; - ex_rtl_fileop touch "${DEFAULT_BUILD_LOG_FNAME}"; + export PATH="${PREFIX}/bin${PATH:+:${PATH}}"; fi; return "${_rc}"; }; buildp_init_getopts() { - local _opt="" _shiftfl=0; _status=""; + local _opt="" _rc=0 _shiftfl=0 OPTIND=0; _status=""; while [ "${#}" -gt 0 ]; do case "${1}" in --as-needed) ARG_AS_NEEDED=1; _shiftfl=1; ;; @@ -148,108 +169,75 @@ buildp_init_getopts() { if [ "${_rc}" -eq 0 ]; then while [ ${#} -gt 0 ]; do case "${1}" in - *=*) ex_rtl_set_var_unsafe "${1%%=*}" "${1#*=}"; ;; - [^a-zA-Z]*) _rc=2; _status="Error: build group names must start with [a-zA-Z]."; ;; - *[^_a-zA-Z]*) _rc=3; _status="Error: build group names must not contain [^_a-zA-Z]."; ;; - *) BUILD_GROUPS="${BUILD_GROUPS:+${BUILD_GROUPS} }${1}"; ;; + *=*) rtl_set_var_unsafe "${1%%=*}" "${1#*=}"; ;; + [^a-zA-Z]*) _rc=1; _status="Error: build group names must start with [a-zA-Z]."; ;; + *[^_a-zA-Z]*) _rc=1; _status="Error: build group names must not contain [^_a-zA-Z]."; ;; + *) BUILD_GROUPS="$(rtl_lconcat "${BUILD_GROUPS}" "${1}")"; esac; shift; done; fi; return "${_rc}"; }; -buildp_init_prereqs() { - local _cmd="" _cmds_missing="" _rc=0; _status=""; - for _cmd in \ - awk bunzip2 cat chmod cmake cp date find flock g++ \ - gcc git grep gunzip gzip hostname install kill \ - ln lzip make mkdir mkfifo mv paste patch perl \ - pgrep pkill printf readlink rm sed seq sha256sum \ - sort stat tail tar test touch tr wget xz zip; do - if ! which "${_cmd}" >/dev/null 2>&1; then - _cmds_missing="$(ex_rtl_lconcat "${_cmds_missing}" "${_cmd}")"; - fi; - done; - if [ -n "${_cmds_missing}" ]; then - _rc=4; _status="Error: missing prerequisite package(s): ${_cmds_missing}"; - elif ! awk -V 2>/dev/null | grep -q "^GNU Awk "; then - _rc=5; _status="Error: awk(1) in \$PATH must be GNU Awk."; - elif ! sed --version 2>/dev/null | grep -q "^GNU sed "; then - _rc=6; _status="Error: sed(1) in \$PATH must be GNU sed."; - fi; - return "${_rc}"; -}; - -buildp_init_type() { - local _rc=0; _status=""; - : ${ARCH:=nt64}; : ${BUILD:=debug}; - if [ "${ARCH}" = nt32 ]; then - DEFAULT_TARGET="i686-nt32-midipix"; - elif [ "${ARCH}" = nt64 ]; then - DEFAULT_TARGET="x86_64-nt64-midipix"; - else - if [ "${BUILD}" != debug ]\ - && [ "${BUILD}" != release ]; then - _rc=7; _status="Error: unknown build type \`${BUILD}'."; - fi; - _rc=8; _status="Error: invalid architecture \`${ARCH}'."; - fi; - return "${_rc}"; -}; - buildp_init_vars() { - local _fname="" _rc=0; _status=""; - if [ -z "${DEFAULT_BUILD_CPUS}" ]; then - if [ -e /proc/cpuinfo ]; then + local _default_build_groups="" _fname="" _rc=0 _target=""; _status=""; + if ! rtl_lmatch "${ARCH}" "nt32 nt64"; then + _rc=1; _status="Error: invalid architecture \`${ARCH}'."; + elif ! rtl_lmatch "${BUILD}" "debug release"; then + _rc=1; _status="Error: unknown build type \`${BUILD}'."; + elif [ -n "${ARG_PARALLEL}" ] && [ "${ARG_PARALLEL}" != "auto" ]\ + && ! rtl_isnumber "${ARG_PARALLEL}"; then + _rc=1; _status="Error: invalid jobs count \`${ARG_PARALLEL}'."; + else + case "${ARCH}" in + nt32) DEFAULT_TARGET="i686-nt32-midipix"; ;; + nt64) DEFAULT_TARGET="x86_64-nt64-midipix"; ;; + esac; + if [ -e "/proc/cpuinfo" ]; then DEFAULT_BUILD_CPUS="$(awk '/^processor/{cpus++} END{print cpus}' /proc/cpuinfo)"; - else - DEFAULT_BUILD_CPUS=1; + if [ "${ARG_PARALLEL}" = "auto" ]\ + && [ "${DEFAULT_BUILD_CPUS}" -gt 1 ]; then + ARG_PARALLEL=$((${DEFAULT_BUILD_CPUS}/2)); + fi; fi; - fi; - for _fname in \ - ${HOME}/midipix_build.vars \ - ${HOME}/.midipix_build.vars \ - ../midipix_build.vars \ - ./vars/env.vars; do - [ -e ${_fname} ] && . ${_fname}; - done; - for _fname in $(find ./groups -name *.group | sort); do - . "${_fname}"; _fname="${_fname##*/}"; _fname="${_fname%.group}"; - if [ "${_fname#[0-9][0-9][0-9].*}" != "${_fname}" ]\ - && [ "${_fname#*[1-9].*}" = "${_fname}" ]\ - && [ "${_fname}" != "999.invariants.group" ]; then - GROUPS_DEFAULT="${GROUPS_DEFAULT:+${GROUPS_DEFAULT} }${_fname#*.}"; + rtl_fileop source_opt \ + "${HOME}/midipix_build.vars" "${HOME}/.midipix_build.vars" \ + ../midipix_build.vars ./vars/env.vars; + if [ -z "${PREFIX}" ]; then + _rc=1; _status="Error: \${PREFIX} empty or unset."; + else + for _fname in $(find ./groups -name *.group | sort); do + rtl_fileop source_opt "${_fname}"; + if [ -n "${BUILD_TARGET}" ]; then + _target="${BUILD_TARGET}"; unset BUILD_TARGET; + else + _fname="${_fname##*/}"; _fname="${_fname%.group}"; _target="${_fname#*.}"; + fi; + _default_build_groups="$(rtl_lconcat "${_default_build_groups}" "${_target}")"; + done; + if ! rtl_lmatch "${ARG_DIST}" "rpm" ","; then + _default_build_groups="$(rtl_lfilter "${_default_build_groups}" "host_deps_rpm")"; + fi; + if [ -z "${BUILD_GROUPS}" ]; then + BUILD_GROUPS="${_default_build_groups}"; + fi; + BUILD_GROUPS="$(rtl_lfilter "${BUILD_GROUPS}" "invariants")"; + BUILD_GROUPS="$(rtl_lconcat "${BUILD_GROUPS}" "invariants")"; fi; - done; - if [ -z "${PREFIX}" ]; then - _rc=9; _status="Error: \${PREFIX} empty or unset."; fi; return "${_rc}"; }; -build_fini() { - : $((BUILD_TIMES_SECS=$(ex_rtl_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)); - if [ -f "${DEFAULT_BUILD_STATUS_IN_PROGRESS_FNAME}" ]; then - ex_rtl_fileop rm ${DEFAULT_BUILD_STATUS_IN_PROGRESS_FNAME}; - fi; -}; - build_init() { - local _rc=0 _status=""; - if ! buildp_init_exec \ + local _fname="" _rc=0 _status=""; + if ! buildp_init_env \ + || ! buildp_init_defaults \ || ! buildp_init_getopts "${@}" \ - || ! buildp_init_prereqs \ - || ! buildp_init_type \ || ! buildp_init_vars \ - || ! buildp_init_env \ || ! buildp_init_args \ - || ! buildp_init_files \ - || ! buildp_init_clean_prefix; then - _rc="${?}"; ex_rtl_log_msg fail "${_status}"; exit "${_rc}"; + || ! buildp_init_files; then + _rc="${?}"; rtl_log_msg fail "${_status}"; exit "${_rc}"; elif [ -n "${_status}" ]; then - ex_rtl_log_msg info "${_status}"; exit 0; + rtl_log_msg info "${_status}"; exit 0; else return "${_rc}"; fi; diff --git a/subr/ex_pkg.subr b/subr/ex_pkg.subr new file mode 100644 index 00000000..fd2df524 --- /dev/null +++ b/subr/ex_pkg.subr @@ -0,0 +1,75 @@ +# +# set +o errexit -o noglob is assumed. +# + +# +# ex_pkg_check_depends() - check single named package for unsatisfied dependencies +# @_pkg_complete: list of completed packages +# @_pkg_name: single package name +# @_pkg_wait: list of in-progress packages +# @_restart_recursive: optional flag specifiying either no dependency expansion (0,) dependency expansion (1,) dependency expansion and forcibly rebuild (2.) +# +# Return: zero (0) given no outstanding dependencies, non-zero (>0) otherwise +# +ex_pkg_check_depends() { + local _pkg_complete="${1}" _pkg_name="${2}" _pkg_wait="${3}" _restart_recursive="${4}" \ + _pkg_depends="" _pkg_name_depend="" _dependfl=0; + if _pkg_depends="$(rtl_lunfold_depends 'PKG_${_name}_DEPENDS' $(rtl_get_var_unsafe -u "PKG_"${_pkg_name}"_DEPENDS"))"\ + && [ -n "${_pkg_depends}" ]\ + && ! [ -n "${_restart}" ] || [ "${_restart_recursive:-0}" -ge 1 ]; then + for _pkg_name_depend in $(rtl_uniq ${_pkg_depends}); do + if ! rtl_lmatch "${_pkg_complete}" "${_pkg_name_depend}"\ + || rtl_lmatch "${_pkg_wait}" "${_pkg_name_depend}"; then + _dependfl=1; break; + fi; + done; + fi; + return "${_dependfl}"; +}; + +# +# ex_pkg_expand_packages() - expand build group name to list of packages ordered and filtered according to dependency and restart constraints +# @_group_name: build group name +# @_restart: optional comma-separated list of package names to rebuild +# @_restart_recursive: optional flag specifiying either no dependency expansion (0,) dependency expansion (1,) dependency expansion and forcibly rebuild (2.) +# +# Return: zero (0) on success, non-zero (>0) on failure, ${EXP_PKG_COMPLETE}, ${EXP_PKG_DISABLED}, ${EXP_PKG_FINISHED}, and ${EXP_PKG_NAMES} set post-return. +# +ex_pkg_expand_packages() { + local _group_name="${1}" _restart="${2}" _restart_recursive="${3}" \ + _pkg_name="" _pkg_names="" _restart_check=0; + EXP_PKG_COMPLETE=""; EXP_PKG_DISABLED=""; EXP_PKG_FINISHED=""; EXP_PKG_NAMES=""; + if _pkg_names="$(rtl_get_var_unsafe -u "${_group_name}_PACKAGES")"\ + && [ -n "${_pkg_names}" ]; then + if [ -n "${_restart}" ] && ! rtl_lmatch "${_restart}" "ALL LAST"; then + _pkg_names="$(rtl_lsearch "${_pkg_names}" "${_restart}")"; + fi; + if ! [ -n "${_restart}" ] || [ "${_restart_recursive:-0}" -ge 1 ]; then + _pkg_names="$(rtl_uniq $(rtl_lunfold_depends 'PKG_${_name}_DEPENDS' ${_pkg_names}))"; + fi; + for _pkg_name in ${_pkg_names}; do + if [ "${_restart}" = "ALL" ]\ + || rtl_lmatch "${_restart}" "${_pkg_name}"; then + _restart_check=1; + else + _restart_check=0; + fi; + if [ -n "$(rtl_get_var_unsafe -u "PKG_${_pkg_name}_DISABLED")" ]; then + EXP_PKG_COMPLETE="$(rtl_lconcat "${EXP_PKG_COMPLETE}" "${_pkg_name}")"; + EXP_PKG_DISABLED="$(rtl_lconcat "${EXP_PKG_DISABLED}" "${_pkg_name}")"; + _pkg_names="$(rtl_lfilter "${_pkg_names}" "${_pkg_name}")"; + elif ex_pkg_state_test "${_pkg_name}" finish\ + && [ "${_restart_check:-0}" -eq 0 ]\ + && [ "${_restart_recursive:-0}" -ne 2 ]\ + && [ "x$(rtl_get_var_unsafe -u "${_group_name}_FORCE")" != "x1" ]; then + EXP_PKG_COMPLETE="$(rtl_lconcat "${EXP_PKG_COMPLETE}" "${_pkg_name}")"; + EXP_PKG_FINISHED="$(rtl_lconcat "${EXP_PKG_FINISHED}" "${_pkg_name}")"; + _pkg_names="$(rtl_lfilter "${_pkg_names}" "${_pkg_name}")"; + fi; + done; + EXP_PKG_NAMES="${_pkg_names}"; + fi; + return 0; +}; + +# vim:filetype=sh textwidth=0 diff --git a/subr/ex_pkg_dispatch.subr b/subr/ex_pkg_dispatch.subr index 2d34a900..bd152f28 100644 --- a/subr/ex_pkg_dispatch.subr +++ b/subr/ex_pkg_dispatch.subr @@ -3,49 +3,106 @@ # # -# exp_pkg_check_depends() - check single named package for unsatisfied dependencies -# @_pkg_complete: list of completed packages -# @_pkg_name: single package name -# @_pkg_wait: list of in-progress packages -# @_restart_recursive: optional flag specifiying either no dependency expansion (0,) dependency expansion (1,) dependency expansion and forcibly rebuild (2.) -# -# Return: zero (0) given no outstanding dependencies, non-zero (>0) otherwise -# -exp_pkg_check_depends() { - local _pkg_complete="${1}" _pkg_name="${2}" _pkg_wait="${3}" _restart_recursive="${4}" \ - _pkg_depends="" _pkg_name_depend="" _dependfl=0; - if _pkg_depends="$(ex_rtl_lunfold_depends 'PKG_${_name}_DEPENDS' $(ex_rtl_get_var_unsafe -u "PKG_"${_pkg_name}"_DEPENDS"))"\ - && [ -n "${_pkg_depends}" ]\ - && ! [ -n "${_restart}" ] || [ "${_restart_recursive:-0}" -ge 1 ]; then - for _pkg_name_depend in $(ex_rtl_uniq ${_pkg_depends}); do - if ! ex_rtl_lmatch "${_pkg_complete}" "${_pkg_name_depend}"\ - || ex_rtl_lmatch "${_pkg_wait}" "${_pkg_name_depend}"; then - _dependfl=1; break; +# exp_pkg_dispatch_complete() - XXX +# @_dispatch_fn: top-level dispatch function name +# @_group_names: build group name(s) +# @_pkg_disabled: list of disabled packages +# @_pkg_finished: list of finished packages +# +# Return: zero (0) on success, non-zero (>0) on failure. +# +exp_pkg_dispatch_complete() { + local _dispatch_fn="${1}" _group_name="${2}" _pkg_disabled="${3}" _pkg_finished="${4}" _pkg_name=""; + for _pkg_name in ${_pkg_disabled}; do + "${_dispatch_fn}" disabled_pkg "${_group_name}" "${_pkg_name}"; + done; + for _pkg_name in ${_pkg_finished}; do + "${_dispatch_fn}" skipped_pkg "${_group_name}" "${_pkg_name}"; + done; +}; + +# +# exp_pkg_dispatch_group() - dispatch a single build group +# @_build_steps_default: list of default build steps +# @_build_vars_default: list of default build variables +# @_dispatch_fn: top-level dispatch function name +# @_group_name: build group name +# @_njobs_max: maximum count of simultaneous jobs +# @_pipe_path: pathname to build FIFO +# @_restart_at: optional comma-separated list of build steps at which to rebuild or ALL +# @_restart_recursive: optional flag specifiying either no dependency expansion (0,) dependency expansion (1,) dependency expansion and forcibly rebuild (2.) +# @_workdir: pathname to build-specific temporary directory +# +# Return: zero (0) on success, non-zero (>0) on failure. +# +exp_pkg_dispatch_group() { + local _build_steps_default="${1}" _build_vars_default="${2}" _dispatch_fn="${3}" \ + _group_name="${4}" _njobs_max="${5}" _pipe_path="${6}" _restart_at="${7}" \ + _restart_recursive="${8}" _workdir="${9}" _pipe_msg="" _pkg_name="" _rc=0; + rtl_fileop mkfifo "${_pipe_path}"; + while true; do + while [ "${EXP_PKG_DISPATCH_NJOBS:-0}" -gt 0 ] && read _pipe_msg; do + case "${_pipe_msg%% *}" in + done) : $((EXP_PKG_DISPATCH_NJOBS-=1)); _pkg_name="${_pipe_msg#done * }"; + "${_dispatch_fn}" finish_pkg ${_pipe_msg#done }; + EXP_PKG_COMPLETE="$(rtl_lconcat "${EXP_PKG_COMPLETE}" "${_pkg_name}")"; + EXP_PKG_NAMES="$(rtl_lfilter "${EXP_PKG_NAMES}" "${_pkg_name}")"; + EXP_PKG_DISPATCH_WAIT="$(rtl_lfilter "${EXP_PKG_DISPATCH_WAIT}" "${_pkg_name}")"; + if [ -n "${EXP_PKG_NAMES}" ] && [ "${_rc}" -eq 0 ]; then + if [ "${EXP_PKG_DISPATCH_NJOBS}" -ne "${_njobs_max}" ]; then + exp_pkg_dispatch_packages "${_build_steps_default}" \ + "${_build_vars_default}" "${_dispatch_fn}" \ + "${_group_name}" "${_njobs_max}" \ + "${_pipe_path}" "${EXP_PKG_COMPLETE}" \ + "${_restart_at}" "${_restart_recursive}" "${_workdir}"; + fi; + elif [ "${EXP_PKG_DISPATCH_NJOBS:-0}" -eq 0 ]; then + break; + fi; ;; + fail) : $((EXP_PKG_DISPATCH_NJOBS-=1)); _rc=1; + "${_dispatch_fn}" fail_pkg ${_pipe_msg#fail }; ;; + step) "${_dispatch_fn}" step_pkg ${_pipe_msg#step }; ;; + esac; done <>"${_pipe_path}"; + if [ -n "${EXP_PKG_NAMES}" ] && [ "${_rc}" -eq 0 ]; then + if [ "${EXP_PKG_DISPATCH_NJOBS}" -ne "${_njobs_max}" ]; then + exp_pkg_dispatch_packages "${_build_steps_default}" \ + "${_build_vars_default}" "${_dispatch_fn}" \ + "${_group_name}" "${_njobs_max}" "${_pipe_path}" \ + "${EXP_PKG_COMPLETE}" "${_restart_at}" \ + "${_restart_recursive}" "${_workdir}"; fi; - done; - fi; - return "${_dependfl}"; + elif [ "${EXP_PKG_DISPATCH_NJOBS:-0}" -eq 0 ]; then + break; + fi; + done; + rtl_fileop rm "${_pipe_path}"; + return "${_rc}"; }; # # exp_pkg_dispatch_package() - dispatch single named packages -# @_dispatch_fn: top-level dispatch function name -# @_group_name: build group name -# @_pkg_name: single package name -# @_restart_at: optional comma-separated list of build steps at which to rebuild or ALL +# @_build_steps_default: list of default build steps +# @_build_vars_default: list of default build variables +# @_dispatch_fn: top-level dispatch function name +# @_group_name: build group name +# @_pkg_name: single package name +# @_restart_at: optional comma-separated list of build steps at which to rebuild or ALL +# @_workdir: pathname to build-specific temporary directory # -# Return: zero (0) on success, non-zero (>0) on failure, ${NJOBS}, ${PKG_COUNT}, ${PKG_NAMES}, and ${PKG_WAIT} may be mutated post-return. +# Return: zero (0) on success, non-zero (>0) on failure, ${EXP_PKG_DISPATCH_NJOBS}, ${EXP_PKG_DISPATCH_COUNT}, ${EXP_PKG_NAMES}, and ${EXP_PKG_DISPATCH_WAIT} may be mutated post-return. # exp_pkg_dispatch_package() { - local _dispatch_fn="${1}" _group_name="${2}" _pkg_name="${3}" _restart_at="${4}"; - if "${_dispatch_fn}" start_pkg "${_group_name}" "${_pkg_name}" "$((${PKG_COUNT}+1))" "${PKG_COUNT_MAX}"; then - : $((NJOBS+=1)); : $((PKG_COUNT+=1)); PKG_WAIT="$(ex_rtl_lconcat "${PKG_WAIT}" "${_pkg_name}")"; + local _build_steps_default="${1}" _build_vars_default="${2}" _dispatch_fn="${3}" \ + _group_name="${4}" _pkg_name="${5}" _restart_at="${6}" _workdir="${7}"; + if "${_dispatch_fn}" start_pkg "${_group_name}" "${_pkg_name}" "$((${EXP_PKG_DISPATCH_COUNT}+1))" "${EXP_PKG_DISPATCH_COUNT_MAX}"; then + : $((EXP_PKG_DISPATCH_NJOBS+=1)); : $((EXP_PKG_DISPATCH_COUNT+=1)); EXP_PKG_DISPATCH_WAIT="$(rtl_lconcat "${EXP_PKG_DISPATCH_WAIT}" "${_pkg_name}")"; (set +o errexit -o noglob; BUILD_IS_PARENT=0; - if ex_pkg_env "${_group_name}" "${_pkg_name}" "${_restart_at}"; then + if ex_pkg_env "${_build_steps_default}" "${_build_vars_default}" \ + "${_group_name}" "${_pkg_name}" "${_restart_at}" "${_workdir}"; then ex_pkg_exec "${_dispatch_fn}" "${_group_name}" "${_pkg_name}" "${_restart_at}"; else return "${?}"; - fi;) 1>"${BUILD_WORKDIR}/${_pkg_name}_stderrout.log" 2>&1 3>"${_pipe_path}" & + fi;) 1>"${_workdir}/${_pkg_name}_stderrout.log" 2>&1 3>"${_pipe_path}" & else return "${?}"; fi; @@ -53,123 +110,96 @@ exp_pkg_dispatch_package() { # # exp_pkg_dispatch_packages() - dispatch set of packages -# @_dispatch_fn: top-level dispatch function name -# @_group_name: build group name -# @_njobs_max: maximum count of simultaneous jobs -# @_pipe_path: pathname to parent-child process FIFO -# @_pkg_complete: list of completed packages -# @_restart_at: optional comma-separated list of build steps at which to rebuild or ALL -# @_restart_recursive: optional flag specifiying either no dependency expansion (0,) dependency expansion (1,) dependency expansion and forcibly rebuild (2.) -# -# Return: zero (0) on success, non-zero (>0) on failure, ${NJOBS}, ${PKG_COUNT}, ${PKG_NAMES}, and ${PKG_WAIT} may be mutated post-return. +# @_build_steps_default: list of default build steps +# @_build_vars_default: list of default build variables +# @_dispatch_fn: top-level dispatch function name +# @_group_name: build group name +# @_njobs_max: maximum count of simultaneous jobs +# @_pipe_path: pathname to parent-child process FIFO +# @_pkg_complete: list of completed packages +# @_restart_at: optional comma-separated list of build steps at which to rebuild or ALL +# @_restart_recursive: optional flag specifiying either no dependency expansion (0,) dependency expansion (1,) dependency expansion and forcibly rebuild (2.) +# @_workdir: pathname to build-specific temporary directory +# +# Return: zero (0) on success, non-zero (>0) on failure, ${EXP_PKG_DISPATCH_NJOBS}, ${EXP_PKG_DISPATCH_COUNT}, ${EXP_PKG_NAMES}, and ${EXP_PKG_DISPATCH_WAIT} may be mutated post-return. # exp_pkg_dispatch_packages() { - local _dispatch_fn="${1}" _group_name="${2}" _njobs_max="${3}" _pipe_path="${4}" \ - _pkg_complete="${5}" _restart_at="${6}" _restart_recursive="${7}" \ + local _build_steps_default="${1}" _build_vars_default="${2}" _dispatch_fn="${3}" \ + _group_name="${4}" _njobs_max="${5}" _pipe_path="${6}" _pkg_complete="${7}" \ + _restart_at="${8}" _restart_recursive="${9}" _workdir="${10}" \ _njob=0 _pkg_depends="" _pkg_name=""; - for _njob in $(seq 1 $((${_njobs_max}-${NJOBS}))); do - for _pkg_name in ${PKG_NAMES}; do - if ! ex_rtl_lmatch "${_pkg_complete}" "${_pkg_name}"\ - && ! ex_rtl_lmatch "${PKG_WAIT}" "${_pkg_name}"\ - && exp_pkg_check_depends "${_pkg_complete}" "${_pkg_name}" "${PKG_WAIT}" "${_restart_recursive}"; then - exp_pkg_dispatch_package "${_dispatch_fn}" "${_group_name}" "${_pkg_name}" "${_restart_at}"; break; + for _njob in $(seq 1 $((${_njobs_max}-${EXP_PKG_DISPATCH_NJOBS}))); do + for _pkg_name in ${EXP_PKG_NAMES}; do + if ! rtl_lmatch "${_pkg_complete}" "${_pkg_name}"\ + && ! rtl_lmatch "${EXP_PKG_DISPATCH_WAIT}" "${_pkg_name}"\ + && ex_pkg_check_depends "${_pkg_complete}" "${_pkg_name}" "${EXP_PKG_DISPATCH_WAIT}" "${_restart_recursive}"; then + exp_pkg_dispatch_package "${_build_steps_default}" \ + "${_build_vars_default}" "${_dispatch_fn}" \ + "${_group_name}" "${_pkg_name}" "${_restart_at}" \ + "${_workdir}"; break; fi; done; done; }; # -# exp_pkg_expand_packages() - expand build group name to list of packages ordered and filtered according to dependency and restart constraints -# @_group_name: build group name -# @_restart: optional comma-separated list of package names to rebuild -# @_restart_recursive: optional flag specifiying either no dependency expansion (0,) dependency expansion (1,) dependency expansion and forcibly rebuild (2.) +# ex_pkg_dispatch() - dispatch a set of build group +# @_build_steps_default: list of default build steps +# @_build_vars_default: list of default build variables +# @_dispatch_fn: top-level dispatch function name +# @_group_names: build group name(s) +# @_njobs_max: maximum count of simultaneous jobs +# @_pipe_path: pathname to build FIFO +# @_restart: optional comma-separated list of package names to rebuild +# @_restart_at: optional comma-separated list of build steps at which to rebuild or ALL +# @_restart_recursive: optional flag specifiying either no dependency expansion (0,) dependency expansion (1,) dependency expansion and forcibly rebuild (2.) +# @_workdir: pathname to build-specific temporary directory # -# Return: zero (0) on success, non-zero (>0) on failure, ${EX_PKG_NAMES} and ${PKG_COMPLETE} set post-return. +# Return: zero (0) on success, non-zero (>0) on failure, ${EX_PKG_DISPATCH_UNKNOWN} mutated post-return. # -exp_pkg_expand_packages() { - local _group_name="${1}" _restart="${2}" _restart_recursive="${3}" _pkg_name="" _pkg_names=""; - if _pkg_names="$(ex_rtl_get_var_unsafe -u "${_group_name}_PACKAGES")"\ - && [ -n "${_pkg_names}" ]; then - if [ -n "${_restart}" ] && ! ex_rtl_lmatch "${_restart}" "ALL LAST"; then - _pkg_names="$(ex_rtl_lsearch "${_pkg_names}" "${_restart}")"; - fi; - if ! [ -n "${_restart}" ] || [ "${_restart_recursive:-0}" -ge 1 ]; then - _pkg_names="$(ex_rtl_uniq $(ex_rtl_lunfold_depends 'PKG_${_name}_DEPENDS' ${_pkg_names}))"; +ex_pkg_dispatch() { + local _build_steps_default="${1}" _build_vars_default="${2}" _dispatch_fn="${3}" \ + _group_names="${4}" _njobs_max="${5}" _pipe_path="${6}" _restart="${7}" \ + _restart_at="${8}" _restart_recursive="${9}" _workdir="${10}" \ + _pkg_name="" _pkg_names="" _rc=0 \ + EXP_PKG_COMPLETE EXP_PKG_DISABLED EXP_PKG_FINISHED EXP_PKG_DISPATCH_COUNT \ + EXP_PKG_DISPATCH_COUNT_MAX EXP_PKG_DISPATCH_NJOBS EXP_PKG_NAMES EXP_PKG_DISPATCH_WAIT; + EX_PKG_DISPATCH_UNKNOWN=""; + for _group_name in ${_group_names}; do + EXP_PKG_COMPLETE="" EXP_PKG_DISABLED="" EXP_PKG_FINISHED=""; + EXP_PKG_DISPATCH_COUNT=0 EXP_PKG_DISPATCH_COUNT_MAX=0 EXP_PKG_DISPATCH_NJOBS=0; + EXP_PKG_NAMES="" EXP_PKG_DISPATCH_WAIT=""; + if "${_dispatch_fn}" start_group "${_group_name}" ""; then + if rtl_fileop mkdir "${_workdir}"\ + && rtl_log_msg vnfo "Resolving \`${_group_name}' dependencies..."\ + && ex_pkg_expand_packages "${_group_name}" "${_restart}" "${_restart_recursive}"\ + && exp_pkg_dispatch_complete "${_dispatch_fn}" "${_group_name}" "${EXP_PKG_DISABLED}" "${EXP_PKG_FINISHED}"\ + && rtl_log_msg vnfo "Resolved \`${_group_name}' dependencies."\ + && EXP_PKG_DISPATCH_COUNT_MAX="$(rtl_llength "${EXP_PKG_NAMES}")"\ + && [ "${EXP_PKG_DISPATCH_COUNT_MAX}" -gt 0 ]; then + _pkg_names="$(rtl_lconcat "${_pkg_names}" "${EXP_PKG_NAMES}")"; + exp_pkg_dispatch_group "${_build_steps_default}" \ + "${_build_vars_default}" "${_dispatch_fn}" "${_group_name}" \ + "${_njobs_max}" "${_pipe_path}" "${_restart_at}" \ + "${_restart_recursive}" "${_workdir}"; _rc="${?}"; + fi; + "${_dispatch_fn}" finish_group "${_group_name}" ""; + if [ "${_rc}" -ne 0 ]; then + break; + fi; fi; - for _pkg_name in ${_pkg_names}; do - if [ -n "$(ex_rtl_get_var_unsafe -u "PKG_${_pkg_name}_DISABLED")" ]; then - PKG_COMPLETE="$(ex_rtl_lconcat "${PKG_COMPLETE}" "${_pkg_name}")"; - _pkg_names="$(ex_rtl_lfilter "${_pkg_names}" "${_pkg_name}")"; - "${_dispatch_fn}" disabled_pkg "${_group_name}" "${_pkg_name}"; - elif ex_pkg_state_test "${_pkg_name}" finish\ - && ! ex_rtl_lmatch "${_restart}" "${_pkg_name}"\ - && [ "${_restart_recursive:-0}" -ne 2 ]; then - PKG_COMPLETE="$(ex_rtl_lconcat "${PKG_COMPLETE}" "${_pkg_name}")"; - _pkg_names="$(ex_rtl_lfilter "${_pkg_names}" "${_pkg_name}")"; - "${_dispatch_fn}" skipped_pkg "${_group_name}" "${_pkg_name}"; + done; + if ! rtl_lmatch "${_restart}" "ALL LAST"; then + for _pkg_name in ${_restart}; do + if ! rtl_lmatch "${_pkg_names}" "${_restart}"; then + EX_PKG_DISPATCH_UNKNOWN="$(rtl_lconcat "${EX_PKG_DISPATCH_UNKNOWN}" "${_pkg_name}")"; fi; done; - EX_PKG_NAMES="${_pkg_names}"; return 0; fi; -}; - -# -# ex_pkg_dispatch() - dispatch a single build group -# @_dispatch_fn: top-level dispatch function name -# @_group_name: build group name -# @_njobs_max: maximum count of simultaneous jobs -# @_restart: optional comma-separated list of package names to rebuild -# @_restart_at: optional comma-separated list of build steps at which to rebuild or ALL -# @_restart_recursive: optional flag specifiying either no dependency expansion (0,) dependency expansion (1,) dependency expansion and forcibly rebuild (2.) -# -# Return: zero (0) on success, non-zero (>0) on failure, ${EX_PKG_NAMES} set post-return. -# -ex_pkg_dispatch() { - local _dispatch_fn="${1}" _group_name="${2}" _njobs_max="${3}" _restart="${4}" _restart_at="${5}" \ - _restart_recursive="${6}" _pipe_msg="" _pipe_path="${BUILD_WORKDIR}/build.fifo" _pkg_name="" \ - _script_rc=0 NJOBS=0 PKG_COMPLETE="" PKG_COUNT=0 PKG_COUNT_MAX=0 PKG_NAMES="" PKG_WAIT=""; EX_PKG_NAMES=""; - if "${_dispatch_fn}" start_group "${_group_name}" ""; then - if ex_rtl_fileop mkdir "${BUILD_WORKDIR}"\ - && ex_rtl_log_msg vnfo "Resolving \`${_group_name}' dependencies..."\ - && exp_pkg_expand_packages "${_group_name}" "${_restart}" "${_restart_recursive}"\ - && ex_rtl_log_msg vnfo "Resolved \`${_group_name}' dependencies."\ - && PKG_COUNT_MAX="$(ex_rtl_llength "${EX_PKG_NAMES}")"\ - && [ "${PKG_COUNT_MAX}" -gt 0 ]; then - PKG_NAMES="${EX_PKG_NAMES}"; ex_rtl_fileop mkfifo "${_pipe_path}"; - while true; do - while [ "${NJOBS:-0}" -gt 0 ] && read _pipe_msg; do - case "${_pipe_msg%% *}" in - done) : $((NJOBS-=1)); _pkg_name="${_pipe_msg#done * }"; - "${_dispatch_fn}" finish_pkg ${_pipe_msg#done }; - PKG_COMPLETE="$(ex_rtl_lconcat "${PKG_COMPLETE}" "${_pkg_name}")"; - PKG_NAMES="$(ex_rtl_lfilter "${PKG_NAMES}" "${_pkg_name}")"; - PKG_WAIT="$(ex_rtl_lfilter "${PKG_WAIT}" "${_pkg_name}")"; - if [ -n "${PKG_NAMES}" ] && [ "${_script_rc}" -eq 0 ]; then - if [ "${NJOBS}" -ne "${_njobs_max}" ]; then - exp_pkg_dispatch_packages "${_dispatch_fn}" "${_group_name}" "${_njobs_max}" \ - "${_pipe_path}" "${PKG_COMPLETE}" "${_restart_at}" "${_restart_recursive}"; - fi; - elif [ "${NJOBS:-0}" -eq 0 ]; then - break; - fi; ;; - fail) : $((NJOBS-=1)); _script_rc=1; - "${_dispatch_fn}" fail_pkg ${_pipe_msg#fail }; ;; - step) "${_dispatch_fn}" step_pkg ${_pipe_msg#step }; ;; - esac; done <>"${_pipe_path}"; - if [ -n "${PKG_NAMES}" ] && [ "${_script_rc}" -eq 0 ]; then - if [ "${NJOBS}" -ne "${_njobs_max}" ]; then - exp_pkg_dispatch_packages "${_dispatch_fn}" "${_group_name}" "${_njobs_max}" \ - "${_pipe_path}" "${PKG_COMPLETE}" "${_restart_at}" "${_restart_recursive}"; - fi; - elif [ "${NJOBS:-0}" -eq 0 ]; then - break; - fi; - done; - ex_rtl_fileop rm "${_pipe_path}"; - fi; - "${_dispatch_fn}" finish_group "${_group_name}" ""; + if [ -n "${EX_PKG_DISPATCH_UNKNOWN}" ]; then + _rc=1; fi; - return "${_script_rc}"; + return "${_rc}"; }; # vim:filetype=sh textwidth=0 diff --git a/subr/ex_pkg_env.subr b/subr/ex_pkg_env.subr index e92f5e45..7f58d3d0 100644 --- a/subr/ex_pkg_env.subr +++ b/subr/ex_pkg_env.subr @@ -4,17 +4,19 @@ # # exp_pkg_env_defaults() - set package variable defaults for single named package -# @_pkg_name: single package name +# @_build_steps_default: list of default build steps +# @_pkg_name: single package name +# @_workdir: pathname to build-specific temporary directory # # Return: zero (0) on success, non-zero (>0) on failure # exp_pkg_env_defaults() { - local _pkg_name="${1}"; + local _build_steps_default="${1}" _pkg_name="${2}" _workdir="${3}"; : ${PKG_NAME:="${_pkg_name}"}; : ${MIDIPIX_BUILD_PWD:="$(pwd)"}; - : ${PKG_BASE_DIR:="${BUILD_WORKDIR}/${_pkg_name}-${PKG_BUILD_TYPE}-${PKG_TARGET}"}; + : ${PKG_BASE_DIR:="${_workdir}/${_pkg_name}-${PKG_BUILD_TYPE}-${PKG_TARGET}"}; : ${PKG_FNAME:="${PKG_URL##*/}"}; - : ${PKG_BUILD_STEPS:="$(ex_rtl_lfilter "${DEFAULT_BUILD_STEPS}" "${PKG_BUILD_STEPS_DISABLE}")"}; + : ${PKG_BUILD_STEPS:="$(rtl_lfilter "${_build_steps_default}" "${PKG_BUILD_STEPS_DISABLE}")"}; if [ -z "${PKG_SUBDIR}" ]; then if [ -n "${PKG_URLS_GIT}" ]; then PKG_SUBDIR="${PKG_URLS_GIT%%=*}"; @@ -36,6 +38,7 @@ exp_pkg_env_defaults() { # # exp_pkg_env_set() - set package variables for single named package +# @_build_vars_default: list of default build variables # @_group_name: build group name # @_pkg_name: single package name # @@ -47,40 +50,44 @@ exp_pkg_env_defaults() { # Return: zero (0) on success, non-zero (>0) on failure # exp_pkg_env_set() { - local _group_name="${1}" _pkg_name="${2}" _var_prefixes="" _vars_set="" _vname=""; - ex_rtl_set_vars _vars_set BUILD_TYPE "DEFAULT ${_group_name} PKG_${_pkg_name}"; - ex_rtl_set_vars _vars_set INHERIT_FROM "PKG_${_pkg_name}"; - _var_prefixes="$(ex_rtl_toupper "DEFAULT DEFAULT_${PKG_BUILD_TYPE} ${_group_name}")"; - for _vname in $(ex_rtl_lfilter "${DEFAULT_BUILD_VARS}" BUILD_TYPE); do + local _build_vars_default="${1}" _group_name="${2}" _pkg_name="${3}" _var_prefixes="" _vars_set="" _vname=""; + rtl_set_vars _vars_set BUILD_TYPE "DEFAULT ${_group_name} PKG_${_pkg_name}"; + rtl_set_vars _vars_set INHERIT_FROM "PKG_${_pkg_name}"; + _var_prefixes="$(rtl_toupper "DEFAULT DEFAULT_${PKG_BUILD_TYPE} ${_group_name}")"; + for _vname in $(rtl_lfilter "${_build_vars_default}" BUILD_TYPE); do if [ -n "${PKG_INHERIT_FROM}" ]; then - ex_rtl_set_vars _vars_set "${_vname}" \ - "$(ex_rtl_lconcat "${_var_prefixes}" "$(ex_rtl_toupper "PKG_${PKG_INHERIT_FROM} PKG_${_pkg_name}")")" + rtl_set_vars _vars_set "${_vname}" \ + "$(rtl_lconcat "${_var_prefixes}" "$(rtl_toupper "PKG_${PKG_INHERIT_FROM} PKG_${_pkg_name}")")" else - ex_rtl_set_vars _vars_set "${_vname}" \ - "$(ex_rtl_lconcat "${_var_prefixes}" "$(ex_rtl_toupper "PKG_${_pkg_name}")")"; + rtl_set_vars _vars_set "${_vname}" \ + "$(rtl_lconcat "${_var_prefixes}" "$(rtl_toupper "PKG_${_pkg_name}")")"; fi; done; - ex_rtl_push_IFS :; for _vname in ${PKG_ENV_VARS_EXTRA}; do + rtl_push_IFS :; for _vname in ${PKG_ENV_VARS_EXTRA}; do export "${_vname}"; - done; ex_rtl_pop_IFS; - ex_rtl_unset_vars $(ex_rtl_lfilter \ + done; rtl_pop_IFS; + rtl_unset_vars $(rtl_lfilter \ "$(set | awk -F= '/^PKG_/{print $1}' | sort)" \ "${_vars_set}"); }; # # ex_pkg_env() - set package variables for single named package -# @_group_name: build group name -# @_pkg_name: single package name -# @_restart_at: optional comma-separated list of build steps at which to rebuild or ALL +# @_build_steps_default: list of default build steps +# @_build_vars_default: list of default build variables +# @_group_name: build group name +# @_pkg_name: single package name +# @_restart_at: optional comma-separated list of build steps at which to rebuild or ALL +# @_workdir: pathname to build-specific temporary directory # # Return: zero (0) on success, non-zero (>0) on failure # ex_pkg_env() { - local _group_name="${1}" _pkg_name="${2}" _restart_at="${3}" _vname=""; - ex_rtl_fileop source_opt "vars/${_pkg_name}.vars"; - if ! exp_pkg_env_set "${_group_name}" "${_pkg_name}"\ - || ! exp_pkg_env_defaults "${_pkg_name}"; then + local _build_steps_default="${1}" _build_vars_default="${2}" _group_name="${3}" \ + _pkg_name="${4}" _restart_at="${5}" _workdir="${6}" _vname=""; + rtl_fileop source_opt "vars/${_pkg_name}.vars"; + if ! exp_pkg_env_set "${_build_vars_default}" "${_group_name}" "${_pkg_name}"\ + || ! exp_pkg_env_defaults "${_build_steps_default}" "${_pkg_name}" "${_workdir}"; then return "${?}"; fi; }; @@ -94,7 +101,7 @@ ex_pkg_env() { # Return: zero (0) on success, non-zero (>0) on failure # ex_pkg_state_set() { - ex_rtl_state_set "${BUILD_WORKDIR}" "${@}"; + rtl_state_set "${_workdir}" "${@}"; }; # @@ -107,7 +114,7 @@ ex_pkg_state_set() { # Return: zero (0) on success, non-zero (>0) on failure # ex_pkg_state_test() { - ex_rtl_state_test "${BUILD_WORKDIR}" "${@}"; + rtl_state_test "${_workdir}" "${@}"; }; # vim:filetype=sh diff --git a/subr/ex_pkg_exec.subr b/subr/ex_pkg_exec.subr index 2d14a018..0a40cfcf 100644 --- a/subr/ex_pkg_exec.subr +++ b/subr/ex_pkg_exec.subr @@ -15,21 +15,21 @@ exp_pkg_exec_pre() { if [ -z "${PKG_URL}" ]\ && [ -z "${PKG_URLS_GIT}" ]\ && [ -z "${PKG_VERSION}" ]\ - && ! ex_rtl_test_cmd "pkg_${_pkg_name}_all"; then - "${_dispatch_fn}" exec_missing "${_group_name}" "${_pkg_name}"; + && ! rtl_test_cmd "pkg_${_pkg_name}_all"; then + "${_dispatch_fn}" missing_pkg "${_group_name}" "${_pkg_name}"; return 1; elif ! ex_pkg_state_test "${_pkg_name}" "start" "${_restart_at}"; then if [ "${PKG_NO_CLEAN_BASE_DIR:-0}" -eq 0 ]\ - && ! ex_rtl_fileop rm "${PKG_BASE_DIR}" "${PKG_BUILD_DIR}" "${PKG_DESTDIR}"\ - || ! ex_rtl_fileop mkdir "${PKG_BASE_DIR}"; then + && ! rtl_fileop rm "${PKG_BASE_DIR}" "${PKG_BUILD_DIR}" "${PKG_DESTDIR}"\ + || ! rtl_fileop mkdir "${PKG_BASE_DIR}"; then return "${?}"; fi; - if ! ex_rtl_fileop mkdir "${PKG_BUILD_DIR}" "${PKG_DESTDIR}"\ + if ! rtl_fileop mkdir "${PKG_BUILD_DIR}" "${PKG_DESTDIR}"\ || ! ex_pkg_state_set "${_pkg_name}" "start"; then return "${?}"; fi; fi; - ex_rtl_fileop cd "${PKG_BUILD_DIR}"; + rtl_fileop cd "${PKG_BUILD_DIR}"; }; # @@ -44,7 +44,7 @@ exp_pkg_exec_pre() { exp_pkg_exec_step() { local _group_name="${1}" _pkg_name="${2}" _restart_at="${3}" _step="${4}" \ _fn_name="" _pkg_step_fn="" _rc=0; - if ex_rtl_test_cmd "pkg_${_pkg_name}_${_step}"; then + if rtl_test_cmd "pkg_${_pkg_name}_${_step}"; then _pkg_step_fn="pkg_${_pkg_name}_${_step}"; else _pkg_step_fn="pkg_${_step}"; @@ -53,7 +53,7 @@ exp_pkg_exec_step() { "pkg_${_pkg_name}_${_step}_pre" \ "${_pkg_step_fn}" \ "pkg_${_pkg_name}_${_step}_post"; do - if ex_rtl_test_cmd "${_fn_name}"\ + if rtl_test_cmd "${_fn_name}"\ && ! "${_fn_name}" "${_group_name}" "${_pkg_name}" "${_restart_at}"; then _rc=1; break; fi; @@ -80,24 +80,23 @@ ex_pkg_exec() { pkill -U "${$}"; \ fi;" EXIT HUP INT TERM USR1 USR2; if exp_pkg_exec_pre "${_group_name}" "${_pkg_name}" "${_restart_at}"\ - && "${_dispatch_fn}" exec_start "${_group_name}" "${_pkg_name}"; then - if ex_rtl_test_cmd "pkg_${_pkg_name}_all"; then + && "${_dispatch_fn}" start_pkg_child "${_group_name}" "${_pkg_name}"; then + if rtl_test_cmd "pkg_${_pkg_name}_all"; then "pkg_${_pkg_name}_all" "${_restart_at}"; else set -- ${PKG_BUILD_STEPS}; while [ ${#} -gt 0 ]; do _step="${1}"; _step_next="${2}"; shift; - if ex_pkg_state_test "${_pkg_name}" "${_step}" "${_restart_at}"; then + if [ "${PKG_FORCE:-0}" -eq 0 ]\ + && ex_pkg_state_test "${_pkg_name}" "${_step}" "${_restart_at}" ; then continue; elif ! exp_pkg_exec_step "${_group_name}" "${_pkg_name}" "${_restart_at}" "${_step}"; then _rc=1; break; else echo "step ${_group_name} ${_pkg_name} ${_step}" >&3; - "${_dispatch_fn}" exec_step "${_group_name}" "${_pkg_name}" "${_step}"; ex_pkg_state_set "${_pkg_name}" "${_step}" "${_step_next:+-${_step_next}}"; fi; done; fi; - "${_dispatch_fn}" exec_finish "${_group_name}" "${_pkg_name}"; ex_pkg_state_set "${_pkg_name}" finish; fi; return "${_rc}"; diff --git a/subr/ex_rtl.subr b/subr/ex_rtl.subr deleted file mode 100644 index 1c48bb00..00000000 --- a/subr/ex_rtl.subr +++ /dev/null @@ -1,17 +0,0 @@ -# -# set +o errexit -o noglob is assumed. -# - -EXP_RTL_IFS="${IFS}"; - -ex_rtl_basename() { echo "${1##*/}"; }; -ex_rtl_date() { command date "+${1:-${DEFAULT_TIMESTAMP_FMT}}"; }; -ex_rtl_dirname() { echo "${1%/*}"; }; -ex_rtl_pop_IFS() { IFS="${EXP_RTL_IFS}"; }; -ex_rtl_push_IFS() { EXP_RTL_IFS="${IFS}"; IFS="${1}"; }; -ex_rtl_set_var_unsafe() { [ -n "${2}" ] && eval ${1}=\"${2}\" || return 0; }; -ex_rtl_test_cmd() { command -v "${1}" >/dev/null; }; -ex_rtl_uniq() { echo "${@}" | sed 's/ /\n/g' | awk '!x[$0]++' | paste -s -d" "; }; -ex_rtl_unset_vars() { while [ ${#} -gt 0 ]; do unset "${1}"; shift; done; }; - -# vim:filetype=sh diff --git a/subr/ex_rtl_complex.subr b/subr/ex_rtl_complex.subr deleted file mode 100644 index 682a950e..00000000 --- a/subr/ex_rtl_complex.subr +++ /dev/null @@ -1,114 +0,0 @@ -# -# set +o errexit -o noglob is assumed. -# - -ex_rtl_check_path_vars() { - local _vnames="${1}" _rc=0 _vname="" _vname_val=""; _status=""; - for _vname in ${_vnames}; do - _vname_val="$(ex_rtl_get_var_unsafe "${_vname}")"; - if [ -z "${_vname_val}" ]; then - _rc=1; _status="Error: variable \`${_vname}' is empty or unset."; break; - elif [ "${_vname_val#* *}" != "${_vname_val}" ]; then - _rc=2; _status="Error: variable \`${_vname}' contains one or more whitespace characters."; break; - fi; - done; - return "${_rc}"; -}; - -ex_rtl_clean_env() { - local _env_vars_except="${1}" _env_var="" _env_vars=""; - _env_vars="$(export | sed -ne '/^export/{s/^export //;s/=.*$//p}')"; - for _env_var in ${_env_vars}; do - if [ "${_env_var#DEFAULT_}" != "${_env_var}" ]\ - || [ "${_env_var#PKG_}" != "${_env_var}" ]; then - _env_vars_except="${_env_vars_except:+${_env_vars_except} }${_env_var}"; - fi; - done; - ex_rtl_unset_vars $(ex_rtl_lfilter "${_env_vars}" "${_env_vars_except}"); -}; - -ex_rtl_exists_any() { - local _subdir="${1}"; shift; - while [ "${#}" -gt 0 ]; do - if [ -e "${_subdir}/${1}" ]; then - return 0; - else - shift; - fi; - done; return 1; -}; - -ex_rtl_export_vars() { - local _unsetfl=0; [ "x${1}" = "x-u" ] && { _unsetfl=1; shift; }; - while [ "${#}" -ge 2 ]; do - if [ -n "${2}" ]; then - if [ "${_unsetfl:-0}" -eq 0 ]; then - ex_rtl_set_var_unsafe "${1}" "${2}"; export "${1}"; - else - unset "${1}"; - fi; - fi; - shift 2; - done; -}; - -ex_rtl_get_var_unsafe() { - local _vname=""; - if [ "x${1}" = "x-u" ]; then - shift; _vname="$(ex_rtl_toupper "${1}")"; - else - _vname="${1}"; - fi; - eval echo \${${_vname}}; -}; - -ex_rtl_head() { - local _pattern="${1}" _s="${2}"; - while true; do - if [ "${_s%%${_pattern}}" = "${_s}" ]; then - break; - else - _s="${_s%%${_pattern}}"; - fi; - done; - echo "${_s}"; -}; - -ex_rtl_kill_tree() { - local _pid="${1}" _signal="TERM" _pid_child="" _pid_top=""; - for _pid_top in $(pgrep -P "${_pid}"); do - for _pid_child in $(pgrep -P "${_pid_top}" 2>/dev/null); do - _pids_killed="${_pids_killed:+${_pids_killed} }${_pid_child}"; kill "-${_signal}" "${_pid_child}" 2>/dev/null; - done; - _pids_killed="${_pids_killed:+${_pids_killed} }${_pid_top}"; kill "-${_signal}" "${_pid_top}" 2>/dev/null; - done; -}; - -ex_rtl_run_cmd_unsplit() { - local _cmd="${1}" _cmdline="" _rc="" IFS; shift; - while [ ${#} -gt 0 ]; do - [ -n "${1}" ] &&\ - _cmdline="${_cmdline:+${_cmdline}:}${1}"; - shift; - done; - IFS=:; ${_cmd} ${_cmdline}; _rc=$?; - return ${_rc}; -}; - -ex_rtl_set_vars() { - local _vars_set_vname="${1}" _vname_dst="${2}" _vname_src_tmpls="${3}" \ - _vars_set_old="" _vars_set_tmp="" _vname_src=""; - for _vname_src in $(ex_rtl_toupper "${_vname_src_tmpls}"); do - _vname_src="${_vname_src}_${_vname_dst}"; - _vval_src="$(ex_rtl_get_var_unsafe "${_vname_src}")"; - if [ -n "${_vval_src}" ]; then - ex_rtl_set_var_unsafe "PKG_${_vname_dst}" "${_vval_src}"; - _vars_set_tmp="${_vars_set_tmp:+${_vars_set_tmp} }PKG_${_vname_dst}"; - fi; - done; - _vars_set_old="$(ex_rtl_get_var_unsafe "${_vars_set_vname}")"; - ex_rtl_set_var_unsafe "${_vars_set_vname}" \ - "${_vars_set_old:+${_vars_set_old} }${_vars_set_tmp}"; -}; - -# vim:filetype=sh diff --git a/subr/ex_rtl_fetch.subr b/subr/ex_rtl_fetch.subr deleted file mode 100644 index c4ba862d..00000000 --- a/subr/ex_rtl_fetch.subr +++ /dev/null @@ -1,92 +0,0 @@ -# -# set +o errexit -o noglob is assumed. -# - -exp_rtl_fetch_url_git() { - local _tgtdir="${1}" _subdir="${2}" _url="${3}" _branch="${4}" \ - _oldpwd=""; - (set -o errexit -o noglob; trap "rm -f \"${BUILD_DLCACHEDIR}/${_subdir%%[/]}.fetching\"" EXIT; - while true; do - if flock -E 622 -w 3600 4; then - break; - elif [ "${?}" -eq 622 ]; then - continue; - else - exit "${?}"; - fi; - done; - if [ -e "${BUILD_DLCACHEDIR}/${_subdir}" ]; then - (ex_rtl_fileop cd "${BUILD_DLCACHEDIR}/${_subdir}" &&\ - git pull ${DEFAULT_GIT_ARGS} origin "${_branch:-main}"); - (ex_rtl_fileop cd "${BUILD_DLCACHEDIR}/${_subdir}" &&\ - git submodule update); - else - git clone ${DEFAULT_GIT_ARGS} "${_url}" "${BUILD_DLCACHEDIR}/${_subdir}"; - if [ -n "${_branch}" ]; then - (ex_rtl_fileop cd "${BUILD_DLCACHEDIR}/${_subdir}" &&\ - git checkout "${_branch}"); - fi; - (ex_rtl_fileop cd "${BUILD_DLCACHEDIR}/${_subdir}" &&\ - git submodule update --init); - fi; - _oldpwd="${PWD}"; ex_rtl_fileop cd "${PKG_BASE_DIR}"; - ex_rtl_fileop rm "${_tgtdir}/${_subdir}"; - ex_rtl_fileop cp "${BUILD_DLCACHEDIR}/${_subdir}" "${_tgtdir}"; - ex_rtl_fileop cd "${_oldpwd}";) 4<>"${BUILD_DLCACHEDIR}/${_subdir%%[/]}.fetching"; - if [ "${?}" -eq 0 ]; then - cd "$(pwd)"; - else - return "${?}"; - fi; -}; - -ex_rtl_fetch_urls_git() { - local _tgtdir="" _url_spec="" _subdir="" _url="" _git_branch=""; - _tgtdir="${1}"; shift; - if [ "${ARG_FETCH_FORCE}" = "offline" ]; then - return 0; - fi; - for _url_spec in "${@}"; do - _subdir="${_url_spec%=*}"; - _url="${_url_spec#*=}"; - _url="${_url%@*}"; - if [ "${_url_spec#*@}" != "${_url_spec}" ]; then - _git_branch=${_url_spec#*@}; - fi; - exp_rtl_fetch_url_git "${_tgtdir}" "${_subdir}" \ - "${_url}" "${_git_branch}"; - done; -}; - -# N.B. URLs ($1) may contain `?' or '&' characters. -ex_rtl_fetch_url_wget() { - local _url="${1}" _sha256sum_src="${2}" _target_fname="${3}" _sha256sum_dst=""; - if [ "${ARG_FETCH_FORCE}" = "offline" ]; then - return 0; - elif [ -z "${_target_fname}" ]; then - _target_fname="$(ex_rtl_basename "${_url}")"; - fi; - _url_dst="${BUILD_DLCACHEDIR}/${_target_fname}"; - (set -o errexit -o noglob; trap "_rc=\"\${?}\" ;rm -f \"${_url_dst}.fetching\"; exit \"\${_rc}\";" EXIT; - while true; do - if flock -E 622 -w 3600 4; then - break; - elif [ "${?}" -eq 622 ]; then - continue; - else - exit "${?}"; - fi; - done; - if [ ! -e "${_url_dst}.fetched" ]; then - wget ${DEFAULT_WGET_ARGS} -O "${_url_dst}" "${_url}"; - if [ -n "${_sha256sum_src}" ]; then - set -- $(sha256sum "${_url_dst}"); - if [ "${_sha256sum_dst:=${1}}" != "${_sha256sum_src}" ]; then - ex_rtl_log_msg failexit "Error: hash mismatch for URL \`${_url}' (downloaded file: ${_sha256sum_dst}, from build variables: ${_sha256sum_src}.)"; - fi; - fi; - ex_rtl_fileop touch "${_url_dst}.fetched"; - fi;) 4<>"${_url_dst}.fetching"; -}; - -# vim:filetype=sh diff --git a/subr/ex_rtl_fileop.subr b/subr/ex_rtl_fileop.subr deleted file mode 100644 index 417ec261..00000000 --- a/subr/ex_rtl_fileop.subr +++ /dev/null @@ -1,111 +0,0 @@ -# -# set +o errexit -o noglob is assumed. -# - -exp_rtl_fileop_check() { - local _prefix="${1}" _pname="" _rname=""; shift; - while [ "${#}" -gt 0 ]; do - return 0; - shift; done; -}; - -ex_rtl_fileop() { - local _op="${1}" _dst="" _install_args="" _rc=0 _src=""; shift; - case "${_op}" in - cd) if [ \( -z "${1}" \) -o ! \( -L "${1}" -o -e "${1}" \) ]; then - ex_rtl_log_msg failexit "Invalid or non-existent directory \`${1}'."; - elif exp_rtl_fileop_check "${PREFIX}" "${1}"; then - ex_rtl_log_msg vvvv "Changing working directory to \`${1}'."; - cd -- "${1}"; _rc="${?}"; - fi; ;; - cp_follow) - if [ "${#}" -lt 2 ]; then - ex_rtl_log_msg failexit "Missing parameters (in: cp_follow ${*}.)"; - elif exp_rtl_fileop_check "${PREFIX}" "${*}"; then - _src="${*}"; _src="${_src% *}"; - _dst="${*}"; _dst="${_dst##* }"; - ex_rtl_log_msg vvvv "Copying \`${_src}' into \`${_dst}' w/ -pLR."; - cp -pLR -- "${@}"; _rc="${?}"; - fi; ;; - cp) if [ "${#}" -lt 2 ]; then - ex_rtl_log_msg failexit "Missing parameters (in: cp ${*}.)"; - elif exp_rtl_fileop_check "${PREFIX}" "${*}"; then - _src="${*}"; _src="${_src% *}"; - _dst="${*}"; _dst="${_dst##* }"; - ex_rtl_log_msg vvvv "Copying \`${_src}' into \`${_dst}' w/ -pPR."; - cp -pPR -- "${@}"; _rc="${?}"; - fi; ;; - install) - if [ "${#}" -lt 2 ]; then - ex_rtl_log_msg failexit "Missing parameters (in: install ${*}.)"; - else _dst="$(while [ ""${#}"" -gt 2 ]; do shift; done; echo "${2}")"; - _install_args="$(while [ ""${#}"" -gt 2 ]; do echo "${1}"; shift; done)"; - _src="$(while [ ""${#}"" -gt 2 ]; do shift; done; echo "${1}")"; - if exp_rtl_fileop_check "${PREFIX}" "${_dst}" "${_src}"; then - ex_rtl_log_msg vvvv "Installing \`${_src}' into \`${_dst}' w/ ${_install_args}."; - install "${@}"; _rc="${?}"; - fi; - fi; ;; - ln_symbolic) - if [ \( -z "${1}" \) -o \( -z "${2}" \) ]; then - ex_rtl_log_msg failexit "Missing parameters (in: ln_symbolic ${*}.)"; - elif exp_rtl_fileop_check "${PREFIX}" "${2}"; then - if ex_rtl_fileop test "${2}"; then - ex_rtl_fileop rm "${2}"; - fi; - if [ "${?}" -eq 0 ]; then - ex_rtl_log_msg vvvv "Linking \`${1}' to \`${2}' w/ -fs"; - ln -fs -- "${1}" "${2}"; _rc="${?}"; - fi; - fi; ;; - mv) if [ \( -z "${1}" \) -o \( -z "${2}" \) ]; then - ex_rtl_log_msg failexit "Missing parameters (in: mv ${*}.)"; - elif exp_rtl_fileop_check "${PREFIX}" "${1}" "${2}"; then - ex_rtl_log_msg vvvv "Moving \`${1}' to \`${2}' w/ -fs"; - mv -f -- "${1}" "${2}"; _rc="${?}"; - fi; ;; - mkdir|mkfifo|rm|source_opt|test|touch) - while [ \( "${?}" -eq 0 \) -a \( ""${#}"" -gt 0 \) ]; do - if [ -z "${1}" ]; then - ex_rtl_log_msg failexit "Missing parameters (in: ${_op} ${*}.)"; - elif [ "${_op}" = mkdir ]\ - && [ ! -d "${1}" ]\ - && exp_rtl_fileop_check "${PREFIX}" "${1}"; then - if ex_rtl_fileop test "${1}"; then - ex_rtl_fileop rm "${1}"; - fi; - ex_rtl_log_msg vvvv "Making directory \`${1}'."; - mkdir -p -- "${1}"; _rc="${?}"; - elif [ "${_op}" = mkfifo ]\ - && exp_rtl_fileop_check "${PREFIX}" "${1}"; then - if ex_rtl_fileop test "${1}"; then - ex_rtl_fileop rm "${1}"; - fi; - ex_rtl_log_msg vvvv "Creating FIFO \`${1}'."; - exp_rtl_fileop_check "${PREFIX}" "${1}"; - mkfifo -- "${1}"; _rc="${?}"; - elif [ "${_op}" = rm ]\ - && ex_rtl_fileop test "${1}"\ - && exp_rtl_fileop_check "${PREFIX}" "${1}"; then - ex_rtl_log_msg vvvv "Removing directory or file \`${1}'."; - rm -rf -- "${1}"; _rc="${?}"; - elif [ "${_op}" = source_opt ]\ - && ex_rtl_fileop test "${1}"\ - && exp_rtl_fileop_check "${PREFIX}" "${1}"; then - ex_rtl_log_msg vvvv "Sourcing file \`${1}'."; - . "${1}"; _rc="${?}"; - elif [ "${_op}" = test ]\ - && exp_rtl_fileop_check "${PREFIX}" "${1}"\ - && ! [ \( -L "${1}" \) -o \( -e "${1}" \) ]; then - return 1; - elif [ "${_op}" = touch ]\ - && exp_rtl_fileop_check "${PREFIX}" "${1}"; then - ex_rtl_log_msg vvvv "Touching file \`${1}'."; - touch -- "${1}"; _rc="${?}"; - fi; shift; - done; ;; - *) ex_rtl_log_msg failexit "Error: ex_rtl_fileop() called w/ invalid parameter(s): ${*}"; ;; - esac; return "${_rc}"; -}; - -# vim:filetype=sh diff --git a/subr/ex_rtl_install.subr b/subr/ex_rtl_install.subr deleted file mode 100644 index 742347d7..00000000 --- a/subr/ex_rtl_install.subr +++ /dev/null @@ -1,47 +0,0 @@ -# -# set +o errexit -o noglob is assumed. -# - -ex_rtl_install() { - local _verbose="" _prefix="" _ln_target="" _ln_fname="" \ - _mkdir_fname="" _file_fname_src="" _file_fname_dst=""; - if [ "${1}" = "-v" ]; then - _verbose=1; shift; - fi; _prefix="${1}"; shift; - while [ ${#} -gt 0 ]; do - case "${1}" in - @*=*) - _ln_target="${1%=*}"; - _ln_target="${_ln_target#@}"; - _ln_fname="${1#*=}"; - if [ "${_ln_fname#/}" = "${_ln_fname}" ]; then - _ln_fname="${_prefix:+${_prefix}/}${_ln_fname}"; - fi; - if [ -e "${_ln_fname}" ]; then - ex_rtl_fileop rm "${_ln_fname}"; - fi; - ex_rtl_fileop ln_symbolic "${_ln_target}" "${_ln_fname}"; - ;; - /=*) - _mkdir_fname="${1#/=}"; - if [ "${_mkdir_fname#/}" = "${_mkdir_fname}" ]; then - _mkdir_fname="${_prefix:+${_prefix}/}${_mkdir_fname}"; - fi; - ex_rtl_fileop mkdir "${_mkdir_fname}"; - ;; - *) - _file_fname_src="${1%=*}"; - _file_fname_dst="${1#*=}"; - if [ "${_file_fname_src#/}" = "${_file_fname_src}" ]; then - _file_fname_src="${_prefix:+${_prefix}/}${_file_fname_src}"; - fi; - if [ "${_file_fname_dst#/}" = "${_file_fname_dst}" ]; then - _file_fname_dst="${_prefix:+${_prefix}/}${_file_fname_dst}"; - fi; - ex_rtl_fileop cp "${_file_fname_src}" "${_file_fname_dst}"; - ;; - esac; shift; - done; -}; - -# vim:filetype=sh diff --git a/subr/ex_rtl_list.subr b/subr/ex_rtl_list.subr deleted file mode 100644 index fb2bde72..00000000 --- a/subr/ex_rtl_list.subr +++ /dev/null @@ -1,75 +0,0 @@ -# -# set +o errexit -o noglob is assumed. -# - -ex_rtl_lconcat() { - local _list="${1}" _litem_new="${2}" _sep="${3:- }" IFS="${3:-${IFS}}"; - if [ -n "${_list}" ]; then - printf "%s%s%s" "${_list}" "${_sep}" "${_litem_new}"; - else - printf "%s" "${_litem_new}"; - fi; -}; - -ex_rtl_lfilter() { - local _list="${1}" _filter="${2}" _sep="${3:- }" IFS="${3:-${IFS}}" \ - _filterfl="" _litem="" _litem_filter="" _lnew=""; - if [ -z "${_filter}" ]; then - echo "${_list}"; return 0; - else for _litem in ${_list}; do - _filterfl=0; - for _litem_filter in ${_filter}; do - if [ "${_litem_filter}" = "${_litem}" ]; then - _filterfl=1; break; - fi; - done; - if [ "${_filterfl:-0}" -eq 0 ]; then - _lnew="${_lnew:+${_lnew}${_sep}}${_litem}"; - fi; - done; fi; - echo "${_lnew}"; -}; - -ex_rtl_llength() { - local _list="${1}" _sep="${2:- }" IFS="${2:-${IFS}}" _litem="" _llength=0; - for _litem in ${_list}; do - : $((_llength+=1)); - done; - echo "${_llength}"; -}; - -ex_rtl_lmatch() { - local _list="${1}" _item="${2}" _sep="${3}"; - [ -n "$(ex_rtl_lsearch "${_list}" "${_item}" "${_sep}")" ]; -}; - -ex_rtl_lsearch() { - local _list="${1}" _filter="${2}" _sep="${3:- }" IFS="${3:-${IFS}}" \ - _litem="" _litem_filter="" _lnew=""; - if [ -z "${_filter}" ]; then - echo "${_list}"; return 0; - else for _litem in ${_list}; do - for _litem_filter in ${_filter}; do - if [ "${_litem_filter}" = "${_litem}" ]; then - _lnew="${_lnew:+${_lnew}${_sep}}${_litem}"; - break; - fi; - done; - done; fi; - echo "${_lnew}"; -}; - -ex_rtl_lunfold_depends() { - local _vname_template="${1}" _depends="" _name="" _names=""; shift; - for _name in "${@}"; do - if _depends="$(ex_rtl_get_var_unsafe -u "$(eval printf \"%s\" \""${_vname_template}"\")")"\ - && [ -n "${_depends}" ]; then - _depends="$(ex_rtl_lunfold_depends "${_vname_template}" ${_depends})"; - _names="$(ex_rtl_lconcat "${_names}" "${_depends}")"; - fi; - _names="$(ex_rtl_lconcat "${_names}" "${_name}")"; - done; - echo "${_names}"; -}; - -# vim:filetype=sh diff --git a/subr/ex_rtl_log.subr b/subr/ex_rtl_log.subr deleted file mode 100644 index 514d4636..00000000 --- a/subr/ex_rtl_log.subr +++ /dev/null @@ -1,78 +0,0 @@ -# -# set +o errexit -o noglob is assumed. -# - -: ${DEFAULT_LOG_MSG_FAIL_COLOUR:=91}; -: ${DEFAULT_LOG_MSG_INFO_COLOUR:=93}; -: ${DEFAULT_LOG_MSG_INF2_COLOUR:=33}; -: ${DEFAULT_LOG_MSG_SUCC_COLOUR:=92}; -: ${DEFAULT_LOG_MSG_SUC2_COLOUR:=32}; -: ${DEFAULT_LOG_MSG_VNFO_COLOUR:=96}; -: ${DEFAULT_LOG_MSG_VUCC_COLOUR:=90}; -: ${DEFAULT_LOG_MSG_VVFO_COLOUR:=96}; -: ${DEFAULT_LOG_MSG_VVVO_COLOUR:=96}; -: ${DEFAULT_LOG_MSG_VVVV_COLOUR:=96}; - -exp_rtl_log_printf() { - local _attrs="${1}" _msg=""; shift; _msg="$(printf "${@}")"; - if [ "${BUILD_IS_PARENT:-0}" -eq 1 ]\ - && [ -n "${DEFAULT_BUILD_LOG_FNAME}" ]\ - && [ -e "${DEFAULT_BUILD_LOG_FNAME}" ]; then - printf "%s\n" "${_msg}" >> "${DEFAULT_BUILD_LOG_FNAME}"; - fi; - printf "\033[0m\033[${_attr}m%s\033[0m\n" "${_msg}"; -}; - -ex_rtl_log_env_vars() { - local _nvar=1 _arg="" _arg_len_max=0; - ex_rtl_log_msg info "Variables for this ${1:-build}:"; shift; - while [ ${_nvar} -le ${#} ]; do - _arg="$(eval echo \${${_nvar}})"; - _arg="${_arg%%=*}"; - if [ ${#_arg} -gt ${_arg_len_max} ]; then - _arg_len_max=${#_arg}; - fi; : $((_nvar+=1)); - done; - while [ ${#} -gt 0 ]; do - ex_rtl_log_msg info "$(printf \ - "%${_arg_len_max}.${_arg_len_max}s=%s" \ - "${1%%=*}" "$(ex_rtl_get_var_unsafe ${1#*=})")"; - shift; - done; -}; - -ex_rtl_log_set_vnfo_lvl() { - EXP_RTL_LOG_VNFO_LVL="${1}"; -}; - -ex_rtl_log_msg() { - local _lvl="${1}" _lvl_uc="" _attr=""; shift; - if [ "${_lvl}" = vnfo ]\ - || [ "${_lvl}" = vucc ]\ - && [ "${EXP_RTL_LOG_VNFO_LVL:-0}" -lt 1 ]; then - return; - elif [ "${_lvl}" = vvfo ]\ - && [ "${EXP_RTL_LOG_VNFO_LVL:-0}" -lt 2 ]; then - return; - elif [ "${_lvl}" = vvvo ]\ - && [ "${EXP_RTL_LOG_VNFO_LVL:-0}" -lt 3 ]; then - return; - elif [ "${_lvl}" = vvvv ]\ - && [ "${EXP_RTL_LOG_VNFO_LVL:-0}" -lt 4 ]; then - return; - fi; - _lvl_uc="$(ex_rtl_toupper "${_lvl%exit}")"; - _attr="$(ex_rtl_get_var_unsafe "DEFAULT_LOG_MSG_${_lvl_uc}_COLOUR")"; - if [ ${#} -gt 1 ]; then - exp_rtl_log_printf "${_attrs}" "==> %s %s %s" "$(ex_rtl_date)" "${1}" "$*"; - else - exp_rtl_log_printf "${_attrs}" "==> %s %s" "$(ex_rtl_date)" "${1}"; - fi; - if [ ${_lvl} = failexit ]; then - exit 1; - else - return 0; - fi; -}; - -# vim:filetype=sh diff --git a/subr/ex_rtl_state.subr b/subr/ex_rtl_state.subr deleted file mode 100644 index 406da477..00000000 --- a/subr/ex_rtl_state.subr +++ /dev/null @@ -1,40 +0,0 @@ -# -# set +o errexit -o noglob is assumed. -# - -ex_rtl_state_clear() { - local _workdir="${1}" _pkg_name="${2}" _pkg_fname=""; - for _pkg_fname in $(find "${_workdir}" \ - -maxdepth 1 -mindepth 1 -name .${_pkg_name}.\* -type f); do - ex_rtl_fileop rm "${_pkg_fname}"; - done; -}; - -ex_rtl_state_set() { - local _workdir="${1}" _pkg_fname="${2}" _done_fname_pfx=""; - _done_fname_pfx="${_workdir}/.${_pkg_fname}"; - shift 2; while [ ${#} -ge 1 ]; do - if [ -z "${1}" ]; then - shift; continue; - elif [ "${1#-}" != "${1}" ]; then - ex_rtl_fileop rm "${_done_fname_pfx}.${1#-}"; - else - ex_rtl_fileop touch "${_done_fname_pfx}.${1}"; - fi; - shift; done; -}; - -ex_rtl_state_test() { - local _workdir="${1}" _pkg_name="${2}" _build_step="${3}" \ - _restart_at="${4}" _done_fname=""; - _done_fname="${_workdir}/.${_pkg_name}.${_build_step}"; - if [ -z "${_restart_at}" ]; then - ex_rtl_fileop test "${_done_fname}"; - elif [ "${_restart_at}" = "ALL" ]; then - return 1; - else - ! ex_rtl_lmatch "${_restart_at}" "${_build_step}" ","; - fi; -}; - -# vim:filetype=sh diff --git a/subr/ex_rtl_string.subr b/subr/ex_rtl_string.subr deleted file mode 100644 index 9b8874fa..00000000 --- a/subr/ex_rtl_string.subr +++ /dev/null @@ -1,83 +0,0 @@ -# -# set +o errexit -o noglob is assumed. -# - -ex_rtl_tolower() { - local _s="${1}" _s_new=""; - while [ -n "${_s}" ]; do - case "${_s}" in - A*) _s_new="${_s_new:+${_s_new}}a"; _s="${_s#A}"; ;; - B*) _s_new="${_s_new:+${_s_new}}b"; _s="${_s#B}"; ;; - C*) _s_new="${_s_new:+${_s_new}}c"; _s="${_s#C}"; ;; - D*) _s_new="${_s_new:+${_s_new}}d"; _s="${_s#D}"; ;; - E*) _s_new="${_s_new:+${_s_new}}e"; _s="${_s#E}"; ;; - F*) _s_new="${_s_new:+${_s_new}}f"; _s="${_s#F}"; ;; - G*) _s_new="${_s_new:+${_s_new}}g"; _s="${_s#G}"; ;; - H*) _s_new="${_s_new:+${_s_new}}h"; _s="${_s#H}"; ;; - I*) _s_new="${_s_new:+${_s_new}}i"; _s="${_s#I}"; ;; - J*) _s_new="${_s_new:+${_s_new}}j"; _s="${_s#J}"; ;; - K*) _s_new="${_s_new:+${_s_new}}k"; _s="${_s#K}"; ;; - L*) _s_new="${_s_new:+${_s_new}}l"; _s="${_s#L}"; ;; - M*) _s_new="${_s_new:+${_s_new}}m"; _s="${_s#M}"; ;; - N*) _s_new="${_s_new:+${_s_new}}n"; _s="${_s#N}"; ;; - O*) _s_new="${_s_new:+${_s_new}}o"; _s="${_s#O}"; ;; - P*) _s_new="${_s_new:+${_s_new}}p"; _s="${_s#P}"; ;; - Q*) _s_new="${_s_new:+${_s_new}}q"; _s="${_s#Q}"; ;; - R*) _s_new="${_s_new:+${_s_new}}r"; _s="${_s#R}"; ;; - S*) _s_new="${_s_new:+${_s_new}}s"; _s="${_s#S}"; ;; - T*) _s_new="${_s_new:+${_s_new}}t"; _s="${_s#T}"; ;; - U*) _s_new="${_s_new:+${_s_new}}u"; _s="${_s#U}"; ;; - V*) _s_new="${_s_new:+${_s_new}}v"; _s="${_s#V}"; ;; - W*) _s_new="${_s_new:+${_s_new}}w"; _s="${_s#W}"; ;; - X*) _s_new="${_s_new:+${_s_new}}x"; _s="${_s#X}"; ;; - Y*) _s_new="${_s_new:+${_s_new}}y"; _s="${_s#Y}"; ;; - Z*) _s_new="${_s_new:+${_s_new}}z"; _s="${_s#Z}"; ;; - [^ABCDEFGHIJKLMNOPQRSTUVWXYZ]*) - _s_new="${_s_new:+${_s_new}}${_s%%[ABCDEFGHIJKLMNOPQRSTUVWXYZ]*}"; - while [ "${_s#[^ABCDEFGHIJKLMNOPQRSTUVWXYZ]}" != "${_s}" ]; do - _s="${_s#[^ABCDEFGHIJKLMNOPQRSTUVWXYZ]}"; - done; ;; - esac; done; - echo "${_s_new}"; -}; - -ex_rtl_toupper() { - local _s="${1}" _s_new=""; - while [ -n "${_s}" ]; do - case "${_s}" in - a*) _s_new="${_s_new:+${_s_new}}A"; _s="${_s#a}"; ;; - b*) _s_new="${_s_new:+${_s_new}}B"; _s="${_s#b}"; ;; - c*) _s_new="${_s_new:+${_s_new}}C"; _s="${_s#c}"; ;; - d*) _s_new="${_s_new:+${_s_new}}D"; _s="${_s#d}"; ;; - e*) _s_new="${_s_new:+${_s_new}}E"; _s="${_s#e}"; ;; - f*) _s_new="${_s_new:+${_s_new}}F"; _s="${_s#f}"; ;; - g*) _s_new="${_s_new:+${_s_new}}G"; _s="${_s#g}"; ;; - h*) _s_new="${_s_new:+${_s_new}}H"; _s="${_s#h}"; ;; - i*) _s_new="${_s_new:+${_s_new}}I"; _s="${_s#i}"; ;; - j*) _s_new="${_s_new:+${_s_new}}J"; _s="${_s#j}"; ;; - k*) _s_new="${_s_new:+${_s_new}}K"; _s="${_s#k}"; ;; - l*) _s_new="${_s_new:+${_s_new}}L"; _s="${_s#l}"; ;; - m*) _s_new="${_s_new:+${_s_new}}M"; _s="${_s#m}"; ;; - n*) _s_new="${_s_new:+${_s_new}}N"; _s="${_s#n}"; ;; - o*) _s_new="${_s_new:+${_s_new}}O"; _s="${_s#o}"; ;; - p*) _s_new="${_s_new:+${_s_new}}P"; _s="${_s#p}"; ;; - q*) _s_new="${_s_new:+${_s_new}}Q"; _s="${_s#q}"; ;; - r*) _s_new="${_s_new:+${_s_new}}R"; _s="${_s#r}"; ;; - s*) _s_new="${_s_new:+${_s_new}}S"; _s="${_s#s}"; ;; - t*) _s_new="${_s_new:+${_s_new}}T"; _s="${_s#t}"; ;; - u*) _s_new="${_s_new:+${_s_new}}U"; _s="${_s#u}"; ;; - v*) _s_new="${_s_new:+${_s_new}}V"; _s="${_s#v}"; ;; - w*) _s_new="${_s_new:+${_s_new}}W"; _s="${_s#w}"; ;; - x*) _s_new="${_s_new:+${_s_new}}X"; _s="${_s#x}"; ;; - y*) _s_new="${_s_new:+${_s_new}}Y"; _s="${_s#y}"; ;; - z*) _s_new="${_s_new:+${_s_new}}Z"; _s="${_s#z}"; ;; - [^abcdefghijklmnopqrstuvwxyz]*) - _s_new="${_s_new:+${_s_new}}${_s%%[abcdefghijklmnopqrstuvwxyz]*}"; - while [ "${_s#[^abcdefghijklmnopqrstuvwxyz]}" != "${_s}" ]; do - _s="${_s#[^abcdefghijklmnopqrstuvwxyz]}"; - done; ;; - esac; done; - echo "${_s_new}"; -}; - -# vim:filetype=sh diff --git a/subr/pkg_build.subr b/subr/pkg_build.subr index e7ea6beb..2433ea81 100644 --- a/subr/pkg_build.subr +++ b/subr/pkg_build.subr @@ -10,7 +10,7 @@ pkg_build() { # N.B. We only specify CC= here if the current package does not use GNU # autoconf as it often abuses it by appending -std={gnu99,...} to it # instead of amending CFLAGS. - ex_rtl_run_cmd_unsplit make \ + rtl_run_cmd_unsplit make \ ${PKG_MAKEFLAGS_BUILD} \ ${PKG_MAKEFLAGS_BUILD_EXTRA} \ "AR=${PKG_AR}" "${_no_autoconf:+CC=${PKG_CC}}" \ diff --git a/subr/pkg_clean.subr b/subr/pkg_clean.subr index 40d56540..b122823e 100644 --- a/subr/pkg_clean.subr +++ b/subr/pkg_clean.subr @@ -4,14 +4,14 @@ pkg_clean() { if [ "${PKG_NO_CLEAN:-0}" -eq 0 ]; then - if ex_rtl_lmatch "${ARG_CLEAN_BUILDS}" "build" ","; then - ex_rtl_fileop rm "${PKG_BUILD_DIR}" || return "${?}"; + if rtl_lmatch "${ARG_CLEAN_BUILDS}" "build" ","; then + rtl_fileop rm "${PKG_BUILD_DIR}" || return "${?}"; fi; - if ex_rtl_lmatch "${ARG_CLEAN_BUILDS}" "dest" ","; then - ex_rtl_fileop rm "${PKG_DESTDIR}" || return "${?}"; + if rtl_lmatch "${ARG_CLEAN_BUILDS}" "dest" ","; then + rtl_fileop rm "${PKG_DESTDIR}" || return "${?}"; fi; - if ex_rtl_lmatch "${ARG_CLEAN_BUILDS}" "src" ","; then - ex_rtl_fileop rm "${PKG_BASE_DIR}/${PKG_SUBDIR}" || return "${?}"; + if rtl_lmatch "${ARG_CLEAN_BUILDS}" "src" ","; then + rtl_fileop rm "${PKG_BASE_DIR}/${PKG_SUBDIR}" || return "${?}"; fi; fi; }; diff --git a/subr/pkg_configure.subr b/subr/pkg_configure.subr index 0adc7acf..c6819886 100644 --- a/subr/pkg_configure.subr +++ b/subr/pkg_configure.subr @@ -5,7 +5,7 @@ pkg_configure() { local _rc=0; if [ -x "${PKG_CONFIGURE}" ]; then - ex_rtl_export_vars PKG_CONFIG "${PKG_PKG_CONFIG}" PKG_CONFIG_PATH "${PKG_PKG_CONFIG_PATH}" PYTHON "${PKG_PYTHON}"; + rtl_export_vars PKG_CONFIG "${PKG_PKG_CONFIG}" PKG_CONFIG_PATH "${PKG_PKG_CONFIG_PATH}" PYTHON "${PKG_PYTHON}"; AR="${PKG_AR}" \ CC="${PKG_CC}" \ RANLIB="${PKG_RANLIB}" \ @@ -14,7 +14,7 @@ pkg_configure() { CXXFLAGS="${PKG_CXXFLAGS_CONFIGURE}${PKG_CXXFLAGS_CONFIGURE_EXTRA:+ ${PKG_CXXFLAGS_CONFIGURE_EXTRA}}" \ LDFLAGS="${PKG_LDFLAGS_CONFIGURE}${PKG_LDFLAGS_CONFIGURE_EXTRA:+ ${PKG_LDFLAGS_CONFIGURE_EXTRA}}" \ "${PKG_CONFIGURE}" ${PKG_CONFIGURE_ARGS} ${PKG_CONFIGURE_ARGS_EXTRA} ${PKG_CONFIGURE_ARGS_EXTRA_DEBUG}; _rc="${?}" - ex_rtl_export_vars -u PKG_CONFIG "${PKG_PKG_CONFIG}" PKG_CONFIG_PATH "${PKG_PKG_CONFIG_PATH}" PYTHON "${PKG_PYTHON}"; + rtl_export_vars -u PKG_CONFIG "${PKG_PKG_CONFIG}" PKG_CONFIG_PATH "${PKG_PKG_CONFIG_PATH}" PYTHON "${PKG_PYTHON}"; fi; return "${?}"; }; diff --git a/subr/pkg_configure_autotools.subr b/subr/pkg_configure_autotools.subr index 7c1ee329..bc3b6c23 100644 --- a/subr/pkg_configure_autotools.subr +++ b/subr/pkg_configure_autotools.subr @@ -4,9 +4,9 @@ pkg_configure_autotools() { local _config_cache="" _fname="" _subdir_tgt=""; - if ex_rtl_exists_any "${PKG_BASE_DIR}/${PKG_SUBDIR}" \ + if rtl_exists_any "${PKG_BASE_DIR}/${PKG_SUBDIR}" \ "config.guess" "configure.ac" "configure.in" "configure"; - then ex_rtl_export_vars PKG_CONFIG "${PKG_PKG_CONFIG}" PKG_CONFIG_PATH "${PKG_PKG_CONFIG_PATH}"; + then rtl_export_vars PKG_CONFIG "${PKG_PKG_CONFIG}" PKG_CONFIG_PATH "${PKG_PKG_CONFIG_PATH}"; if [ -e "${PKG_BASE_DIR}/${PKG_SUBDIR}/configure.ac" ]\ && [ ! -e "${PKG_BASE_DIR}/${PKG_SUBDIR}/configure" ]; then for _fname in bootstrap bootstrap.sh autogen.sh; do @@ -15,25 +15,25 @@ pkg_configure_autotools() { "${PKG_BASE_DIR}/${PKG_SUBDIR}/build-aux" \ "${PKG_BASE_DIR}/${PKG_SUBDIR}"; do if [ -e "${_subdir_tgt}" ]; then - ex_rtl_fileop install -m 0700 \ + rtl_fileop install -m 0700 \ "${MIDIPIX_BUILD_PWD}/etc/config.sub" \ "${_subdir_tgt}/config.sub" || return "${?}" && break; fi; done; - (ex_rtl_fileop cd "${PKG_BASE_DIR}/${PKG_SUBDIR}" && \ + (rtl_fileop cd "${PKG_BASE_DIR}/${PKG_SUBDIR}" && \ /bin/sh "${_fname}") || return "${?}" && break; fi; done; - (ex_rtl_fileop cd "${PKG_BASE_DIR}/${PKG_SUBDIR}" && autoconf) || return "${?}"; + (rtl_fileop cd "${PKG_BASE_DIR}/${PKG_SUBDIR}" && autoconf) || return "${?}"; fi; for _fname in $(find "${PKG_BASE_DIR}/${PKG_SUBDIR}" -name config.sub); do - if ! ex_rtl_fileop mv "${_fname}" "${_fname}.orig"\ - || ! ex_rtl_fileop install -m 0700 "${MIDIPIX_BUILD_PWD}/etc/config.sub" "${_fname}"; then + if ! rtl_fileop mv "${_fname}" "${_fname}.orig"\ + || ! rtl_fileop install -m 0700 "${MIDIPIX_BUILD_PWD}/etc/config.sub" "${_fname}"; then return 1; fi; done if [ "${PKG_BUILD_TYPE}" != host ]; then - if ! ex_rtl_fileop touch "${PKG_BUILD_DIR}/config.cache"; then + if ! rtl_fileop touch "${PKG_BUILD_DIR}/config.cache"; then return 1; else for _config_cache in \ "${PKG_CONFIG_CACHE}" \ @@ -45,7 +45,7 @@ pkg_configure_autotools() { sed -i"" "s,%PREFIX%,${PKG_PREFIX},g" "${PKG_BUILD_DIR}/config.cache" || return "${?}"; fi; fi; - ex_rtl_export_vars -u PKG_CONFIG "${PKG_PKG_CONFIG}" PKG_CONFIG_PATH "${PKG_PKG_CONFIG_PATH}"; + rtl_export_vars -u PKG_CONFIG "${PKG_PKG_CONFIG}" PKG_CONFIG_PATH "${PKG_PKG_CONFIG_PATH}"; fi; }; diff --git a/subr/pkg_configure_patch.subr b/subr/pkg_configure_patch.subr index 366a9e52..80690b67 100644 --- a/subr/pkg_configure_patch.subr +++ b/subr/pkg_configure_patch.subr @@ -12,9 +12,9 @@ pkg_configure_patch() { "${_patch_dir}/${_pkg_name_full}.local@${BUILD_HNAME}.patch" \ ${PKG_PATCHES_EXTRA}; do if [ -r "${_patch_fname}" ]\ - && ! ex_rtl_lmatch "${_patches_done}" "${_patch_fname}"; then + && ! rtl_lmatch "${_patches_done}" "${_patch_fname}"; then patch -b -d "${PKG_BASE_DIR}/${PKG_SUBDIR}" -p1 < "${_patch_fname}" || return "${?}"; - _patches_done="$(ex_rtl_lconcat "${_patches_done}" "${_patch_fname}")"; + _patches_done="$(rtl_lconcat "${_patches_done}" "${_patch_fname}")"; fi; done; set -o noglob; }; diff --git a/subr/pkg_configure_patch_pre.subr b/subr/pkg_configure_patch_pre.subr index f38b5188..1c572efd 100644 --- a/subr/pkg_configure_patch_pre.subr +++ b/subr/pkg_configure_patch_pre.subr @@ -17,8 +17,8 @@ pkgp_configure_patch_pre_chainport() { local _chainport_patch_fname="${BUILD_WORKDIR}/chainport/patches/${PKG_NAME%%_*}/${PKG_NAME%%_*}-${PKG_VERSION}.midipix.patch"\ _chainport_patch_dname="${PKG_BASE_DIR}/${PKG_SUBDIR}/patches/${PKG_NAME%%_*}" _oldpwd=""; if [ -e "${_chainport_patch_fname}" ]; then - ex_rtl_fileop mkdir "${_chainport_patch_dname}" || return "${?}"; - ex_rtl_fileop cp "${_chainport_patch_fname}" "${_chainport_patch_dname}" || return "${?}"; + rtl_fileop mkdir "${_chainport_patch_dname}" || return "${?}"; + rtl_fileop cp "${_chainport_patch_fname}" "${_chainport_patch_dname}" || return "${?}"; fi; }; diff --git a/subr/pkg_fetch_download.subr b/subr/pkg_fetch_download.subr index 8e1d193b..a23b8b9d 100644 --- a/subr/pkg_fetch_download.subr +++ b/subr/pkg_fetch_download.subr @@ -4,10 +4,10 @@ pkg_fetch_download() { if [ -n "${PKG_URL}" ]; then - ex_rtl_fetch_url_wget "${PKG_URL}" "${PKG_SHA256SUM}" "${PKG_FNAME}" || return "${?}"; + rtl_fetch_url_wget "${PKG_URL}" "${PKG_SHA256SUM}" "${PKG_FNAME}" || return "${?}"; fi; if [ -n "${PKG_URLS_GIT}" ]; then - ex_rtl_fetch_urls_git "${PKG_BASE_DIR}" ${PKG_URLS_GIT} || return "${?}"; + rtl_fetch_urls_git "${PKG_BASE_DIR}" ${PKG_URLS_GIT} || return "${?}"; fi; }; diff --git a/subr/pkg_fetch_extract.subr b/subr/pkg_fetch_extract.subr index 66e51669..9df9f93e 100644 --- a/subr/pkg_fetch_extract.subr +++ b/subr/pkg_fetch_extract.subr @@ -14,8 +14,8 @@ pkgp_fetch_extract_type() { pkg_fetch_extract() { if [ -n "${PKG_URL}" ]\ && [ "${PKG_URL_TYPE:-wget}" = wget ]; then - _oldpwd="${PWD}"; ex_rtl_fileop cd "${PKG_BASE_DIR}" || return "${?}"; - ex_rtl_fileop rm "${PKG_BASE_DIR}/${PKG_SUBDIR}" || return "${?}"; + _oldpwd="${PWD}"; rtl_fileop cd "${PKG_BASE_DIR}" || return "${?}"; + rtl_fileop rm "${PKG_BASE_DIR}/${PKG_SUBDIR}" || return "${?}"; case "$(pkgp_fetch_extract_type "${PKG_NAME}")" in bz2) bunzip2 -d < "${BUILD_DLCACHEDIR}/${PKG_FNAME}" | tar -C "${PKG_BASE_DIR}" -xf - || return "${?}"; ;; gz) gunzip -d < "${BUILD_DLCACHEDIR}/${PKG_FNAME}" | tar -C "${PKG_BASE_DIR}" -xf - || return "${?}"; ;; @@ -23,7 +23,7 @@ pkg_fetch_extract() { xz) xz -d < "${BUILD_DLCACHEDIR}/${PKG_FNAME}" | tar -C "${PKG_BASE_DIR}" -xf - || return "${?}"; ;; *) tar -C "${PKG_BASE_DIR}" -xf "${BUILD_DLCACHEDIR}/${PKG_FNAME}" || return "${?}"; ;; esac; - ex_rtl_fileop cd "${_oldpwd}" || return "${?}"; + rtl_fileop cd "${_oldpwd}" || return "${?}"; fi; }; diff --git a/subr/pkg_install.subr b/subr/pkg_install.subr index 46024e8e..87182d9c 100644 --- a/subr/pkg_install.subr +++ b/subr/pkg_install.subr @@ -4,14 +4,14 @@ pkg_install() { local _pkglist_name=""; - if ! ex_rtl_fileop mkdir "${PKG_PREFIX}"\ + if ! rtl_fileop mkdir "${PKG_PREFIX}"\ || ! find "${PKG_DESTDIR}" -type d -exec chmod 0755 {} \;\ || ! find "${PKG_DESTDIR}" \( -not -perm /0111 \) -type f -exec chmod 0644 {} \;\ || ! find "${PKG_DESTDIR}" -perm /0111 -type f -exec chmod 0755 {} \;\ || ! tar -C "${PKG_DESTDIR}" -cpf - . | tar -C "${PKG_PREFIX}" --overwrite -xpf -; then return "${?}"; else - if ex_rtl_lmatch "${ARG_DIST}" "pkg" ","; then + if rtl_lmatch "${ARG_DIST}" "pkg" ","; then tar -C "${PKG_DESTDIR}" -cpf - . |\ gzip -c -9 - > "${PKG_BASE_DIR}/${PKG_NAME}.tgz" || return "${?}"; fi; diff --git a/subr/pkg_install_files.subr b/subr/pkg_install_files.subr index 92c7ed7e..5a4d9708 100644 --- a/subr/pkg_install_files.subr +++ b/subr/pkg_install_files.subr @@ -4,7 +4,7 @@ pkgp_install_files() { if [ -n "${PKG_INSTALL_FILES}" ]; then - ex_rtl_install -v "${PKG_DESTDIR}" ${PKG_INSTALL_FILES} || return "${?}"; + rtl_install -v "${PKG_DESTDIR}" ${PKG_INSTALL_FILES} || return "${?}"; fi; }; @@ -30,7 +30,7 @@ pkgp_install_files_strip() { fi; for _bin_path in $(find "${_tree_root}" -perm /a=x -type f); do if objdump -sj .debug_info "${_bin_path}" >/dev/null 2>&1; then - ex_rtl_log_msg info "Stripping ${_bin_path}..."; + rtl_log_msg info "Stripping ${_bin_path}..."; "${PKG_TARGET}-strip" "${_bin_path}" || return "${?}"; fi; done; diff --git a/subr/pkg_install_libs.subr b/subr/pkg_install_libs.subr index 379a0374..a00f15bb 100644 --- a/subr/pkg_install_libs.subr +++ b/subr/pkg_install_libs.subr @@ -5,7 +5,7 @@ pkgp_install_libs_purge_la() { local _la_path=""; for _la_path in $(find "${PKG_DESTDIR}" -type f -name \*.la); do - ex_rtl_fileop rm "${_la_path}" || return "${?}"; + rtl_fileop rm "${_la_path}" || return "${?}"; done; }; @@ -14,8 +14,8 @@ pkgp_install_libs_shared_link() { if _lib_link_tgt="$(find "${_so_dir}" -name "${_lib_name%%.*}.*.lib.a" | sort | tail -1)"\ && [ -n "${_lib_link_tgt}" ]\ && [ "${_lib_link_tgt}" != "${_lib_link_path}" ]; then - if ! ex_rtl_fileop rm "${_lib_link_path}"\ - || ! ex_rtl_fileop ln_symbolic "$(ex_rtl_basename "${_lib_link_tgt}")" "${_lib_link_path}"; then + if ! rtl_fileop rm "${_lib_link_path}"\ + || ! rtl_fileop ln_symbolic "$(rtl_basename "${_lib_link_tgt}")" "${_lib_link_path}"; then return 1; fi; fi; @@ -28,21 +28,21 @@ pkgp_install_libs_shared() { $(find "${PKG_DESTDIR}" \ \( -name "*.so" -or -name "*.so.*" \) -print); do if [ "$(readlink -f "${_so_path}")" != "/dev/null" ]\ - && [ -z "$(ex_rtl_head "[0-9.]" "${_so_src_path##*.so}")" ]; then + && [ -z "$(rtl_head "[0-9.]" "${_so_src_path##*.so}")" ]; then case "${_so_src_path}" in *.so) _lib_src_path="${_so_src_path%%.so}.lib.a"; ;; *.so.*) _lib_src_path="${_so_src_path%%.so.*}.${_so_src_path##*.so.}.lib.a"; ;; esac; _so_dst_dir="${_so_src_path%/*}"; - _lib_name="$(ex_rtl_basename "${_lib_src_path}")"; + _lib_name="$(rtl_basename "${_lib_src_path}")"; _lib_dst_path="${_so_dst_dir}/${_lib_name}"; if [ ! -L "${_lib_src_path}" ]\ && [ ! -e "${_lib_dst_path}" ]; then - (ex_rtl_fileop cd "$(ex_rtl_dirname "${_so_src_path}")" &&\ - perk -e "$(ex_rtl_basename "${_so_src_path}")" |\ + (rtl_fileop cd "$(rtl_dirname "${_so_src_path}")" &&\ + perk -e "$(rtl_basename "${_so_src_path}")" |\ "${PKG_TARGET}-mdso" \ - -i "$(ex_rtl_basename "${_lib_dst_path}")" \ - -n "$(ex_rtl_basename "${_so_src_path}")" -) || return "${?}"; + -i "$(rtl_basename "${_lib_dst_path}")" \ + -n "$(rtl_basename "${_so_src_path}")" -) || return "${?}"; fi; pkgp_install_libs_shared_link "${_lib_name}" "${_so_dst_dir}" "${_so_src_path}" || return "${?}"; fi; diff --git a/subr/pkg_install_make.subr b/subr/pkg_install_make.subr index 5cf16fe9..45f5d58f 100644 --- a/subr/pkg_install_make.subr +++ b/subr/pkg_install_make.subr @@ -3,7 +3,7 @@ # pkg_install_make() { - ex_rtl_run_cmd_unsplit make \ + rtl_run_cmd_unsplit make \ ${PKG_MAKEFLAGS_INSTALL} \ ${PKG_MAKEFLAGS_INSTALL_EXTRA} \ AR=${PKG_AR} CC=${PKG_CC} RANLIB=${PKG_RANLIB} \ diff --git a/subr/pkg_install_rpm.subr b/subr/pkg_install_rpm.subr index b3c939ab..ae76ac70 100644 --- a/subr/pkg_install_rpm.subr +++ b/subr/pkg_install_rpm.subr @@ -4,7 +4,7 @@ pkg_install_rpm() { local _pkg_url="" _pkg_version_full="" _pkg_version_rpm="" _rc=0; - if ex_rtl_lmatch "${ARG_DIST}" "rpm" ","\ + if rtl_lmatch "${ARG_DIST}" "rpm" ","\ && [ "${PKG_RPM_DISABLE:-0}" -eq 0 ]\ && [ -x "$(which rpmbuild 2>/dev/null)" ]; then if [ -n "${PKG_URL}" ]; then @@ -17,7 +17,7 @@ pkg_install_rpm() { _pkg_url="Unknown"; fi; fi; - if ! ex_rtl_fileop cp "${MIDIPIX_BUILD_PWD}/etc/package.spec" \ + if ! rtl_fileop cp "${MIDIPIX_BUILD_PWD}/etc/package.spec" \ "${PKG_BASE_DIR}/${PKG_NAME}-${_pkg_version_rpm}.spec"; then return 1; else while true; do @@ -41,8 +41,8 @@ pkg_install_rpm() { done; if ! find "${PREFIX_RPM}/${PKG_NAME}-${_pkg_version_rpm}/RPMS" \ -iname \*.rpm -exec cp -pP {} "${PREFIX_RPM}/" \; \ - || ! ex_rtl_fileop rm "${PREFIX_RPM}/${PKG_NAME}-${_pkg_version_rpm}" \ - || ! ex_rtl_fileop cp "${PKG_BASE_DIR}/${PKG_NAME}-${_pkg_version_rpm}.spec" "${PREFIX_RPM}/"; then + || ! rtl_fileop rm "${PREFIX_RPM}/${PKG_NAME}-${_pkg_version_rpm}" \ + || ! rtl_fileop cp "${PKG_BASE_DIR}/${PKG_NAME}-${_pkg_version_rpm}.spec" "${PREFIX_RPM}/"; then return "${?}"; fi; fi; diff --git a/subr/pkg_install_subdirs.subr b/subr/pkg_install_subdirs.subr index 379592f5..94557586 100644 --- a/subr/pkg_install_subdirs.subr +++ b/subr/pkg_install_subdirs.subr @@ -7,10 +7,10 @@ pkg_install_subdirs() { for _spec in \ "${PKG_INSTALL_FILES_DESTDIR}" \ "${PKG_INSTALL_FILES_DESTDIR_EXTRA}"; do - ex_rtl_install "${PKG_DESTDIR}" ${_spec} || return "${?}"; + rtl_install "${PKG_DESTDIR}" ${_spec} || return "${?}"; done; if [ "${PKG_PREFIX%/}" = "${PREFIX_NATIVE%/}" ]; then - ex_rtl_install \ + rtl_install \ "${PKG_DESTDIR}/${DEFAULT_TARGET}" ${PKG_INSTALL_FILES_DESTDIR} || return "${?}"; fi; }; diff --git a/subr/rtl.subr b/subr/rtl.subr new file mode 100644 index 00000000..18ddb8d6 --- /dev/null +++ b/subr/rtl.subr @@ -0,0 +1,17 @@ +# +# set +o errexit -o noglob is assumed. +# + +EXP_RTL_IFS="${IFS}"; + +rtl_basename() { echo "${1##*/}"; }; +rtl_date() { command date "+${1:-${DEFAULT_TIMESTAMP_FMT}}"; }; +rtl_dirname() { echo "${1%/*}"; }; +rtl_pop_IFS() { IFS="${EXP_RTL_IFS}"; }; +rtl_push_IFS() { EXP_RTL_IFS="${IFS}"; IFS="${1}"; }; +rtl_set_var_unsafe() { [ -n "${2}" ] && eval ${1}=\"${2}\" || return 0; }; +rtl_test_cmd() { command -v "${1}" >/dev/null; }; +rtl_uniq() { echo "${@}" | sed 's/ /\n/g' | awk '!x[$0]++' | paste -s -d" "; }; +rtl_unset_vars() { while [ ${#} -gt 0 ]; do unset "${1}"; shift; done; }; + +# vim:filetype=sh diff --git a/subr/rtl_complex.subr b/subr/rtl_complex.subr new file mode 100644 index 00000000..6d9750dc --- /dev/null +++ b/subr/rtl_complex.subr @@ -0,0 +1,114 @@ +# +# set +o errexit -o noglob is assumed. +# + +rtl_check_path_vars() { + local _vnames="${1}" _rc=0 _vname="" _vname_val=""; _status=""; + for _vname in ${_vnames}; do + _vname_val="$(rtl_get_var_unsafe "${_vname}")"; + if [ -z "${_vname_val}" ]; then + _rc=1; _status="Error: variable \`${_vname}' is empty or unset."; break; + elif [ "${_vname_val#* *}" != "${_vname_val}" ]; then + _rc=2; _status="Error: variable \`${_vname}' contains one or more whitespace characters."; break; + fi; + done; + return "${_rc}"; +}; + +rtl_clean_env() { + local _env_vars_except="${1}" _env_var="" _env_vars=""; + _env_vars="$(export | sed -ne '/^export/{s/^export //;s/=.*$//p}')"; + for _env_var in ${_env_vars}; do + if [ "${_env_var#DEFAULT_}" != "${_env_var}" ]\ + || [ "${_env_var#PKG_}" != "${_env_var}" ]; then + _env_vars_except="${_env_vars_except:+${_env_vars_except} }${_env_var}"; + fi; + done; + rtl_unset_vars $(rtl_lfilter "${_env_vars}" "${_env_vars_except}"); +}; + +rtl_exists_any() { + local _subdir="${1}"; shift; + while [ "${#}" -gt 0 ]; do + if [ -e "${_subdir}/${1}" ]; then + return 0; + else + shift; + fi; + done; return 1; +}; + +rtl_export_vars() { + local _unsetfl=0; [ "x${1}" = "x-u" ] && { _unsetfl=1; shift; }; + while [ "${#}" -ge 2 ]; do + if [ -n "${2}" ]; then + if [ "${_unsetfl:-0}" -eq 0 ]; then + rtl_set_var_unsafe "${1}" "${2}"; export "${1}"; + else + unset "${1}"; + fi; + fi; + shift 2; + done; +}; + +rtl_get_var_unsafe() { + local _vname=""; + if [ "x${1}" = "x-u" ]; then + shift; _vname="$(rtl_toupper "${1}")"; + else + _vname="${1}"; + fi; + eval echo \${${_vname}}; +}; + +rtl_head() { + local _pattern="${1}" _s="${2}"; + while true; do + if [ "${_s%%${_pattern}}" = "${_s}" ]; then + break; + else + _s="${_s%%${_pattern}}"; + fi; + done; + echo "${_s}"; +}; + +rtl_kill_tree() { + local _pid="${1}" _signal="TERM" _pid_child="" _pid_top=""; + for _pid_top in $(pgrep -P "${_pid}"); do + for _pid_child in $(pgrep -P "${_pid_top}" 2>/dev/null); do + _pids_killed="${_pids_killed:+${_pids_killed} }${_pid_child}"; kill "-${_signal}" "${_pid_child}" 2>/dev/null; + done; + _pids_killed="${_pids_killed:+${_pids_killed} }${_pid_top}"; kill "-${_signal}" "${_pid_top}" 2>/dev/null; + done; +}; + +rtl_run_cmd_unsplit() { + local _cmd="${1}" _cmdline="" _rc="" IFS; shift; + while [ ${#} -gt 0 ]; do + [ -n "${1}" ] &&\ + _cmdline="${_cmdline:+${_cmdline}:}${1}"; + shift; + done; + IFS=:; ${_cmd} ${_cmdline}; _rc=$?; + return ${_rc}; +}; + +rtl_set_vars() { + local _vars_set_vname="${1}" _vname_dst="${2}" _vname_src_tmpls="${3}" \ + _vars_set_old="" _vars_set_tmp="" _vname_src=""; + for _vname_src in $(rtl_toupper "${_vname_src_tmpls}"); do + _vname_src="${_vname_src}_${_vname_dst}"; + _vval_src="$(rtl_get_var_unsafe "${_vname_src}")"; + if [ -n "${_vval_src}" ]; then + rtl_set_var_unsafe "PKG_${_vname_dst}" "${_vval_src}"; + _vars_set_tmp="${_vars_set_tmp:+${_vars_set_tmp} }PKG_${_vname_dst}"; + fi; + done; + _vars_set_old="$(rtl_get_var_unsafe "${_vars_set_vname}")"; + rtl_set_var_unsafe "${_vars_set_vname}" \ + "${_vars_set_old:+${_vars_set_old} }${_vars_set_tmp}"; +}; + +# vim:filetype=sh diff --git a/subr/rtl_fetch.subr b/subr/rtl_fetch.subr new file mode 100644 index 00000000..d61d7858 --- /dev/null +++ b/subr/rtl_fetch.subr @@ -0,0 +1,92 @@ +# +# set +o errexit -o noglob is assumed. +# + +exp_rtl_fetch_url_git() { + local _tgtdir="${1}" _subdir="${2}" _url="${3}" _branch="${4}" \ + _oldpwd=""; + (set -o errexit -o noglob; trap "rm -f \"${BUILD_DLCACHEDIR}/${_subdir%%[/]}.fetching\"" EXIT; + while true; do + if flock -E 622 -w 3600 4; then + break; + elif [ "${?}" -eq 622 ]; then + continue; + else + exit "${?}"; + fi; + done; + if [ -e "${BUILD_DLCACHEDIR}/${_subdir}" ]; then + (rtl_fileop cd "${BUILD_DLCACHEDIR}/${_subdir}" &&\ + git pull ${DEFAULT_GIT_ARGS} origin "${_branch:-main}"); + (rtl_fileop cd "${BUILD_DLCACHEDIR}/${_subdir}" &&\ + git submodule update); + else + git clone ${DEFAULT_GIT_ARGS} "${_url}" "${BUILD_DLCACHEDIR}/${_subdir}"; + if [ -n "${_branch}" ]; then + (rtl_fileop cd "${BUILD_DLCACHEDIR}/${_subdir}" &&\ + git checkout "${_branch}"); + fi; + (rtl_fileop cd "${BUILD_DLCACHEDIR}/${_subdir}" &&\ + git submodule update --init); + fi; + _oldpwd="${PWD}"; rtl_fileop cd "${PKG_BASE_DIR}"; + rtl_fileop rm "${_tgtdir}/${_subdir}"; + rtl_fileop cp "${BUILD_DLCACHEDIR}/${_subdir}" "${_tgtdir}"; + rtl_fileop cd "${_oldpwd}";) 4<>"${BUILD_DLCACHEDIR}/${_subdir%%[/]}.fetching"; + if [ "${?}" -eq 0 ]; then + cd "$(pwd)"; + else + return "${?}"; + fi; +}; + +rtl_fetch_urls_git() { + local _tgtdir="" _url_spec="" _subdir="" _url="" _git_branch=""; + _tgtdir="${1}"; shift; + if [ "${ARG_FETCH_FORCE}" = "offline" ]; then + return 0; + fi; + for _url_spec in "${@}"; do + _subdir="${_url_spec%=*}"; + _url="${_url_spec#*=}"; + _url="${_url%@*}"; + if [ "${_url_spec#*@}" != "${_url_spec}" ]; then + _git_branch=${_url_spec#*@}; + fi; + exp_rtl_fetch_url_git "${_tgtdir}" "${_subdir}" \ + "${_url}" "${_git_branch}"; + done; +}; + +# N.B. URLs ($1) may contain `?' or '&' characters. +rtl_fetch_url_wget() { + local _url="${1}" _sha256sum_src="${2}" _target_fname="${3}" _sha256sum_dst=""; + if [ "${ARG_FETCH_FORCE}" = "offline" ]; then + return 0; + elif [ -z "${_target_fname}" ]; then + _target_fname="$(rtl_basename "${_url}")"; + fi; + _url_dst="${BUILD_DLCACHEDIR}/${_target_fname}"; + (set -o errexit -o noglob; trap "_rc=\"\${?}\" ;rm -f \"${_url_dst}.fetching\"; exit \"\${_rc}\";" EXIT; + while true; do + if flock -E 622 -w 3600 4; then + break; + elif [ "${?}" -eq 622 ]; then + continue; + else + exit "${?}"; + fi; + done; + if [ ! -e "${_url_dst}.fetched" ]; then + wget ${DEFAULT_WGET_ARGS} -O "${_url_dst}" "${_url}"; + if [ -n "${_sha256sum_src}" ]; then + set -- $(sha256sum "${_url_dst}"); + if [ "${_sha256sum_dst:=${1}}" != "${_sha256sum_src}" ]; then + rtl_log_msg failexit "Error: hash mismatch for URL \`${_url}' (downloaded file: ${_sha256sum_dst}, from build variables: ${_sha256sum_src}.)"; + fi; + fi; + rtl_fileop touch "${_url_dst}.fetched"; + fi;) 4<>"${_url_dst}.fetching"; +}; + +# vim:filetype=sh diff --git a/subr/rtl_fileop.subr b/subr/rtl_fileop.subr new file mode 100644 index 00000000..cc861787 --- /dev/null +++ b/subr/rtl_fileop.subr @@ -0,0 +1,111 @@ +# +# set +o errexit -o noglob is assumed. +# + +exp_rtl_fileop_check() { + local _prefix="${1}" _pname="" _rname=""; shift; + while [ "${#}" -gt 0 ]; do + return 0; + shift; done; +}; + +rtl_fileop() { + local _op="${1}" _dst="" _install_args="" _rc=0 _src=""; shift; + case "${_op}" in + cd) if [ \( -z "${1}" \) -o ! \( -L "${1}" -o -e "${1}" \) ]; then + rtl_log_msg failexit "Invalid or non-existent directory \`${1}'."; + elif exp_rtl_fileop_check "${PREFIX}" "${1}"; then + rtl_log_msg vvvv "Changing working directory to \`${1}'."; + cd -- "${1}"; _rc="${?}"; + fi; ;; + cp_follow) + if [ "${#}" -lt 2 ]; then + rtl_log_msg failexit "Missing parameters (in: cp_follow ${*}.)"; + elif exp_rtl_fileop_check "${PREFIX}" "${*}"; then + _src="${*}"; _src="${_src% *}"; + _dst="${*}"; _dst="${_dst##* }"; + rtl_log_msg vvvv "Copying \`${_src}' into \`${_dst}' w/ -pLR."; + cp -pLR -- "${@}"; _rc="${?}"; + fi; ;; + cp) if [ "${#}" -lt 2 ]; then + rtl_log_msg failexit "Missing parameters (in: cp ${*}.)"; + elif exp_rtl_fileop_check "${PREFIX}" "${*}"; then + _src="${*}"; _src="${_src% *}"; + _dst="${*}"; _dst="${_dst##* }"; + rtl_log_msg vvvv "Copying \`${_src}' into \`${_dst}' w/ -pPR."; + cp -pPR -- "${@}"; _rc="${?}"; + fi; ;; + install) + if [ "${#}" -lt 2 ]; then + rtl_log_msg failexit "Missing parameters (in: install ${*}.)"; + else _dst="$(while [ ""${#}"" -gt 2 ]; do shift; done; echo "${2}")"; + _install_args="$(while [ ""${#}"" -gt 2 ]; do echo "${1}"; shift; done)"; + _src="$(while [ ""${#}"" -gt 2 ]; do shift; done; echo "${1}")"; + if exp_rtl_fileop_check "${PREFIX}" "${_dst}" "${_src}"; then + rtl_log_msg vvvv "Installing \`${_src}' into \`${_dst}' w/ ${_install_args}."; + install "${@}"; _rc="${?}"; + fi; + fi; ;; + ln_symbolic) + if [ \( -z "${1}" \) -o \( -z "${2}" \) ]; then + rtl_log_msg failexit "Missing parameters (in: ln_symbolic ${*}.)"; + elif exp_rtl_fileop_check "${PREFIX}" "${2}"; then + if rtl_fileop test "${2}"; then + rtl_fileop rm "${2}"; + fi; + if [ "${?}" -eq 0 ]; then + rtl_log_msg vvvv "Linking \`${1}' to \`${2}' w/ -fs"; + ln -fs -- "${1}" "${2}"; _rc="${?}"; + fi; + fi; ;; + mv) if [ \( -z "${1}" \) -o \( -z "${2}" \) ]; then + rtl_log_msg failexit "Missing parameters (in: mv ${*}.)"; + elif exp_rtl_fileop_check "${PREFIX}" "${1}" "${2}"; then + rtl_log_msg vvvv "Moving \`${1}' to \`${2}' w/ -fs"; + mv -f -- "${1}" "${2}"; _rc="${?}"; + fi; ;; + mkdir|mkfifo|rm|source_opt|test|touch) + while [ \( "${?}" -eq 0 \) -a \( ""${#}"" -gt 0 \) ]; do + if [ -z "${1}" ]; then + rtl_log_msg failexit "Missing parameters (in: ${_op} ${*}.)"; + elif [ "${_op}" = mkdir ]\ + && [ ! -d "${1}" ]\ + && exp_rtl_fileop_check "${PREFIX}" "${1}"; then + if rtl_fileop test "${1}"; then + rtl_fileop rm "${1}"; + fi; + rtl_log_msg vvvv "Making directory \`${1}'."; + mkdir -p -- "${1}"; _rc="${?}"; + elif [ "${_op}" = mkfifo ]\ + && exp_rtl_fileop_check "${PREFIX}" "${1}"; then + if rtl_fileop test "${1}"; then + rtl_fileop rm "${1}"; + fi; + rtl_log_msg vvvv "Creating FIFO \`${1}'."; + exp_rtl_fileop_check "${PREFIX}" "${1}"; + mkfifo -- "${1}"; _rc="${?}"; + elif [ "${_op}" = rm ]\ + && rtl_fileop test "${1}"\ + && exp_rtl_fileop_check "${PREFIX}" "${1}"; then + rtl_log_msg vvvv "Removing directory or file \`${1}'."; + rm -rf -- "${1}"; _rc="${?}"; + elif [ "${_op}" = source_opt ]\ + && rtl_fileop test "${1}"\ + && exp_rtl_fileop_check "${PREFIX}" "${1}"; then + rtl_log_msg vvvv "Sourcing file \`${1}'."; + . "${1}"; _rc="${?}"; + elif [ "${_op}" = test ]\ + && exp_rtl_fileop_check "${PREFIX}" "${1}"\ + && ! [ \( -L "${1}" \) -o \( -e "${1}" \) ]; then + return 1; + elif [ "${_op}" = touch ]\ + && exp_rtl_fileop_check "${PREFIX}" "${1}"; then + rtl_log_msg vvvv "Touching file \`${1}'."; + touch -- "${1}"; _rc="${?}"; + fi; shift; + done; ;; + *) rtl_log_msg failexit "Error: rtl_fileop() called w/ invalid parameter(s): ${*}"; ;; + esac; return "${_rc}"; +}; + +# vim:filetype=sh diff --git a/subr/rtl_install.subr b/subr/rtl_install.subr new file mode 100644 index 00000000..a1c70a01 --- /dev/null +++ b/subr/rtl_install.subr @@ -0,0 +1,47 @@ +# +# set +o errexit -o noglob is assumed. +# + +rtl_install() { + local _verbose="" _prefix="" _ln_target="" _ln_fname="" \ + _mkdir_fname="" _file_fname_src="" _file_fname_dst=""; + if [ "${1}" = "-v" ]; then + _verbose=1; shift; + fi; _prefix="${1}"; shift; + while [ ${#} -gt 0 ]; do + case "${1}" in + @*=*) + _ln_target="${1%=*}"; + _ln_target="${_ln_target#@}"; + _ln_fname="${1#*=}"; + if [ "${_ln_fname#/}" = "${_ln_fname}" ]; then + _ln_fname="${_prefix:+${_prefix}/}${_ln_fname}"; + fi; + if [ -e "${_ln_fname}" ]; then + rtl_fileop rm "${_ln_fname}"; + fi; + rtl_fileop ln_symbolic "${_ln_target}" "${_ln_fname}"; + ;; + /=*) + _mkdir_fname="${1#/=}"; + if [ "${_mkdir_fname#/}" = "${_mkdir_fname}" ]; then + _mkdir_fname="${_prefix:+${_prefix}/}${_mkdir_fname}"; + fi; + rtl_fileop mkdir "${_mkdir_fname}"; + ;; + *) + _file_fname_src="${1%=*}"; + _file_fname_dst="${1#*=}"; + if [ "${_file_fname_src#/}" = "${_file_fname_src}" ]; then + _file_fname_src="${_prefix:+${_prefix}/}${_file_fname_src}"; + fi; + if [ "${_file_fname_dst#/}" = "${_file_fname_dst}" ]; then + _file_fname_dst="${_prefix:+${_prefix}/}${_file_fname_dst}"; + fi; + rtl_fileop cp "${_file_fname_src}" "${_file_fname_dst}"; + ;; + esac; shift; + done; +}; + +# vim:filetype=sh diff --git a/subr/rtl_list.subr b/subr/rtl_list.subr new file mode 100644 index 00000000..056d8016 --- /dev/null +++ b/subr/rtl_list.subr @@ -0,0 +1,75 @@ +# +# set +o errexit -o noglob is assumed. +# + +rtl_lconcat() { + local _list="${1}" _litem_new="${2}" _sep="${3:- }" IFS="${3:-${IFS}}"; + if [ -n "${_list}" ]; then + printf "%s%s%s" "${_list}" "${_sep}" "${_litem_new}"; + else + printf "%s" "${_litem_new}"; + fi; +}; + +rtl_lfilter() { + local _list="${1}" _filter="${2}" _sep="${3:- }" IFS="${3:-${IFS}}" \ + _filterfl="" _litem="" _litem_filter="" _lnew=""; + if [ -z "${_filter}" ]; then + echo "${_list}"; return 0; + else for _litem in ${_list}; do + _filterfl=0; + for _litem_filter in ${_filter}; do + if [ "${_litem_filter}" = "${_litem}" ]; then + _filterfl=1; break; + fi; + done; + if [ "${_filterfl:-0}" -eq 0 ]; then + _lnew="${_lnew:+${_lnew}${_sep}}${_litem}"; + fi; + done; fi; + echo "${_lnew}"; +}; + +rtl_llength() { + local _list="${1}" _sep="${2:- }" IFS="${2:-${IFS}}" _litem="" _llength=0; + for _litem in ${_list}; do + : $((_llength+=1)); + done; + echo "${_llength}"; +}; + +rtl_lmatch() { + local _list="${1}" _item="${2}" _sep="${3}"; + [ -n "$(rtl_lsearch "${_list}" "${_item}" "${_sep}")" ]; +}; + +rtl_lsearch() { + local _list="${1}" _filter="${2}" _sep="${3:- }" IFS="${3:-${IFS}}" \ + _litem="" _litem_filter="" _lnew=""; + if [ -z "${_filter}" ]; then + echo "${_list}"; return 0; + else for _litem in ${_list}; do + for _litem_filter in ${_filter}; do + if [ "${_litem_filter}" = "${_litem}" ]; then + _lnew="${_lnew:+${_lnew}${_sep}}${_litem}"; + break; + fi; + done; + done; fi; + echo "${_lnew}"; +}; + +rtl_lunfold_depends() { + local _vname_template="${1}" _depends="" _name="" _names=""; shift; + for _name in "${@}"; do + if _depends="$(rtl_get_var_unsafe -u "$(eval printf \"%s\" \""${_vname_template}"\")")"\ + && [ -n "${_depends}" ]; then + _depends="$(rtl_lunfold_depends "${_vname_template}" ${_depends})"; + _names="$(rtl_lconcat "${_names}" "${_depends}")"; + fi; + _names="$(rtl_lconcat "${_names}" "${_name}")"; + done; + echo "${_names}"; +}; + +# vim:filetype=sh diff --git a/subr/rtl_log.subr b/subr/rtl_log.subr new file mode 100644 index 00000000..e27e81d6 --- /dev/null +++ b/subr/rtl_log.subr @@ -0,0 +1,78 @@ +# +# set +o errexit -o noglob is assumed. +# + +: ${DEFAULT_LOG_MSG_FAIL_COLOUR:=91}; +: ${DEFAULT_LOG_MSG_INFO_COLOUR:=93}; +: ${DEFAULT_LOG_MSG_INF2_COLOUR:=33}; +: ${DEFAULT_LOG_MSG_SUCC_COLOUR:=92}; +: ${DEFAULT_LOG_MSG_SUC2_COLOUR:=32}; +: ${DEFAULT_LOG_MSG_VNFO_COLOUR:=96}; +: ${DEFAULT_LOG_MSG_VUCC_COLOUR:=90}; +: ${DEFAULT_LOG_MSG_VVFO_COLOUR:=96}; +: ${DEFAULT_LOG_MSG_VVVO_COLOUR:=96}; +: ${DEFAULT_LOG_MSG_VVVV_COLOUR:=96}; + +exp_rtl_log_printf() { + local _attrs="${1}" _msg=""; shift; _msg="$(printf "${@}")"; + if [ "${BUILD_IS_PARENT:-0}" -eq 1 ]\ + && [ -n "${DEFAULT_BUILD_LOG_FNAME}" ]\ + && [ -e "${DEFAULT_BUILD_LOG_FNAME}" ]; then + printf "%s\n" "${_msg}" >> "${DEFAULT_BUILD_LOG_FNAME}"; + fi; + printf "\033[0m\033[${_attr}m%s\033[0m\n" "${_msg}"; +}; + +rtl_log_env_vars() { + local _nvar=1 _arg="" _arg_len_max=0; + rtl_log_msg info "Variables for this ${1:-build}:"; shift; + while [ ${_nvar} -le ${#} ]; do + _arg="$(eval echo \${${_nvar}})"; + _arg="${_arg%%=*}"; + if [ ${#_arg} -gt ${_arg_len_max} ]; then + _arg_len_max=${#_arg}; + fi; : $((_nvar+=1)); + done; + while [ ${#} -gt 0 ]; do + rtl_log_msg info "$(printf \ + "%${_arg_len_max}.${_arg_len_max}s=%s" \ + "${1%%=*}" "$(rtl_get_var_unsafe ${1#*=})")"; + shift; + done; +}; + +rtl_log_set_vnfo_lvl() { + EXP_RTL_LOG_VNFO_LVL="${1}"; +}; + +rtl_log_msg() { + local _lvl="${1}" _lvl_uc="" _attr=""; shift; + if [ "${_lvl}" = vnfo ]\ + || [ "${_lvl}" = vucc ]\ + && [ "${EXP_RTL_LOG_VNFO_LVL:-0}" -lt 1 ]; then + return; + elif [ "${_lvl}" = vvfo ]\ + && [ "${EXP_RTL_LOG_VNFO_LVL:-0}" -lt 2 ]; then + return; + elif [ "${_lvl}" = vvvo ]\ + && [ "${EXP_RTL_LOG_VNFO_LVL:-0}" -lt 3 ]; then + return; + elif [ "${_lvl}" = vvvv ]\ + && [ "${EXP_RTL_LOG_VNFO_LVL:-0}" -lt 4 ]; then + return; + fi; + _lvl_uc="$(rtl_toupper "${_lvl%exit}")"; + _attr="$(rtl_get_var_unsafe "DEFAULT_LOG_MSG_${_lvl_uc}_COLOUR")"; + if [ ${#} -gt 1 ]; then + exp_rtl_log_printf "${_attrs}" "==> %s %s %s" "$(rtl_date)" "${1}" "$*"; + else + exp_rtl_log_printf "${_attrs}" "==> %s %s" "$(rtl_date)" "${1}"; + fi; + if [ ${_lvl} = failexit ]; then + exit 1; + else + return 0; + fi; +}; + +# vim:filetype=sh diff --git a/subr/rtl_state.subr b/subr/rtl_state.subr new file mode 100644 index 00000000..1ee8258b --- /dev/null +++ b/subr/rtl_state.subr @@ -0,0 +1,40 @@ +# +# set +o errexit -o noglob is assumed. +# + +rtl_state_clear() { + local _workdir="${1}" _pkg_name="${2}" _pkg_fname=""; + for _pkg_fname in $(find "${_workdir}" \ + -maxdepth 1 -mindepth 1 -name .${_pkg_name}.\* -type f); do + rtl_fileop rm "${_pkg_fname}"; + done; +}; + +rtl_state_set() { + local _workdir="${1}" _pkg_fname="${2}" _done_fname_pfx=""; + _done_fname_pfx="${_workdir}/.${_pkg_fname}"; + shift 2; while [ ${#} -ge 1 ]; do + if [ -z "${1}" ]; then + shift; continue; + elif [ "${1#-}" != "${1}" ]; then + rtl_fileop rm "${_done_fname_pfx}.${1#-}"; + else + rtl_fileop touch "${_done_fname_pfx}.${1}"; + fi; + shift; done; +}; + +rtl_state_test() { + local _workdir="${1}" _pkg_name="${2}" _build_step="${3}" \ + _restart_at="${4}" _done_fname=""; + _done_fname="${_workdir}/.${_pkg_name}.${_build_step}"; + if [ -z "${_restart_at}" ]; then + rtl_fileop test "${_done_fname}"; + elif [ "${_restart_at}" = "ALL" ]; then + return 1; + else + ! rtl_lmatch "${_restart_at}" "${_build_step}" ","; + fi; +}; + +# vim:filetype=sh diff --git a/subr/rtl_string.subr b/subr/rtl_string.subr new file mode 100644 index 00000000..0e549d3c --- /dev/null +++ b/subr/rtl_string.subr @@ -0,0 +1,93 @@ +# +# set +o errexit -o noglob is assumed. +# + +rtl_isnumber() { + local _s="${1}" _rc=0; + while [ -n "${_s}" ]; do + case "${_s}" in + [0-9]*) _s="${_s#[0-9]}"; ;; + *) _rc=1; break; ;; + esac; done; + return "${_rc}"; +}; + +rtl_tolower() { + local _s="${1}" _s_new=""; + while [ -n "${_s}" ]; do + case "${_s}" in + A*) _s_new="${_s_new:+${_s_new}}a"; _s="${_s#A}"; ;; + B*) _s_new="${_s_new:+${_s_new}}b"; _s="${_s#B}"; ;; + C*) _s_new="${_s_new:+${_s_new}}c"; _s="${_s#C}"; ;; + D*) _s_new="${_s_new:+${_s_new}}d"; _s="${_s#D}"; ;; + E*) _s_new="${_s_new:+${_s_new}}e"; _s="${_s#E}"; ;; + F*) _s_new="${_s_new:+${_s_new}}f"; _s="${_s#F}"; ;; + G*) _s_new="${_s_new:+${_s_new}}g"; _s="${_s#G}"; ;; + H*) _s_new="${_s_new:+${_s_new}}h"; _s="${_s#H}"; ;; + I*) _s_new="${_s_new:+${_s_new}}i"; _s="${_s#I}"; ;; + J*) _s_new="${_s_new:+${_s_new}}j"; _s="${_s#J}"; ;; + K*) _s_new="${_s_new:+${_s_new}}k"; _s="${_s#K}"; ;; + L*) _s_new="${_s_new:+${_s_new}}l"; _s="${_s#L}"; ;; + M*) _s_new="${_s_new:+${_s_new}}m"; _s="${_s#M}"; ;; + N*) _s_new="${_s_new:+${_s_new}}n"; _s="${_s#N}"; ;; + O*) _s_new="${_s_new:+${_s_new}}o"; _s="${_s#O}"; ;; + P*) _s_new="${_s_new:+${_s_new}}p"; _s="${_s#P}"; ;; + Q*) _s_new="${_s_new:+${_s_new}}q"; _s="${_s#Q}"; ;; + R*) _s_new="${_s_new:+${_s_new}}r"; _s="${_s#R}"; ;; + S*) _s_new="${_s_new:+${_s_new}}s"; _s="${_s#S}"; ;; + T*) _s_new="${_s_new:+${_s_new}}t"; _s="${_s#T}"; ;; + U*) _s_new="${_s_new:+${_s_new}}u"; _s="${_s#U}"; ;; + V*) _s_new="${_s_new:+${_s_new}}v"; _s="${_s#V}"; ;; + W*) _s_new="${_s_new:+${_s_new}}w"; _s="${_s#W}"; ;; + X*) _s_new="${_s_new:+${_s_new}}x"; _s="${_s#X}"; ;; + Y*) _s_new="${_s_new:+${_s_new}}y"; _s="${_s#Y}"; ;; + Z*) _s_new="${_s_new:+${_s_new}}z"; _s="${_s#Z}"; ;; + [^ABCDEFGHIJKLMNOPQRSTUVWXYZ]*) + _s_new="${_s_new:+${_s_new}}${_s%%[ABCDEFGHIJKLMNOPQRSTUVWXYZ]*}"; + while [ "${_s#[^ABCDEFGHIJKLMNOPQRSTUVWXYZ]}" != "${_s}" ]; do + _s="${_s#[^ABCDEFGHIJKLMNOPQRSTUVWXYZ]}"; + done; ;; + esac; done; + echo "${_s_new}"; +}; + +rtl_toupper() { + local _s="${1}" _s_new=""; + while [ -n "${_s}" ]; do + case "${_s}" in + a*) _s_new="${_s_new:+${_s_new}}A"; _s="${_s#a}"; ;; + b*) _s_new="${_s_new:+${_s_new}}B"; _s="${_s#b}"; ;; + c*) _s_new="${_s_new:+${_s_new}}C"; _s="${_s#c}"; ;; + d*) _s_new="${_s_new:+${_s_new}}D"; _s="${_s#d}"; ;; + e*) _s_new="${_s_new:+${_s_new}}E"; _s="${_s#e}"; ;; + f*) _s_new="${_s_new:+${_s_new}}F"; _s="${_s#f}"; ;; + g*) _s_new="${_s_new:+${_s_new}}G"; _s="${_s#g}"; ;; + h*) _s_new="${_s_new:+${_s_new}}H"; _s="${_s#h}"; ;; + i*) _s_new="${_s_new:+${_s_new}}I"; _s="${_s#i}"; ;; + j*) _s_new="${_s_new:+${_s_new}}J"; _s="${_s#j}"; ;; + k*) _s_new="${_s_new:+${_s_new}}K"; _s="${_s#k}"; ;; + l*) _s_new="${_s_new:+${_s_new}}L"; _s="${_s#l}"; ;; + m*) _s_new="${_s_new:+${_s_new}}M"; _s="${_s#m}"; ;; + n*) _s_new="${_s_new:+${_s_new}}N"; _s="${_s#n}"; ;; + o*) _s_new="${_s_new:+${_s_new}}O"; _s="${_s#o}"; ;; + p*) _s_new="${_s_new:+${_s_new}}P"; _s="${_s#p}"; ;; + q*) _s_new="${_s_new:+${_s_new}}Q"; _s="${_s#q}"; ;; + r*) _s_new="${_s_new:+${_s_new}}R"; _s="${_s#r}"; ;; + s*) _s_new="${_s_new:+${_s_new}}S"; _s="${_s#s}"; ;; + t*) _s_new="${_s_new:+${_s_new}}T"; _s="${_s#t}"; ;; + u*) _s_new="${_s_new:+${_s_new}}U"; _s="${_s#u}"; ;; + v*) _s_new="${_s_new:+${_s_new}}V"; _s="${_s#v}"; ;; + w*) _s_new="${_s_new:+${_s_new}}W"; _s="${_s#w}"; ;; + x*) _s_new="${_s_new:+${_s_new}}X"; _s="${_s#x}"; ;; + y*) _s_new="${_s_new:+${_s_new}}Y"; _s="${_s#y}"; ;; + z*) _s_new="${_s_new:+${_s_new}}Z"; _s="${_s#z}"; ;; + [^abcdefghijklmnopqrstuvwxyz]*) + _s_new="${_s_new:+${_s_new}}${_s%%[abcdefghijklmnopqrstuvwxyz]*}"; + while [ "${_s#[^abcdefghijklmnopqrstuvwxyz]}" != "${_s}" ]; do + _s="${_s#[^abcdefghijklmnopqrstuvwxyz]}"; + done; ;; + esac; done; + echo "${_s_new}"; +}; + +# vim:filetype=sh -- cgit v1.2.3