From e9fa0774ed2e7e030a68f5b0ae51fe6dd69fe492 Mon Sep 17 00:00:00 2001 From: Lucía Andrea Illanes Albornoz Date: Feb 17 2023 18:29:28 +0000 Subject: Make everything a bit faster. 0) Issues several prayers and sacrifices to Enki under threat of a terrible deluge sent down by Ellil 1) Convert fork-write/read exprs to be non-forking 2) Pass mostly everything by reference 3) Don't bother cleaning the variable namespace because Bourne shell is an abomination 4) Removes broken ./pkgtool.sh -s, --restart-at, --update-diff & ./build.sh --dump-{in,on-abort} 5) Cleanup --- diff --git a/build.sh b/build.sh index 449e389..e735dc1 100755 --- a/build.sh +++ b/build.sh @@ -2,114 +2,459 @@ # Copyright (c) 2016, 2017, 2018, 2019, 2020, 2021 Lucía Andrea Illanes Albornoz # +# {{{ buildp_ast($_param) buildp_ast() { trap '' HUP INT TERM USR1 USR2; - local _param="${1}" _pids="" _pids_niter=0 _pkg_name="" RTL_KILL_TREE_PIDS=""; - if [ "${_param}" = "abort" ]; then + local _bpa_param="${1}" \ + _bpa_cmd="" _bpa_pids="" _bpa_pids_new="" \ + _bpa_pids_niter=0 _bpa_pkg_name=""; + + for _bpa_cmd in \ + rtl_fileop rtl_kill_tree rtl_lconcat \ + rtl_log_msg rtl_uniq rtl_state_clear; + do + if ! command -v "${_bpa_cmd}" >/dev/null 2>&1; then + return 0; + fi; + done; + + if [ "${_bpa_param}" = "abort" ]; then rtl_log_msg "fatalexit" "${MSG_build_aborted}"; fi; - while [ "${_pids_niter}" -lt 8 ]; do - _pids="$(rtl_lconcat "${_pids}" "${RTL_KILL_TREE_PIDS}")"; RTL_KILL_TREE_PIDS=""; - if ! rtl_kill_tree "${$}" "TERM"\ - || [ -z "${RTL_KILL_TREE_PIDS}" ]; then + + while [ "${_bpa_pids_niter}" -lt 8 ]; do + rtl_lconcat \$_bpa_pids "${_bpa_pids_new}"; + _bpa_pids_new=""; + if ! rtl_kill_tree \$_bpa_pids_new "${$}" "TERM"\ + || [ "${_bpa_pids_new:+1}" != 1 ]; then break; else - : $((_pids_niter+=1)); + : $((_bpa_pids_niter+=1)); fi; done; - if [ -n "${_pids}" ]; then - rtl_log_msg "verbose" "${MSG_build_killed_pids}" "$(rtl_uniq ${_pids})"; + + if [ "${_bpa_pids:+1}" = 1 ]; then + rtl_log_msg "verbose" "${MSG_build_killed_pids}" "$(rtl_uniq ${_bpa_pids})"; fi; - if [ -n "${EX_PKG_DISPATCH_WAIT}" ]\ + + if [ "${BUILD_PKG_WAIT:+1}" = 1 ]\ && [ "${ARG_RESET_PKG}" -eq 1 ]; then - for _pkg_name in ${EX_PKG_DISPATCH_WAIT}; do - rtl_state_clear "${BUILD_WORKDIR}" "${_pkg_name}"; + for _bpa_pkg_name in ${BUILD_PKG_WAIT}; do + rtl_state_clear "${BUILD_WORKDIR}" "${_bpa_pkg_name}"; done; - rtl_log_msg "verbose" "${MSG_build_reset_pkg_state}" "${EX_PKG_DISPATCH_WAIT}"; + rtl_log_msg "verbose" "${MSG_build_reset_pkg_state}" "${BUILD_PKG_WAIT}"; fi; - if [ -n "${DEFAULT_BUILD_STATUS_IN_PROGRESS_FNAME}" ]; then + + if [ "${DEFAULT_BUILD_STATUS_IN_PROGRESS_FNAME:+1}" = 1 ]; then rtl_fileop rm "${DEFAULT_BUILD_STATUS_IN_PROGRESS_FNAME}"; fi; + + return 0; +}; +# }}} + +# {{{ buildp_init($_rstatus) +buildp_init() { + local _bi_rstatus="${1#\$}" \ + _bi_args_long="--as-needed --debug-minipx --reset-state" \ + _bi_name_base="build" \ + _bi_optstring="a:b:C:D:F:hp:Pr:RxvV:" \ + _bi_rc=0 _bi_status=""; + shift; + + if ! . "${0%/*}/subr.ex/ex_init.subr"; then + _bi_rc=1; + _bi_status='failed to source \`'"${0%/*}/subr/ex_init.subr"\'; + eval ${_bi_rstatus}=\"${_bi_status}\"; + elif ! ex_init_help \ + "${_bi_rstatus}" "${_bi_args_long}" \ + "${_bi_name_base}" "${_bi_optstring}" "${@}" \ + || ! ex_init_env "${_bi_rstatus}" \ + \$BUILD_HNAME \$BUILD_USER "${_bi_name_base}" \ + || ! ex_init_getopts \ + "${_bi_rstatus}" "buildp_init_getopts_fn" \ + "${_bi_optstring}" "${@}" \ + || ! ex_init_logging "${_bi_rstatus}" \$ARG_VERBOSE_TAGS "${ARG_VERBOSE}" \ + || ! ex_pkg_load_vars "${_bi_rstatus}" \ + || ! ex_init_prereqs "${_bi_rstatus}" "${DEFAULT_PREREQS}" \ + || ! buildp_init_args "${_bi_rstatus}" \ + || ! ex_init_files \ + "${_bi_rstatus}" \ + \$ARG_CLEAN_BUILDS \$ARG_DIST \ + "${DEFAULT_BUILD_LOG_FNAME}" \ + "${DEFAULT_BUILD_LOG_LAST_FNAME}" \ + "${DEFAULT_BUILD_STATUS_IN_PROGRESS_FNAME}" \ + "${DEFAULT_CHECK_PATH_VARS}" \ + "${DEFAULT_CLEAR_ENV_VARS_EXCEPT}" \ + "${DEFAULT_CLEAR_PREFIX_PATHS}" \ + "${BUILD_DLCACHEDIR}" "${PREFIX}" \ + "${PREFIX_RPM}" "${BUILD_WORKDIR}"; + then + _bi_rc=1; + fi; + return "${_bi_rc}"; +}; +# }}} +# {{{ buildp_init_args($_rstatus) +buildp_init_args() { + local _bpia_rstatus="${1#\$}" \ + _bpia_foundfl=0 _bpia_group="" _bpia_groups="" _bpia_groups_noauto="" \ + _bpia_pkg_names="" _bpia_pkg_names_unknown="" _bpia_pkg_names_unknown_count=0 \ + _bpia_rc=0; + + case "${ARG_FETCH_FORCE}" in + ipv4) rtl_lconcat \$DEFAULT_GIT_ARGS "-4"; + rtl_lconcat \$DEFAULT_WGET_ARGS "-4"; ;; + ipv6) rtl_lconcat \$DEFAULT_GIT_ARGS "-6"; + rtl_lconcat \$DEFAULT_WGET_ARGS "-6"; ;; + esac; + + if [ "${ARG_AS_NEEDED:-0}" -eq 1 ]\ + && [ -e "${PREFIX}/build.gitref" ]\ + && [ "$(git rev-parse HEAD)" = "$(cat "${PREFIX}/build.gitref")" ]; then + _bpia_rc=0; + rtl_setrstatus "${_bpia_rstatus}" 'Git repository has not changed since last build and --as-needed was specified.'; + elif ! ex_pkg_process_restart_spec "${_bpia_rstatus}" \$ARG_RESTART \$ARG_RESTART_AT \$ARG_RESTART_RECURSIVE; then + _bpia_rc=1; + rtl_setrstatus "${_bpia_rstatus}" 'failed to process -r specification: ${'"${_bpia_rstatus}"'}.'; + elif ! ex_pkg_load_groups \$_bpia_groups \$_bpia_groups_noauto \$GROUP_AUTO \$GROUP_TARGET; then + _bpia_rc=1; + rtl_setrstatus "${_bpia_rstatus}" 'failed to load build groups.'; + else + if ! rtl_lmatch \$ARG_DIST:- "rpm" ","; then + rtl_lfilter \$_bpia_groups "host_deps_rpm"; + fi; + + if [ "${BUILD_GROUPS:+1}" != 1 ]; then + BUILD_GROUPS="${_bpia_groups}"; + else _bpia_foundfl=0; for _bpia_group in ${BUILD_GROUPS}; do + if rtl_lmatch \$_bpia_groups "${_bpia_group}"; then + _bpia_foundfl=1; break; + fi; + done; + if [ "${_bpia_foundfl}" -eq 0 ]; then + _bpia_foundfl=0; for _bpia_group in ${BUILD_GROUPS}; do + if rtl_lmatch \$_bpia_groups "${_bpia_group}"; then + _bpia_rc=1; + rtl_setrstatus "${_bpia_rstatus}" 'unknown build group \`'"${_bpia_group}'"'.'; + fi; + done; + fi; + fi; + + if [ "${_bpia_rc:-0}" -eq 0 ]; then + if rtl_lmatch \$ARG_DIST "zipdist" ","\ + && ! rtl_lmatch \$ARG_DIST "minipix" ","; then + rtl_lconcat \$ARG_DIST "minipix" ","; + fi; + + if [ "${ARG_DIST:+1}" = 1 ]; then + rtl_lfilter \$BUILD_GROUPS "dist"; + rtl_lconcat \$BUILD_GROUPS "dist"; + fi; + + if [ "${ARG_RESTART:+1}" = 1 ]\ + && ! rtl_lmatch \$ARG_RESTART "ALL LAST"; then + for _bpia_pkg_name in ${ARG_RESTART}; do + if ! ex_pkg_find_package \$_bpia_pkg_names "${BUILD_GROUPS}" "${_bpia_pkg_name}" >/dev/null; then + rtl_lconcat \$_bpia_pkg_names_unknown "${_bpia_pkg_name}"; + fi; + done; + rtl_llength \$_bpia_pkg_names_unknown_count \$_bpia_pkg_names_unknown; + + case "${_bpia_pkg_names_unknown_count}" in + 0) ;; + + 1) _bpia_rc=1; + rtl_setrstatus "${_bpia_rstatus}" 'unknown package \`'"${_bpia_pkg_names_unknown}'"'.'; + ;; + + *) rtl_subst \$_bpia_pkg_names_unknown " " ", "; + _bpia_rc=1 + rtl_setrstatus "${_bpia_rstatus}" 'unknown packages: '"${_bpia_pkg_names_unknown}'"'.'; + ;; + esac; + fi; + fi; + fi; + + return "${_bpia_rc}"; }; +# }}} +# {{{ buildp_init_getopts_fn(...) +buildp_init_getopts_fn() { + local _bpigf_rc=0 _bpigf_shiftfl=0; + + case "${1}" in + init) + local _bpigf_verb="${1}" _bpigf_rstatus="${2#\$}"; + + : ${ARCH:="nt64"}; + : ${BUILD_KIND:="debug"}; + + ARG_AS_NEEDED=0; ARG_CLEAN_BUILDS=""; ARG_DEBUG_MINIPIX=0; ARG_DIST=""; + ARG_FETCH_FORCE=""; ARG_PARALLEL=1; ARG_RELAXED=0; ARG_RESET_PKG=0; + ARG_RESTART=""; ARG_RESTART_AT=""; ARG_RESTART_RECURSIVE=""; ARG_VERBOSE=0; + ARG_VERBOSE_TAGS=""; + ;; + + longopt) + local _bpigf_verb="${1}" _bpigf_rstatus="${2#\$}" _bpigf_opt="${3}"; + + case "${_bpigf_opt}" in + --as-needed) ARG_AS_NEEDED=1; _bpigf_shiftfl=1; ;; + --debug-minipx) ARG_DEBUG_MINIPIX=1; _bpigf_shiftfl=1; ;; + --help) _bpigf_shiftfl=1; ;; + --reset-state) ARG_RESET_PKG=1; _bpigf_shiftfl=1; ;; + + # {{{ --roar + --roar) printf "%s\n" ' + ▃▃▃▃ + ▟ ▙ +▟▙▃▟▙  /\ /\  roar! +▜▒▓▒▛  ▛ """ ▜  / + ▜ ▛   ^ _bpigf_ ^   / + ▀   (_bpigf__y_)   + ▟▙ ▁▂▃▟▐▙▜`\_bpigf_/▛▟▌ + ▟▙ ▟ ▓▓▓| |▍▓▓▓ + ▜\▙ ▟ ▓▓▓▓▓ |▓▓▓▓▓ + ▜\\ \ ▒▒▒| | ▒▒▒ + ▜\ ) ▒_| |▙ ▒ + ( / ))))))'; + exit 0; + ;; + # }}} + + *) _bpigf_shiftfl=0; ;; + esac; + ;; + + opt) + local _bpigf_verb="${1}" _bpigf_rstatus="${2#\$}" \ + _bpigf_opt="${3}" _bpigf_optarg="${4:-}"; + shift 4; + + case "${_bpigf_opt}" in + a) ARCH="${_bpigf_optarg}"; _bpigf_shiftfl=2; ;; + b) BUILD_KIND="${_bpigf_optarg}"; _bpigf_shiftfl=2; ;; + C) ARG_CLEAN_BUILDS="${_bpigf_optarg}"; _bpigf_shiftfl=2; ;; + D) ARG_DIST="${_bpigf_optarg}"; _bpigf_shiftfl=2; ;; + F) ARG_FETCH_FORCE="${_bpigf_optarg}"; _bpigf_shiftfl=2; ;; + h) _bpigf_shiftfl=1; ;; + p) ARG_PARALLEL="${_bpigf_optarg}"; _bpigf_shiftfl=2; ;; + + P) ARG_PARALLEL="auto"; + if [ "${2:+1}" = 1 ]\ + && rtl_isnumber "${2}"; then + _bpigf_rc=1; + rtl_setrstatus "${_bpigf_rstatus}" 'maximum parallelisation job count is set with the \`-p jobs'\'' option.'; + break; + fi; + _bpigf_shiftfl=1; + ;; + + r) ARG_RESTART="${_bpigf_optarg}"; _bpigf_shiftfl=2; ;; + R) ARG_RELAXED=1; _bpigf_shiftfl=1; ;; + + x) ARG_VERBOSE_TAGS="${ARG_VERBOSE_TAGS:+${ARG_VERBOSE_TAGS},}xtrace"; + _bpigf_shiftfl=1; ;; + + v) ARG_VERBOSE=1; _bpigf_shiftfl=1; ;; + V) ARG_VERBOSE_TAGS="${_bpigf_optarg}"; _bpigf_shiftfl=2; ;; + *) cat etc/build.usage.short; exit 1; ;; + esac; + ;; + + nonopt) + local _bpigf_verb="${1}" _bpigf_rstatus="${2#\$}"; + shift 2; + + if rtl_match "${1}" "=*"; then + BUILD_GROUPS_INHIBIT_DEPS=1; _bpigf_arg="${1#=}"; + else + _bpigf_arg="${1}"; + fi; + + case "${_bpigf_arg}" in + *=*) rtl_set_var_unsafe "${_bpigf_arg%%=*}" "${_bpigf_arg#*=}"; ;; + + [!a-zA-Z]*) _bpigf_rc=1; + rtl_setrstatus "${_bpigf_rstatus}" 'build group names must start with [a-zA-Z] (in argument \`'"${_bpigf_arg}"''\''.)'; + ;; + + *[!_bpigf_a-zA-Z]*) + _bpigf_rc=1; + rtl_setrstatus "${_bpigf_rstatus}" 'build group names must not contain [!_a-zA-Z] (in argument \`'"${_bpigf_arg}"''\''.)'; + ;; + + *) rtl_lconcat \$BUILD_GROUPS "${_bpigf_arg}"; ;; + esac; + + if [ "${_bpigf_rc}" -ne 0 ]; then + return "${_bpigf_rc}"; + else + _bpigf_shiftfl=1; + fi; + ;; + + done) + local _bpigf_verb="${1}" _bpigf_rstatus="${2#\$}"; + case "${ARG_PARALLEL}" in + auto) if ! rtl_get_cpu_count "${_bpigf_rstatus}" \$ARG_PARALLEL; then + _bpigf_rc=1; + else + ARG_PARALLEL=$((${ARG_PARALLEL}/2)); + fi; ;; + + max) if ! rtl_get_cpu_count "${_bpigf_rstatus}" \$ARG_PARALLEL; then + _bpigf_rc=1; + + fi; ;; + + "") ARG_PARALLEL=1; ;; + + *) if ! rtl_isnumber "${ARG_PARALLEL}"; then + _bpigf_rc=1; + rtl_setrstatus "${_bpigf_rstatus}" 'invalid jobs count \`'"${ARG_PARALLEL}"''\''.'; + fi; ;; + esac; + + if [ "${_bpigf_rc}" -eq 0 ]; then + DEFAULT_BUILD_CPUS="${ARG_PARALLEL}"; + else + return "${_bpigf_rc}"; + fi; + ;; + + *) + return 1; + ;; + esac; + + if [ "${_bpigf_shiftfl}" -ge 1 ]; then + return "$((${_bpigf_shiftfl} + 1))"; + else + return 0; + fi; + + return "${_bpigf_rc}"; +}; +# }}} + +# {{{ buildp_dispatch($_msg) +buildp_dispatch() { + local _bpd_msg="${1}"; shift; + + case "${_bpd_msg}" in + disabled_pkg|finish_pkg|missing_pkg|msg_pkg|skipped_pkg|start_pkg|start_pkg_child|step_pkg) + buildp_dispatch_pkg_state "${_bpd_msg}" "${@}"; ;; + + finish_group|start_group) + buildp_dispatch_group_state "${_bpd_msg}" "${@}"; ;; + + *) if command -v "buildp_dispatch_${_bpd_msg}" >/dev/null 2>&1; then + "buildp_dispatch_${_bpd_msg}" "${@}"; + fi; ;; + esac; + + return 0; +}; +# }}} +# {{{ buildp_dispatch_fail_pkg($_group_name, $_pkg_name) buildp_dispatch_fail_pkg() { - local _group_name="${1}" _pkg_name="${2}"; - : $((BUILD_NFAIL+=1)); BUILD_PKGS_FAILED="$(rtl_lconcat "${BUILD_PKGS_FAILED}" "${_pkg_name}")"; + local _bpdfp_group_name="${1}" _bpdfp_pkg_name="${2}"; + + : $((BUILD_NFAIL+=1)) + rtl_lconcat \$BUILD_PKGS_FAILED "${_bpdfp_pkg_name}"; + if [ "${ARG_RELAXED:-0}" -eq 0 ]; then - rtl_log_msg "fatal" "${MSG_pkg_stderrout_log}" "${BUILD_WORKDIR}" "${_pkg_name}"; - cat "${BUILD_WORKDIR}/${_pkg_name}_stderrout.log"; - if [ -n "${DEFAULT_BUILD_LAST_FAILED_PKG_FNAME}" ]; then - printf "%s\n" "${_pkg_name}" > "${DEFAULT_BUILD_LAST_FAILED_PKG_FNAME}"; + rtl_log_msg "fatal" "${MSG_pkg_stderrout_log}" "${BUILD_WORKDIR}" "${_bpdfp_pkg_name}"; + cat "${BUILD_WORKDIR}/${_bpdfp_pkg_name}_stderrout.log"; + + if [ "${DEFAULT_BUILD_LAST_FAILED_PKG_FNAME:+1}" = 1 ]; then + printf "%s\n" "${_bpdfp_pkg_name}" > "${DEFAULT_BUILD_LAST_FAILED_PKG_FNAME}"; fi; - rtl_log_msg "fatal" "${MSG_build_failed_in}" "${_pkg_name}" "${BUILD_WORKDIR}/${_pkg_name}_stderrout.log"; - else rtl_log_msg "warning" "${MSG_build_failed_in}" "${_pkg_name}" "${BUILD_WORKDIR}/${_pkg_name}_stderrout.log"; - fi; - if [ "${ARG_DUMP_ON_ABORT:-0}" -eq 1 ]; then - rtl_log_msg "pkg_faildump" "${MSG_pkg_faildump1}" "${_pkg_name}" "${BUILD_WORKDIR}/${_pkg_name}.dump"; - rtl_log_msg "pkg_faildump" "${MSG_pkg_faildump2}" "${ARCH}" "${BUILD_KIND}" "${_pkg_name}" "${PREFIX}"; + + rtl_log_msg "fatal" "${MSG_build_failed_in}" "${_bpdfp_pkg_name}" "${BUILD_WORKDIR}/${_bpdfp_pkg_name}_stderrout.log"; + else + rtl_log_msg "warning" "${MSG_build_failed_in}" "${_bpdfp_pkg_name}" "${BUILD_WORKDIR}/${_bpdfp_pkg_name}_stderrout.log"; fi; + if [ "${ARG_RELAXED:-0}" -eq 0 ]; then exit 1; fi; -}; + return 0; +}; +# }}} +# {{{ buildp_dispatch_group_state($_msg, $_group_name) buildp_dispatch_group_state() { - local _msg="${1}" _group_name="${2}"; - case "${_msg}" in - finish_group) rtl_log_msg "group_finish" "${MSG_group_finish}" "${6}" "${4}" "${5}" "${_group_name}"; ;; - start_group) rtl_log_msg "group_begin" "${MSG_group_begin}" "${6}" "${4}" "${5}" "${_group_name}"; ;; + local _bpdgs_msg="${1}" _bpdgs_group_name="${2}"; + + case "${_bpdgs_msg}" in + finish_group) rtl_log_msg "group_finish" "${MSG_group_finish}" "${6}" "${4}" "${5}" "${_bpdgs_group_name}"; ;; + start_group) rtl_log_msg "group_begin" "${MSG_group_begin}" "${6}" "${4}" "${5}" "${_bpdgs_group_name}"; ;; esac; -}; + return 0; +}; +# }}} +# {{{ buildp_dispatch_pkg_state($_msg, $_group_name, $_pkg_name) buildp_dispatch_pkg_state() { - local _msg="${1}" _group_name="${2}" _pkg_name="${3}"; - case "${_msg}" in - disabled_pkg) : $((BUILD_NSKIP+=1)); rtl_log_msg "pkg_skip" "${MSG_pkg_skip_disabled}" "${_pkg_name}"; ;; - missing_pkg) rtl_log_msg "fatalexit" "${MSG_pkg_skip_unknown}" "${_pkg_name}"; ;; - msg_pkg) shift 3; rtl_log_msg "${MSG_pkg_msg}" "${_group_name}" "${_pkg_name}" "${*}"; ;; - skipped_pkg) : $((BUILD_NSKIP+=1)); rtl_log_msg "pkg_skip" "${MSG_pkg_skip_finished}" "${_pkg_name}"; ;; - start_pkg) rtl_log_msg "pkg_begin" "${MSG_pkg_begin}" "${7}" "${6}" "${4}" "${5}" "${_pkg_name}"; ;; - step_pkg) rtl_log_msg "pkg_step" "${MSG_pkg_step}" "${4}" "${_pkg_name}"; ;; + local _bpdps_msg="${1}" _bpdps_group_name="${2}" _bpdps_pkg_name="${3}" \ + _bpdps_var="" _bpdps_vars=""; + + case "${_bpdps_msg}" in + disabled_pkg) : $((BUILD_NSKIP+=1)); rtl_log_msg "pkg_skip" "${MSG_pkg_skip_disabled}" "${_bpdps_pkg_name}"; ;; + missing_pkg) rtl_log_msg "fatalexit" "${MSG_pkg_skip_unknown}" "${_bpdps_pkg_name}"; ;; + msg_pkg) shift 3; rtl_log_msg "${MSG_pkg_msg}" "${_bpdps_group_name}" "${_bpdps_pkg_name}" "${*}"; ;; + skipped_pkg) : $((BUILD_NSKIP+=1)); rtl_log_msg "pkg_skip" "${MSG_pkg_skip_finished}" "${_bpdps_pkg_name}"; ;; + start_pkg) rtl_log_msg "pkg_begin" "${MSG_pkg_begin}" "${7}" "${6}" "${4}" "${5}" "${_bpdps_pkg_name}"; ;; + step_pkg) rtl_log_msg "pkg_step" "${MSG_pkg_step}" "${4}" "${_bpdps_pkg_name}"; ;; + finish_pkg) : $((BUILD_NFINI+=1)); - if rtl_lmatch "${ARG_VERBOSE_TAGS}" "build" ","; then - cat "${BUILD_WORKDIR}/${_pkg_name}_stderrout.log"; + if rtl_lmatch \$ARG_VERBOSE_TAGS "build" ","; then + cat "${BUILD_WORKDIR}/${_bpdps_pkg_name}_stderrout.log"; fi; - rtl_log_msg "pkg_finish" "${MSG_pkg_finish}" "${7}" "${6}" "${4}" "${5}" "${_pkg_name}"; ;; + rtl_log_msg "pkg_finish" "${MSG_pkg_finish}" "${7}" "${6}" "${4}" "${5}" "${_bpdps_pkg_name}"; ;; + start_pkg_child) if [ "${PKG_NO_LOG_VARS:-0}" -eq 0 ]; then - rtl_log_env_vars "info" "build" $(rtl_get_vars_fast "^PKG_"); + for _bpdps_var in ${DEFAULT_BUILD_VARS}; do + if eval [ \"\${PKG_${_bpdps_var}:+1}\" = 1 ]; then + _bpdps_vars="${_bpdps_vars:+${_bpdps_vars} }PKG_${_bpdps_var}"; + fi; + done; + rtl_log_env_vars "info" "build" ${_bpdps_vars}; fi; - if rtl_lmatch "${ARG_VERBOSE_TAGS}" "xtrace" ","; then + if rtl_lmatch \$ARG_VERBOSE_TAGS "xtrace" ","; then set -o xtrace; fi; ;; esac; -}; -buildp_dispatch() { - local _msg="${1}"; shift; - case "${_msg}" in - disabled_pkg|finish_pkg|missing_pkg|msg_pkg|skipped_pkg|start_pkg|start_pkg_child|step_pkg) - buildp_dispatch_pkg_state "${_msg}" "${@}"; ;; - finish_group|start_group) - buildp_dispatch_group_state "${_msg}" "${@}"; ;; - *) if command -v "buildp_dispatch_${_msg}" >/dev/null 2>&1; then - "buildp_dispatch_${_msg}" "${@}"; - fi; ;; - esac; + return 0; }; +# }}} +# {{{ buildp_time_init() buildp_time_init() { - BUILD_DATE_START="$(rtl_date %Y-%m-%d-%H-%M-%S)"; - _build_time_secs="$(rtl_date %s)"; + rtl_date \$BUILD_DATE_START "%Y-%m-%d-%H-%M-%S"; + rtl_date \$_build_time_secs "%s"; }; - +# }}} +# {{{ buildp_time_update() buildp_time_update() { - : $((_build_time_secs=$(rtl_date %s)-${_build_time_secs})); + local _bptu_date; + + rtl_date \$_bptu_date "%s"; + : $((_build_time_secs=${_bptu_date}-${_build_time_secs})); : $((_build_time_hours=${_build_time_secs}/3600)); : $((_build_time_minutes=(${_build_time_secs}%3600)/60)); : $((_build_time_secs=(${_build_time_secs}%3600)%60)); }; +# }}} build() { local _build_time_hours=0 _build_time_mins=0 _build_time_secs=0 _pkg_name="" _rc=0 _status="" \ @@ -119,31 +464,40 @@ build() { DEFAULT_BUILD_STEPS="" DEFAULT_BUILD_VARS="" DEFAULT_CLEAR_PREFIX_PATHS="" DEFAULT_GIT_ARGS="" \ DEFAULT_GITROOT_HEAD="${DEFAULT_GITROOT_HEAD:-}" DEFAULT_LOG_ENV_VARS="" DEFAULT_MIRRORS="" \ DEFAULT_TARGET="" DEFAULT_WGET_ARGS="" MIDIPIX_BUILD_PWD=""; - DEFAULT_BUILD_STATUS_IN_PROGRESS_FNAME=""; EX_PKG_DISPATCH_WAIT=""; - if ! . "${0%/*}/subr/build_init.subr"; then - printf "Error: failed to source \`${0%/*}/subr/build_init.subr'." >&2; exit "${_rc}"; - elif ! build_init "${@}"; then - printf "Error during initialisation: %s\n" "${_status}" >&2; exit "${_rc}"; - elif [ -n "${_status}" ]; then - _rc=0; _status="${_status}"; - else trap "buildp_ast exit" EXIT; trap "buildp_ast abort" HUP INT TERM USR1 USR2; + + BUILD_PKG_WAIT=""; + DEFAULT_BUILD_STATUS_IN_PROGRESS_FNAME=""; + + trap "buildp_ast exit" EXIT; trap "buildp_ast abort" HUP INT TERM USR1 USR2; + + if ! buildp_init \$_status "${@}"; then + _rc=0; + else buildp_time_init; rtl_log_msg "build_begin" "${MSG_build_begin}" "${BUILD_USER}" "${BUILD_HNAME}" "${BUILD_DATE_START}"; rtl_log_env_vars "build_vars" "build (global)" ${DEFAULT_LOG_ENV_VARS}; - ex_pkg_dispatch "${DEFAULT_BUILD_STEPS}" "${DEFAULT_BUILD_VARS}" \ - buildp_dispatch "${BUILD_GROUPS}" "${BUILD_GROUPS_INHIBIT_DEPS}" \ - "${ARG_PARALLEL}" "${BUILD_WORKDIR}/build.fifo" "${ARG_RESTART}" \ - "${ARG_RESTART_AT}" "${ARG_RESTART_RECURSIVE}" "${BUILD_WORKDIR}"; + + ex_pkg_dispatch \ + \$BUILD_PKG_WAIT "${DEFAULT_BUILD_STEPS}" "${DEFAULT_BUILD_VARS}" \ + buildp_dispatch "${BUILD_GROUPS}" "${BUILD_GROUPS_INHIBIT_DEPS}" \ + "${ARG_PARALLEL}" "${BUILD_WORKDIR}/build.fifo" "${ARG_RESTART}" \ + "${ARG_RESTART_AT}" "${ARG_RESTART_RECURSIVE}" "${BUILD_WORKDIR}"; + buildp_time_update; rtl_log_msg "build_finish" "${MSG_build_finish}" "${BUILD_NFINI:-0}" "${BUILD_NSKIP:-0}" "${BUILD_NFAIL:-0}"; rtl_log_msg "build_finish_time" "${MSG_build_finish_time}" "${_build_time_hours:-0}" "${_build_time_minutes:-0}" "${_build_time_secs:-0}"; - if [ -n "${BUILD_PKGS_FAILED}" ]; then - _rc=1; _status="Build script failure(s) in: ${BUILD_PKGS_FAILED}."; + + if [ "${BUILD_PKGS_FAILED:+1}" = 1 ]; then + _rc=1; + _status="Build script failure(s) in: ${BUILD_PKGS_FAILED}."; fi; fi; + if [ "${_rc}" -ne 0 ]; then + rtl_log_enable_tags "${LOG_TAGS_all}"; rtl_log_msg "fatalexit" "0;${_status}"; - elif [ -n "${_status}" ]; then + elif [ "${_status:+1}" = 1 ]; then + rtl_log_enable_tags "${LOG_TAGS_all}"; rtl_log_msg "info" "0;${_status}"; fi; }; diff --git a/dist/dist_gitref.dist b/dist/dist_gitref.dist index 4ebd412..3d8426b 100644 --- a/dist/dist_gitref.dist +++ b/dist/dist_gitref.dist @@ -3,7 +3,11 @@ # pkg_dist_gitref_all() { - (rtl_fileop cd "${MIDIPIX_BUILD_PWD}" && git rev-parse HEAD > "${PREFIX}/build.gitref"); + local _pdga_group_name="${1}" _pdga_pkg_name="${2}" _pdga_restart_at="${3}"; + + (rtl_fileop cd "${MIDIPIX_BUILD_PWD}" &&\ + git rev-parse HEAD > "${PREFIX}/build.gitref"); + return "${?}"; }; # vim:filetype=sh diff --git a/dist/dist_minipix.dist b/dist/dist_minipix.dist index 86ec026..fe5acb2 100644 --- a/dist/dist_minipix.dist +++ b/dist/dist_minipix.dist @@ -75,20 +75,25 @@ "}; pkg_dist_minipix_all() { - local _vflag=""; + local _pdma_group_name="${1}" _pdma_pkg_name="${2}" _pdma_restart_at="${3}" \ + _pdma_status="" _pdma_vflag=""; - if rtl_lmatch "${ARG_VERBOSE_TAGS}" "install" ","; then - _vflag="-v"; + if rtl_lmatch \$ARG_VERBOSE_TAGS "install" ","; then + _pdma_vflag="-v"; fi; - if rtl_lmatch "${ARG_DIST}" "minipix" "," \ - && ! rtl_install_v2 \ - -p "_minipix=${PREFIX_MINIPIX##*/}" \ - -p "_minipix_dist=${PREFIX}/minipix_dist" \ - -p "_native=${PREFIX_NATIVE##*/}" \ - ${_vflag} -- "${PREFIX}" \ + + if rtl_lmatch \$ARG_DIST "minipix" "," \ + && ! rtl_install_v2 \ + \$_pdma_status \ + -p "_minipix=${PREFIX_MINIPIX##*/}" \ + -p "_minipix_dist=${PREFIX}/minipix_dist" \ + -p "_native=${PREFIX_NATIVE##*/}" \ + ${_pdma_vflag} -- "${PREFIX}" \ "${PKG_INSTALL_FILES_V2}"; then return 1; fi; + + return 0; }; # vim:filetype=sh diff --git a/dist/dist_zipdist.dist b/dist/dist_zipdist.dist index 1b0c193..7678c8e 100644 --- a/dist/dist_zipdist.dist +++ b/dist/dist_zipdist.dist @@ -3,53 +3,66 @@ # pkg_dist_zipdist_all() { - local _dist_fname="" _pkg_name="" _pkglist_fname="${PREFIX}/pkglist.native"; - if rtl_lmatch "${ARG_DIST}" "zipdist" ","; then - echo "msg_pkg dist dist_zipdist ${MSG_zipdist_begin}" >&3; - rtl_log_msg "zipdist" "${MSG_zipdist_begin}"; - for _pkg_name in $(cat "${_pkglist_fname}"); do - if [ ! -e "${BUILD_WORKDIR}/${_pkg_name}-native-${DEFAULT_TARGET}" ]; then - rtl_log_msg "fatalexit" "${MSG_zipdist_missing_pkg_build_dir}" "${_pkg_name}"; - fi; - done; - _dist_fname="${DEFAULT_ZIPDIST_FNAME_PREFIX}${BUILD_USER}@${BUILD_HNAME}-${BUILD_DATE_START}.zip"; - if [ -e "${BUILD_WORKDIR}/zipdist" ]\ - && ! rtl_fileop rm "${BUILD_WORKDIR}/zipdist"; then - return 1; - elif ! rtl_fileop mkdir "${BUILD_WORKDIR}/zipdist"; then - return 1; - elif ! "${BUILD_WORKDIR}/mpackage/mpackage.sh" \ - --defroot="${DEFAULT_ZIPDIST_DEFROOT}" \ - --flysyms \ - --minroot="${PREFIX_MINIPIX}" \ - --objroot="${BUILD_WORKDIR}" \ - --pkgroot="${BUILD_WORKDIR}/zipdist/pkgroot" \ - --product=Midipix \ - --subset="${_pkglist_fname}" \ - --symbols \ - --sysroot="${BUILD_WORKDIR}/zipdist/sysroot" \ - --target="${DEFAULT_TARGET}" \ - --tmproot="${BUILD_WORKDIR}/zipdist/tmproot" \ - --zipfile="${PREFIX}/${_dist_fname}"; then + local _pdza_group_name="${1}" _pdza_pkg_name="${2}" _pdza_restart_at="${3}" \ + _pdza_dist_fname="" _pdza_pkg_name="" _pdza_pkglist_fname="${PREFIX}/pkglist.native"; + + if ! rtl_lmatch \$ARG_DIST "zipdist" ","; then + return 0; + fi; + + echo "msg_pkg dist dist_zipdist ${MSG_zipdist_begin}" >&3; + rtl_log_msg "zipdist" "${MSG_zipdist_begin}"; + + for _pdza_pkg_name in $(cat "${_pdza_pkglist_fname}"); do + if [ ! -e "${BUILD_WORKDIR}/${_pdza_pkg_name}-native-${DEFAULT_TARGET}" ]; then + rtl_log_msg "fatalexit" "${MSG_zipdist_missing_pkg_build_dir}" "${_pdza_pkg_name}"; + fi; + done; + + _pdza_dist_fname="${DEFAULT_ZIPDIST_FNAME_PREFIX}${BUILD_USER}@${BUILD_HNAME}-${BUILD_DATE_START}.zip"; + + if [ -e "${BUILD_WORKDIR}/zipdist" ]\ + && ! rtl_fileop rm "${BUILD_WORKDIR}/zipdist"; then + return 1; + elif ! rtl_fileop mkdir "${BUILD_WORKDIR}/zipdist"; then + return 1; + elif ! "${BUILD_WORKDIR}/mpackage/mpackage.sh" \ + --defroot="${DEFAULT_ZIPDIST_DEFROOT}" \ + --flysyms \ + --minroot="${PREFIX_MINIPIX}" \ + --objroot="${BUILD_WORKDIR}" \ + --pkgroot="${BUILD_WORKDIR}/zipdist/pkgroot" \ + --product=Midipix \ + --subset="${_pdza_pkglist_fname}" \ + --symbols \ + --sysroot="${BUILD_WORKDIR}/zipdist/sysroot" \ + --target="${DEFAULT_TARGET}" \ + --tmproot="${BUILD_WORKDIR}/zipdist/tmproot" \ + --zipfile="${PREFIX}/${_pdza_dist_fname}"; then + return 1; + fi; + + echo "msg_pkg dist dist_zipdist ${MSG_zipdist_finished}" >&3; + rtl_log_msg "zipdist" "${MSG_zipdist_finished}"; + + if [ "${DEFAULT_ZIPDIST_SIGN_GPG_KEY:+}" = 1 ]\ + && command which gpg >/dev/null 2>&1\ + && gpg --list-keys "${DEFAULT_ZIPDIST_SIGN_GPG_KEY}" >/dev/null 2>&1; + then + echo "msg_pkg dist dist_zipdist ${MSG_zipdist_signing}" >&3; + rtl_log_msg "zipdist" "${MSG_zipdist_signing}"; + + if ! gpg --armor --passphrase-file /dev/null \ + --local-user "${DEFAULT_ZIPDIST_SIGN_GPG_KEY}" \ + --sign "${PREFIX}/${_pdza_dist_fname}"; then return 1; - else - echo "msg_pkg dist dist_zipdist ${MSG_zipdist_finished}" >&3; - rtl_log_msg "zipdist" "${MSG_zipdist_finished}"; - if [ -n "${DEFAULT_ZIPDIST_SIGN_GPG_KEY:-}" ]\ - && [ -x "$(which gpg 2>/dev/null)" ]\ - && gpg --list-keys "${DEFAULT_ZIPDIST_SIGN_GPG_KEY}" >/dev/null 2>&1; then - echo "msg_pkg dist dist_zipdist ${MSG_zipdist_signing}" >&3; - rtl_log_msg "zipdist" "${MSG_zipdist_signing}"; - if ! gpg --armor --passphrase-file /dev/null \ - --local-user "${DEFAULT_ZIPDIST_SIGN_GPG_KEY}" \ - --sign "${PREFIX}/${_dist_fname}"; then - return 1; - fi; - echo "msg_pkg dist dist_zipdist ${MSG_zipdist_signed}" >&3; - rtl_log_msg "zipdist" "${MSG_zipdist_signed}"; - fi; fi; + + echo "msg_pkg dist dist_zipdist ${MSG_zipdist_signed}" >&3; + rtl_log_msg "zipdist" "${MSG_zipdist_signed}"; fi; + + return 0; }; # vim:filetype=sh diff --git a/etc/README.md b/etc/README.md index 784373a..0dabff4 100644 --- a/etc/README.md +++ b/etc/README.md @@ -25,9 +25,8 @@ into account when deploying and using Midipix distributions. 3.2. [Adding a package](#32-adding-a-package) 3.3. [Addressing build failure](#33-addressing-build-failure) 3.4. [Package archive files and Git repositories](#34-package-archive-files-and-git-repositories) - 3.5. [``-s``: package build shell environment](#35--s-package-build-shell-environment) - 3.6. [Package-package and {package,group}-group relationships](#36-package-package-and-packagegroup-group-relationships) - 3.7. [Patches and ``vars`` files](#37-patches-and-vars-files) + 3.5. [Package-package and {package,group}-group relationships](#35-package-package-and-packagegroup-group-relationships) + 3.6. [Patches and ``vars`` files](#36-patches-and-vars-files) 4. [Units reference](#4-units-reference) 4.1. [Build steps](#41-build-steps) 4.2. [Build variables](#42-build-variables) @@ -326,7 +325,7 @@ which are specified in this order. Pick a build group according to the criteria mentioned, add the package to the build group's list of contained packages in its corresponding file, and add the set of package variables required (see above and section [4.5](#45-package-variables).) -Consult section [3.7](#37-patches-and-vars-files) if the package to be added +Consult section [3.6](#36-patches-and-vars-files) if the package to be added requires patches or additional code amending or replacing package build steps or the entire package build. Consult section [4.1](#41-build-steps) for a list of package build steps and how they are overriden. @@ -344,11 +343,6 @@ output. If ``-V xtrace`` was specified, ``xtrace`` will be set during package bu rudimentary debugging purposes. Additionally, packages using GNU autotools will, if package configuration failed or appears relevant, log the configuration process in detail in, most usually, ``${PKG_BUILD_DIR}/config.log``. - -If ``--dump-on-abort`` was specified, a subset of the variables set and environment -variables exported will be written to ``${BUILD_WORKDIR}/${PKG_NAME}.dump``, which may -subsequently be used in order to obtain a package build shell environment with the -``pkgtool.sh`` script (see sections [4.6](#46-pkgtoolsh), [3.5](#35--s-package-build-shell-environment).) [Back to top](#table-of-contents) @@ -376,37 +370,8 @@ A list of pertinent package variables and their formats follows: [Back to top](#table-of-contents) [//]: # "}}}" -[//]: # "{{{ 3.5. -s: package build shell environment" -### 3.5. -s: package build shell environment - -When ``build.sh`` is executed with the ``--dump-on-abort`` option, a subset of the -variables set and environment variables exported will be written to ``${BUILD_WORKDIR}/${PKG_NAME}.dump`` -on build failure, which may subsequently be used in order to obtain a package build shell -environment with the ``pkgtool.sh`` script, e.g.: - -``` -midipix_build@sandbox:(src/midipix_build)> $ ./pkgtool.sh -a nt64 -b debug -s mc -==> 2020/03/11 15:46:28 Launching shell `/usr/bin/zsh' within package environment and `/home/midipix_build/midipix/nt64/debug/tmp'. -==> 2020/03/11 15:46:28 Run $R to rebuild `mc'. -==> 2020/03/11 15:46:28 Run $RS to restart the specified build step of `mc' -==> 2020/03/11 15:46:28 Run $D to automatically regenerate the patch for `mc'. -midipix_build@sandbox:(mc-native-x86_64-nt64-midipix/obj)> $ -``` - -If a package build shell environment is desired for a package that has either not been -built at all or built successfully, ``pkgshell.sh`` will attempt to rebuild the package -at build steps up until, by default, ``build``, and then forcibly abort the build and -write ``${BUILD_WORKDIR}/${PKG_NAME}.dump`` as above prior to entering the shell. - -Consult sections [3.2](#32-adding-a-package), [3.7](#37-patches-and-vars-files), [4.2](#42-build-variables), -[4.1](#41-build-steps), and [4.5](#45-package-variables) for further information -concerning the package build process. - -[Back to top](#table-of-contents) - -[//]: # "}}}" -[//]: # "{{{ 3.6. Package-package and {package,group}-group relationships" -### 3.6. Package-package and {package,group}-group relationships +[//]: # "{{{ 3.5. Package-package and {package,group}-group relationships" +### 3.5. Package-package and {package,group}-group relationships Packages, as well as groups, are interrelated through implicit as well as explicit parametrised, typed relationships and form namespaces correspondingly. @@ -433,8 +398,8 @@ A list of relationship types follows: [Back to top](#table-of-contents) [//]: # "}}}" -[//]: # "{{{ 3.7. Patches and ``vars`` files" -## 3.7. Patches and ``vars`` files +[//]: # "{{{ 3.6. Patches and ``vars`` files" +## 3.6. Patches and ``vars`` files Package patches are applied prior and/or subsequent to (GNU autotools or similar) package configuration during the ``configure_patch_pre`` and/or ``configure_patch`` build steps, @@ -546,7 +511,7 @@ usage: ./build.sh [-a nt32|nt64] [-b debug|release] [-C dir[,..]] [-D kind[ [-r [*[*[*]]]name[,..][:ALL|LAST|[^|<|<=|>|>=]step,..]] [-R] [-v] [-V [+]tag|pat[,..]] - [--as-needed] [--debug-minipix] [--dump-on-abort] [--reset-state] + [--as-needed] [--debug-minipix] [--reset-state] [--roar] [[=]|=[ ..]] -a nt32|nt64 Selects 32-bit or 64-bit architecture; defaults to nt64. @@ -621,13 +586,11 @@ usage: ./build.sh [-a nt32|nt64] [-b debug|release] [-C dir[,..]] [-D kind[ build_*.....: general build messages (viz.: begin, finish, finish_time, vars,) group_*.....: build group messages (viz.: begin, finish,) - pkg_*.......: package build messages (viz.: begin, faildump, finish, msg, skip, step, strip.) + pkg_*.......: package build messages (viz.: begin, finish, msg, skip, step, strip.) --as-needed Don't build unless the midipix_build repository has received new commits. --debug-minipix Don't strip(1) minipix binaries to facilitate debugging minipix. - --dump-on-abort Produce package environment dump files on build failure to be - used in conjuction with pkg_shell.sh script (excludes -R.) --reset-state Reset package build step state on exit. [ ..] One of: dev_packages, dist, host_deps, host_deps_rpm, @@ -857,7 +820,7 @@ VERSION`` and/or ``URLS_GIT``, respectively. | FlagLine | String of {SP,VT}-separated flags, arguments, options, etc. pp. to a command | | List([,..]) | \-separated list, optionally recursively and/or sub-typing, e.g.: ``List(:,=,String)`` and ``"name=value:name2=value"`` | | PkgName | Single name of package | -| PkgRelation | Single, possibly parametrised, package-package relation; see section [3.6](#36-package-package-and-packagegroup-group-relationships) | +| PkgRelation | Single, possibly parametrised, package-package relation; see section [3.5](#35-package-package-and-packagegroup-group-relationships) | | PkgVersion | Single version of package | | Set() | Set of alternatives of , e.g. one of ``cross``, ``host``, ``native`` | | String | Semantically generic string | @@ -963,7 +926,7 @@ VERSION`` and/or ``URLS_GIT``, respectively. ## 4.6. ``pkgtool.sh`` ``` -usage: ./pkgtool.sh [-a nt32|nt64] [-b debug|release] [-i|-m -M |-r|-s|-t] [-v] +usage: ./pkgtool.sh [-a nt32|nt64] [-b debug|release] [-i|-m -M |-r|-R|-t] [-v] [=[ ..]] name -a nt32|nt64 Selects 32-bit or 64-bit architecture; defaults to nt64. @@ -972,11 +935,7 @@ usage: ./pkgtool.sh [-a nt32|nt64] [-b debug|release] [-i|-m -M | -m Setup package archives mirror in and/or -M Setup Git repositories mirror in -r List reverse dependencies of single named package. - -s Enter interactive package build shell environment for single - named package; requires a package dump file. If the package - has not been built yet or built successfully, it will be rebuilt - at build steps up until, by default, the `build' build step and - forcibly aborted and dumped prior to enterting the shell. + -R List full reverse dependencies of single named package. -t Produce tarball of package build root directory and build log file for the purpose of distribution given build failure. -v Increase verbosity. diff --git a/etc/build.msgs.en b/etc/build.msgs.en index 59578e1..2823ba8 100644 --- a/etc/build.msgs.en +++ b/etc/build.msgs.en @@ -18,8 +18,6 @@ MSG_group_begin="4;[%3d%% ] [%03d/%03d] Starting \`%s' build group..."; MSG_group_finish="4;[%3d%% ] [%03d/%03d] Finished \`%s' build group."; MSG_pkg_begin="5;[%3d%%/%3d%%] [%03d/%03d] Starting \`%s' build..."; -MSG_pkg_faildump1="2;Logged environment dump for failed package \`%s' to \`%s'."; -MSG_pkg_faildump2="4;Enter an interactive package build shell w/ the command line: ./pkgtool.sh -a %s -b %s \"%s\" PREFIX=\"%s\""; MSG_pkg_fail_missing_vars="Error: \${PKG_SUBDIR} must be specified given both \${PKG_FNAME} and \${PKG_URLS_GIT}."; MSG_pkg_finish="5;[%3d%%/%3d%%] [%03d/%03d] Finished \`%s' build."; MSG_pkg_msg="3;%s/%s: %s"; diff --git a/etc/build.theme b/etc/build.theme index fb52fc3..cc5d83f 100644 --- a/etc/build.theme +++ b/etc/build.theme @@ -35,8 +35,8 @@ # # Tag sets # -LOG_TAGS_all="build,fileop,install,zipdist,xtrace,fatal,info,verbose,warning,build_begin,build_finish,build_finish_time,build_vars,group_begin,group_finish,pkg_begin,pkg_faildump,pkg_finish,pkg_msg,pkg_skip,pkg_step,pkg_strip"; -LOG_TAGS_normal="fatal,info,warning,build_begin,build_finish,build_finish_time,pkg_begin,pkg_faildump,pkg_finish,pkg_msg"; +LOG_TAGS_all="build,fileop,install,zipdist,xtrace,fatal,info,verbose,warning,build_begin,build_finish,build_finish_time,build_vars,group_begin,group_finish,pkg_begin,pkg_finish,pkg_msg,pkg_skip,pkg_step,pkg_strip"; +LOG_TAGS_normal="fatal,info,warning,build_begin,build_finish,build_finish_time,pkg_begin,pkg_finish,pkg_msg"; LOG_TAGS_verbose="${LOG_TAGS_normal:+${LOG_TAGS_normal},}zipdist,verbose,build_vars,group_begin,group_finish,pkg_skip,pkg_step,pkg_strip"; # @@ -74,7 +74,6 @@ LOG_TAG_group_finish="4;92"; # Underline; Bright green # Package build tags # LOG_TAG_pkg_begin=93; # Bright yellow -LOG_TAG_pkg_faildump=93; # Bright yellow LOG_TAG_pkg_finish=92; # Bright green LOG_TAG_pkg_msg=90; # Dark grey LOG_TAG_pkg_skip=36; # Cyan diff --git a/etc/build.usage b/etc/build.usage index 218343d..0e2f14f 100644 --- a/etc/build.usage +++ b/etc/build.usage @@ -3,7 +3,7 @@ [-r [*[*[*]]]name[,..][:ALL|LAST|[^|<|<=|>|>=]step,..]] [-R] [-v] [-V [+]tag|pat[,..]] - [--as-needed] [--debug-minipix] [--dump-on-abort] [--reset-state] + [--as-needed] [--debug-minipix] [--reset-state] [--roar] [[=]<group>|<variable name>=<variable override>[ ..]] -a nt32|nt64 Selects 32-bit or 64-bit architecture; defaults to nt64. @@ -78,13 +78,11 @@ build_*.....: general build messages (viz.: begin, finish, finish_time, vars,) group_*.....: build group messages (viz.: begin, finish,) - pkg_*.......: package build messages (viz.: begin, faildump, finish, msg, skip, step, strip.) + pkg_*.......: package build messages (viz.: begin, finish, msg, skip, step, strip.) --as-needed Don't build unless the midipix_build repository has received new commits. --debug-minipix Don't strip(1) minipix binaries to facilitate debugging minipix. - --dump-on-abort Produce package environment dump files on build failure to be - used in conjuction with pkg_shell.sh script (excludes -R.) --reset-state Reset package build step state on exit. <group>[ ..] One of: dev_packages, dist, host_deps, host_deps_rpm, diff --git a/etc/build.usage.short b/etc/build.usage.short index 7e58f8b..43b2ad1 100644 --- a/etc/build.usage.short +++ b/etc/build.usage.short @@ -3,7 +3,7 @@ [-r [*[*[*]]]name[,..][:ALL|LAST|[^|<|<=|>|>=]step,..]] [-R] [-v] [-V [+]tag|pat[,..]] - [--as-needed] [--debug-minipix] [--dump-on-abort] [--reset-state] + [--as-needed] [--debug-minipix] [--reset-state] [--roar] [[=]<group>|<variable name>=<variable override>[ ..]] -a nt32|nt64 Selects 32-bit or 64-bit architecture; defaults to nt64. diff --git a/etc/pkgtool.msgs.en b/etc/pkgtool.msgs.en index 55b1206..95deb0f 100644 --- a/etc/pkgtool.msgs.en +++ b/etc/pkgtool.msgs.en @@ -3,7 +3,6 @@ # MSG_pkgtool_build_group="1;Build group: %s"; -MSG_pkgtool_no_env_dump="2;Warning: failed to locate environment dump for package \`%s' in \`%s'."; MSG_pkgtool_pkg_archive_mirroring="2;Mirroring package \`%s', archive URL(s): \`%s'..."; MSG_pkgtool_pkg_archive_mirroring_parent="3;Mirroring package \`%s' (parent package: \`%s'), archive URL(s): \`%s'..."; MSG_pkgtool_pkg_deps_fail="1;Warning: failed to unfold dependency-expanded package name list for \`%s'."; @@ -23,11 +22,6 @@ MSG_pkgtool_pkg_skip_archive_mirror="1;Archive URL(s) mirroring disabled, skippi MSG_pkgtool_pkg_skip_git_mirror_disabled="1;Package \`%s' specifies to skip Git URL(s) mirroring, skipping."; MSG_pkgtool_pkg_skip_git_mirror="1;Git URL(s) mirroring disabled, skipping \`%s'."; MSG_pkgtool_pkg_skip_no_urls="1;Package \`%s' has neither archive nor Git URL(s), skipping."; -MSG_pkgtool_rebuilding_pkg="1;Rebuilding package \`%s' w/ --dump-in build..."; -MSG_pkgtool_shell_env1="2;Launching shell \`%s' within package environment and \`%s'."; -MSG_pkgtool_shell_env2="1;Run \$R to rebuild \`%s'."; -MSG_pkgtool_shell_env3="1;Run \$RS to restart the specified build step of \`%s'"; -MSG_pkgtool_shell_env4="1;Run \$D to automatically regenerate the patch for \`%s'."; MSG_pkgtool_tarball_created="2;Created compressed tarball of \`%s' and \`%s_stderrout.log'."; MSG_pkgtool_tarball_creating="2;Creating compressed tarball of \`%s' and \`%s_stderrout.log'..."; MSG_pkgtool_updated_patches="2;Updated \`%s/patches/%s'."; diff --git a/etc/pkgtool.usage b/etc/pkgtool.usage index 4812690..6c86e86 100644 --- a/etc/pkgtool.usage +++ b/etc/pkgtool.usage @@ -1,4 +1,4 @@ -usage: ./pkgtool.sh [-a nt32|nt64] [-b debug|release] [-i|-m <dname> -M <dname>|-r|-s|-t] [-v] +usage: ./pkgtool.sh [-a nt32|nt64] [-b debug|release] [-i|-m <dname> -M <dname>|-r|-R|-t] [-v] [<variable name>=<variable override>[ ..]] name -a nt32|nt64 Selects 32-bit or 64-bit architecture; defaults to nt64. @@ -7,11 +7,7 @@ -m <dname> Setup package archives mirror in <dname> and/or -M <dname> Setup Git repositories mirror in <dname> -r List reverse dependencies of single named package. - -s Enter interactive package build shell environment for single - named package; requires a package dump file. If the package - has not been built yet or built successfully, it will be rebuilt - at build steps up until, by default, the `build' build step and - forcibly aborted and dumped prior to enterting the shell. + -R List recursive reverse dependencies of single named package. -t Produce tarball of package build root directory and build log file for the purpose of distribution given build failure. -v Increase verbosity. diff --git a/groups/010.host_deps.group b/groups/010.host_deps.group index 62953a1..c3845ec 100644 --- a/groups/010.host_deps.group +++ b/groups/010.host_deps.group @@ -2,8 +2,8 @@ # Build group host_deps # HOST_DEPS_BUILD_TYPE="host"; -HOST_DEPS_CFLAGS_CONFIGURE="$(rtl_lconcat "${DEFAULT_CFLAGS_HOST}" "-I${PREFIX}/include")"; -HOST_DEPS_CXXFLAGS_CONFIGURE="$(rtl_lconcat "${DEFAULT_CXXFLAGS_HOST}" "-I${PREFIX}/include")"; +rtl_lconcat2 \$HOST_DEPS_CFLAGS_CONFIGURE \$DEFAULT_CFLAGS_HOST "-I${PREFIX}/include"; +rtl_lconcat2 \$HOST_DEPS_CXXFLAGS_CONFIGURE \$DEFAULT_CXXFLAGS_HOST "-I${PREFIX}/include"; HOST_DEPS_CONFIGURE_ARGS="--disable-nls --prefix=${PREFIX} --program-prefix="; HOST_DEPS_GROUP_DEPENDS="host_tools"; HOST_DEPS_LDFLAGS_CONFIGURE="-L${PREFIX}/lib -Wl,-rpath,${PREFIX}/lib"; diff --git a/groups/020.host_deps_rpm.group b/groups/020.host_deps_rpm.group index 32c2aec..f348dc4 100644 --- a/groups/020.host_deps_rpm.group +++ b/groups/020.host_deps_rpm.group @@ -2,8 +2,8 @@ # Build group host_deps_rpm # HOST_DEPS_RPM_BUILD_TYPE="host"; -HOST_DEPS_RPM_CFLAGS_CONFIGURE="$(rtl_lconcat "${DEFAULT_CFLAGS_HOST}" "-I${PREFIX}/include")"; -HOST_DEPS_RPM_CXXFLAGS_CONFIGURE="$(rtl_lconcat "${DEFAULT_CXXFLAGS_HOST}" "-I${PREFIX}/include")"; +rtl_lconcat2 \$HOST_DEPS_RPM_CFLAGS_CONFIGURE \$DEFAULT_CFLAGS_HOST "-I${PREFIX}/include"; +rtl_lconcat2 \$HOST_DEPS_RPM_CXXFLAGS_CONFIGURE \$DEFAULT_CXXFLAGS_HOST "-I${PREFIX}/include"; HOST_DEPS_RPM_CONFIGURE_ARGS="--disable-nls --prefix=${PREFIX}"; HOST_DEPS_RPM_GROUP_DEPENDS="host_deps host_tools"; HOST_DEPS_RPM_LDFLAGS_CONFIGURE="-L${PREFIX}/lib -Wl,-rpath,${PREFIX}/lib"; diff --git a/groups/200.native_packages.group b/groups/200.native_packages.group index 886fab5..d9231f6 100644 --- a/groups/200.native_packages.group +++ b/groups/200.native_packages.group @@ -1,8 +1,8 @@ # # Build group native_packages # -NATIVE_PACKAGES_CFLAGS_CONFIGURE="$(rtl_lconcat "${DEFAULT_CFLAGS}" "--sysroot=${PREFIX_NATIVE}")"; -NATIVE_PACKAGES_CXXFLAGS_CONFIGURE="$(rtl_lconcat "${DEFAULT_CXXFLAGS}" "--sysroot=${PREFIX_NATIVE}")"; +rtl_lconcat2 \$NATIVE_PACKAGES_CFLAGS_CONFIGURE \$DEFAULT_CFLAGS "--sysroot=${PREFIX_NATIVE}"; +rtl_lconcat2 \$NATIVE_PACKAGES_CXXFLAGS_CONFIGURE \$DEFAULT_CFLAGS "--sysroot=${PREFIX_NATIVE}"; NATIVE_PACKAGES_CONFIG_CACHE_LOCAL="${CONFIG_CACHE_GNULIB}"; NATIVE_PACKAGES_CONFIGURE_ARGS="-C --disable-nls --host=${DEFAULT_TARGET} --prefix= --program-prefix= --target=${DEFAULT_TARGET}"; NATIVE_PACKAGES_GROUP_DEPENDS="host_deps host_deps_rpm host_toolchain host_tools native_toolchain native_tools"; diff --git a/groups/211.native_packages_cmdline.group b/groups/211.native_packages_cmdline.group index 6f29fd1..aa121ab 100644 --- a/groups/211.native_packages_cmdline.group +++ b/groups/211.native_packages_cmdline.group @@ -2,11 +2,11 @@ # Build group native_packages (cmdline) # GROUP_TARGET="native_packages"; -NATIVE_PACKAGES_PACKAGES="$(rtl_lconcat "${NATIVE_PACKAGES_PACKAGES}" " +rtl_lconcat \$NATIVE_PACKAGES_PACKAGES " bas bash bc busybox cabextract calcurse clipboard_utils coreutils cpio dash datamash dos2unix ed exif figlet findutils gawk gcal grep html_xml_utils jush lzop mawk mc mksh moe moon_buggy mpg123 mp3splt nano ninvaders openbsd_baseutils profanity pixz pv rc sash sbase screen sed sharutils sloccount tar tcsh -the_silver_searcher toilet tree terminally_tetris ubase which zsh")"; +the_silver_searcher toilet tree terminally_tetris ubase which zsh"; : ${PKG_BAS_DEPENDS:="ncurses"}; : ${PKG_BAS_SHA256SUM:=ec45efa90aaa7f15647fe7898fa0789ba26dc8e10b7ecf8e049b1310f626b884}; : ${PKG_BAS_VERSION:=2.6}; diff --git a/groups/221.native_packages_dev.group b/groups/221.native_packages_dev.group index fcde0b3..6694a00 100644 --- a/groups/221.native_packages_dev.group +++ b/groups/221.native_packages_dev.group @@ -2,9 +2,9 @@ # Build group native_packages (dev) # GROUP_TARGET="native_packages"; -NATIVE_PACKAGES_PACKAGES="$(rtl_lconcat "${NATIVE_PACKAGES_PACKAGES}" " +rtl_lconcat \$NATIVE_PACKAGES_PACKAGES " bison cdecl chicken cparser cssc diffutils flex gdb gengetopt gnucobol indent lua lunix m4 make mandoc nasm -patch patchutils perl posix_cc python2 python3 ruby sbsigntools tk")"; +patch patchutils perl posix_cc python2 python3 ruby sbsigntools tk"; : ${PKG_BISON_DEPENDS:="readline libiconv"}; : ${PKG_BISON_SHA256SUM:=9bba0214ccf7f1079c5d59210045227bcf619519840ebfa80cd3849cff5a5bf2}; : ${PKG_BISON_VERSION:=3.8.2}; diff --git a/groups/231.native_packages_etc.group b/groups/231.native_packages_etc.group index 7534c22..1ca72ec 100644 --- a/groups/231.native_packages_etc.group +++ b/groups/231.native_packages_etc.group @@ -2,7 +2,7 @@ # Build group native_packages (etc) # GROUP_TARGET="native_packages"; -NATIVE_PACKAGES_PACKAGES="$(rtl_lconcat "${NATIVE_PACKAGES_PACKAGES}" " +rtl_lconcat \$NATIVE_PACKAGES_PACKAGES " apr apr_util bdwgc bmake bochs bzip2 cherokee clzip cmake cron dante dosbox doomgeneric emacs enscript expat ffmpeg file gdbm geoip gettext_tiny ghostpdl giflib gnuchess graphicsmagick gzip hastyhex hexcurse hexer icoutils imagemagick infounzip infozip @@ -10,7 +10,7 @@ john lbreakout2 lcms2 less libmetalink lolcode ltris minizip mintty mlogin musl_ ncurses ncursestw ncursesw npth openjazz openjpeg p7zip pcre pcre2 php popt potrace procps_ng qemu qpdf qrencode rpm rw sdlquake shared_mime_info slang sqlite3 tcl tdnf texinfo tiff tmux tzdb utf8proc util_linux vim vorbis_tools w32api w32lib xorriso xpdf xz yabasic -zstd")"; +zstd"; : ${PKG_APR_SHA256SUM:=a67ca9fcf9c4ff59bce7f428a323c8b5e18667fdea7b0ebad47d194371b0a105}; : ${PKG_APR_VERSION:=1.6.5}; : ${PKG_APR_URL:=http://ftp.fau.de/apache/apr/apr-${PKG_APR_VERSION}.tar.bz2}; diff --git a/groups/241.native_packages_inet.group b/groups/241.native_packages_inet.group index 32a9445..d96fa2a 100644 --- a/groups/241.native_packages_inet.group +++ b/groups/241.native_packages_inet.group @@ -2,11 +2,11 @@ # Build group native_packages (inet) # GROUP_TARGET="native_packages"; -NATIVE_PACKAGES_PACKAGES="$(rtl_lconcat "${NATIVE_PACKAGES_PACKAGES}" " +rtl_lconcat \$NATIVE_PACKAGES_PACKAGES " apk_tools bind ca_certificates curl cvs dropbear elinks fetchmail git gnupg gpgme gnutls httpd icecast inetutils irssi isync ldns lighttpd links lynx mailutils microsocks mutt nginx ngircd nullmailer openlitespeed opensmtpd openssh -proxytunnel rsync socat thttpd w3m weechat wget wget2 whois")"; +proxytunnel rsync socat thttpd w3m weechat wget wget2 whois"; : ${PKG_APK_TOOLS_DEPENDS:="libfetch libressl libz"}; : ${PKG_APK_TOOLS_SHA256SUM:=def2b2c23cd12fd2a9c19be49653b0d1bf9d81a26dac5a0ee79a1351d674f93b}; : ${PKG_APK_TOOLS_VERSION:=2.6.8}; diff --git a/groups/251.native_packages_lib.group b/groups/251.native_packages_lib.group index c97d338..05b2053 100644 --- a/groups/251.native_packages_lib.group +++ b/groups/251.native_packages_lib.group @@ -2,14 +2,14 @@ # Build group native_packages (libs) # GROUP_TARGET="native_packages"; -NATIVE_PACKAGES_PACKAGES="$(rtl_lconcat "${NATIVE_PACKAGES_PACKAGES}" " +rtl_lconcat \$NATIVE_PACKAGES_PACKAGES " aspell bearssl enchant fribidi glib hunspell ivykis jansson kvazaar lame libao libarchive libass libassuan libatomic_ops libdmtx libedit libeditline libelf libestr libevent libexif libfastjson libfetch libffi libfirm libflac libglob libgcrypt libgpg_error libiconv libidn2 libite libjpeg_turbo libksba libmad libmd libmspack libmp3splt libogg libpcap libpng libpsl readline libredwg libressl libsasl2 libshine libsndfile libsolv libssh libstrophe libtasn1 libtelnet libtheora libtirpc libudns libunistring libuv libvorbis libxml2 libxslt libz libzip lzlib lzo nettle onig opus sdl1 sdl1_net sdl1_mixer -sdl1_image sdl1_ttf sdl2 sdl2_image sdl2_ttf sdl2_net twolame wolfssl")"; +sdl1_image sdl1_ttf sdl2 sdl2_image sdl2_ttf sdl2_net twolame wolfssl"; : ${PKG_ASPELL_SHA256SUM:=f9b77e515334a751b2e60daab5db23499e26c9209f5e7b7443b05235ad0226f2}; : ${PKG_ASPELL_VERSION:=0.60.8}; : ${PKG_ASPELL_URL:=https://ftp.gnu.org/gnu/aspell/aspell-${PKG_ASPELL_VERSION}.tar.gz}; diff --git a/groups/261.native_packages_x11.group b/groups/261.native_packages_x11.group index 5636113..eb62afc 100644 --- a/groups/261.native_packages_x11.group +++ b/groups/261.native_packages_x11.group @@ -2,13 +2,13 @@ # Build group native_packages (x11) # GROUP_TARGET="native_packages"; -NATIVE_PACKAGES_PACKAGES="$(rtl_lconcat "${NATIVE_PACKAGES_PACKAGES}" " +rtl_lconcat \$NATIVE_PACKAGES_PACKAGES " cairo fontconfig freetype freetype_pre gxemul harfbuzz imlib2 libcaca libfontenc libICE libpthread_stubs libSM libX11 libXau libXaw libXdamage libXdmcp libXext libXfixes libXfont2 libXft libXi libxkbfile libXmu libXpm libXt libXtst libXcursor pango pixman rdesktop rxvt_unicode st util_macros xcb xcb_proto xcb_util xcb_util_image xcb_util_wm xcalc -xeyes xorgproto Xrender xterm xtrans xwd xwin")"; +xeyes xorgproto Xrender xterm xtrans xwd xwin"; : ${PKG_CAIRO_DEPENDS:="fontconfig freetype ghostpdl glib libXext libpng pixman"}; : ${PKG_CAIRO_VERSION:=1.15.6}; : ${PKG_CAIRO_URL:=http://cairographics.org/snapshots/cairo-${PKG_CAIRO_VERSION}.tar.xz}; diff --git a/groups/800.minipix.group b/groups/800.minipix.group index f5db961..43f6d2e 100644 --- a/groups/800.minipix.group +++ b/groups/800.minipix.group @@ -1,8 +1,8 @@ # # Build group minipix # -MINIPIX_CFLAGS_CONFIGURE="$(rtl_lconcat "${DEFAULT_CFLAGS}" "--sysroot=${PREFIX_NATIVE}")"; -MINIPIX_CXXFLAGS_CONFIGURE="$(rtl_lconcat "${DEFAULT_CXXFLAGS}" "--sysroot=${PREFIX_NATIVE}")"; +rtl_lconcat2 \$MINIPIX_CFLAGS_CONFIGURE \$DEFAULT_CFLAGS "--sysroot=${PREFIX_NATIVE}"; +rtl_lconcat2 \$MINIPIX_CXXFLAGS_CONFIGURE \$DEFAULT_CXXFLAGS "--sysroot=${PREFIX_NATIVE}"; MINIPIX_CONFIG_CACHE_LOCAL="${CONFIG_CACHE_GNULIB}"; MINIPIX_CONFIGURE_ARGS="-C --disable-nls --host=${DEFAULT_TARGET} --prefix= --program-prefix= --target=${DEFAULT_TARGET}"; MINIPIX_GROUP_DEPENDS="host_deps host_deps_rpm host_toolchain host_tools native_packages native_toolchain native_tools"; diff --git a/groups/dev_packages.group b/groups/dev_packages.group index fc9e406..a141a7a 100644 --- a/groups/dev_packages.group +++ b/groups/dev_packages.group @@ -2,8 +2,8 @@ # Build group dev_packages # GROUP_AUTO=0; -DEV_PACKAGES_CFLAGS_CONFIGURE="$(rtl_lconcat "${DEFAULT_CFLAGS}" "--sysroot=${PREFIX_NATIVE}")"; -DEV_PACKAGES_CXXFLAGS_CONFIGURE="$(rtl_lconcat "${DEFAULT_CXXFLAGS}" "--sysroot=${PREFIX_NATIVE}")"; +rtl_lconcat2 \$DEV_PACKAGES_CFLAGS_CONFIGURE \$DEFAULT_CFLAGS "--sysroot=${PREFIX_NATIVE}"; +rtl_lconcat2 \$DEV_PACKAGES_CXXFLAGS_CONFIGURE \$DEFAULT_CXXFLAGS "--sysroot=${PREFIX_NATIVE}"; DEV_PACKAGES_CONFIG_CACHE_LOCAL="${CONFIG_CACHE_GNULIB}"; DEV_PACKAGES_CONFIGURE_ARGS="-C --disable-nls --host=${DEFAULT_TARGET} --prefix= --program-prefix= --target=${DEFAULT_TARGET}"; DEV_PACKAGES_GROUP_DEPENDS="host_deps host_deps_rpm host_toolchain host_tools native_toolchain native_tools"; diff --git a/midipix.env b/midipix.env index f49c540..6a10e53 100644 --- a/midipix.env +++ b/midipix.env @@ -100,40 +100,40 @@ https://midipix.luciaillanes.de/repos_git/ \ : ${DEFAULT_CFLAGS_RELEASE:="-D_REDIR_TIME64=0 -g0 -O0"}; : ${DEFAULT_CFLAGS_RELEASE_HOST:="-D_REDIR_TIME64=0 -g0 -O0"}; : ${DEFAULT_CFLAGS_RELEASE_RUNTIME:="-D_REDIR_TIME64=0 -g0 -O0"}; -: ${DEFAULT_CFLAGS:=$(rtl_get_var_unsafe "DEFAULT_CFLAGS_$(rtl_toupper "${BUILD_KIND}")")}; +rtl_get_var_unsafe \$DEFAULT_CFLAGS -u "DEFAULT_CFLAGS_${BUILD_KIND}"; : ${DEFAULT_CFLAGS_CONFIGURE:=${DEFAULT_CFLAGS}}; -: ${DEFAULT_CFLAGS_HOST:=$(rtl_get_var_unsafe "DEFAULT_CFLAGS_$(rtl_toupper "${BUILD_KIND}")_HOST")}; -: ${DEFAULT_CFLAGS_RUNTIME:=$(rtl_get_var_unsafe "DEFAULT_CFLAGS_$(rtl_toupper "${BUILD_KIND}")_RUNTIME")}; +rtl_get_var_unsafe \$DEFAULT_CFLAGS_HOST -u "DEFAULT_CFLAGS_${BUILD_KIND}_HOST"; +rtl_get_var_unsafe \$DEFAULT_CFLAGS_RUNTIME -u "DEFAULT_CFLAGS_${BUILD_KIND}_RUNTIME"; : ${DEFAULT_CPPFLAGS_DEBUG:="-D_REDIR_TIME64=0 -g2 -O0"}; : ${DEFAULT_CPPFLAGS_DEBUG_HOST:="-D_REDIR_TIME64=0 -g0 -O2"}; : ${DEFAULT_CPPFLAGS_DEBUG_RUNTIME:="-D_REDIR_TIME64=0 -g3 -O0"}; : ${DEFAULT_CPPFLAGS_RELEASE:="-D_REDIR_TIME64=0 -g0 -O0"}; : ${DEFAULT_CPPFLAGS_RELEASE_HOST:="-D_REDIR_TIME64=0 -g0 -O0"}; : ${DEFAULT_CPPFLAGS_RELEASE_RUNTIME:="-D_REDIR_TIME64=0 -g0 -O0"}; -: ${DEFAULT_CPPFLAGS:=$(rtl_get_var_unsafe "DEFAULT_CPPFLAGS_$(rtl_toupper "${BUILD_KIND}")")}; +rtl_get_var_unsafe \$DEFAULT_CPPFLAGS -u "DEFAULT_CPPFLAGS_${BUILD_KIND}"; : ${DEFAULT_CPPFLAGS_CONFIGURE:=${DEFAULT_CPPFLAGS}}; -: ${DEFAULT_CPPFLAGS_HOST:=$(rtl_get_var_unsafe "DEFAULT_CPPFLAGS_$(rtl_toupper "${BUILD_KIND}")_HOST")}; -: ${DEFAULT_CPPFLAGS_RUNTIME:=$(rtl_get_var_unsafe "DEFAULT_CPPFLAGS_$(rtl_toupper "${BUILD_KIND}")_RUNTIME")}; +rtl_get_var_unsafe \$DEFAULT_CPPFLAGS_HOST -u "DEFAULT_CPPFLAGS_${BUILD_KIND}_HOST"; +rtl_get_var_unsafe \$DEFAULT_CPPFLAGS_RUNTIME -u "DEFAULT_CPPFLAGS_${BUILD_KIND}_RUNTIME"; : ${DEFAULT_CXXFLAGS_DEBUG:="-D_REDIR_TIME64=0 -g2 -O0"}; : ${DEFAULT_CXXFLAGS_DEBUG_HOST:="-D_REDIR_TIME64=0 -g0 -O2"}; : ${DEFAULT_CXXFLAGS_DEBUG_RUNTIME:="-D_REDIR_TIME64=0 -g3 -O0"}; : ${DEFAULT_CXXFLAGS_RELEASE:="-D_REDIR_TIME64=0 -g0 -O0"}; : ${DEFAULT_CXXFLAGS_RELEASE_HOST:="-D_REDIR_TIME64=0 -g0 -O0"}; : ${DEFAULT_CXXFLAGS_RELEASE_RUNTIME:="-D_REDIR_TIME64=0 -g0 -O0"}; -: ${DEFAULT_CXXFLAGS:=$(rtl_get_var_unsafe "DEFAULT_CXXFLAGS_$(rtl_toupper "${BUILD_KIND}")")}; +rtl_get_var_unsafe \$DEFAULT_CXXFLAGS -u "DEFAULT_CXXFLAGS_${BUILD_KIND}"; : ${DEFAULT_CXXFLAGS_CONFIGURE:=${DEFAULT_CXXFLAGS}}; -: ${DEFAULT_CXXFLAGS_HOST:=$(rtl_get_var_unsafe "DEFAULT_CXXFLAGS_$(rtl_toupper "${BUILD_KIND}")_HOST")}; -: ${DEFAULT_CXXFLAGS_RUNTIME:=$(rtl_get_var_unsafe "DEFAULT_CXXFLAGS_$(rtl_toupper "${BUILD_KIND}")_RUNTIME")}; +rtl_get_var_unsafe \$DEFAULT_CXXFLAGS_HOST -u "DEFAULT_CXXFLAGS_${BUILD_KIND}_HOST"; +rtl_get_var_unsafe \$DEFAULT_CXXFLAGS_RUNTIME -u "DEFAULT_CXXFLAGS_${BUILD_KIND}_RUNTIME"; : ${DEFAULT_LDFLAGS_DEBUG:=""}; : ${DEFAULT_LDFLAGS_DEBUG_HOST:=""}; : ${DEFAULT_LDFLAGS_DEBUG_RUNTIME:=""}; : ${DEFAULT_LDFLAGS_RELEASE:=""}; : ${DEFAULT_LDFLAGS_RELEASE_HOST:=""}; : ${DEFAULT_LDFLAGS_RELEASE_RUNTIME:=""}; -: ${DEFAULT_LDFLAGS:=$(rtl_get_var_unsafe "DEFAULT_LDFLAGS_$(rtl_toupper "${BUILD_KIND}")")}; +rtl_get_var_unsafe \$DEFAULT_LDFLAGS -u "DEFAULT_LDFLAGS_${BUILD_KIND}"; : ${DEFAULT_LDFLAGS_CONFIGURE:=${DEFAULT_LDFLAGS}}; -: ${DEFAULT_LDFLAGS_HOST:=$(rtl_get_var_unsafe "DEFAULT_LDFLAGS_$(rtl_toupper "${BUILD_KIND}")_HOST")}; -: ${DEFAULT_LDFLAGS_RUNTIME:=$(rtl_get_var_unsafe "DEFAULT_LDFLAGS_$(rtl_toupper "${BUILD_KIND}")_RUNTIME")}; +rtl_get_var_unsafe \$DEFAULT_LDFLAGS_HOST -u "DEFAULT_LDFLAGS_${BUILD_KIND}_HOST"; +rtl_get_var_unsafe \$DEFAULT_LDFLAGS_RUNTIME -u "DEFAULT_LDFLAGS_${BUILD_KIND}_RUNTIME"; # # Target-relative toolchain defaults diff --git a/pkgtool.sh b/pkgtool.sh index af911ec..9d7465d 100755 --- a/pkgtool.sh +++ b/pkgtool.sh @@ -2,299 +2,476 @@ # Copyright (c) 2020, 2021 Lucía Andrea Illanes Albornoz # +# {{{ pkgtoolp_init($_rstatus) +pkgtoolp_init() { + local _pi_rstatus="${1#\$}" \ + _pi_args_long="" \ + _pi_name_base="pkgtool" \ + _pi_optstring="a:b:him:M:rRtv" \ + _pi_prereqs=" + awk bzip2 cat chmod cp date find grep hostname mkdir + mktemp mv paste printf readlink rm sed sort tar test + touch tr uniq" \ + _pi_fname="" _pi_rc=0; + shift; + + if ! . "${0%/*}/subr.ex/ex_init.subr"; then + _pi_rc=1; + _pi_status='failed to source \`'"${0%/*}/subr/ex_init.subr"\'; + eval ${_pi_rstatus}=\"${_pi_status}\"; + elif ! ex_init_help \ + "${_pi_rstatus}" "${_pi_args_long}" \ + "${_pi_name_base}" "${_pi_optstring}" "${@}" \ + || ! ex_init_env \ + "${_pi_rstatus}" \$BUILD_HNAME \$BUILD_USER \ + "${_pi_name_base}" \ + || ! ex_init_getopts \ + "${_pi_rstatus}" "pkgtoolp_init_getopts_fn" \ + "${_pi_optstring}" "${@}" \ + || ! ex_init_prereqs "${_pi_rstatus}" "${_pi_prereqs}" \ + || ! ex_pkg_load_vars "${_pi_rstatus}" \ + || ! pkgtoolp_init_args "${_pi_rstatus}"; + then + _pi_rc=1; + fi; + return "${_pi_rc}"; +}; +# }}} +# {{{ pkgtoolp_init_args($_rstatus) +pkgtoolp_init_args() { + local _ppia_rstatus="${1#\$}" \ + _ppia_rc=0; + + if [ "$((${ARG_INFO:-0} + + ${ARG_MIRROR:-0} + + ${ARG_RDEPENDS:-0} + + ${ARG_RDEPENDS_FULL:-0} + + ${ARG_TARBALL:-0}))" -gt 1 ]; + then + cat etc/pkgtool.usage; + _ppia_rc=1; + rtl_setrstatus "${_ppia_rstatus}" 'only one of -i, -m and/or -M, -r, -R, -s, or -t must be specified.'; + elif [ "$((${ARG_INFO:-0} + + ${ARG_MIRROR:-0} + + ${ARG_RDEPENDS:-0} + + ${ARG_RDEPENDS_FULL:-0} + + ${ARG_TARBALL:-0}))" -eq 0 ]; + then + cat etc/pkgtool.usage; + _ppia_rc=1; + rtl_setrstatus "${_ppia_rstatus}" 'one of -i, -m and/or -M, -r, -R, -s, or -t must be specified.'; + else + _ppia_rc=0; + export TMP="${BUILD_WORKDIR}" TMPDIR="${BUILD_WORKDIR}"; + fi; + + return "${_ppia_rc}"; +}; +# }}} +# {{{ pkgtoolp_init_getopts_fn(...) +pkgtoolp_init_getopts_fn() { + local _ppigf_rc=0 _ppigf_shiftfl=0; + + case "${1}" in + init) + local _ppigf_verb="${1}" _ppigf_rstatus="${2#\$}"; + + : ${ARCH:="nt64"}; + : ${BUILD_KIND:="debug"}; + + ARG_INFO=0; ARG_MIRROR=0; ARG_MIRROR_DNAME=""; ARG_MIRROR_DNAME_GIT=""; + ARG_RDEPENDS=0; ARG_RDEPENDS_FULL=0; ARG_TARBALL=0; ARG_VERBOSE=0; + ;; + + longopt) + _ppigf_rc=1; + ;; + + opt) + local _ppigf_verb="${1}" _ppigf_rstatus="${2#\$}" \ + _ppigf_opt="${3}" _ppigf_optarg="${4:-}"; + shift 4; + + case "${_ppigf_opt}" in + a) ARCH="${OPTARG}"; _ppigf_shiftfl=2; ;; + b) BUILD_KIND="${OPTARG}"; _ppigf_shiftfl=2; ;; + h) cat etc/pkgtool.usage; exit 0; ;; + i) ARG_INFO=1; _ppigf_shiftfl=1; ;; + m) ARG_MIRROR=1; ARG_MIRROR_DNAME="${OPTARG}"; _ppigf_shiftfl=2; ;; + M) ARG_MIRROR=1; ARG_MIRROR_DNAME_GIT="${OPTARG}"; _ppigf_shiftfl=2; ;; + r) ARG_RDEPENDS=1; _ppigf_shiftfl=1; ;; + R) ARG_RDEPENDS_FULL=1; _ppigf_shiftfl=1; ;; + t) ARG_TARBALL=1; _ppigf_shiftfl=1; ;; + v) ARG_VERBOSE=1; _ppigf_shiftfl=1; ;; + *) cat etc/pkgtool.usage; exit 1; ;; + esac; + ;; + + nonopt) + local _ppigf_verb="${1}" _ppigf_rstatus="${2#\$}"; + shift 2; + + case "${1}" in + *=*) rtl_set_var_unsafe "${1%%=*}" "${1#*=}"; ;; + *) PKGTOOL_PKG_NAME="${1}"; ;; + esac; + _ppigf_shiftfl=1; + ;; + + done) + local _ppigf_verb="${1}" _ppigf_rstatus="${2#\$}"; + + if [ "${PKGTOOL_PKG_NAME:+1}" != 1 ]\ + && [ "${ARG_MIRROR:-0}" -eq 0 ]; then + _ppigf_rc=1; + rtl_setrstatus "${_ppigf_rstatus}" 'missing package name.'; + else + export PKGTOOL_PKG_NAME; + case "${ARG_VERBOSE:-0}" in + + 0) rtl_log_enable_tags "${LOG_TAGS_normal}"; ;; + 1) rtl_log_enable_tags "${LOG_TAGS_verbose}"; ;; + *) _ppigf_rc=1; + rtl_setrstatus "${_ppigf_rstatus}" 'invalid verbosity level (max. -v)'; + ;; + + esac; + fi; + + if [ "${_ppigf_rc}" -ne 0 ]; then + return "${_ppigf_rc}"; + fi; + ;; + + *) + return 1; + ;; + esac; + + if [ "${_ppigf_shiftfl}" -ge 1 ]; then + return "$((${_ppigf_shiftfl} + 1))"; + else + return 0; + fi; + + return "${_ppigf_rc}"; +}; +# }}} + +# {{{ pkgtoolp_info($_rstatus, $_pkg_name) pkgtoolp_info() { - local _pkg_name="${1}" _group_name="" _pkg_name_uc="$(rtl_toupper "${1}")" _fname="" _pkg_names=""\ - _rc=0 EX_PKG_BUILD_GROUPS="" EX_PKG_DISABLED="" EX_PKG_FINISHED="" EX_PKG_NAMES=""; _status=""; - - if ! ex_pkg_load_groups; then - _rc=1; _status="Error: failed to load build groups."; - elif ! _group_name="$(ex_pkg_find_package "${EX_PKG_BUILD_GROUPS}" "${_pkg_name}")"; then - _rc=1; _status="Error: unknown package \`${_pkg_name}'."; - elif ! _pkg_names="$(ex_pkg_get_packages "${_group_name}")"; then - _rc=1; _status="Error: failed to expand package list of build group \`${_group_name}'."; + local _ppi_rstatus="${1}" _ppi_pkg_name="${2}" \ + _ppi_fname="" _ppi_group_name="" _ppi_groups="" _ppi_groups_noauto="" \ + _ppi_pkg_disabled="" _ppi_pkg_finished="" _ppi_pkg_name_uc="" \ + _ppi_pkg_names="" _ppi_rc=0; + rtl_toupper2 \$_ppi_pkg_name \$_ppi_pkg_name_uc; + + if ! ex_pkg_load_groups \$_ppi_groups \$_ppi_groups_noauto \$GROUP_AUTO \$GROUP_TARGET; then + _ppi_rc=1; + rtl_setrstatus "${_ppi_rstatus}" 'Error: failed to load build groups.'; + elif ! ex_pkg_find_package \$_ppi_group_name "${_ppi_groups}" "${_ppi_pkg_name}"; then + _ppi_rc=1; + rtl_setrstatus "${_ppi_rstatus}" 'Error: unknown package \`'"${_ppi_pkg_name}'"'.'; + elif ! ex_pkg_get_packages \$_ppi_pkg_names "${_ppi_group_name}"; then + _ppi_rc=1; + rtl_setrstatus "${_ppi_rstatus}" 'Error: failed to expand package list of build group \`'"${_ppi_group_name}'"'.'; elif ! ex_pkg_env "${DEFAULT_BUILD_STEPS}" "${DEFAULT_BUILD_VARS}"\ - "${_group_name}" 1 "${_pkg_name}" "" "${BUILD_WORKDIR}"; then - _rc=1; _status="Error: failed to set package environment for \`${_pkg_name}'."; - else _pkg_version="$(rtl_get_var_unsafe -u "PKG_"${_pkg_name}"_VERSION")"; - rtl_log_env_vars "verbose" "package" $(rtl_get_vars_fast "^PKG_${_pkg_name_uc}"); - rtl_log_msg "info" "${MSG_pkgtool_build_group}" "${_group_name}"; - if [ -z "${PKG_DEPENDS:-}" ]; then - rtl_log_msg "info" "${MSG_pkgtool_pkg_no_deps}" "${_pkg_name}"; - else rtl_log_msg "info" "${MSG_pkgtool_pkg_direct_deps}" "${_pkg_name}" "${PKG_DEPENDS}"; - if ! ex_pkg_unfold_depends 1 1 "${_group_name}" "${_pkg_names}" "${_pkg_name}" 0; then - rtl_log_msg "warning" "${MSG_pkgtool_pkg_deps_fail}" "${_pkg_name}"; - else EX_PKG_NAMES="$(rtl_lfilter "${EX_PKG_NAMES}" "${_pkg_name}")"; - if [ -n "${EX_PKG_NAMES}" ]; then + "${_ppi_group_name}" "${_ppi_pkg_name}" "" "${BUILD_WORKDIR}"; then + _ppi_rc=1; + rtl_setrstatus "${_ppi_rstatus}" 'Error: failed to set package environment for \`'"${_ppi_pkg_name}'"'.'; + else + rtl_get_var_unsafe \$_ppi_pkg_version -u "PKG_${_ppi_pkg_name}_VERSION"; + rtl_log_env_vars "verbose" "package" $(rtl_get_vars_fast "^PKG_${_ppi_pkg_name_uc}"); + rtl_log_msg "info" "${MSG_pkgtool_build_group}" "${_ppi_group_name}"; + + if [ "${PKG_DEPENDS:+1}" != 1 ]; then + rtl_log_msg "info" "${MSG_pkgtool_pkg_no_deps}" "${_ppi_pkg_name}"; + else + rtl_log_msg "info" "${MSG_pkgtool_pkg_direct_deps}" "${_ppi_pkg_name}" "${PKG_DEPENDS}"; + if ! ex_pkg_unfold_depends \ + \$_ppi_pkg_disabled \$_ppi_pkg_finished \ + \$_ppi_pkg_names 1 1 "${_ppi_group_name}" \ + "${_ppi_pkg_names}" "${_ppi_pkg_name}" 0 \ + "${BUILD_WORKDIR}"; + then + rtl_log_msg "warning" "${MSG_pkgtool_pkg_deps_fail}" "${_ppi_pkg_name}"; + else + rtl_lfilter \$_ppi_pkg_names "${_ppi_pkg_name}"; + + if [ "${_ppi_pkg_names:+1}" = 1 ]; then rtl_log_msg "info" "${MSG_pkgtool_pkg_deps_full}"\ - "${_pkg_name}" "$(rtl_lsort "${EX_PKG_NAMES}")"; + "${_ppi_pkg_name}" "$(rtl_lsort "${_ppi_pkg_names}")"; fi; - if [ -n "${EX_PKG_DISABLED}" ]; then + + if [ "${_ppi_pkg_disabled:+1}" = 1 ]; then rtl_log_msg "info" "${MSG_pkgtool_pkg_deps_full_disabled}"\ - "${_pkg_name}" "$(rtl_lsort "${EX_PKG_DISABLED}")"; + "${_ppi_pkg_name}" "$(rtl_lsort "${_ppi_pkg_disabled}")"; fi; fi; fi; + set +o noglob; - for _fname in \ - "vars/${_pkg_name}.vars" \ - "patches/${_pkg_name}/"*.patch \ - "patches/${_pkg_name}${_pkg_version:+-${_pkg_version}}.local.patch" \ - "patches/${_pkg_name}${_pkg_version:+-${_pkg_version}}.local@${BUILD_HNAME}.patch" \ - "patches/${_pkg_name}${_pkg_version:+-${_pkg_version}}_pre.local.patch" \ - "patches/${_pkg_name}${_pkg_version:+-${_pkg_version}}_pre.local@${BUILD_HNAME}.patch" \ - "${BUILD_WORKDIR}/chainport/patches/${_pkg_name%%_*}/${_pkg_name%%_*}-${_pkg_version}.midipix.patch"; do - if [ -e "${_fname}" ]; then - sha256sum "${_fname}"; + for _ppi_fname in \ + "vars/${_ppi_pkg_name}.vars" \ + "patches/${_ppi_pkg_name}/"*.patch \ + "patches/${_ppi_pkg_name}${_ppi_pkg_version:+-${_ppi_pkg_version}}.local.patch" \ + "patches/${_ppi_pkg_name}${_ppi_pkg_version:+-${_ppi_pkg_version}}.local@${BUILD_HNAME}.patch" \ + "patches/${_ppi_pkg_name}${_ppi_pkg_version:+-${_ppi_pkg_version}}_ppi_pre.local.patch" \ + "patches/${_ppi_pkg_name}${_ppi_pkg_version:+-${_ppi_pkg_version}}_ppi_pre.local@${BUILD_HNAME}.patch" \ + "${BUILD_WORKDIR}/chainport/patches/${_ppi_pkg_name%%_ppi_*}/${_ppi_pkg_name%%_ppi_*}-${_ppi_pkg_version}.midipix.patch"; + do + if [ -e "${_ppi_fname}" ]; then + sha256sum "${_ppi_fname}"; fi; done; set -o noglob; - fi; return "${_rc}"; -}; + fi; + + return "${_ppi_rc}"; +}; +# }}} +# {{{ pkgtoolp_mirror($_rstatus, $_mirror_dname, $_mirror_dname_git) pkgtoolp_mirror() { - local _mirror_dname="${1}" _mirror_dname_git="${2}" _group_name="" _pkg_name="" _pkg_parent="" _rc=0; + local _ppm_rstatus="${1}" _ppm_mirror_dname="${2}" _ppm_mirror_dname_git="${3}" \ + _ppm_group_name="" _ppm_groups="" _ppm_groups_noauto="" _ppm_pkg_name="" \ + _ppm_pkg_names="" _ppm_pkg_parent="" _ppm_rc=0; umask 022; - _mirror_dname="$(rtl_subst "${_mirror_dname}" "~" "${HOME}")"; - _mirror_dname_git="$(rtl_subst "${_mirror_dname_git}" "~" "${HOME}")"; - if ! ex_pkg_load_groups; then - _rc=1; _status="Error: failed to load build groups."; - elif [ -n "${_mirror_dname}" ]\ - && ! rtl_fileop mkdir "${_mirror_dname}"; then - _rc=1; _status="Error: failed to create \`${_mirror_dname}'."; - elif [ -n "${_mirror_dname_git}" ]\ - && ! rtl_fileop mkdir "${_mirror_dname_git}"; then - _rc=1; _status="Error: failed to create \`${_mirror_dname_git}'."; - else for _group_name in ${EX_PKG_BUILD_GROUPS}; do - for _pkg_name in $(ex_pkg_get_packages "${_group_name}"); do - _pkg_parent="$(rtl_get_var_unsafe -u "PKG_${_pkg_name}_INHERIT_FROM")"; - if ! pkgtoolp_mirror_fetch \ - "${_mirror_dname}" "${_mirror_dname_git}" "${_pkg_name}"\ - "${_pkg_parent:-${_pkg_name}}"; then - _rc=1; _status="Warning: failed to mirror one or more packages."; + rtl_subst \$_ppm_mirror_dname "~" "${HOME}"; + rtl_subst \$_ppm_mirror_dname_git "~" "${HOME}"; + + if ! ex_pkg_load_groups \$_ppm_groups \$_ppm_groups_noauto \$GROUP_AUTO \$GROUP_TARGET; then + _ppm_rc=1; + rtl_setrstatus "${_ppm_rstatus}" 'Error: failed to load build groups.'; + elif [ "${_ppm_mirror_dname:+1}" = 1 ]\ + && ! rtl_fileop mkdir "${_ppm_mirror_dname}"; then + _ppm_rc=1; + rtl_setrstatus "${_ppm_rstatus}" 'Error: failed to create \`${_ppm_mirror_dname}'"'"'.'; + elif [ "${_ppm_mirror_dname_git:+1}" = 1 ]\ + && ! rtl_fileop mkdir "${_ppm_mirror_dname_git}"; then + _ppm_rc=1; + rtl_setrstatus "${_ppm_rstatus}" 'Error: failed to create \`${_ppm_mirror_dname_git}'"'"'.'; + else + for _ppm_group_name in ${_ppm_groups}; do + ex_pkg_get_packages \$_ppm_pkg_names "${_ppm_group_name}"; + + for _ppm_pkg_name in ${_ppm_pkg_names}; do + rtl_get_var_unsafe \$_ppm_pkg_parent -u "PKG_${_ppm_pkg_name}_INHERIT_FROM"; + if ! pkgtoolp_mirror_fetch \ + "${_ppm_rstatus}" "${_ppm_mirror_dname}" \ + "${_ppm_mirror_dname_git}" "${_ppm_pkg_name}" \ + "${_ppm_pkg_parent:-${_ppm_pkg_name}}"; + then + _ppm_rc=1; + rtl_setrstatus "${_ppm_rstatus}" 'Warning: failed to mirror one or more packages.'; fi; done; done; - fi; return "${_rc}"; -}; + fi; + return "${_ppm_rc}"; +}; +# }}} +# {{{ pkgtoolp_mirror_fetch($_rstatus, $_mirror_dname, $_mirror_dname_git, $_pkg_name) pkgtoolp_mirror_fetch() { - local _mirror_dname="${1}" _mirror_dname_git="${2}" _pkg_name="${3}" _pkg_name_real="${4}"\ - _fname="" _pkg_disabled=0 _pkg_fname="" _pkg_sha256sum="" _pkg_url="" _pkg_urls_git=""\ - _rc=0; - - if _pkg_disabled="$(rtl_get_var_unsafe -u "PKG_${_pkg_name_real}_DISABLED")"\ - && [ "${_pkg_disabled:-0}" -eq 1 ]; then - rtl_log_msg "verbose" "${MSG_pkgtool_pkg_disabled}" "${_pkg_name}" "${_pkg_name_real}"; - else if _pkg_url="$(rtl_get_var_unsafe -u "PKG_${_pkg_name_real}_URL")"\ - && _pkg_sha256sum="$(rtl_get_var_unsafe -u "PKG_${_pkg_name_real}_SHA256SUM")"; then - if [ -z "${_mirror_dname}" ]; then - _rc=0; rtl_log_msg "verbose" "${MSG_pkgtool_pkg_skip_archive_mirror}" "${_pkg_name}"; - elif [ "${_pkg_name}" != "${_pkg_name_real}" ]; then - rtl_log_msg "info" "${MSG_pkgtool_pkg_archive_mirroring_parent}" "${_pkg_name}" "${_pkg_name_real}" "${_pkg_url}"; - if ! rtl_fileop ln_symbolic "${_pkg_name_real}" "${_mirror_dname}/${_pkg_name}"; then - _rc=1; rtl_log_msg "warning" "${MSG_pkgtool_pkg_link_fail}"\ - "${_mirror_dname}/${_pkg_name}" "${_pkg_name}" "${_pkg_name_real}"; + local _ppmf_rstatus="${1}" _ppmf_mirror_dname="${2}" _ppmf_mirror_dname_git="${3}" _ppmf_pkg_name="${4}" \ + _ppmf_pkg_name_real="${5}" \ + _ppmf_fname="" _ppmf_pkg_disabled=0 _ppmf_pkg_fname="" _ppmf_pkg_mirrors_git="" _ppmf_pkg_sha256sum="" \ + _ppmf_pkg_url="" _ppmf_pkg_urls_git="" _ppmf_rc=0; + + if rtl_get_var_unsafe \$_ppmf_pkg_disabled -u "PKG_${_ppmf_pkg_name_real}_DISABLED"\ + && [ "${_ppmf_pkg_disabled:-0}" -eq 1 ]; then + rtl_log_msg "verbose" "${MSG_pkgtool_pkg_disabled}" "${_ppmf_pkg_name}" "${_ppmf_pkg_name_real}"; + else + if rtl_get_var_unsafe \$_ppmf_pkg_url -u "PKG_${_ppmf_pkg_name_real}_URL"\ + && rtl_get_var_unsafe \$_ppmf_pkg_sha256sum -u "PKG_${_ppmf_pkg_name_real}_SHA256SUM"; then + if [ "${_ppmf_mirror_dname:+1}" != 1 ]; then + _ppmf_rc=0; rtl_log_msg "verbose" "${MSG_pkgtool_pkg_skip_archive_mirror}" "${_ppmf_pkg_name}"; + elif [ "${_ppmf_pkg_name}" != "${_ppmf_pkg_name_real}" ]; then + rtl_log_msg "info" "${MSG_pkgtool_pkg_archive_mirroring_parent}" "${_ppmf_pkg_name}" "${_ppmf_pkg_name_real}" "${_ppmf_pkg_url}"; + if ! rtl_fileop ln_symbolic "${_ppmf_pkg_name_real}" "${_ppmf_mirror_dname}/${_ppmf_pkg_name}"; then + _ppmf_rc=1; rtl_log_msg "warning" "${MSG_pkgtool_pkg_link_fail}"\ + "${_ppmf_mirror_dname}/${_ppmf_pkg_name}" "${_ppmf_pkg_name}" "${_ppmf_pkg_name_real}"; fi; else - if ! _pkg_fname="$(rtl_get_var_unsafe -u "PKG_${_pkg_name_real}_FNAME")"; then - _pkg_fname="${_pkg_url##*/}"; + if ! rtl_get_var_unsafe \$_ppmf_pkg_fname -u "PKG_${_ppmf_pkg_name_real}_FNAME"; then + _ppmf_pkg_fname="${_ppmf_pkg_url##*/}"; fi; - rtl_log_msg "info" "${MSG_pkgtool_pkg_archive_mirroring}" "${_pkg_name}" "${_pkg_url}"; - if ! rtl_fileop mkdir "${_mirror_dname}/${_pkg_name}"\ - || ! rtl_fetch_url_wget "${_pkg_url}" "${_pkg_sha256sum}" "${_mirror_dname}/${_pkg_name}" "${_pkg_fname}" "${_pkg_name_real}" ""; then - _rc=1; rtl_log_msg "warning" "${MSG_pkgtool_pkg_mirror_fail}" "${_pkg_name}"; + rtl_log_msg "info" "${MSG_pkgtool_pkg_archive_mirroring}" "${_ppmf_pkg_name}" "${_ppmf_pkg_url}"; + if ! rtl_fileop mkdir "${_ppmf_mirror_dname}/${_ppmf_pkg_name}"\ + || ! rtl_fetch_url_wget "${_ppmf_pkg_url}" "${_ppmf_pkg_sha256sum}" "${_ppmf_mirror_dname}/${_ppmf_pkg_name}" "${_ppmf_pkg_fname}" "${_ppmf_pkg_name_real}" ""; then + _ppmf_rc=1; rtl_log_msg "warning" "${MSG_pkgtool_pkg_mirror_fail}" "${_ppmf_pkg_name}"; else - pkg_fetch_download_clean_dlcache "${_mirror_dname}" "${_pkg_name}" "${_pkg_fname}" "${_pkg_urls_git}"; + rtl_fetch_clean_dlcache "${_ppmf_mirror_dname}" "${_ppmf_pkg_name}" "${_ppmf_pkg_fname}" "${_ppmf_pkg_urls_git}"; fi; fi; fi; - if _pkg_urls_git="$(rtl_get_var_unsafe -u "PKG_${_pkg_name_real}_URLS_GIT")"; then - if [ -z "${_mirror_dname_git}" ]; then - _rc=0; rtl_log_msg "verbose" "${MSG_pkgtool_pkg_skip_git_mirror}" "${_pkg_name}"; - elif [ "$(rtl_get_var_unsafe -u "PKG_${_pkg_name_real}_MIRRORS_GIT")" = "skip" ]; then - _rc=0; rtl_log_msg "verbose" "${MSG_pkgtool_pkg_skip_git_mirror_disabled}" "${_pkg_name}"; - elif [ "${_pkg_name}" != "${_pkg_name_real}" ]; then - rtl_log_msg "info" "${MSG_pkgtool_pkg_git_mirroring_parent}" "${_pkg_name}" "${_pkg_name_real}" "${_pkg_urls_git}"; - if ! rtl_fileop ln_symbolic "${_pkg_name_real}" "${_mirror_dname_git}/${_pkg_name}"; then - _rc=1; rtl_log_msg "warning" "${MSG_pkgtool_pkg_link_fail}"\ - "${_mirror_dname_git}/${_pkg_name}" "${_pkg_name}" "${_pkg_name_real}"; + + if rtl_get_var_unsafe \$_ppmf_pkg_urls_git -u "PKG_${_ppmf_pkg_name_real}_URLS_GIT"; then + if [ "${_ppmf_mirror_dname_git:+1}" != 1 ]; then + _ppmf_rc=0; rtl_log_msg "verbose" "${MSG_pkgtool_pkg_skip_git_mirror}" "${_ppmf_pkg_name}"; + elif rtl_get_var_unsafe \$_ppmf_pkg_mirrors_git -u "PKG_${_ppmf_pkg_name_real}_MIRRORS_GIT"\ + && [ "${_ppmf_pkg_mirrors_git}" = "skip" ]; then + _ppmf_rc=0; rtl_log_msg "verbose" "${MSG_pkgtool_pkg_skip_git_mirror_disabled}" "${_ppmf_pkg_name}"; + elif [ "${_ppmf_pkg_name}" != "${_ppmf_pkg_name_real}" ]; then + rtl_log_msg "info" "${MSG_pkgtool_pkg_git_mirroring_parent}" "${_ppmf_pkg_name}" "${_ppmf_pkg_name_real}" "${_ppmf_pkg_urls_git}"; + if ! rtl_fileop ln_symbolic "${_ppmf_pkg_name_real}" "${_ppmf_mirror_dname_git}/${_ppmf_pkg_name}"; then + _ppmf_rc=1; rtl_log_msg "warning" "${MSG_pkgtool_pkg_link_fail}"\ + "${_ppmf_mirror_dname_git}/${_ppmf_pkg_name}" "${_ppmf_pkg_name}" "${_ppmf_pkg_name_real}"; fi; else - rtl_log_msg "info" "${MSG_pkgtool_pkg_git_mirroring}" "${_pkg_name}" "${_pkg_urls_git}"; - if ! rtl_fileop mkdir "${_mirror_dname_git}/${_pkg_name}"\ - || ! rtl_fetch_mirror_urls_git "${DEFAULT_GIT_ARGS}" "${_mirror_dname_git}/${_pkg_name}" ${_pkg_urls_git}; then - _rc=1; rtl_log_msg "warning" "${MSG_pkgtool_pkg_mirror_fail}" "${_pkg_name}"; + rtl_log_msg "info" "${MSG_pkgtool_pkg_git_mirroring}" "${_ppmf_pkg_name}" "${_ppmf_pkg_urls_git}"; + if ! rtl_fileop mkdir "${_ppmf_mirror_dname_git}/${_ppmf_pkg_name}"\ + || ! rtl_fetch_mirror_urls_git "${DEFAULT_GIT_ARGS}" "${_ppmf_mirror_dname_git}/${_ppmf_pkg_name}" ${_ppmf_pkg_urls_git}; then + _ppmf_rc=1; rtl_log_msg "warning" "${MSG_pkgtool_pkg_mirror_fail}" "${_ppmf_pkg_name}"; else - pkg_fetch_download_clean_dlcache "${_mirror_dname_git}" "${_pkg_name}" "${_pkg_fname}" "${_pkg_urls_git}"; + rtl_fetch_clean_dlcache "${_ppmf_mirror_dname_git}" "${_ppmf_pkg_name}" "${_ppmf_pkg_fname}" "${_ppmf_pkg_urls_git}"; fi; fi; fi; - if [ -z "${_pkg_url}" ]\ - && [ -z "${_pkg_sha256sum}" ]\ - && [ -z "${_pkg_urls_git}" ]; then - _rc=0; rtl_log_msg "verbose" "${MSG_pkgtool_pkg_skip_no_urls}" "${_pkg_name}"; + + if [ "${_ppmf_pkg_url:+1}" != 1 ]\ + && [ "${_ppmf_pkg_sha256sum:+1}" != 1 ]\ + && [ "${_ppmf_pkg_urls_git:+1}" != 1 ]; then + _ppmf_rc=0; rtl_log_msg "verbose" "${MSG_pkgtool_pkg_skip_no_urls}" "${_ppmf_pkg_name}"; fi; - fi; return "${_rc}"; -}; + fi; -pkgtoolp_restart_at() { - local _pkg_name="${1}" _rc=0; _status=""; - - if ! ex_pkg_load_dump "${_pkg_name}" "${BUILD_WORKDIR}"; then - _rc=1; _status="${_status}"; - else case "${ARG_RESTART_AT}" in - ALL) if ! "${MIDIPIX_BUILD_PWD}/build.sh" -P -r "${_pkg_name}" -v; then - _rc=1; _status="Error: failed to run command line ${MIDIPIX_BUILD_PWD}/build.sh -P -r ${_pkg_name} -v"; - fi; ;; - *) if ! "${MIDIPIX_BUILD_PWD}/build.sh" -P -r "${_pkg_name}:${ARG_RESTART_AT}" -v; then - _rc=1; _status="Error: failed to run command line ${MIDIPIX_BUILD_PWD}/build.sh -P -r ${_pkg_name}:${ARG_RESTART_AT} -v"; - fi; ;; - esac; - fi; return "${_rc}"; + return "${_ppmf_rc}"; }; - +# }}} +# {{{ pkgtoolp_rdepends($_rstatus, $_pkg_name, $_full_rdependsfl) pkgtoolp_rdepends() { - local _pkg_name="${1}" _group_name="" _pkg_depends="" _pkg_name_rdepend="" _pkg_names=""\ - _pkg_rdepends="" _rc=0 EX_PKG_BUILD_GROUPS="" EX_PKG_DISABLED="" EX_PKG_RDEPENDS_DIRECT=""; _status=""; - - if ! ex_pkg_load_groups; then - _rc=1; _status="Error: failed to load build groups."; - elif ! _group_name="$(ex_pkg_find_package "${EX_PKG_BUILD_GROUPS}" "${_pkg_name}")"; then - _rc=1; _status="Error: unknown package \`${_pkg_name}'."; - elif ! _pkg_names="$(ex_pkg_get_packages "${_group_name}")"; then - _rc=1; _status="Error: failed to expand package list of build group \`${_group_name}'."; - elif ! ex_pkg_unfold_rdepends_direct "${_group_name}" "${_pkg_names}" "${_pkg_name}"; then - _rc=1; _status="Error: failed to unfold reverse dependency-expanded package name list for \`${_pkg_name}'."; - elif [ -z "${EX_PKG_DISABLED}" ] && [ -z "${EX_PKG_RDEPENDS_DIRECT}" ]; then - rtl_log_msg "info" "${MSG_pkgtool_pkg_deps_rev_none}" "${_pkg_name}"; - else for _pkg_name_rdepend in $(rtl_lsort "${EX_PKG_RDEPENDS_DIRECT}"); do - _pkg_rdepends="$(rtl_lconcat "${_pkg_rdepends}" "${_pkg_name_rdepend}")"; - if _pkg_depends="$(rtl_lunfold_depends 'PKG_${_name}_DEPENDS' $(rtl_get_var_unsafe -u "PKG_"${_pkg_name}"_DEPENDS"))"\ - && [ -n "${_pkg_depends}" ]; then - _pkg_rdepends="$(rtl_lconcat "${_pkg_rdepends}" "${_pkg_depends}")"; + local _ppr_rstatus="${1}" _ppr_pkg_name="${2}" _ppr_full_rdependsfl="${3}" \ + _ppr_depends="" _ppr_group_name="" _ppr_groups="" _ppr_groups_noauto="" \ + _ppr_pkg_depends="" _ppr_pkg_disabled="" _ppr_pkg_finished="" \ + _ppr_pkg_name_rdepend="" _ppr_pkg_names="" _ppr_pkg_rdepends="" \ + _ppr_pkg_rdepends_direct="" _ppr_rc=0; + + if ! ex_pkg_load_groups \$_ppr_groups \$_ppr_groups_noauto \$GROUP_AUTO \$GROUP_TARGET; then + _ppr_rc=1; + rtl_setrstatus "${_ppr_rstatus}" 'Error: failed to load build groups.'; + elif ! ex_pkg_find_package \$_ppr_group_name "${_ppr_groups}" "${_ppr_pkg_name}"; then + _ppr_rc=1; + rtl_setrstatus "${_ppr_rstatus}" 'Error: unknown package \`'"${_ppr_pkg_name}'"'.'; + elif ! ex_pkg_get_packages \$_ppr_pkg_names "${_ppr_group_name}"; then + _ppr_rc=1; + rtl_setrstatus "${_ppr_rstatus}" 'Error: failed to expand package list of build group \`'"${_ppr_group_name}'"'.'; + elif ! ex_pkg_unfold_rdepends \ + \$_ppr_pkg_disabled \$_ppr_pkg_finished \ + \$_ppr_pkg_rdepends_direct \ + "${_ppr_group_name}" "${_ppr_pkg_names}" \ + "${_ppr_pkg_name}" 1 "${BUILD_WORKDIR}"; + then + _ppr_rc=1; + rtl_setrstatus "${_ppr_rstatus}" 'Error: failed to unfold reverse dependency-expanded package name list for \`'"${_ppr_pkg_name}'"'.'; + elif [ "${_ppr_pkg_disabled:+1}" != 1 ]\ + && [ "${_ppr_pkg_finished:+1}" != 1 ]\ + && [ "${_ppr_pkg_rdepends_direct:+1}" != 1 ]; + then + rtl_log_msg "info" "${MSG_pkgtool_pkg_deps_rev_none}" "${_ppr_pkg_name}"; + else + for _ppr_pkg_name_rdepend in $(rtl_lsort \ + ${_ppr_pkg_finished} \ + ${_ppr_pkg_rdepends_direct}); + do + rtl_lconcat \$_ppr_pkg_rdepends "${_ppr_pkg_name_rdepend}"; + + if [ "${_ppr_full_rdependsfl}" -eq 1 ]; then + rtl_get_var_unsafe \$_ppr_depends -u "PKG_"${_ppr_pkg_name}"_DEPENDS"; + if rtl_lunfold_depends 'PKG_${_rld_name}_DEPENDS' \$_ppr_pkg_depends ${_ppr_depends}\ + && [ "${_ppr_pkg_depends:+1}" = 1 ]; then + rtl_lconcat \$_ppr_pkg_rdepends "${_ppr_pkg_depends}"; + fi; fi; done; - if [ -n "${_pkg_rdepends}" ]; then - rtl_log_msg "info" "${MSG_pkgtool_pkgs_deps_rev}" "${_pkg_name}" "${_pkg_rdepends}"; + + if [ "${_ppr_pkg_rdepends:+1}" = 1 ]; then + rtl_log_msg "info" "${MSG_pkgtool_pkgs_deps_rev}" "${_ppr_pkg_name}" "${_ppr_pkg_rdepends}"; fi; - if [ -n "${EX_PKG_DISABLED}" ]; then - rtl_log_msg "info" "${MSG_pkgtool_pkgs_deps_rev_disabled}" "${_pkg_name}" "$(rtl_lsort "${EX_PKG_DISABLED}")"; + + if [ "${_ppr_pkg_disabled:+1}" = 1 ]; then + rtl_log_msg "info" "${MSG_pkgtool_pkgs_deps_rev_disabled}" "${_ppr_pkg_name}" "$(rtl_lsort "${_ppr_pkg_disabled}")"; fi; - fi; return "${_rc}"; -}; + fi; -pkgtoolp_shell() { - local _pkg_name="${1}" _rc=0; _status=""; - - if ! ex_pkg_load_dump "${_pkg_name}" "${BUILD_WORKDIR}"; then - _rc=1; _status="${_status}"; - else rtl_log_env_vars "verbose" "package" $(rtl_get_vars_fast "^PKG_"); - rtl_log_msg "info" "${MSG_pkgtool_shell_env1}" "${SHELL}" "${PKG_BUILD_DIR}"; - rtl_log_msg "info" "${MSG_pkgtool_shell_env2}" "${_pkg_name}"; - rtl_log_msg "info" "${MSG_pkgtool_shell_env3}" "${_pkg_name}"; - rtl_log_msg "info" "${MSG_pkgtool_shell_env4}" "${_pkg_name}"; - export ARCH BUILD_KIND \ - BUILD_DLCACHEDIR BUILD_WORKDIR \ - MAKE="make LIBTOOL=${PKG_LIBTOOL:-slibtool}" \ - MIDIPIX_BUILD_PWD \ - PKG_NAME \ - PREFIX PREFIX_CROSS PREFIX_MINGW32 PREFIX_MINIPIX \ - PREFIX_NATIVE PREFIX_ROOT PREFIX_RPM; - D="${MIDIPIX_BUILD_PWD}/${0##*/} --update-diff" \ - R="${MIDIPIX_BUILD_PWD}/${0##*/} --restart-at ALL" \ - RS="${MIDIPIX_BUILD_PWD}/${0##*/} --restart-at " \ - "${SHELL}"; - fi; return "${_rc}"; + return "${_ppr_rc}"; }; - +# }}} +# {{{ pkgtoolp_tarball($_rstatus, $_pkg_name) pkgtoolp_tarball() { - local _pkg_name="${1}" _date="" _group_name="" _hname="" _pkg_name_full=""\ - _pkg_version="" _rc=0 _tarball_fname="" EX_PKG_BUILD_GROUPS=""; _status=""; + local _ppt_rstatus="${1}" _ppt_pkg_name="${2}" \ + _ppt_date="" _ppt_group_name="" _ppt_groups="" _ppt_groups_noauto="" \ + _ppt_hname="" _ppt_pkg_name_full="" _ppt_pkg_version="" _ppt_rc=0 \ + _ppt_tarball_fname=""; - if ! ex_pkg_load_groups; then - _rc=1; _status="Error: failed to load build groups."; - elif ! _group_name="$(ex_pkg_find_package "${EX_PKG_BUILD_GROUPS}" "${_pkg_name}")"; then - _rc=1; _status="Error: unknown package \`${_pkg_name}'."; + if ! ex_pkg_load_groups \$_ppt_groups \$_ppt_groups_noauto \$GROUP_AUTO \$GROUP_TARGET; then + _ppt_rc=1; + rtl_setrstatus "${_ppt_rstatus}" 'Error: failed to load build groups.'; + elif ! ex_pkg_find_package \$_ppt_group_name "${_ppt_groups}" "${_ppt_pkg_name}"; then + _ppt_rc=1; + rtl_setrstatus "${_ppt_rstatus}" 'Error: unknown package \`'"${_ppt_pkg_name}'"'.'; elif ! ex_pkg_env "${DEFAULT_BUILD_STEPS}" "${DEFAULT_BUILD_VARS}" \ - "${_group_name}" 0 "${_pkg_name}" "" "${BUILD_WORKDIR}"; then - _rc=1; _status="Error: failed to set package environment for \`${_pkg_name}'."; - elif ! _date="$(date +%Y%m%d_%H%M%S)"; then - _rc=1; _status="Error: failed to call date(1)."; - elif ! _hname="$(hostname -f)"; then - _rc=1; _status="Error: failed to call hostname(1)."; - else if [ -n "${PKG_VERSION}" ]; then - _pkg_name_full="${_pkg_name}-${PKG_VERSION}"; + "${_ppt_group_name}" 0 "${_ppt_pkg_name}" "" "${BUILD_WORKDIR}"; + then + _ppt_rc=1; + rtl_setrstatus "${_ppt_rstatus}" 'Error: failed to set package environment for \`'"${_ppt_pkg_name}'"'.'; + elif ! _ppt_date="$(date +%Y%m%d_%H%M%S)"; then + _ppt_rc=1; + rtl_setrstatus "${_ppt_rstatus}" 'Error: failed to call date(1).'; + elif ! _ppt_hname="$(hostname -f)"; then + _ppt_rc=1; + rtl_setrstatus "${_ppt_rstatus}" 'Error: failed to call hostname(1).'; + else + if [ "${PKG_VERSION:+1}" = 1 ]; then + _ppt_pkg_name_full="${_ppt_pkg_name}-${PKG_VERSION}"; else - _pkg_name_full="${_pkg_name}"; + _ppt_pkg_name_full="${_ppt_pkg_name}"; fi; - _tarball_fname="${_pkg_name_full}@${_hname}-${_date}.tbz2"; - rtl_log_msg "info" "${MSG_pkgtool_tarball_creating}" "${PKG_BASE_DIR}" "${_pkg_name}"; - if ! tar -C "${BUILD_WORKDIR}" -cpf - \ - "${PKG_BASE_DIR#${BUILD_WORKDIR%/}/}" \ - "${_pkg_name}_stderrout.log" |\ - bzip2 -c -9 - > "${_tarball_fname}"; then - _rc=1; _status="Error: failed to create compressed tarball of \`${PKG_BASE_DIR}' and \`${_pkg_name}_stderrout.log'."; - else - rtl_log_msg "info" "${MSG_pkgtool_tarball_created}" "${PKG_BASE_DIR}" "${_pkg_name}"; - fi; - fi; return "${_rc}"; -}; -pkgtoolp_update_diff() { - local _pkg_name="${1}" _diff_fname_dst="" _diff_fname_src="" _fname=""\ - _fname_base="" _rc=0; _status=""; + _ppt_tarball_fname="${_ppt_pkg_name_full}@${_ppt_hname}-${_ppt_date}.tbz2"; + rtl_log_msg "info" "${MSG_pkgtool_tarball_creating}" "${PKG_BASE_DIR}" "${_ppt_pkg_name}"; - if ! ex_pkg_load_dump "${_pkg_name}" "${BUILD_WORKDIR}"; then - _rc=1; _status="${_status}"; - else if [ -n "${PKG_VERSION}" ]; then - _diff_fname_dst="${_pkg_name}-${PKG_VERSION}.local.patch"; + if ! tar -C "${BUILD_WORKDIR}" -cpf - \ + "${PKG_BASE_DIR#${BUILD_WORKDIR%/}/}" \ + "${_ppt_pkg_name}_stderrout.log" |\ + bzip2 -c -9 - > "${_ppt_tarball_fname}"; + then + _ppt_rc=1; + rtl_setrstatus "${_ppt_rstatus}" 'Error: failed to create compressed tarball of \`'"${PKG_BASE_DIR}'"' and \`'"${_ppt_pkg_name}"'_stderrout.log'"'"'.'; else - _diff_fname_dst="${_pkg_name}.local.patch"; - fi; - if ! _diff_fname_src="$(mktemp)"; then - _rc=1; _status="Error: failed to create temporary target diff(1) file."; - else trap "rm -f \"${_diff_fname_src}\" >/dev/null 2>&1" EXIT HUP INT TERM USR1 USR2; - (cd "${PKG_BASE_DIR}" && printf "" > "${_diff_fname_src}"; - for _fname in $(find "${PKG_SUBDIR}" -iname \*.orig); do - _fname_base="${_fname##*/}"; _fname_base="${_fname_base%.orig}"; - case "${_fname_base}" in - config.sub) - continue; ;; - *) diff -u "${_fname}" "${_fname%.orig}" >> "${_diff_fname_src}"; ;; - esac; - done); - if [ "${?}" -ne 0 ]; then - _rc=1; _status="Error: failed to create diff(1)."; - elif ! rtl_fileop mv "${_diff_fname_src}" "${MIDIPIX_BUILD_PWD}/patches/${_diff_fname_dst}"; then - _rc=1; _status="Error: failed to rename diff(1) to \`${MIDIPIX_BUILD_PWD}/patches/${_diff_fname_dst}'."; - else trap - EXIT HUP INT TERM USR1 USR2; - rtl_log_msg "info" "${MSG_pkgtool_updated_patches}" "${MIDIPIX_BUILD_PWD}" "${_diff_fname_dst}"; - fi; + rtl_log_msg "info" "${MSG_pkgtool_tarball_created}" "${PKG_BASE_DIR}" "${_ppt_pkg_name}"; fi; - fi; return "${_rc}"; + fi; + + return "${_ppt_rc}"; }; +# }}} pkgtool() { - local _rc=0 _status="" BUILD_GROUPS="" ARCH BUILD_KIND BUILD_WORKDIR PKGTOOL_PKGNAME PREFIX; - - if ! . "${0%/*}/subr/pkgtool_init.subr"; then - _rc=1; printf "Error: failed to source \`${0%/*}/subr/pkgtool_init.subr'." >&2; - elif ! pkgtool_init "${@}"; then - _rc=1; _status="${_status}"; - else case "1" in - "${ARG_INFO:-0}") pkgtoolp_info "${PKGTOOL_PKG_NAME}"; ;; - "${ARG_MIRROR:-0}") pkgtoolp_mirror "${ARG_MIRROR_DNAME}" "${ARG_MIRROR_DNAME_GIT}"; ;; - "${ARG_RDEPENDS:-0}") pkgtoolp_rdepends "${PKGTOOL_PKG_NAME}"; ;; - "${ARG_RESTART_AT:+1}") pkgtoolp_restart_at "${PKGTOOL_PKG_NAME}"; ;; - "${ARG_SHELL:-0}") pkgtoolp_shell "${PKGTOOL_PKG_NAME}"; ;; - "${ARG_TARBALL:-0}") pkgtoolp_tarball "${PKGTOOL_PKG_NAME}"; ;; - "${ARG_UPDATE_DIFF:-0}") pkgtoolp_update_diff "${PKGTOOL_PKG_NAME}"; ;; + local _rc=0 _status="" \ + BUILD_GROUPS="" ARCH BUILD_KIND \ + BUILD_WORKDIR PKGTOOL_PKGNAME PREFIX; + + if ! pkgtoolp_init \$_status "${@}"; then + _rc=1; + _status="Error: ${_status}"; + else + case "1" in + "${ARG_INFO:-0}") pkgtoolp_info \$_status "${PKGTOOL_PKG_NAME}"; ;; + "${ARG_MIRROR:-0}") pkgtoolp_mirror \$_status "${ARG_MIRROR_DNAME}" "${ARG_MIRROR_DNAME_GIT}"; ;; + "${ARG_RDEPENDS:-0}") pkgtoolp_rdepends \$_status "${PKGTOOL_PKG_NAME}" 0; ;; + "${ARG_RDEPENDS_FULL:-0}") pkgtoolp_rdepends \$_status "${PKGTOOL_PKG_NAME}" 1; ;; + "${ARG_TARBALL:-0}") pkgtoolp_tarball \$_status "${PKGTOOL_PKG_NAME}"; ;; esac; _rc="${?}"; fi; + if [ "${_rc}" -ne 0 ]; then + rtl_log_enable_tags "${LOG_TAGS_all}"; rtl_log_msg "fatalexit" "0;${_status}"; - elif [ -n "${_status}" ]; then + elif [ "${_status:+1}" = 1 ]; then + rtl_log_enable_tags "${LOG_TAGS_all}"; rtl_log_msg "info" "0;${_status}"; fi; }; diff --git a/subr.ex/ex_init.subr b/subr.ex/ex_init.subr new file mode 100644 index 0000000..9f5462b --- /dev/null +++ b/subr.ex/ex_init.subr @@ -0,0 +1,397 @@ +# +# set +o errexit -o noglob -o nounset is assumed. +# + +exp_setrstatus() { + local _epsrs_rstatus="${1#\$}" _epsrs_status="${2}"; + eval ${_epsrs_rstatus}=\"${_epsrs_status}\"; + return 0; +}; + +# +# ex_init_env() - initialise build environment +# @_rstatus: reference to out variable of status string on failure +# @_rhname: reference to out variable of build hostname +# @_ruser: reference to out variable of build user +# @_name_base: base name for messages and theme file(s) +# +# Return: zero (0) on success, non-zero (>0) on failure +# +ex_init_env() { + local _eie_rstatus="${1#\$}" _eie_rhname="${2#\$}" _eie_ruser="${3#\$}" \ + _eie_name_base="${4}" \ + _eie_fname="" _eie_lang="${LANG:-C}" _eie_lang_="" _eie_name="" \ + _eie_rc=0; + _eie_lang="${_eie_lang%%_*}"; + + if ! cd "${0%/*}"; then + _eie_rc=1; + exp_setrstatus "${_eie_rstatus}" 'failed to change working directory to \`'"${0%/*}"''\''.'; + elif ! umask 022; then + _eie_rc=1; + exp_setrstatus "${_eie_rstatus}" 'failed to set umask(2).'; + elif ! eval ${_eie_rhname}=\"\$\(hostname\)\"; then + _eie_rc=1; + exp_setrstatus "${_eie_rstatus}" 'failed to obtain hostname.'; + elif ! eval ${_eie_ruser}=\"\$\(id -nu\)\"; then + _eie_rc=1; + exp_setrstatus "${_eie_rstatus}" 'failed to obtain username.'; + else + for _eie_fname in \ + $(find subr.ex -name *.subr) \ + $(find subr.pkg -name *.subr) \ + $(find subr.rtl -name *.subr) \ + "etc/${_eie_name_base}.theme" \ + ; + do + if ! . "${_eie_fname}"; then + _eie_rc=1; + exp_setrstatus "${_eie_rstatus}" 'failed to source \`'"${_eie_fname}"''\''.'; + break; + fi; + done; + + if [ "${_eie_rc}" -eq 0 ]; then + if [ -e "${_eie_name_base}.local" ]; then + if ! . "${_eie_name_base}.local"; then + _eie_rc=1; + exp_setrstatus "${_eie_rstatus}" 'failed to source \`'"${_eie_name_base}"'.local'\''.'; + fi; + fi; + fi; + + if [ "${_eie_rc}" -eq 0 ]; then + for _eie_name in ${_eie_name_base} rtl; do + for _eie_lang_ in ${_eie_lang} C; do + _eie_fname="etc/${_eie_name}.msgs.${_eie_lang_}"; + if [ -e "${_eie_fname}" ]; then + if ! . "${_eie_fname}"; then + _eie_rc=1; + exp_setrstatus "${_eie_rstatus}" 'failed to source \`'"${_eie_fname}"''\''.'; + break; + fi; + + if [ -e "${_eie_fname}.local" ]; then + if ! . "${_eie_fname}.local"; then + _eie_rc=1; + exp_setrstatus "${_eie_rstatus}" 'failed to source \`'"${_eie_fname}"'.local'\''.'; + fi; + fi; + break; + fi; + done; + + if [ "${_eie_rc}" -ne 0 ]; then + break; + fi; + done; + fi; + fi; + export LANG=C LC_ALL=C; + + return "${_eie_rc}"; +}; + +# +# ex_init_getopts() - process command-line arguments +# @_rstatus: reference to out variable of status string on failure +# @_fn: reference to function called to process command-line argument +# @_optstring: getopts(1) optstring +# @...: command-line arguments as "${@}" +# +# Return: zero (0) on success, non-zero (>0) on failure +# +ex_init_getopts() { + local _eig_rstatus="${1#\$}" _eig_fn="${2}" _eig_optstring="${3}" \ + _eig_arg="" _eig_fn_rc=0 _eig_opt="" _eig_shiftfl=0 \ + OPTARG="" OPTIND=0; + shift 3; + + if ! "${_eig_fn}" init "${_eig_rstatus}"; then + return 1; + fi; + + while [ "${#}" -gt 0 ]; do + case "${1}" in + --*) + "${_eig_fn}" longopt "${_eig_rstatus}" "${1}"; + _eig_fn_rc="${?}"; + + case "${_eig_fn_rc}" in + 0) ;; + 1) return 1; ;; + + *) shift "$((${_eig_fn_rc} - 1))"; + continue; ;; + esac; + ;; + esac; + + if getopts "${_eig_optstring}" _eig_opt; then + "${_eig_fn}" opt "${_eig_rstatus}" "${_eig_opt}" "${OPTARG:-}" "${@}"; + _eig_fn_rc="${?}"; + + case "${_eig_fn_rc}" in + 0) ;; + 1) return 1; ;; + + *) shift "$((${_eig_fn_rc} - 1))"; + continue; ;; + esac; + else + "${_eig_fn}" nonopt "${_eig_rstatus}" "${@}"; + _eig_fn_rc="${?}"; + + case "${_eig_fn_rc}" in + 0) ;; + 1) return 1; ;; + + *) shift "$((${_eig_fn_rc} - 1))"; + continue; ;; + esac; + fi; + done; + + if ! "${_eig_fn}" done "${_eig_rstatus}"; then + return 1; + fi; + + return 0; +}; + +# +# ex_init_help() - display usage screen and exit if requested in command-line arguments +# @_rstatus: reference to out variable of status string on failure +# @_args_long: optional list of long (prefixed with `--') arguments +# @_name_base: base name for usage screen file +# @_optstring: getopts(1) optstring +# +# Return: zero (0) on success, non-zero (>0) on failure +# +ex_init_help() { + local _eih_rstatus="${1#\$}" _eih_args_long="${2}" \ + _eih_name_base="${3}" _eih_optstring="${4}" \ + _eih_arg_long="" _eih_opt="" _eih_shiftfl=0; + shift 4; + + while [ "${#}" -gt 0 ]; do + case "${1}" in + -h|--help) + if [ -t 1 ]; then + cat "etc/${_eih_name_base}.usage"; + else + sed 's/\[[0-9]\+m//g' "etc/${_eih_name_base}.usage"; + fi; + exit 0; + ;; + + *=*) shift; continue; + ;; + + *) _eih_shiftfl=0; + for _eih_arg_long in ${_eih_args_long}; do + if [ "${_eih_arg_long}" = "${1}" ]; then + _eih_shiftfl=1; + fi; + done; + if [ "${_eih_shiftfl}" = 1 ]; then + shift; continue; + fi; + ;; + esac; + + if getopts "${_eih_optstring}" _eih_opt 2>/dev/null; then + case "${_eih_opt}" in + h) + if [ -t 1 ]; then + cat "etc/${_eih_name_base}.usage"; + else + sed 's/\[[0-9]\+m//g' "etc/${_eih_name_base}.usage"; + fi; + exit 0; + ;; + esac; + shift $((${OPTIND}-1)); OPTIND=1; + else + shift; + fi; + done; + + return 0; +}; + +# +# ex_init_files() - initialise build files +# @_rstatus: reference to out variable of status string on failure +# @_rclean_builds: reference to in variable of -C argument value +# @_rdist: reference to in variable of -D argument value +# @_build_log_fname: absolute pathname to build log file +# @_build_log_last_fname: absolute pathname to last build log file +# @_build_status_in_progress_fname: absolute pathname to build-in-progress status file +# @_check_path_vars: list of pathname variables to check +# @_clear_env_vars_except: list of environment variables to not unset when clearing the environment +# @_clear_prefix_paths: list of directory pathnames to clear in the top-level prefix +# @_dlcachedir: absolute pathname to download cache directory +# @_prefix: absolute pathname to top-level prefix +# @_prefix_rpm: absolute pathname to RPM files prefix +# @_workdir: absolute pathname to build-specific temporary directory +# +# Return: zero (0) on success, non-zero (>0) on failure +# +ex_init_files() { + local _eif_rstatus="${1#\$}" _eif_rclean_builds="${2#\$}" _eif_rdist="${3#\$}" \ + _eif_build_log_fname="${4}" _eif_build_log_last_fname="${5}" \ + _eif_build_status_in_progress_fname="${6}" _eif_check_path_vars="${7}" \ + _eif_clear_env_vars_except="${8}" _eif_clear_prefix_paths="${9}" \ + _eif_dlcachedir="${10}" _eif_prefix="${11}" _eif_prefix_rpm="${12}" \ + _eif_workdir="${13}" \ + _eif_log_last_fname="" _eif_log_last_num=1 _eif_rc=0; + + if ! rtl_fileop mkdir "${_eif_dlcachedir}" "${_eif_workdir}"\ + || rtl_lmatch "${_eif_rdist}" "rpm" ","\ + && ! rtl_fileop mkdir "${_eif_prefix_rpm}"; then + _eif_rc=1; + rtl_setrstatus "${_eif_rstatus}" 'cannot create build directories.'; + elif [ -e "${_eif_build_status_in_progress_fname}" ]; then + _eif_rc=1; + rtl_setrstatus "${_eif_rstatus}" 'another build targeting this architecture and build type is currently in progress.'; + elif ! rtl_clean_env "${_eif_clear_env_vars_except}"; then + _eif_rc=1; + rtl_setrstatus "${_eif_rstatus}" 'failed to clean environment.'; + elif ! rtl_check_path_vars "${_eif_rstatus}" "${_eif_check_path_vars}"; then + _eif_rc=1; + else + export TMP="${_eif_workdir}" TMPDIR="${_eif_workdir}"; + touch "${_eif_build_status_in_progress_fname}"; + + if [ -e "${_eif_build_log_fname}" ]; then + while [ -e "${_eif_build_log_fname}.${_eif_log_last_num}" ]; do + : $((_eif_log_last_num+=1)); + done; + + _eif_log_last_fname="${_eif_build_log_fname}.${_eif_log_last_num}"; + rtl_fileop mv "${_eif_build_log_fname}" "${_eif_log_last_fname}"; + rtl_fileop ln_symbolic "${_eif_log_last_fname}" "${_eif_build_log_last_fname}"; + fi; + + rtl_fileop touch "${_eif_build_log_fname}"; rtl_log_set_fname "${_eif_build_log_fname}"; + if rtl_lmatch "${_eif_rclean_builds}" $"prefix" ","; then + trap "rm -f \"${_eif_build_status_in_progress_fname}\" 2>/dev/null; + + rtl_log_msg \"fatalexit\" \"${MSG_build_aborted}\"" HUP INT TERM USR1 USR2; + rtl_log_msg "info" "${MSG_build_clean_prefix}"; + + for _eif_pname in ${_eif_clear_prefix_paths}; do + if ! rtl_fileop rm "${_eif_prefix}/${_eif_pname}"; then + _eif_rc=1; + rtl_setrstatus "${_eif_rstatus}" 'failed to remove \`'"${_eif_prefix:+${_eif_prefix}/}${_eif_pname}'"'.'; + break; + fi; + done; + + trap - HUP INT TERM USR1 USR2; + fi; + + export PATH="${_eif_prefix}/bin${PATH:+:${PATH}}"; + fi; + + return "${_eif_rc}"; +}; + +# +# ex_init_logging() - initialise build logging +# @_rstatus: reference to out variable of status string on failure +# @_rverbose_tags: reference to inout variable of -V argument value +# @_verbose: -[vV] argument value +# +# Return: zero (0) on success, non-zero (>0) on failure +# +ex_init_logging() { + local _eil_rstatus="${1#\$}" _eil_rverbose_tags="${2#\$}" _eil_verbose="${3}" \ + _eil_tag="" _eil_tags="" _eil_tags_enable="" _eil_rc=0; + + rtl_log_clear_tags; + case "${_eil_verbose}" in + + 0) if eval [ \"\${#${_eil_rverbose_tags}}\" -eq 0 ]; then + rtl_log_enable_tags "${LOG_TAGS_normal}"; + fi; + ;; + + 1) rtl_log_enable_tags "${LOG_TAGS_verbose}"; ;; + + *) _eil_rc=1; + rtl_setrstatus "${_eil_rstatus}" 'invalid verbosity level (max. -v)'; + ;; + + esac; + + if [ "${_eil_rc}" -eq 0 ]; then + eval _eil_tags="\${${_eil_rverbose_tags}}"; + case "${_eil_tags}" in + + +*) rtl_log_enable_tags "${LOG_TAGS_normal}"; + eval ${_eil_rverbose_tags}="\${${_eil_rverbose_tags}#+}"; + ;; + + *) ;; + + esac; + + rtl_llift2 "${_eil_rverbose_tags}" \$_eil_tags "," " "; + + for _eil_tag in ${_eil_tags}; do + case "${_eil_tag}" in + + all) rtl_log_enable_tags "${LOG_TAGS_all}"; ;; + + clear|none) rtl_log_clear_tags; ;; + + normal) rtl_log_enable_tags "${LOG_TAGS_normal}"; ;; + + verbose) rtl_log_enable_tags "${LOG_TAGS_verbose}"; ;; + + *) rtl_lsearch_patternl2 \$LOG_TAGS_all \$_eil_tags_enable "${_eil_tag}" ","; + if [ "${#_eil_tags_enable}" -gt 0 ]; then + rtl_log_enable_tags "${_eil_tags_enable}"; + else + _eil_rc=1; + rtl_setrstatus "${_eil_rstatus}" 'invalid log tag or tag pattern \`'"${_eil_tag}"''\''.'; + break; + fi; + ;; + + esac; + done; + fi; + + return "${_eil_rc}"; +}; + +# +# ex_init_prereqs() - initialise build prerequisite commands +# @_rstatus: reference to out variable of status string on failure +# @_prereqs: list of prerequisite commands +# +# Return: zero (0) on success, non-zero (>0) on failure +# +ex_init_prereqs() { + local _eip_rstatus="${1#\$}" _eip_prereqs="${2}" \ + _eip_rc=0; + + if ! rtl_check_prereqs "${_eip_rstatus}" ${_eip_prereqs}; then + _eip_rc=1; + elif ! awk -V 2>/dev/null | grep -q "^GNU Awk "; then + _eip_rc=1; + rtl_setrstatus "${_eip_rstatus}" 'awk(1) in \$PATH must be GNU Awk.'; + elif ! (FNAME="$(mktemp)" && { trap "rm -f \"\${FNAME}\"" EXIT; \ + sed -i'' -e '' "${FNAME}" >/dev/null 2>&1; }); + then + _eip_rc=1; + rtl_setrstatus "${_eip_rstatus}" 'sed(1) in \${PATH} does not support the \`-i'\'' option.'; + fi; + + return "${_eip_rc}"; +}; + +# vim:filetype=sh textwidth=0 diff --git a/subr.ex/ex_pkg.subr b/subr.ex/ex_pkg.subr new file mode 100644 index 0000000..6a5670b --- /dev/null +++ b/subr.ex/ex_pkg.subr @@ -0,0 +1,324 @@ +# +# set +o errexit -o noglob -o nounset is assumed. +# + +# +# ex_pkg_check_depends() - check single named package for unsatisfied dependencies +# @_checkfl: enable (1) or inhibit (0) dependency expansion +# @_rpkg_disabled: reference to in variable of list of disabled packages +# @_rpkg_finished: reference to in variable of list of finished packages +# @_pkg_name: single package name +# @_rpkg_names: reference to in variable of list of package names +# @_workdir: pathname to build-specific temporary directory +# +# Return: zero (0) given no outstanding dependencies, non-zero (>0) otherwise +# Side effects: ${PKG_${_PKG_NAME}_DEPENDS_FULL} may be mutated +# +ex_pkg_check_depends() { + local _epcd_checkfl="${1}" _epcd_rpkg_disabled="${2}" _epcd_rpkg_finished="${3#\$}" \ + _epcd_pkg_name="${4}" _epcd_rpkg_names="${5#\$}" _epcd_workdir="${6}" \ + _epcd_dependfl=0 _epcd_depends="" _epcd_pkg_name_depend=""; + + if [ "${_epcd_checkfl}" -eq 1 ]; then + if ! rtl_get_var_unsafe \$_epcd_depends -u "PKG_"${_epcd_pkg_name}"_DEPENDS_FULL"\ + || [ "${_epcd_depends:+1}" != 1 ]; + then + if rtl_get_var_unsafe \$_epcd_depends -u "PKG_"${_epcd_pkg_name}"_DEPENDS"; + then + eval PKG_"${_epcd_pkg_name}"_DEPENDS_FULL='$(rtl_uniq ${_epcd_depends})'; + else + return 0; + fi; + fi; + + for _epcd_pkg_name_depend in ${_epcd_depends}; do + if ! rtl_lmatch "${_epcd_rpkg_disabled}" "${_epcd_pkg_name_depend}"\ + && ! rtl_lmatch "${_epcd_rpkg_finished}" "${_epcd_pkg_name_depend}"\ + && ! ex_pkg_state_test2 "${_epcd_workdir}" "${_epcd_pkg_name_depend}" finish; + then + if ! rtl_lmatch "${_epcd_rpkg_names}" "${_epcd_pkg_name_depend}"; then + rtl_log_msg "fatalexit" "${MSG_build_unknown_dep}" "${_epcd_pkg_name_depend}" "${_epcd_pkg_name}"; + else + _epcd_dependfl=1; break; + fi; + fi; + done; + fi; + + return "${_epcd_dependfl}"; +}; + +# +# ex_pkg_find_package() - find build group a single named package belongs to +# @_rgroup_name: reference to out variable of build group name +# @_group_names: build group names +# @_pkg_name: single named package +# +# Return: zero (0) on success, non-zero (>0) if package not found, group name on stdout if package was found. +# +ex_pkg_find_package() { + local _epfp_rgroup_name="${1#\$}" _epfp_group_names="${2}" _epfp_pkg_name="${3}" \ + _epfp_foundfl=0 _epfp_group_name="" _epfp_pkg_names=""; + + for _epfp_group_name in ${_epfp_group_names}; do + if rtl_get_var_unsafe \$_epfp_pkg_names -u "${_epfp_group_name}_PACKAGES"\ + && [ "${_epfp_pkg_names:+1}" = 1 ]\ + && rtl_lmatch \$_epfp_pkg_names "${_epfp_pkg_name}"; then + _epfp_foundfl=1; break; + fi; + done; + + case "${_epfp_foundfl:-0}" in + 0) eval ${_epfp_rgroup_name}=; + return 1; ;; + + 1) eval ${_epfp_rgroup_name}='${_epfp_group_name}'; + return 0; ;; + esac; +}; + +# +# ex_pkg_get_packages() - get list of packages belonging to single named build group +# @_rpkg_names: reference to out variable of package names +# @_group_name: build group name +# +# Return: zero (0) on success, non-zero (>0) on failure, list of package names on stdout on success. +# +ex_pkg_get_packages() { + local _epgp_rpkg_names="${1#\$}" _epgp_group_name="${2}" \ + _epgp_pkg_names=""; + + if rtl_get_var_unsafe \$_epgp_pkg_names -u "${_epgp_group_name}_PACKAGES"\ + && [ "${_epgp_pkg_names:+1}" = 1 ]; then + eval ${_epgp_rpkg_names}='${_epgp_pkg_names}'; + return 0; + else + eval ${_epgp_rpkg_names}=; + return 1; + fi; +}; + +# +# ex_pkg_load_vars() - load build variables +# @_rstatus: out reference to status string +# +# Return: zero (0) on success, non-zero (>0) on failure, build variables post-return on success. +# +ex_pkg_load_vars() { + local _eplv_rstatus="${1#\$}" \ + _eplv_rc=0 _eplv_fname=""; + + if ! rtl_lmatch \$ARCH "nt32 nt64"; then + _eplv_rc=1; + rtl_setrstatus "${_eplv_rstatus}" 'Error: invalid architecture \`'"${ARCH}"''\''.'; + elif ! rtl_lmatch \$BUILD_KIND "debug release"; then + _eplv_rc=1; + rtl_setrstatus "${_eplv_rstatus}" 'Error: unknown build type \`'"${BUILD_KIND}"''\''.'; + else + case "${ARCH}" in + nt32) DEFAULT_TARGET="i686-nt32-midipix"; ;; + nt64) DEFAULT_TARGET="x86_64-nt64-midipix"; ;; + esac; + + for _eplv_fname in \ + "${HOME}/midipix_build.vars" \ + "${HOME}/.midipix_build.vars" \ + ../midipix_build.vars \ + ./midipix.env; + do + if [ -r "${_eplv_fname}" ]; then + rtl_fileop source "${_eplv_fname}"; + fi; + done; + + if [ "${PREFIX:+1}" != 1 ]; then + _eplv_rc=1; + rtl_setrstatus "${_eplv_rstatus}" 'Error: ${PREFIX} empty or unset.'; + fi; + fi; + + return "${_eplv_rc}"; +}; + +# +# ex_pkg_load_groups() - load all available build groups +# @_rgroups: reference to out variable of build groups +# @_rgroups_noauoto: optional reference to out variable of build groups not built automatically +# @_rgroup_auto: reference to in variable of flag controlling whether to build group automatically +# @_rgroup_target: reference to in variable of build group targets +# +# Return: zero (0) on success, non-zero (>0) on failure. +# +ex_pkg_load_groups() { + local _eplg_rgroups="${1#\$}" _eplg_rgroups_noauto="${2#\$}" \ + _eplg_rgroup_auto="${3#\$}" _eplg_rgroup_target="${4#\$}" \ + _eplg_build_groups="" _eplg_build_groups_noauto="" \ + _eplg_fname="" _eplg_group="" _eplg_groups=""; + + for _eplg_fname in $(find ./groups -name *.group | sort); do + rtl_fileop source_opt "${_eplg_fname}"; + + if eval [ \"\${${_eplg_rgroup_target}:+1}\" = 1 ]; then + eval _eplg_group=\"\${${_eplg_rgroup_target}}\"; + eval unset ${_eplg_rgroup_target}; + else + _eplg_group="${_eplg_fname##*/}"; + _eplg_group="${_eplg_group%.group}"; + _eplg_group="${_eplg_group#*.}"; + fi; + + if ! rtl_lmatch \$_eplg_groups "${_eplg_group}"; then + rtl_lconcat \$_eplg_groups "${_eplg_group}"; + if eval [ \"\${${_eplg_rgroup_auto}:+1}\" = 1 ]; then + if eval [ \"\${${_eplg_rgroup_auto}:-0}\" -ne 0 ]; then + rtl_lconcat \$_eplg_build_groups "${_eplg_group}"; + else + rtl_lconcat \$_eplg_build_groups_noauto "${_eplg_group}"; + fi; + eval unset ${_eplg_rgroup_auto}; + else + rtl_lconcat \$_eplg_build_groups "${_eplg_group}"; + fi; + fi; + done; + + _eplg_build_groups="$(rtl_uniq "${_eplg_build_groups}")"; + eval ${_eplg_rgroups}=\"${_eplg_build_groups}\"; + + if [ "${_eplg_rgroups_noauto:+1}" = 1 ]; then + _eplg_build_groups_noauto="$(rtl_uniq "${_eplg_build_groups_noauto}")"; + eval ${_eplg_rgroups_noauto}=\"${_eplg_build_groups_noauto}\"; + fi; + + return 0; +}; + +# +# ex_pkg_unfold_depends() - unfold list of package names into dependency-expanded set of complete, disabled, finished, and outstanding package names +# @_rdisabled: reference to inout variable of disabled packages +# @_rfinished: reference to inout variable of finished packages +# @_rnames: reference to out variable of package names +# @_checkfl: enable (1) or inhibit (0) dependency expansion +# @_forcefl: enable (1) or inhibit (0) forcibly rebuilding finished packages +# @_group_name: build group name +# @_pkg_names: list of package names +# @_restart: optional whitespace-separated list of package names to rebuild +# @_test_finished: only exclude disabled packages (0,) split finished packages +# @_workdir: pathname to build-specific temporary directory +# +# Return: zero (0) on success, non-zero (>0) on failure. +# +ex_pkg_unfold_depends() { + local _epud_rdisabled="${1#\$}" _epud_rfinished="${2#\$}" _epud_rnames="${3#\$}" \ + _epud_checkfl="${4}" _epud_forcefl="${5}" _epud_group_name="${6}" \ + _epud_pkg_names="${7}" _epud_restart="${8}" _epud_test_finished="${9}" \ + _epud_workdir="${10}" \ + _epud_pkg_disabled="" _epud_pkg_force="" _epud_pkg_name="" \ + _epud_pkg_names_new="" _epud_restartfl=0; + + if [ "${_epud_restart:+1}" = 1 ]\ + && ! rtl_lmatch \$_epud_restart "ALL LAST"; then + rtl_lsearch \$_epud_pkg_names "${_epud_restart}"; + fi; + if [ "${_epud_restart:+1}" = 1 ]\ + && [ "${_epud_checkfl:-0}" -eq 1 ]; then + rtl_lunfold_depends 'PKG_${_rld_name}_DEPENDS' \$_epud_pkg_names ${_epud_pkg_names}; + _epud_pkg_names="$(rtl_uniq ${_epud_pkg_names})"; + fi; + + for _epud_pkg_name in ${_epud_pkg_names}; do + if [ "${_epud_restart}" = "ALL" ]\ + || rtl_lmatch \$_epud_restart "${_epud_pkg_name}"; then + _epud_restartfl=1; + else + _epud_restartfl=0; + fi; + + if rtl_get_var_unsafe \$_epud_pkg_disabled -u "PKG_${_epud_pkg_name}_DISABLED"\ + && [ "${_epud_pkg_disabled}" = 1 ]; + then + rtl_lconcat "${_epud_rdisabled}" "${_epud_pkg_name}"; + + elif [ "${_epud_test_finished:-1}" -eq 1 ]\ + && ex_pkg_state_test2 "${_epud_workdir}" "${_epud_pkg_name}" finish\ + && [ "${_epud_restartfl:-0}" -eq 0 ]\ + && [ "${_epud_forcefl:-0}" -ne 1 ]\ + && rtl_get_var_unsafe \$_epud_pkg_force -u "${_epud_group_name}_FORCE"\ + && [ "${_epud_pkg_force}" != 1 ]; + then + rtl_lconcat "${_epud_rfinished}" "${_epud_pkg_name}"; + + else + rtl_lconcat \$_epud_pkg_names_new "${_epud_pkg_name}"; + fi; + done; + + eval ${_epud_rdisabled}='$(rtl_uniq2 "${_epud_rdisabled}")'; + eval ${_epud_rfinished}='$(rtl_uniq2 "${_epud_rfinished}")'; + eval ${_epud_rnames}='$(rtl_uniq "${_epud_pkg_names_new}")'; + + return 0; +}; + +# +# ex_pkg_unfold_rdepends() - unfold list of package names into reverse dependency-expanded set of complete, disabled, finished, and outstanding package names +# @_rdisabled: reference to inout variable of disabled packages +# @_rfinished: reference to inout variable of finished packages +# @_rnames: reference to out variable of package names +# @_group_name: build group name +# @_pkg_names: list of package names +# @_restart: optional whitespace-separated list of package names to rebuild +# @_test_finished: only exclude disabled packages (0,) split finished packages +# @_workdir: pathname to build-specific temporary directory +# +# Return: zero (0) on success, non-zero (>0) on failure. +# +ex_pkg_unfold_rdepends() { + local _epur_rdisabled="${1#\$}" _epur_rfinished="${2#\$}" _epur_rnames="${3#\$}" \ + _epur_group_name="${4}" _epur_pkg_names="${5}" _epur_restart="${6}" \ + _epur_test_finished="${7}" _epur_workdir="${8}" \ + _epur_depends="" _epur_disabled=0 _epur_force=0 _epur_pkg_depends="" \ + _epur_pkg_name="" _epur_pkg_names_new="" _epur_pkg_name_depend="" \ + _epur_pkg_rdepends=""; + + for _epur_pkg_name_depend in ${_epur_restart}; do + for _epur_pkg_name in ${_epur_pkg_names}; do + if [ "${_epur_pkg_name}" = "${_epur_pkg_name_depend}" ]; then + continue; + + elif rtl_get_var_unsafe \$_epur_depends -u "PKG_"${_epur_pkg_name}"_DEPENDS"\ + && rtl_lunfold_depends 'PKG_${_rld_name}_DEPENDS' \$_epur_pkg_depends ${_epur_depends}\ + && [ "${_epur_pkg_depends:+1}" = 1 ]\ + && rtl_lmatch \$_epur_pkg_depends "${_epur_pkg_name_depend}"; + then + if rtl_get_var_unsafe \$_epur_disabled -u "PKG_${_epur_pkg_name}_DISABLED"\ + && [ "${_epur_disabled}" = 1 ]; + then + rtl_lconcat "${_epur_rdisabled}" "${_epur_pkg_name}"; + + elif [ "${_epur_test_finished}" -eq 1 ]\ + && ex_pkg_state_test2 "${_epur_workdir}" "${_epur_pkg_name}" finish\ + && rtl_get_var_unsafe \$_epur_force -u "${_epur_group_name}_FORCE"\ + && [ "${_epur_force}" != 1 ]; + then + rtl_lconcat "${_epur_rfinished}" "${_epur_pkg_name}"; + + elif [ "${_epur_test_finished:-1}" -eq 0 ]\ + || ! ex_pkg_state_test2 "${_epur_workdir}" "${_epur_pkg_name}" finish\ + || ( rtl_get_var_unsafe \$_epur_force -u "${_epur_group_name}_FORCE"\ + && [ "${_epur_force}" = 1 ] ); + then + rtl_lconcat \$_epur_pkg_names_new "${_epur_pkg_name}"; + fi; + fi; + done; + done; + + eval ${_epur_rdisabled}='$(rtl_uniq2 "${_epur_rdisabled}")'; + eval ${_epur_rfinished}='$(rtl_uniq2 "${_epur_rfinished}")'; + eval ${_epur_rnames}='$(rtl_uniq "${_epur_pkg_names_new}")'; + + return 0; +}; + +# vim:filetype=sh textwidth=0 diff --git a/subr.ex/ex_pkg_dispatch.subr b/subr.ex/ex_pkg_dispatch.subr new file mode 100644 index 0000000..f89b874 --- /dev/null +++ b/subr.ex/ex_pkg_dispatch.subr @@ -0,0 +1,378 @@ +# +# set +o errexit -o noglob -o nounset is assumed. +# + +# +# 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 _epdc_dispatch_fn="${1}" _epdc_group_name="${2}" _epdc_pkg_disabled="${3}" \ + _epdc_pkg_finished="${4}" \ + _epdc_pkg_name=""; + + for _epdc_pkg_name in ${_epdc_pkg_disabled}; do + "${_epdc_dispatch_fn}" disabled_pkg "${_epdc_group_name}" "${_epdc_pkg_name}"; + done; + for _epdc_pkg_name in ${_epdc_pkg_finished}; do + "${_epdc_dispatch_fn}" skipped_pkg "${_epdc_group_name}" "${_epdc_pkg_name}"; + done; + + return 0; +}; + +# +# exp_pkg_dispatch_expand_packages() - expand build group name to list of packages ordered and filtered according to dependency and restart constraints +# @_rdisabled: reference to out variable of disabled packages +# @_rfinished: reference to out variable of finished packages +# @_rnames: reference to out variable of package names +# @_checkfl: enable (1) or inhibit (0) dependency expansion +# @_forcefl: enable (1) or inhibit (0) forcibly rebuilding finished packages +# @_group_name: build group name +# @_restart: optional whitespace-separated list of package names to rebuild +# @_reversefl: unfold reverse dependencies (1) or dependencies (0) +# @_workdir: pathname to build-specific temporary directory +# +# Return: zero (0) on success, non-zero (>0) on failure. +# +exp_pkg_dispatch_expand_packages() { + local _epdep_rdisabled="${1#\$}" _epdep_rfinished="${2#\$}" _epdep_rnames="${3#\$}" \ + _epdep_checkfl="${4}" _epdep_forcefl="${5}" _epdep_group_name="${6}" \ + _epdep_restart="${7}" _epdep_reversefl="${8}" _epdep_workdir="${9}" \ + _epdep_pkg_names=""; + + eval ${_epdep_rdisabled}=; + eval ${_epdep_rfinished}=; + eval ${_epdep_rnames}=; + + if rtl_get_var_unsafe \$_epdep_pkg_names -u "${_epdep_group_name}_PACKAGES"\ + && [ "${_epdep_pkg_names:+1}" = 1 ]; then + if [ "${_epdep_reversefl:-0}" -eq 0 ]; then + ex_pkg_unfold_depends \ + "${_epdep_rdisabled}" "${_epdep_rfinished}" \ + "${_epdep_rnames}" "${_epdep_checkfl}" "${_epdep_forcefl}" \ + "${_epdep_group_name}" "${_epdep_pkg_names}" \ + "${_epdep_restart}" 1 "${_epdep_workdir}"; + else + ex_pkg_unfold_rdepends \ + "${_epdep_rdisabled}" "${_epdep_rfinished}" \ + "${_epdep_rnames}" "${_epdep_group_name}" \ + "${_epdep_pkg_names}" "${_epdep_restart}" 1 \ + "${_epdep_workdir}"; + fi; + fi; + + eval ${_epdep_rdisabled}='$(rtl_uniq2 "${_epdep_rdisabled}")'; + eval ${_epdep_rfinished}='$(rtl_uniq2 "${_epdep_rfinished}")'; + eval ${_epdep_rnames}='$(rtl_uniq2 "${_epdep_rnames}")'; + + return 0; +}; + +# +# exp_pkg_dispatch_group() - dispatch a single build group +# @_rdispatch_count: reference to inout variable of dispatcher count +# @_rdispatch_count_cur: reference to inout variable of current dispatcher count +# @_dispatch_count_max: maximum dispatcher count +# @_dispatch_group_cur: current group +# @_dispatch_group_max: maximum group +# @_rdispatch_njobs: reference to inout variable of dispatcher count +# @_rdispatch_wait: reference to inout variable of package names in a wait state +# @_rpkg_disabled: reference to in variable of list of disabled packages +# @_rpkg_finished: reference to inout variable of list of finished packages +# @_rpkg_names: reference to inout variable of list of package names +# @_build_steps_default: list of default build steps +# @_build_vars_default: list of default build variables +# @_checkfl: enable (1) or inhibit (0) dependency expansion +# @_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 or LAST +# @_workdir: pathname to build-specific temporary directory +# +# Return: zero (0) on success, non-zero (>0) on failure. +# +exp_pkg_dispatch_group() { + local _epdg_rdispatch_count="${1#\$}" _epdg_rdispatch_count_cur="${2#\$}" _epdg_dispatch_count_max="${3#\$}" \ + _epdg_dispatch_group_cur="${4#\$}" _epdg_dispatch_group_max="${5#\$}" _epdg_rdispatch_njobs="${6#\$}" \ + _epdg_rdispatch_wait="${7#\$}" _epdg_rpkg_disabled="${8#\$}" _epdg_rpkg_finished="${9#\$}" \ + _epdg_rpkg_names="${10#\$}" _epdg_build_steps_default="${11}" _epdg_build_vars_default="${12}" \ + _epdg_checkfl="${13}" _epdg_dispatch_fn="${14}" _epdg_group_name="${15}" _epdg_njobs_max="${16}" \ + _epdg_pipe_path="${17}" _epdg_restart_at="${18}" _epdg_workdir="${19}" \ + _epdg_perc_group=0 _epdg_perc_pkg=0 _epdg_pipe_msg="" _epdg_pkg_name="" _epdg_rc=0; + + rtl_fileop mkfifo "${_epdg_pipe_path}"; + while true; do + while eval [ \"\${${_epdg_rdispatch_njobs}:-0}\" -gt 0 ]\ + && read _epdg_pipe_msg; + do + + case "${_epdg_pipe_msg%% *}" in + + done) _epdg_pkg_name="${_epdg_pipe_msg#done * }"; + eval : '$(('${_epdg_rdispatch_count_cur}'+=1))'; + eval : '$(('${_epdg_rdispatch_njobs}'-=1))'; + + rtl_lconcat "${_epdg_rpkg_finished}" "${_epdg_pkg_name}"; + rtl_percentage2 \$_epdg_dispatch_group_cur \$_epdg_dispatch_group_max \$_epdg_perc_group; + rtl_percentage2 "${_epdg_rdispatch_count_cur}" \$_epdg_dispatch_count_max \$_epdg_perc_pkg; + + "${_epdg_dispatch_fn}" \ + finish_pkg ${_epdg_pipe_msg#done } \ + "${_epdg_dispatch_count_max}" \ + "${_epdg_perc_group}" "${_epdg_perc_pkg}"; + + rtl_lfilter "${_epdg_rpkg_names}" "${_epdg_pkg_name}"; + rtl_lfilter "${_epdg_rdispatch_wait}" "${_epdg_pkg_name}"; + + if eval [ \"\${${_epdg_rpkg_names}:+1}\" = 1 ]\ + && [ "${_epdg_rc}" -eq 0 ]; + then + if eval [ \"\${${_epdg_rdispatch_njobs}:-0}\" -ne \"\${_epdg_njobs_max}\" ]; then + exp_pkg_dispatch_packages \ + "${_epdg_rdispatch_count}" \ + "${_epdg_rdispatch_count_cur}" \ + "${_epdg_dispatch_count_max}" \ + "${_epdg_dispatch_group_cur}" \ + "${_epdg_dispatch_group_max}" \ + "${_epdg_rdispatch_njobs}" \ + "${_epdg_rdispatch_wait}" \ + "${_epdg_rpkg_disabled}" \ + "${_epdg_rpkg_finished}" "${_epdg_rpkg_names}" \ + "${_epdg_build_steps_default}" \ + "${_epdg_build_vars_default}" "${_epdg_checkfl}" \ + "${_epdg_dispatch_fn}" "${_epdg_group_name}" \ + "${_epdg_njobs_max}" "${_epdg_pipe_path}" \ + "${_epdg_restart_at}" "${_epdg_workdir}"; + fi; + elif eval [ \"\${${_epdg_rdispatch_njobs}:-0}\" -eq 0 ]; then + break; + fi; + ;; + + fail) eval : '$(('${_epdg_rdispatch_njobs}'-=1))'; + _epdg_rc=1; + "${_epdg_dispatch_fn}" \ + fail_pkg ${_epdg_pipe_msg#fail } \ + "${_epdg_dispatch_count_max}"; + ;; + + msg_pkg) + "${_epdg_dispatch_fn}" msg_pkg ${_epdg_pipe_msg#msg_pkg }; + ;; + + step) "${_epdg_dispatch_fn}" step_pkg ${_epdg_pipe_msg#step }; + ;; + + esac; done <>"${_epdg_pipe_path}"; + + if eval [ \"\${${_epdg_rpkg_names}:+1}\" = 1 ]\ + && [ "${_epdg_rc}" -eq 0 ]; + then + if eval [ \"\${${_epdg_rdispatch_njobs}:-0}\" -ne \"\${_epdg_njobs_max}\" ]; then + exp_pkg_dispatch_packages \ + "${_epdg_rdispatch_count}" \ + "${_epdg_rdispatch_count_cur}" \ + "${_epdg_dispatch_count_max}" \ + "${_epdg_dispatch_group_cur}" \ + "${_epdg_dispatch_group_max}" \ + "${_epdg_rdispatch_njobs}" \ + "${_epdg_rdispatch_wait}" \ + "${_epdg_rpkg_disabled}" \ + "${_epdg_rpkg_finished}" "${_epdg_rpkg_names}" \ + "${_epdg_build_steps_default}" \ + "${_epdg_build_vars_default}" "${_epdg_checkfl}" \ + "${_epdg_dispatch_fn}" "${_epdg_group_name}" \ + "${_epdg_njobs_max}" "${_epdg_pipe_path}" \ + "${_epdg_restart_at}" "${_epdg_workdir}"; + fi; + elif eval [ \"\${${_epdg_rdispatch_njobs}:-0}\" -eq 0 ]; then + break; + fi; + done; + + rtl_fileop rm "${_epdg_pipe_path}"; + + return "${_epdg_rc}"; +}; + +# +# exp_pkg_dispatch_packages() - dispatch set of packages +# @_rdispatch_count: reference to inout variable of dispatcher count +# @_dispatch_count_cur: current dispatcher count +# @_dispatch_count_max: maximum dispatcher count +# @_dispatch_group_cur: current group +# @_dispatch_group_max: maximum group +# @_rdispatch_njobs: reference to inout variable of dispatcher count +# @_rdispatch_wait: reference to inout variable of package names in a wait state +# @_rpkg_disabled: reference to in variable of list of disabled packages +# @_rpkg_finished: reference to inout variable of list of finished packages +# @_rpkg_names: reference to inout variable of list of package names +# @_build_steps_default: list of default build steps +# @_build_vars_default: list of default build variables +# @_checkfl: enable (1) or inhibit (0) dependency expansion +# @_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 +# @_restart_at: optional comma-separated list of build steps at which to rebuild or ALL or LAST +# @_workdir: pathname to build-specific temporary directory +# +# Return: zero (0) on success, non-zero (>0) on failure. +# +exp_pkg_dispatch_packages() { + local _epdp2_rdispatch_count="${1#\$}" _epdp2_dispatch_count_cur="${2}" _epdp2_dispatch_count_max="${3}" \ + _epdp2_dispatch_group_cur="${4}" _epdp2_dispatch_group_max="${5}" _epdp2_rdispatch_njobs="${6#\$}" \ + _epdp2_rdispatch_wait="${7#\$}" _epdp2_rpkg_disabled="${8#\$}" _epdp2_rpkg_finished="${9#\$}" \ + _epdp2_rpkg_names="${10#\$}" _epdp2_build_steps_default="${11}" _epdp2_build_vars_default="${12}" \ + _epdp2_checkfl="${13}" _epdp2_dispatch_fn="${14}" _epdp2_group_name="${15}" _epdp2_njobs_max="${16}" \ + _epdp2_pipe_path="${17}" _epdp2_restart_at="${18}" _epdp2_workdir="${19}" \ + _epdp2_foundfl=0 _epdp2_njob=0 _epdp2_pkg_depends="" _epdp2_pkg_name=""; + + while eval [ \"\${${_epdp2_rdispatch_njobs}}\" -lt \"\${_epdp2_njobs_max}\" ]; do + _epdp2_foundfl=0; + eval _epdp2_pkg_names="\${${_epdp2_rpkg_names}}"; + for _epdp2_pkg_name in ${_epdp2_pkg_names}; do + if ! rtl_lmatch "${_epdp2_rdispatch_wait}" "${_epdp2_pkg_name}"\ + && ex_pkg_check_depends \ + "${_epdp2_checkfl}" "${_epdp2_rpkg_disabled}" \ + "${_epdp2_rpkg_finished}" "${_epdp2_pkg_name}" \ + "${_epdp2_rpkg_names}" "${_epdp2_workdir}"; + then + ex_pkg_exec \ + "${_epdp2_rdispatch_count}" \ + "${_epdp2_dispatch_count_cur}" "${_epdp2_dispatch_count_max}" \ + "${_epdp2_dispatch_group_cur}" "${_epdp2_dispatch_group_max}" \ + "${_epdp2_rdispatch_njobs}" "${_epdp2_rdispatch_wait}" \ + "${_epdp2_build_steps_default}" \ + "${_epdp2_build_vars_default}" "${_epdp2_dispatch_fn}" \ + "${_epdp2_group_name}" "${_epdp2_pipe_path}" \ + "${_epdp2_pkg_name}" "${_epdp2_restart_at}" \ + "${_epdp2_workdir}"; + _epdp2_foundfl=1; break; + fi; + done; + + if [ "${_epdp2_foundfl:-0}" -eq 0 ]; then + break; + fi; + done; + + return "${_epdp2_foundfl}"; +}; + +# +# ex_pkg_dispatch() - dispatch a set of build group +# @_rdispatch_wait: reference to out variable of package names in a wait state +# @_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) +# @_groups_inhibit_deps: inhibit group-group dependency expansion +# @_njobs_max: maximum count of simultaneous jobs +# @_pipe_path: pathname to build FIFO +# @_restart: optional whitespace-separated list of package names to rebuild +# @_restart_at: optional comma-separated list of build steps at which to rebuild or ALL or LAST +# @_restart_recursive: optional flag specifiying either no dependency expansion (0,) dependency expansion (1,) dependency expansion and forcibly rebuild (2,) forcibly rebuild reverse dependencies (3.) +# @_workdir: pathname to build-specific temporary directory +# +# Return: zero (0) on success, non-zero (>0) on failure. +# +ex_pkg_dispatch() { + local _epd_rdispatch_wait="${1#\$}" _epd_build_steps_default="${2}" _epd_build_vars_default="${3}" \ + _epd_dispatch_fn="${4}" _epd_group_names="${5}" _epd_groups_inhibit_deps="${6}" _epd_njobs_max="${7}" \ + _epd_pipe_path="${8}" _epd_restart="${9}" _epd_restart_at="${10}" _epd_restart_recursive="${11}" \ + _epd_workdir="${12}" \ + _epd_checkfl=1 _epd_forcefl=0 _epd_perc_group=0 \ + _epd_pkg_disabled="" _epd_pkg_finished="" _epd_pkg_names="" _epd_pkg_name="" \ + _epd_pkg_dispatch_count=0 _epd_pkg_dispatch_count_cur=0 _epd_pkg_dispatch_count_max=0 \ + _epd_pkg_dispatch_group_cur=0 _epd_pkg_dispatch_group_max=0 \ + _epd_pkg_dispatch_njobs=0 \ + _epd_rc=0 _epd_reversefl=0; + + case "${_epd_groups_inhibit_deps:-0}" in + 0) rtl_lunfold_depends '${_rld_name}_GROUP_DEPENDS' \$_epd_group_names ${_epd_group_names}; + _epd_group_names="$(rtl_uniq2 \$_epd_group_names)"; + esac; + + if [ "${_epd_restart:+1}" = 1 ]; then + case "${_epd_restart_recursive:-0}" in + 0) _epd_checkfl=0; _epd_forcefl=0; _epd_reversefl=0; ;; + 1) _epd_checkfl=1; _epd_forcefl=0; _epd_reversefl=0; ;; + 2) _epd_checkfl=1; _epd_forcefl=1; _epd_reversefl=0; ;; + 3) _epd_checkfl=1; _epd_forcefl=1; _epd_reversefl=1; ;; + esac; + fi; + + rtl_llength \$_epd_pkg_dispatch_group_max \$_epd_group_names; + + for _epd_group_name in ${_epd_group_names}; do + _epd_pkg_disabled=""; + _epd_pkg_finished=""; + _epd_pkg_names=""; + eval ${_epd_rdispatch_wait}=; + _epd_pkg_dispatch_count=0; + _epd_pkg_dispatch_count_cur=0; + _epd_pkg_dispatch_count_max=0; + _epd_pkg_dispatch_njobs=0; + + rtl_percentage "${_epd_pkg_dispatch_group_cur}" "${_epd_pkg_dispatch_group_max}" \$_epd_perc_group; + + if "${_epd_dispatch_fn}" \ + start_group "${_epd_group_name}" \ + "" "${_epd_pkg_dispatch_group_cur}" \ + "${_epd_pkg_dispatch_group_max}" \ + "${_epd_perc_group}"; + then + if rtl_fileop mkdir "${_epd_workdir}"\ + && rtl_log_msg "verbose" "${MSG_build_resolving_deps}" "${_epd_group_name}"\ + && exp_pkg_dispatch_expand_packages \ + \$_epd_pkg_disabled \$_epd_pkg_finished \ + \$_epd_pkg_names "${_epd_checkfl}" \ + "${_epd_forcefl}" "${_epd_group_name}" \ + "${_epd_restart}" "${_epd_reversefl}" \ + "${_epd_workdir}" \ + && exp_pkg_dispatch_complete \ + "${_epd_dispatch_fn}" "${_epd_group_name}" \ + "${_epd_pkg_disabled}" "${_epd_pkg_finished}" \ + && rtl_log_msg "verbose" "${MSG_build_resolved_deps}" "${_epd_group_name}"\ + && rtl_llength \$_epd_pkg_dispatch_count_max \$_epd_pkg_names\ + && [ "${_epd_pkg_dispatch_count_max}" -gt 0 ]; + then + exp_pkg_dispatch_group \ + \$_epd_pkg_dispatch_count \$_epd_pkg_dispatch_count_cur \ + "${_epd_pkg_dispatch_count_max}" \ + "${_epd_pkg_dispatch_group_cur}" "${_epd_pkg_dispatch_group_max}" \ + \$_epd_pkg_dispatch_njobs "${_epd_rdispatch_wait}" \ + \$_epd_pkg_disabled \$_epd_pkg_finished \$_epd_pkg_names \ + "${_epd_build_steps_default}" "${_epd_build_vars_default}" \ + "${_epd_checkfl}" "${_epd_dispatch_fn}" "${_epd_group_name}" \ + "${_epd_njobs_max}" "${_epd_pipe_path}" "${_epd_restart_at}" \ + "${_epd_workdir}"; + _epd_rc="${?}"; + fi; + + : $((_epd_pkg_dispatch_group_cur+=1)); + rtl_percentage "${_epd_pkg_dispatch_group_cur}" "${_epd_pkg_dispatch_group_max}" \$_epd_perc_group; + + "${_epd_dispatch_fn}" \ + finish_group "${_epd_group_name}" \ + "" "${_epd_pkg_dispatch_group_cur}" \ + "${_epd_pkg_dispatch_group_max}" \ + "${_epd_perc_group}"; + if [ "${_epd_rc}" -ne 0 ]; then + break; + fi; + fi; + done; + + return "${_epd_rc}"; +}; + +# vim:filetype=sh textwidth=0 diff --git a/subr.ex/ex_pkg_env.subr b/subr.ex/ex_pkg_env.subr new file mode 100644 index 0000000..265262a --- /dev/null +++ b/subr.ex/ex_pkg_env.subr @@ -0,0 +1,178 @@ +# +# set +o errexit -o noglob -o nounset is assumed. +# + +# +# exp_pkg_env_defaults() - set package variable defaults for single named package +# @_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 _epped_build_steps_default="${1}" _epped_pkg_name="${2}" _epped_workdir="${3}"; + + : ${PKG_NAME:="${_epped_pkg_name}"}; + : ${MIDIPIX_BUILD_PWD:="$(pwd)"}; + : ${PKG_BASE_DIR:="${_epped_workdir}/${_epped_pkg_name}-${PKG_BUILD_TYPE}-${PKG_TARGET}"}; + + if [ "${PKG_BUILD_STEPS_DISABLE:+1}" = 1 ]; then + rtl_lfilter2 \$_epped_build_steps_default \$PKG_BUILD_STEPS "${PKG_BUILD_STEPS_DISABLE:-}"; + else + : ${PKG_BUILD_STEPS:="${_epped_build_steps_default}"}; + fi; + + if [ "${PKG_URL:+1}" = 1 ]; then + : ${PKG_FNAME:="${PKG_URL##*/}"}; + fi; + + if [ "${PKG_SUBDIR:+1}" != 1 ]; then + if [ "${PKG_URLS_GIT:+1}" = 1 ]\ + && [ "${PKG_FNAME:+1}" = 1 ]; then + rtl_log_msg "fatalexit" "${MSG_pkg_fail_missing_vars}"; + elif [ "${PKG_URLS_GIT:+1}" = 1 ]; then + PKG_SUBDIR="${PKG_URLS_GIT%%=*}"; + else case "${PKG_FNAME:-}" in + *.t*) PKG_SUBDIR="${PKG_FNAME%%.t*}"; ;; + *) PKG_SUBDIR="${_epped_pkg_name}"; ;; + esac; fi; + fi; + + if [ "${PKG_BUILD_DIR:+1}" != 1 ]; then + case "${PKG_IN_TREE:-0}" in + 0) PKG_BUILD_DIR="obj"; ;; + 1) PKG_BUILD_DIR="${PKG_SUBDIR}"; ;; + esac; + fi; + + PKG_BUILD_DIR="${PKG_BASE_DIR}/${PKG_BUILD_DIR}"; + PKG_CONFIGURE="${PKG_BASE_DIR}/${PKG_CONFIGURE:-${PKG_SUBDIR}/configure}"; + PKG_DESTDIR="${PKG_BASE_DIR}/${PKG_DESTDIR:-destdir}"; + PKG_DESTDIR_HOST="${PKG_BASE_DIR}/${PKG_DESTDIR_HOST:-destdir_host}"; + + return 0; +}; + +# +# 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 +# +# Sets package variables from either defaults, defaults specific to build type, +# build group, package to inherit from if any, or package for a single named +# package, and exports variables optionally named in ${PKG_ENV_VARS_EXTRA}. +# +# Return: zero (0) on success, non-zero (>0) on failure +# +exp_pkg_env_set() { + local _eppes_build_vars_default="${1}" _eppes_group_name="${2}" _eppes_pkg_name="${3}" \ + _eppes_cmd_name="" _eppes_lvars="" _eppes_var_prefixes="" _eppes_vars_set="" \ + _eppes_vars_unset="" _eppes_vname="" _eppes_vnames="" IFS IFS0; + + rtl_set_vars _eppes_vars_set BUILD_TYPE "DEFAULT ${_eppes_group_name} PKG_${_eppes_pkg_name}"; + rtl_set_vars _eppes_vars_set INHERIT_FROM "PKG_${_eppes_pkg_name}"; + _eppes_var_prefixes="DEFAULT DEFAULT_${PKG_BUILD_TYPE} ${_eppes_group_name}"; + rtl_toupper \$_eppes_var_prefixes; + rtl_lfilter2 \$_eppes_build_vars_default \$_eppes_vnames BUILD_TYPE; + + for _eppes_vname in ${_eppes_vnames}; do + if [ "${PKG_INHERIT_FROM:+1}" = 1 ]; then + _eppes_lvars="PKG_${PKG_INHERIT_FROM} PKG_${PKG_INHERIT_FROM}_${BUILD_KIND} PKG_${_eppes_pkg_name} PKG_${_eppes_pkg_name}_${BUILD_KIND}"; + rtl_toupper \$_eppes_lvars; + rtl_lconcat2 \$_eppes_lvars \$_eppes_var_prefixes "${_eppes_lvars}"; + rtl_set_vars _eppes_vars_set "${_eppes_vname}" "${_eppes_lvars}"; + else + _eppes_lvars="PKG_${_eppes_pkg_name} PKG_${_eppes_pkg_name}_${BUILD_KIND}"; + rtl_toupper \$_eppes_lvars; + rtl_lconcat2 \$_eppes_lvars \$_eppes_var_prefixes "${_eppes_lvars}"; + rtl_set_vars _eppes_vars_set "${_eppes_vname}" "${_eppes_lvars}"; + fi; + done; + + IFS0="${IFS:- }"; IFS=":"; for _eppes_vname in ${PKG_ENV_VARS_EXTRA:-}; do + export "${_eppes_vname}"; + done; IFS="${IFS0}"; + + for _eppes_vname in AR CC CXX PKG_CONFIG RANLIB; do + if eval [ '"${PKG_'"${_eppes_vname}"':+1}"' = 1 ]\ + && eval [ '"${PKG_'"${_eppes_vname}"'#/}"' = '"${_eppes_cmd_name:=${PKG_'"${_eppes_vname}"'}}"' ]; then + eval PKG_${_eppes_vname}='$(which "${_eppes_cmd_name}")'; + fi; _eppes_cmd_name=""; + done; + + return 0; +}; + +# +# ex_pkg_env() - set package variables for single named package +# @_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 or LAST +# @_workdir: pathname to build-specific temporary directory +# +# Return: zero (0) on success, non-zero (>0) on failure +# +ex_pkg_env() { + local _epe_build_steps_default="${1}" _epe_build_vars_default="${2}" _epe_group_name="${3}" \ + _epe_pkg_name="${4}" _epe_restart_at="${5}" _epe_workdir="${6}" \ + _epe_inherit_from="" _epe_vars_file="" _epe_vname=""; + + if rtl_get_var_unsafe \$_epe_inherit_from -u "PKG_${_epe_pkg_name}_INHERIT_FROM"\ + && [ "${_epe_inherit_from:+1}" = 1 ]; then + rtl_get_var_unsafe \$_epe_vars_file -u "PKG_${_epe_inherit_from}_VARS_FILE"; + else + rtl_get_var_unsafe \$_epe_vars_file -u "PKG_${_epe_pkg_name}_VARS_FILE"; + fi; + if [ "${_epe_vars_file:+1}" != 1 ]; then + _epe_vars_file="vars/${_epe_pkg_name}.vars"; + fi; + + rtl_fileop source_opt "${_epe_vars_file}" "${_epe_group_name}/${_epe_pkg_name}.${_epe_group_name}"; + if ! exp_pkg_env_set "${_epe_build_vars_default}" "${_epe_group_name}" "${_epe_pkg_name}"\ + || ! exp_pkg_env_defaults "${_epe_build_steps_default}" "${_epe_pkg_name}" "${_epe_workdir}"; then + return 1; + fi; + + return 0; +}; + +# +# ex_pkg_state_set() - update build step status for single named package +# @_pkg_name: single package name +# @_build_step: build step set status of +# [@${@}]: optional list of build steps to invalidate status of +# +# Return: zero (0) on success, non-zero (>0) on failure +# +ex_pkg_state_set() { + rtl_state_set "${BUILD_WORKDIR}" "${@}"; +}; + + +ex_pkg_state_set2() { + local _epss2_workdir="${1}"; shift; + rtl_state_set "${_epss2_workdir}" "${@}"; +}; + +# +# ex_pkg_state_test() - test build step status of single named package +# @_pkg_name: single package name +# @_build_step: build step to test status of +# @_restart_at: optional comma-separated list of build steps at which to rebuild or ALL or LAST +# +# Return: zero (0) on success, non-zero (>0) on failure +# +ex_pkg_state_test() { + rtl_state_test "${BUILD_WORKDIR}" "${@}"; +}; + +ex_pkg_state_test2() { + local _epst2_workdir="${1}"; shift; + rtl_state_test "${_epst2_workdir}" "${@}"; +}; + +# vim:filetype=sh diff --git a/subr.ex/ex_pkg_exec.subr b/subr.ex/ex_pkg_exec.subr new file mode 100644 index 0000000..1c4e13d --- /dev/null +++ b/subr.ex/ex_pkg_exec.subr @@ -0,0 +1,219 @@ +# +# set +o errexit -o noglob -o nounset is assumed. +# + +# +# exp_pkg_exec_pre() - XXX +# @_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 or LAST +# @_workdir: pathname to build-specific temporary directory +# +# Return: zero (0) on success, non-zero (>0) on failure +# +exp_pkg_exec_pre() { + local _eppep_group_name="${1}" _eppep_pkg_name="${2}" _eppep_restart_at="${3}" _eppep_workdir="${4}"; + + if [ "${PKG_URL:+1}" != 1 ]\ + && [ "${PKG_URLS_GIT:+1}" != 1 ]\ + && [ "${PKG_VERSION:+1}" != 1 ]\ + && [ "${PKG_INSTALL_FILES:+1}" != 1 ]\ + && [ "${PKG_INSTALL_FILES_V2:+1}" != 1 ]\ + && ! rtl_test_cmd "pkg_${_eppep_pkg_name}_all"; + then + "${_eppep_dispatch_fn}" missing_pkg "${_eppep_group_name}" "${_eppep_pkg_name}"; + return 1; + elif ! ex_pkg_state_test2 \ + "${_eppep_workdir}" \ + "${_eppep_pkg_name}" "start" \ + "${_eppep_restart_at}"; + then + if [ "${PKG_NO_CLEAN_BASE_DIR:-0}" -eq 0 ]\ + && ! rtl_fileop rm "${PKG_BASE_DIR}" "${PKG_BUILD_DIR}" "${PKG_DESTDIR}" "${PKG_DESTDIR_HOST}"\ + || ! rtl_fileop mkdir "${PKG_BASE_DIR}"; + then + return 1; + fi; + + if ! rtl_fileop mkdir "${PKG_BUILD_DIR}" "${PKG_DESTDIR}"\ + || ! ex_pkg_state_set2 "${_eppep_workdir}" "${_eppep_pkg_name}" "start"; + then + return 1; + fi; + elif ! rtl_exists_any "${PKG_BASE_DIR}" "${PKG_BUILD_DIR}" "${PKG_DESTDIR}" "${PKG_DESTDIR_HOST}"\ + && ! rtl_fileop mkdir "${PKG_BASE_DIR}" "${PKG_BUILD_DIR}" "${PKG_DESTDIR}" "${PKG_DESTDIR_HOST}"; + then + return 1 + fi; + + rtl_fileop cd "${PKG_BUILD_DIR}"; + return "${?}"; +}; + +# +# exp_pkg_exec_step() - XXX +# @_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 or LAST +# @_step: build step to execute +# +# Return: zero (0) on success, non-zero (>0) on failure +# +exp_pkg_exec_step() { + local _eppes_group_name="${1}" _eppes_pkg_name="${2}" _eppes_restart_at="${3}" \ + _eppes_step="${4}" \ + _eppes_fn_name="" _eppes_pkg_step_fn="" _eppes_rc=0; + + if rtl_test_cmd "pkg_${_eppes_pkg_name}_${_eppes_step}"; then + _eppes_pkg_step_fn="pkg_${_eppes_pkg_name}_${_eppes_step}"; + else + _eppes_pkg_step_fn="pkg_${_eppes_step}"; + fi; + + for _eppes_fn_name in \ + "pkg_${_eppes_pkg_name}_${_eppes_step}_pre" \ + "${_eppes_pkg_step_fn}" \ + "pkg_${_eppes_pkg_name}_${_eppes_step}_post"; + do + if rtl_test_cmd "${_eppes_fn_name}"\ + && ! "${_eppes_fn_name}" \ + "${_eppes_group_name}" "${_eppes_pkg_name}" \ + "${_eppes_restart_at}"; + then + _eppes_rc=1; break; + fi; + done; + + return "${_eppes_rc}"; +}; + +# +# exp_pkg_exec() - XXX +# @_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 or LAST +# @_workdir: pathname to build-specific temporary directory +# +# Return: zero (0) on success, non-zero (>0) on failure +# +exp_pkg_exec() { + local _eppe_dispatch_fn="${1}" _eppe_group_name="${2}" _eppe_pkg_name="${3}" \ + _eppe_restart_at="${4}" _eppe_workdir="${5}" \ + _eppe_build_step_last="" _eppe_rc=0 _eppe_step=""; + + if ! exp_pkg_exec_pre \ + "${_eppe_group_name}" "${_eppe_pkg_name}" \ + "${_eppe_restart_at}" "${_eppe_workdir}"\ + || ! "${_eppe_dispatch_fn}" \ + start_pkg_child "${_eppe_group_name}" \ + "${_eppe_pkg_name}"; + then + _eppe_rc=1; + elif rtl_test_cmd "pkg_${_eppe_pkg_name}_all"; then + "pkg_${_eppe_pkg_name}_all" \ + "${_eppe_group_name}" "${_eppe_pkg_name}" \ + "${_eppe_restart_at}"; + _eppe_rc="${?}"; + else + set -- ${PKG_BUILD_STEPS}; + while [ ${#} -gt 0 ]; do + _eppe_step="${1}"; shift; + + if [ "${#_eppe_restart_at}" -gt 0 ]\ + && [ "${_eppe_restart_at}" != "ALL" ]\ + && [ "${_eppe_restart_at}" != "LAST" ]\ + && ! rtl_lmatch \$_eppe_restart_at "${_eppe_step}" ","; then + continue; + fi; + + if [ "${_eppe_step}" = "finish" ]; then + ex_pkg_state_set2 "${_eppe_workdir}" "${_eppe_pkg_name}" finish; break; + elif [ "${PKG_FORCE:-0}" -eq 0 ]\ + && ex_pkg_state_test2 "${_eppe_workdir}" "${_eppe_pkg_name}" "${_eppe_step}" "${_eppe_restart_at}"; + then + continue; + elif ! exp_pkg_exec_step \ + "${_eppe_group_name}" "${_eppe_pkg_name}" \ + "${_eppe_restart_at}" "${_eppe_step}"; + then + _eppe_rc=1; break; + else printf "step %s %s %s\n" "${_eppe_group_name}" "${_eppe_pkg_name}" "${_eppe_step}" >&3; + ex_pkg_state_set2 "${_eppe_workdir}" "${_eppe_pkg_name}" "${_eppe_step}" "${@}"; + fi; + done; + fi; + + return "${_eppe_rc}"; +}; + +# +# ex_pkg_exec() - dispatch single named packages +# @_rdispatch_count: reference to inout variable of dispatcher count +# @_dispatch_count_cur: current dispatcher count +# @_dispatch_count_max: maximum dispatcher count +# @_dispatch_group_cur: current group +# @_dispatch_group_max: maximum group +# @_rdispatch_njobs: reference to inout variable of dispatcher count +# @_rdispatch_wait: reference to inout variable of package names in a wait state +# @_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 +# @_pipe_path: pathname to parent-child process FIFO +# @_pkg_name: single package name +# @_restart_at: optional comma-separated list of build steps at which to rebuild or ALL or LAST +# @_workdir: pathname to build-specific temporary directory +# +# Return: zero (0) on success, non-zero (>0) on failure. +# +ex_pkg_exec() { + local _epdp_rdispatch_count="${1#\$}" _epdp_dispatch_count_cur="${2}" _epdp_dispatch_count_max="${3}" \ + _epdp_dispatch_group_cur="${4}" _epdp_dispatch_group_max="${5}" _epdp_rdispatch_njobs="${6#\$}" \ + _epdp_rdispatch_wait="${7#\$}" _epdp_build_steps_default="${8}" _epdp_build_vars_default="${9}" \ + _epdp_dispatch_fn="${10}" _epdp_group_name="${11}" _epdp_pipe_path="${12}" _epdp_pkg_name="${13}" \ + _epdp_restart_at="${14}" _epdp_workdir="${15}" \ + _epdp_dispatch_count_new=0 _epdp_perc_group=0 _epdp_perc_pkg=0; + + rtl_percentage2 \$_epdp_dispatch_group_cur \$_epdp_dispatch_group_max \$_epdp_perc_group; + rtl_percentage2 \$_epdp_dispatch_count_cur \$_epdp_dispatch_count_max \$_epdp_perc_pkg; + + eval _epdp_dispatch_count_new='$((${'"${_epdp_rdispatch_count}"'}+1))'; + if "${_epdp_dispatch_fn}" \ + start_pkg "${_epdp_group_name}" \ + "${_epdp_pkg_name}" \ + "${_epdp_dispatch_count_new}" \ + "${_epdp_dispatch_count_max}" \ + "${_epdp_perc_group}" "${_epdp_perc_pkg}"; + then + eval : '$(('${_epdp_rdispatch_njobs}'+=1))'; + eval ${_epdp_rdispatch_count}=\"\${_epdp_dispatch_count_new}\"; + rtl_lconcat "${_epdp_rdispatch_wait}" "${_epdp_pkg_name}"; + + (trap "if [ \${?} -eq 0 ]; then \ + printf \"done %s %s %d\n\" \"${_epdp_group_name}\" \"${_epdp_pkg_name}\" \"${_epdp_dispatch_count_new}\" >&3; \ + else \ + printf \"fail %s %s %d\n\" \"${_epdp_group_name}\" \"${_epdp_pkg_name}\" \"${_epdp_dispatch_count_new}\" >&3; \ + pkill -U "${$}"; \ + fi;" EXIT HUP INT TERM USR1 USR2; + set +o errexit -o noglob -o nounset; BUILD_IS_PARENT=0; rtl_log_set_fname ""; rtl_log_set_no_attr 1; + + if ex_pkg_env \ + "${_epdp_build_steps_default}" "${_epdp_build_vars_default}" \ + "${_epdp_group_name}" "${_epdp_pkg_name}" \ + "${_epdp_restart_at}" "${_epdp_workdir}"; + then + exp_pkg_exec \ + "${_epdp_dispatch_fn}" "${_epdp_group_name}" \ + "${_epdp_pkg_name}" "${_epdp_restart_at}" \ + "${_epdp_workdir}"; + else + return 1; + fi;) 1>"${_epdp_workdir}/${_epdp_pkg_name}_stderrout.log" 2>&1 3>"${_epdp_pipe_path}" & + return "${?}"; + else + return 1; + fi; +}; + +# vim:filetype=sh diff --git a/subr.ex/ex_pkg_restart.subr b/subr.ex/ex_pkg_restart.subr new file mode 100644 index 0000000..d93adcb --- /dev/null +++ b/subr.ex/ex_pkg_restart.subr @@ -0,0 +1,331 @@ +# +# set +o errexit -o noglob -o nounset is assumed. +# + +# +# exp_pkg_check_restart_at() - XXX +# @_rstatus: out reference to status string +# @_rspec_at: in reference to restart build step list +# +# Calling convention: in ref. @_rspec_at +# Returns: zero (0) on success, non-zero (>0) on failure +# +exp_pkg_check_restart_at() { + local _epcra_rstatus="${1#\$}" _epcra_rspec_at="${2#\$}" \ + _epcra_len=0 _epcra_rc=0 _epcra_spec_at=""; + + if ! rtl_llift2 "${_epcra_rspec_at}" \$_epcra_spec_at "," " "\ + || ! rtl_lfilter \$_epcra_spec_at "${DEFAULT_BUILD_STEPS} ALL LAST"\ + || ! rtl_llength \$_epcra_spec_at \$_epcra_len; then + _epcra_rc=1; + elif [ "${_epcra_len}" -gt 0 ]; then + _epcra_rc=1; + rtl_setrstatus "${_epcra_rstatus}" 'unknown build step(s) \`'"${_epcra_spec_at}"''\'''; + fi; + + return "${_epcra_rc}"; +}; + +# +# exp_pkg_expand_restart_at_spec() - XXX +# @_rstatus: out reference to status string +# @_rset: in reference to restart virtual build step set +# @_rspec_at: inout reference to restart build step list +# +# Calling convention: in ref. @_rset, inout ref. @_rspec_at +# Returns: zero (0) on success, non-zero (>0) on failure +# +exp_pkg_expand_restart_at_spec() { + local _eperas_rstatus="${1#\$}" _eperas_rset="${2#\$}" _eperas_rspec_at="${3#\$}" \ + _eperas_at="" _eperas_rc=0 _eperas_spec_at="" _eperas_spec_at_=""; + eval _eperas_spec_at='${'"${_eperas_rspec_at}"'}'; + + case "${_eperas_spec_at}" in + ALL|LAST|"") + ;; + + ^*) + _eperas_spec_at="${_eperas_spec_at#^}"; + if exp_pkg_expand_restart_at_virtual \ + "${_eperas_rstatus}" \ + "${_eperas_spec_at}" \$_eperas_spec_at \ + "${_eperas_rset}" \ + && exp_pkg_check_restart_at "${_eperas_rstatus}" \$_eperas_spec_at; + then + rtl_llift2 \$DEFAULT_BUILD_STEPS "${_eperas_rspec_at}" " " ","; + rtl_llift2 \$_eperas_spec_at \$_eperas_spec_at_ "," " "; + for _eperas_at in ${_eperas_spec_at_}; do + rtl_lfilter "${_eperas_rspec_at}" "${_eperas_at}" ","; + done; rtl_lfilter "${_eperas_rspec_at}" "finish" ","; + else + _eperas_rc=1; + fi; ;; + + \<=*|\<*|\>=*|\>*) + exp_pkg_expand_restart_at_spec_cmp \ + "${_eperas_rset}" "${_eperas_rspec_at}"; _eperas_rc="${?}"; ;; + + *) + if ! exp_pkg_expand_restart_at_virtual \ + "${_eperas_rstatus}" \ + "${_eperas_spec_at}" "${_eperas_rspec_at}" \ + "${_eperas_rset}"; then + _eperas_rc=1; + fi; ;; + esac; + + if [ "${_eperas_rc}" -eq 0 ]; then + if ! exp_pkg_check_restart_at "${_eperas_rstatus}" "${_eperas_rspec_at}"; then + _epprs_rc=1; + elif eval [ '"${'"${_eperas_rspec_at}"':+1}"' != 1 ]; then + _epprs_rc=1; + rtl_setrstatus "${_eperas_rstatus}" 'zero-length build step list'; + fi; + fi; + + return "${_eperas_rc}"; +}; + +# +# exp_pkg_expand_restart_at_spec_cmp() - XXX +# @_rstatus: out reference to status string +# @_rset: in reference to restart virtual build step set +# @_rspec_at: inout reference to restart build step list +# +# Calling convention: in ref. @_rset, inout ref. @_rspec_at +# Returns: zero (0) on success, non-zero (>0) on failure +# +exp_pkg_expand_restart_at_spec_cmp() { + local _eperasc_rstatus="${1#\$}" _eperasc_rset="${2#\$}" _eperasc_rspec_at="${3#\$}" \ + _eperasc_at="" _eperasc_eqfl="" _eperasc_foundfl="" _eperasc_ltfl="" _eperasc_rc=0 \ + _eperasc_spec_at="" _eperasc_spec_at0=""; + eval _eperasc_spec_at0='${'"${_eperasc_rspec_at}"'}'; + + [ "${_eperasc_spec_at0#<}" = "${_eperasc_spec_at0}" ]; _eperasc_ltfl="${?}"; + if [ "${_eperasc_spec_at0#[<>]=}" != "${_eperasc_spec_at0}" ]; then + _eperasc_spec_at0="${_eperasc_spec_at0#[<>]=}"; _eperasc_eqfl=1; + else + _eperasc_spec_at0="${_eperasc_spec_at0#[<>]}"; _eperasc_eqfl=0; + fi; _eperasc_spec_at=""; + + if exp_pkg_expand_restart_at_virtual \ + "${_eperasc_rstatus}" \ + "${_eperasc_spec_at0%%,*}" \$_eperasc_spec_at0 \ + "${_eperasc_rset}" \ + && exp_pkg_check_restart_at "${_eperasc_rstatus}" \$_eperasc_spec_at0; then + if [ \( "${_eperasc_eqfl}" -eq 1 \) -a \( "${_eperasc_ltfl}" -eq 1 \) ]\ + || [ \( "${_eperasc_eqfl}" -eq 0 \) -a \( "${_eperasc_ltfl}" -eq 0 \) ]; then + _eperasc_spec_at0="${_eperasc_spec_at0##*,}"; + elif [ \( "${_eperasc_eqfl}" -eq 1 \) -a \( "${_eperasc_ltfl}" -eq 0 \) ]\ + || [ \( "${_eperasc_eqfl}" -eq 0 \) -a \( "${_eperasc_ltfl}" -eq 1 \) ]; then + _eperasc_spec_at0="${_eperasc_spec_at0%%,*}"; + fi; + + _eperasc_foundfl=0; for _eperasc_at in ${DEFAULT_BUILD_STEPS}; do + if [ "${_eperasc_ltfl}" -eq 1 ]; then + if [ "${_eperasc_at}" = "${_eperasc_spec_at0%%,*}" ]; then + if [ "${_eperasc_eqfl}" -eq 1 ]; then + _eperasc_spec_at="${_eperasc_spec_at:+${_eperasc_spec_at},}${_eperasc_at}"; + fi; break; + fi; + else + if [ "${_eperasc_at}" = "${_eperasc_spec_at0%%,*}" ]; then + _eperasc_foundfl=1; [ "${_eperasc_eqfl}" -eq 0 ] && continue; + fi; [ "${_eperasc_foundfl}" -eq 0 ] && continue; + fi; + _eperasc_spec_at="${_eperasc_spec_at:+${_eperasc_spec_at},}${_eperasc_at}"; + done; + else + _eperasc_rc=1; + fi; + + eval ${_eperasc_rspec_at}='${_eperasc_spec_at}'; + return "${_eperasc_rc}"; +}; + +# +# exp_pkg_expand_restart_at_virtual() - XXX +# @_rstatus: out reference to status string +# @_spec_at: restart build step list +# @_rspec_at_new: out reference to new restart build step list +# @_rset: inout reference to restart virtual build step set +# +# Calling convention: inout ref. @_rspec_recursive +# Returns: zero (0) on success, non-zero (>0) on failure +# +exp_pkg_expand_restart_at_virtual() { + local _epera_rstatus="${1#\$}" _epera_spec_at="${2}" _epera_rspec_at_new="${3#\$}" \ + _epera_rset="${4#\$}" \ + _epera_at="" _epera_IFS0="${IFS:- }" _epera_rc=0 _epera_spec_at_new="" \ + IFS; + + eval ${_epera_rspec_at_new}=; + IFS=","; set -- ${_epera_spec_at}; IFS="${_epera_IFS0}"; + while [ "${#}" -gt 0 ]; do + _epera_at="${1}"; shift; + if [ "${_epera_at#@}" != "${_epera_at}" ]; then + _epera_at="${_epera_at#@}"; + _epera_rc=1; + rtl_setrstatus "${_epera_rstatus}" 'invalid virtual build step \`'"${_epera_at}"''\'''; + if [ "${_epera_at%[!0-9a-zA-Z_]*}" != "${_epera_at}" ]; then + _epera_rc=1; + + elif eval [ '"${'"${_epera_rset}${_epera_at}"':+1}"' = 1 ]; then + eval _epera_at='${'"${_epera_rset}${_epera_at}"'}'; + else + _epera_rc=1; + rtl_setrstatus "${_epera_rstatus}" 'unknown virtual build step \`'"${_epera_at}"''\'''; + fi; + fi; + eval ${_epera_rspec_at_new}='${'"${_epera_rspec_at_new}"':+${'"${_epera_rspec_at_new}"'},}${_epera_at}'; + done; + + return "${_epera_rc}"; +}; + +# +# exp_pkg_expand_restart_recursive() - XXX +# @_rspec: inout reference to restart {specification,package name list} +# @_rrecursive: out reference to recursion flag +# +# Calling convention: inout ref. @_rspec, out ref. @_rrecursive +# Returns: zero (0) on success, non-zero (>0) on failure +# +exp_pkg_expand_restart_recursive() { + local _eperr_rspec="${1#\$}" _eperr_rrecursive="${2#\$}" _eperr_spec=""; + eval _eperr_spec='${'"${_eperr_rspec}"'}'; + + case "${_eperr_spec}" in + + \*\*\*[a-zA-Z]*) + eval ${_eperr_rspec}='${_eperr_spec#\*\*\*}' ${_eperr_rrecursive}=3; ;; + \*\*[a-zA-Z]*) eval ${_eperr_rspec}='${_eperr_spec#\*\*}' ${_eperr_rrecursive}=2; ;; + \*[a-zA-Z]*) eval ${_eperr_rspec}='${_eperr_spec#\*}' ${_eperr_rrecursive}=1; ;; + ALL) eval ${_eperr_rrecursive}=2; ;; + LAST) eval ${_eperr_rrecursive}=0; ;; + + esac; + + return 0; +}; + +# +# exp_pkg_expand_restart_spec() - XXX +# @_rstatus: out reference to status string +# @_rspec: inout reference to restart {specification,package name list} +# @_rspec_at: out reference to restart build step list +# +# Calling convention: inout ref. @_rspec, out ref. @_rspec_at, out ref. @_rrecursive +# Returns: zero (0) on success, non-zero (>0) on failure +# +exp_pkg_expand_restart_spec() { + local _epers_rstatus="${1#\$}" _epers_rspec="${2#\$}" _epers_rspec_at="${3#\$}" \ + _epers_last_pkg="" _epers_rc=0 _epers_spec="" _epers_spec_at="" _epers_spec_at0=""; + eval _epers_spec='${'"${_epers_rspec}"'}'; + + case "${_epers_spec}" in + "") eval ${_epers_rspec_at}=; ;; + ALL) eval ${_epers_rspec_at}=ALL; ;; + LAST|LAST:*) + case "${_epers_spec}" in + LAST) eval ${_epers_rspec_at}=LAST; ;; + LAST:*) eval ${_epers_rspec_at}='${_epers_spec#LAST:}'; ;; + esac; + if [ "${DEFAULT_BUILD_LAST_FAILED_PKG_FNAME:+1}" = 1 ]\ + && [ -e "${DEFAULT_BUILD_LAST_FAILED_PKG_FNAME}" ]; then + if read -r _epers_last_pkg <"${DEFAULT_BUILD_LAST_FAILED_PKG_FNAME}"\ + && rtl_fileop rm "${DEFAULT_BUILD_LAST_FAILED_PKG_FNAME}"; then + eval ${_epers_rspec}='${_epers_last_pkg}'; + else + _epers_rc=1; + rtl_setrstatus "${_epers_rstatus}" 'failed to read or clear status of last failed package \`'"${_epers_last_pkg}"''\'''; + fi; + else + _epers_rc=1; + rtl_setrstatus "${_epers_rstatus}" 'cannot rebuild last failed package'; + fi; ;; + + *:*) eval ${_epers_rspec}='${_epers_spec%:*}' ${_epers_rspec_at}='${_epers_spec#*:}'; ;; + *) eval ${_epers_rspec_at}= ${_epers_rspec_at}=ALL; ;; + esac; + + return "${_epers_rc}"; +}; + +# +# exp_pkg_init_restart_at_virtual() - XXX +# @_rset: out reference to restart virtual build step set +# +# Calling convention: out ref. @_rset +# Returns: zero (0) on success, non-zero (>0) on failure +# +exp_pkg_init_restart_at_virtual() { + local _eperav_rset="${1#\$}" _eperav_step="" _eperav_step_virtual="" _epera_steps=""; + + rtl_lfilter2 \$DEFAULT_BUILD_STEPS \$_epera_steps "finish"; + for _eperav_step in ${_epera_steps}; do + _eperav_step_virtual="${_eperav_step%%_*}"; + if eval [ '"${'"${_eperav_rset}${_eperav_step_virtual}"':+1}"' != 1 ]; then + eval ${_eperav_rset}='"${'"${_eperav_rset}"':+${'"${_eperav_rset}"'},}${_eperav_step_virtual}"'; + fi; + eval ${_eperav_rset}${_eperav_step_virtual}='"${'"${_eperav_rset}${_eperav_step_virtual}"':+${'"${_eperav_rset}${_eperav_step_virtual}"'},}${_eperav_step}"'; + done; + + return 0; +}; + +# +# ex_pkg_process_restart_spec() - XXX +# @_rstatus: out reference to status string +# @_rspec: inout reference to restart {specification,package name list} +# @_rspec_at: out reference to restart build step list +# @_rrecursive: out reference to restart recursion flag +# +# Calling convention: inout ref. @_rspec, out ref. @_rspec_at +# Returns: zero (0) on success, non-zero (>0) on failure +# +ex_pkg_process_restart_spec() { + local _epprs_rstatus="${1#\$}" _epprs_rspec="${2#\$}" _epprs_rspec_at="${3#\$}" \ + _epprs_rrecursive="${4#\$}" \ + _epprs_at="" _epprs_rc=0 _epprs_spec_at_new="" _epprs_step="" _epprs_step1="" \ + _epprs_virtual_set=""; + + if eval [ '"${'"${_epprs_rspec}"':+1}"' = 1 ]; then + if exp_pkg_init_restart_at_virtual \$_epprs_virtual_set \ + && exp_pkg_expand_restart_spec "${_epprs_rstatus}" "${_epprs_rspec}" \$_epprs_spec_at_new \ + && exp_pkg_expand_restart_recursive "${_epprs_rspec}" "${_epprs_rrecursive}" \ + && exp_pkg_expand_restart_at_spec "${_epprs_rstatus}" \$_epprs_virtual_set \$_epprs_spec_at_new; + then + + eval ${_epprs_rspec_at}=; + case "${_epprs_spec_at_new}" in + + ALL|LAST) + eval ${_epprs_rspec_at}='${_epprs_spec_at_new}'; ;; + + *) + for _epprs_at in ${DEFAULT_BUILD_STEPS}; do + if rtl_lmatch \$_epprs_at "${_epprs_spec_at_new}" ","; then + eval ${_epprs_rspec_at}='${'"${_epprs_rspec_at}"':+${'"${_epprs_rspec_at}"'},}${_epprs_at}'; + fi; + done; + if eval [ '"${'"${_epprs_rspec_at}"'##*,}"' != "finish" ]; then + rtl_lfilter2 "${_epprs_rspec_at}" \$_epprs_step "clean,finish" ","; _epprs_step="${_epprs_step##*,}"; + rtl_lfilter2 \$DEFAULT_BUILD_STEPS \$_epprs_step1 "clean finish"; _epprs_step1="${_epprs_step1##* }"; + if [ "${_epprs_step}" = "${_epprs_step1}" ]; then + eval ${_epprs_rspec_at}='${'"${_epprs_rspec_at}"':+${'"${_epprs_rspec_at}"'},}finish'; + fi; + fi; ;; + + esac; + rtl_llift "${_epprs_rspec}" "," " " || _epprs_rc=1; + else + _epprs_rc=1; + fi; + rtl_sunset \$_epprs_virtual_set; + fi; + + return "${_epprs_rc}"; +}; + +# vim:filetype=sh diff --git a/subr.pkg/pkg_build.subr b/subr.pkg/pkg_build.subr new file mode 100644 index 0000000..8ea9736 --- /dev/null +++ b/subr.pkg/pkg_build.subr @@ -0,0 +1,67 @@ +# +# set +o errexit -o noglob -o nounset is assumed. +# + +pkg_build() { + local _pb_group_name="${1}" _pb_pkg_name="${2}" _pb_restart_at="${3}" \ + _pb_libtool="" _pb_makeflags_verbosity="" _pb_no_autoconf="" \ + _pb_rc=0 _pb_subdir=""; + _pb_makeflags_verbosity="${PKG_MAKEFLAGS_VERBOSITY:-none}"; + if [ "${_pb_makeflags_verbosity}" = "none" ]; then + _pb_makeflags_verbosity=""; + fi; + + case "${PKG_LIBTOOL:-}" in + "") _pb_libtool=""; ;; + none) _pb_libtool=""; ;; + *) _pb_libtool="${PKG_LIBTOOL}"; ;; + esac; + + if [ ! -x "${PKG_CONFIGURE:-}" ]; then + _pb_no_autoconf=1; + fi; + + for _pb_subdir in ${PKG_MAKE_SUBDIRS:-:}; do + if [ "${_pb_subdir}" = ":" ]; then + _pb_subdir=""; + fi; + + if [ "${#_pb_libtool}" -gt 0 ]; then + export MAKE="make LIBTOOL=${_pb_libtool}"; + fi; + + # 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. + rtl_run_cmd_unsplit "${PKG_MAKE}" \ + ${PKG_MAKEFLAGS_BUILD:-} \ + ${PKG_MAKEFLAGS_BUILD_EXTRA:-} \ + "AR=${PKG_AR}" "${_pb_no_autoconf:+CC=${PKG_CC}}" "RANLIB=${PKG_RANLIB}" \ + "${PKG_CFLAGS_BUILD:+CFLAGS=${PKG_CFLAGS_BUILD}}" \ + "${PKG_CFLAGS_BUILD_EXTRA:+CFLAGS+=${PKG_CFLAGS_BUILD_EXTRA}}" \ + "${PKG_CPPFLAGS_BUILD:+CPPFLAGS=${PKG_CPPFLAGS_BUILD}}" \ + "${PKG_CPPFLAGS_BUILD_EXTRA:+CPPFLAGS+=${PKG_CPPFLAGS_BUILD_EXTRA}}" \ + "${PKG_CXXFLAGS_BUILD:+CXXFLAGS=${PKG_CXXFLAGS_BUILD}}" \ + "${PKG_CXXFLAGS_BUILD_EXTRA:+CXXFLAGS+=${PKG_CXXFLAGS_BUILD_EXTRA}}" \ + "${PKG_LDFLAGS_BUILD:+LDFLAGS=${PKG_LDFLAGS_BUILD}}" \ + "${PKG_LDFLAGS_BUILD_EXTRA:+LDFLAGS+=${PKG_LDFLAGS_BUILD_EXTRA}}" \ + "${PKG_PKG_CONFIG:+PKG_CONFIG=${PKG_PKG_CONFIG}}" \ + "${PKG_PKG_CONFIG_LIBDIR:+PKG_CONFIG_LIBDIR=${PKG_PKG_CONFIG_LIBDIR}}" \ + ${_pb_libtool:+"LIBTOOL=${_pb_libtool}"} \ + ${_pb_makeflags_verbosity} \ + ${_pb_subdir:+-C "${_pb_subdir}"}; + _pb_rc="${?}"; + + if [ "${#_pb_libtool}" -gt 0 ]; then + unset MAKE; + fi; + + if [ "${_pb_rc}" -ne 0 ]; then + break; + fi; + done; + + return "${_pb_rc}"; +}; + +# vim:filetype=sh diff --git a/subr.pkg/pkg_build_clean.subr b/subr.pkg/pkg_build_clean.subr new file mode 100644 index 0000000..bf41456 --- /dev/null +++ b/subr.pkg/pkg_build_clean.subr @@ -0,0 +1,37 @@ +# +# set +o errexit -o noglob -o nounset is assumed. +# + +pkg_build_clean() { + local _pbc_group_name="${1}" _pbc_pkg_name="${2}" _pbc_restart_at="${3}" \ + _pbc_libtool="" _pbc_makeflags_verbosity="${PKG_MAKEFLAGS_VERBOSITY:-}" \ + _pbc_no_autoconf="" _pbc_rc=0 _pbc_subdir=""; + + if ex_pkg_state_test "${PKG_NAME}" "build" "${_pbc_restart_at}"; then + case "${PKG_LIBTOOL:-}" in + "") _pbc_libtool=""; ;; + none) _pbc_libtool=""; ;; + *) _pbc_libtool="${PKG_LIBTOOL}"; ;; + esac; + [ ! -x "${PKG_CONFIGURE:-}" ] && _pbc_no_autoconf=1; + + for _pbc_subdir in ${PKG_MAKE_SUBDIRS:-:}; do + [ "${_pbc_subdir}" = ":" ] && _pbc_subdir=""; + [ "${#_pbc_libtool}" -gt 0 ] && export MAKE="make LIBTOOL=${_pbc_libtool}"; + + rtl_run_cmd_unsplit "${PKG_MAKE}" \ + ${PKG_MAKEFLAGS_BUILD:-} \ + ${PKG_MAKEFLAGS_BUILD_EXTRA:-} \ + ${_pbc_libtool:+"LIBTOOL=${_pbc_libtool}"} \ + ${_pbc_makeflags_verbosity} \ + ${_pbc_subdir:+-C "${_pbc_subdir}"} \ + clean; _pbc_rc="${?}"; + + [ "${#_pbc_libtool}" -gt 0 ] && unset MAKE; + [ "${_pbc_rc}" -ne 0 ] && return 1; + done; + fi; + return 0; +}; + +# vim:filetype=sh diff --git a/subr.pkg/pkg_clean.subr b/subr.pkg/pkg_clean.subr new file mode 100644 index 0000000..0b65ec8 --- /dev/null +++ b/subr.pkg/pkg_clean.subr @@ -0,0 +1,32 @@ +# +# set +o errexit -o noglob -o nounset is assumed. +# + +pkg_clean() { + local _pc_group_name="${1}" _pc_pkg_name="${2}" _pc_restart_at="${3}"; + + if [ "${PKG_NO_CLEAN:-0}" -eq 0 ]; then + if rtl_lmatch \$ARG_CLEAN_BUILDS "build" ","\ + && [ "${PKG_NO_CLEAN_BUILD_DIR:-0}" -eq 0 ]; then + if ! rtl_fileop rm "${PKG_BUILD_DIR}"; then + return 1; + fi; + fi; + if rtl_lmatch \$ARG_CLEAN_BUILDS "dest" ","; then + if ! rtl_fileop rm "${PKG_DESTDIR}"; then + return 1; + elif [ -e "${PKG_DESTDIR_HOST}" ]\ + && ! rtl_fileop rm "${PKG_DESTDIR_HOST}"; then + return 1; + fi; + fi; + if rtl_lmatch \$ARG_CLEAN_BUILDS "src" ","; then + if ! rtl_fileop rm "${PKG_BASE_DIR}/${PKG_SUBDIR}"; then + return 1; + fi; + fi; + fi; + return 0; +}; + +# vim:filetype=sh diff --git a/subr.pkg/pkg_configure.subr b/subr.pkg/pkg_configure.subr new file mode 100644 index 0000000..818ede1 --- /dev/null +++ b/subr.pkg/pkg_configure.subr @@ -0,0 +1,194 @@ +# +# set +o errexit -o noglob -o nounset is assumed. +# + +pkgp_configure_autotools() { + local _ppca_libtool="" _ppca_rc=0; + + if ! [ -x "${PKG_CONFIGURE:-}" ]; then + _ppca_rc=2; + elif [ -d "${PKG_BASE_DIR}/${PKG_SUBDIR}/sofort" ]\ + || [ "${PKG_CONFIGURE_TYPE:-}" = "sofort" ]; + then + _ppca_rc=2; + else + case "${PKG_LIBTOOL:-}" in + "") _ppca_libtool=""; ;; + none) _ppca_libtool=""; ;; + *) _ppca_libtool="${PKG_LIBTOOL}"; ;; + esac; + + rtl_export_vars \ + PKG_CONFIG "${PKG_PKG_CONFIG:-}" \ + PKG_CONFIG_LIBDIR "${PKG_PKG_CONFIG_LIBDIR:-}" \ + PYTHON "${PKG_PYTHON:-}" \ + ${_ppca_libtool:+MAKE} ${_ppca_libtool:+"make LIBTOOL=${_ppca_libtool}"}; + + AR="${PKG_AR}" \ + CC="${PKG_CC}" \ + RANLIB="${PKG_RANLIB}" \ + CFLAGS="${PKG_CFLAGS_CONFIGURE:-}${PKG_CFLAGS_CONFIGURE_EXTRA:+ ${PKG_CFLAGS_CONFIGURE_EXTRA}}" \ + CPPFLAGS="${PKG_CFLAGS_CONFIGURE:-}${PKG_CFLAGS_CONFIGURE_EXTRA:+ ${PKG_CFLAGS_CONFIGURE_EXTRA}}" \ + 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:-}; + _ppca_rc=$((${?} ? 1 : ${_ppca_rc})); + + rtl_export_vars -u \ + PKG_CONFIG "${PKG_PKG_CONFIG:-}" \ + PKG_CONFIG_LIBDIR "${PKG_PKG_CONFIG_LIBDIR:-}" \ + PYTHON "${PKG_PYTHON:-}" \ + ${_ppca_libtool:+MAKE} ${_ppca_libtool:+"make LIBTOOL=${_ppca_libtool}"}; + fi; + + return "${_ppca_rc}"; +}; + +pkgp_configure_cmake() { + local _ppcc_cmake_args_auto"" _ppcc_build_type="" _ppcc_IFS0="${IFS:- }" _ppcc_rc=0 IFS; + + if [ "${PKG_CMAKE_LISTFILE:+1}" != 1 ]\ + || ! [ -e "${PKG_BASE_DIR}/${PKG_SUBDIR}/${PKG_CMAKE_LISTFILE}" ]; then + _ppcc_rc=2; + else + rtl_fileop rm config.cache || return 1; + rtl_export_vars \ + PKG_CONFIG "${PKG_PKG_CONFIG:-}" \ + PKG_CONFIG_LIBDIR "${PKG_PKG_CONFIG_LIBDIR:-}" \ + PYTHON "${PKG_PYTHON:-}"; + + case "${BUILD_KIND}" in + debug) _ppcc_build_type="debug"; ;; + release|*) _ppcc_build_type="release"; ;; + esac; + + _ppcc_cmake_args_auto=" + -DCMAKE_AR=${PKG_AR} + -DCMAKE_BUILD_TYPE=${_ppcc_build_type} + -DCMAKE_C_COMPILER=${PKG_CC} + -DCMAKE_C_FLAGS=${PKG_CFLAGS_CONFIGURE:-}${PKG_CFLAGS_CONFIGURE_EXTRA:+ ${PKG_CFLAGS_CONFIGURE_EXTRA}} + -DCMAKE_CPP_FLAGS=${PKG_CPPFLAGS_CONFIGURE:-}${PKG_CPPFLAGS_CONFIGURE_EXTRA:+ ${PKG_CPPFLAGS_CONFIGURE_EXTRA}} + -DCMAKE_CXX_COMPILER=${PKG_CXX} + -DCMAKE_CXX_FLAGS=${PKG_CXXFLAGS_CONFIGURE:-}${PKG_CXXFLAGS_CONFIGURE_EXTRA:+ ${PKG_CXXFLAGS_CONFIGURE_EXTRA}} + -DCMAKE_EXE_LINKER_FLAGS=${PKG_LDFLAGS_CONFIGURE:-}${PKG_LDFLAGS_CONFIGURE_EXTRA:+ ${PKG_LDFLAGS_CONFIGURE_EXTRA}} + -DCMAKE_FIND_ROOT_PATH=${PKG_PREFIX} + -DCMAKE_INSTALL_PREFIX= + -DCMAKE_LINKER=$(which "ld") + -DCMAKE_MODULE_LINKER_FLAGS=${PKG_LDFLAGS_CONFIGURE:-}${PKG_LDFLAGS_CONFIGURE_EXTRA:+ ${PKG_LDFLAGS_CONFIGURE_EXTRA}} + -DCMAKE_RANLIB=${PKG_RANLIB} + -DCMAKE_SHARED_LINKER_FLAGS=${PKG_LDFLAGS_CONFIGURE:-}${PKG_LDFLAGS_CONFIGURE_EXTRA:+ ${PKG_LDFLAGS_CONFIGURE_EXTRA}} + -DPKG_CONFIG_EXECUTABLE=${PKG_PKG_CONFIG}" || return 1; + + case "${PKG_BUILD_TYPE}" in + host|cross) + ;; + + native) + _ppcc_cmake_args_auto="${_ppcc_cmake_args_auto:+${_ppcc_cmake_args_auto}} + -DCMAKE_LINKER=$(which "${PKG_TARGET}-ld") + -DCMAKE_SYSROOT=${PKG_PREFIX} + -DCMAKE_SYSTEM_NAME=Midipix" || return 1; + + case "${ARCH}" in + nt32) _ppcc_cmake_args_auto="${_ppcc_cmake_args_auto:+${_ppcc_cmake_args_auto}} + -DCMAKE_SYSTEM_PROCESSOR=i686"; ;; + nt64) _ppcc_cmake_args_auto="${_ppcc_cmake_args_auto:+${_ppcc_cmake_args_auto}} + -DCMAKE_SYSTEM_PROCESSOR=x86_64"; ;; + esac; ;; + + esac; + + IFS=" + "; "${PKG_CMAKE}" \ + ${_ppcc_cmake_args_auto} \ + ${PKG_CMAKE_ARGS:-} \ + ${PKG_CMAKE_ARGS_EXTRA:-} \ + "${PKG_BASE_DIR}/${PKG_SUBDIR}"; + _ppcc_rc=$((${?} ? ${?} : ${_ppcc_rc})); IFS="${_ppcc_IFS0}"; + + rtl_export_vars -u \ + PKG_CONFIG "${PKG_PKG_CONFIG:-}" \ + PKG_CONFIG_LIBDIR "${PKG_PKG_CONFIG_LIBDIR:-}" \ + PYTHON "${PKG_PYTHON:-}"; + fi; + + return "${_ppcc_rc}"; +}; + +pkgp_configure_sofort() { + local _ppcs_rc=0 _ppcs_vname="" _ppcs_vnames="" _ppcs_vval=""; + + if ! [ -x "${PKG_CONFIGURE:-}" ]; then + _ppcs_rc=2; + elif ! [ -d "${PKG_BASE_DIR}/${PKG_SUBDIR}/sofort" ]\ + && ! [ "${PKG_CONFIGURE_TYPE:-}" = "sofort" ]; then + _ppcs_rc=2; + else + for _ppcs_vname in AR CC CXX LD RANLIB; do + if eval [ '"${PKG_'"${_ppcs_vname}"':+1}"' = 1 ]; then + _ppcs_vnames="${_ppcs_vnames:+${_ppcs_vnames} }${_ppcs_vname}"; + eval ${_ppcs_vname}='${PKG_'"${_ppcs_vname}"'}'; export ${_ppcs_vname}; + fi; + + if eval [ '"${PKG_SOFORT_NATIVE_'"${_ppcs_vname}"':+1}"' = 1 ]; then + _ppcs_vnames="${_ppcs_vnames:+${_ppcs_vnames} }NATIVE_${_ppcs_vname}"; + eval NATIVE_${_ppcs_vname}='${PKG_SOFORT_NATIVE_'"${_ppcs_vname}"'}'; export NATIVE_${_ppcs_vname}; + fi; + done; + + for _ppcs_vname in CFLAGS CPPFLAGS CXXFLAGS LDFLAGS; do + if eval [ '"${PKG_'"${_ppcs_vname}"'_CONFIGURE:+1}"' = 1 ]; then + eval _ppcs_vval='${PKG_'"${_ppcs_vname}"'_CONFIGURE}'; + if eval [ '"${PKG_'"${_ppcs_vname}"'_CONFIGURE_EXTRA:+1}"' = 1 ]; then + eval _ppcs_vval='${_ppcs_vval:+${_ppcs_vval} }${PKG_'"${_ppcs_vname}"'_CONFIGURE_EXTRA}'; + fi; + _ppcs_vnames="${_ppcs_vnames:+${_ppcs_vnames} }${_ppcs_vname} ${_ppcs_vname}_SHARED ${_ppcs_vname}_STATIC"; + eval ${_ppcs_vname}='${_ppcs_vval}'\; ${_ppcs_vname}_SHARED='${_ppcs_vval}'\; ${_ppcs_vname}_STATIC='${_ppcs_vval}'; + export ${_ppcs_vname} ${_ppcs_vname}_SHARED ${_ppcs_vname}_STATIC; + fi; + + if eval [ '"${PKG_SOFORT_NATIVE_'"${_ppcs_vname}"':+1}"' = 1 ]; then + eval _ppcs_vval='${PKG_SOFORT_NATIVE_'"${_ppcs_vname}"'}'; + if eval [ '"${PKG_SOFORT_NATIVE_'"${_ppcs_vname}"'_EXTRA:+1}"' = 1 ]; then + eval _ppcs_vval='${_ppcs_vval:+${_ppcs_vval} }${PKG_SOFORT_NATIVE_'"${_ppcs_vname}"'_EXTRA}'; + fi; + _ppcs_vnames="${_ppcs_vnames:+${_ppcs_vnames} }NATIVE_${_ppcs_vname}"; + eval NATIVE_${_ppcs_vname}='${_ppcs_vval}'; export NATIVE_${_ppcs_vname}; + fi; + done; + + RANLIB="${PKG_RANLIB}" \ + "${PKG_CONFIGURE}" \ + ${PKG_CONFIGURE_ARGS:-} \ + ${PKG_CONFIGURE_ARGS_EXTRA:-} \ + ${PKG_CONFIGURE_ARGS_EXTRA_DEBUG:-}; + _ppcs_rc=$((${?} ? 1 : ${_ppcs_rc})); + + for _ppcs_vname in ${_ppcs_vnames}; do + unset "${_ppcs_vname}"; + done; + fi; + + return "${_ppcs_rc}"; +}; + +pkg_configure() { + local _pc_group_name="${1}" _pc_pkg_name="${2}" _pc_restart_at="${3}" \ + _pc_rc=0 _pc_type=""; + + for _pc_type in autotools sofort cmake; do + if [ "${PKG_CONFIGURE_TYPE:+1}" = 1 ]\ + && [ "${PKG_CONFIGURE_TYPE}" != "${_pc_type}" ]; then + continue; + else + pkgp_configure_${_pc_type} "${@}"; _pc_rc="${?}"; + case "${_pc_rc}" in + 0|1) return "${_pc_rc}"; ;; + 2) _pc_rc=0; continue; ;; + esac; + fi; + done; + return "${_pc_rc}"; +}; + +# vim:filetype=sh textwidth=0 diff --git a/subr.pkg/pkg_configure_autotools.subr b/subr.pkg/pkg_configure_autotools.subr new file mode 100644 index 0000000..c5753dc --- /dev/null +++ b/subr.pkg/pkg_configure_autotools.subr @@ -0,0 +1,114 @@ +# +# set +o errexit -o noglob -o nounset is assumed. +# + +pkg_configure_autotools() { + local _pca_group_name="${1}" _pca_pkg_name="${2}" _pca_restart_at="${3}" \ + _pca_config_cache="" _pca_config_guest_fname="" _pca_fname="" \ + _pca_subdir_tgt=""; + + if [ "${PKG_CONFIGURE_TYPE:+1}" = 1 ]\ + && [ "${PKG_CONFIGURE_TYPE}" != "autotools" ]; then + return 0; + fi; + + if [ "${PKG_AUTOCONF_CONFIG_GUESS:-midipix}" = "midipix" ]; then + _pca_config_guest_fname="config.guess"; + else + _pca_config_guest_fname=""; + fi; + + if rtl_exists_any "${PKG_BASE_DIR}/${PKG_SUBDIR}" \ + ${_pca_config_guest_fname:+"${_pca_config_guest_fname}"} \ + "configure.ac" "configure.in" "configure"; + then + rtl_export_vars PKG_CONFIG "${PKG_PKG_CONFIG:-}" PKG_CONFIG_LIBDIR "${PKG_PKG_CONFIG_LIBDIR:-}"; + + if [ "${PKG_FORCE_AUTORECONF:-0}" -eq 1 ]\ + && ! (cd "${PKG_BASE_DIR}/${PKG_SUBDIR}" && autoreconf -fiv); then + return 1; + fi; + + if [ -e "${PKG_BASE_DIR}/${PKG_SUBDIR}/configure.ac" ]\ + && [ ! -e "${PKG_BASE_DIR}/${PKG_SUBDIR}/configure" ]; then + for _pca_fname in bootstrap bootstrap.sh autogen.sh; do + if [ -e "${PKG_BASE_DIR}/${PKG_SUBDIR}/${_pca_fname}" ]; then + for _pca_subdir_tgt in \ + "${PKG_BASE_DIR}/${PKG_SUBDIR}/build-aux" \ + "${PKG_BASE_DIR}/${PKG_SUBDIR}"; + do if [ -e "${_pca_subdir_tgt}" ]; then + if ! rtl_fileop install -m 0700 \ + "${MIDIPIX_BUILD_PWD}/etc/config.sub" \ + "${_pca_subdir_tgt}/config.sub"; then + return 1; + fi; + + if [ "${PKG_AUTOCONF_CONFIG_GUESS:-midipix}" = "midipix" ]; then + if ! rtl_fileop install -m 0700 \ + "${MIDIPIX_BUILD_PWD}/etc/config.guess"\ + "${_pca_subdir_tgt}/config.guess"; then + return 1; + else + break; + fi; + fi; + fi; + done; + + if ! (rtl_fileop cd "${PKG_BASE_DIR}/${PKG_SUBDIR}" && \ + /bin/sh "${_pca_fname}"); then + return 1; + else + break; + fi; + fi; + done; + + if ! (rtl_fileop cd "${PKG_BASE_DIR}/${PKG_SUBDIR}" && autoconf); then + return 1; + fi; + fi; + + for _pca_fname in $(find "${PKG_BASE_DIR}/${PKG_SUBDIR}" -name config.sub); do + if ! rtl_fileop mv "${_pca_fname}" "${_pca_fname}.orig"\ + || ! rtl_fileop install -m 0700 "${MIDIPIX_BUILD_PWD}/etc/config.sub" "${_pca_fname}"; then + return 1; + fi; + done; + + if [ "${PKG_AUTOCONF_CONFIG_GUESS:-midipix}" = "midipix" ]; then + for _pca_fname in $(find "${PKG_BASE_DIR}/${PKG_SUBDIR}" -name config.guess); do + if ! rtl_fileop mv "${_pca_fname}" "${_pca_fname}.orig"\ + || ! rtl_fileop install -m 0700 "${MIDIPIX_BUILD_PWD}/etc/config.guess" "${_pca_fname}"; then + return 1; + fi; + done; + fi; + + if [ "${PKG_BUILD_TYPE}" != host ]; then + if ! rtl_fileop touch "${PKG_BUILD_DIR}/config.cache"; then + return 1; + else + for _pca_config_cache in \ + "${PKG_CONFIG_CACHE:-}" \ + "${PKG_CONFIG_CACHE_LOCAL:-}" \ + "${PKG_CONFIG_CACHE_EXTRA:-}"; + do if [ "${_pca_config_cache:+1}" = 1 ]\ + && ! printf "%s\n" "${_pca_config_cache}" |\ + tr " " "\n" >> "${PKG_BUILD_DIR}/config.cache"; then + return 1; + fi; + done; + + if ! sed -i"" "s,%PREFIX%,${PKG_PREFIX},g" "${PKG_BUILD_DIR}/config.cache"; then + return 1; + fi; + fi; + fi; + rtl_export_vars -u PKG_CONFIG "${PKG_PKG_CONFIG:-}" PKG_CONFIG_LIBDIR "${PKG_PKG_CONFIG_LIBDIR:-}"; + fi; + + return 0; +}; + +# vim:filetype=sh diff --git a/subr.pkg/pkg_configure_clean.subr b/subr.pkg/pkg_configure_clean.subr new file mode 100644 index 0000000..dd24efd --- /dev/null +++ b/subr.pkg/pkg_configure_clean.subr @@ -0,0 +1,21 @@ +# +# set +o errexit -o noglob -o nounset is assumed. +# + +pkg_configure_clean() { + local _pcc_group_name="${1}" _pcc_pkg_name="${2}" _pcc_restart_at="${3}"; + + if ex_pkg_state_test \ + "${_pcc_pkg_name}" \ + "configure_patch_pre,configure_autotools,configure_patch,configure" \ + "${_pcc_restart_at}"\ + && [ "${PKG_BUILD_DIR:-}" != "${PKG_SUBDIR:-}" ]; + then + rtl_fileop rm "${PKG_BUILD_DIR}" || return 1; + rtl_fileop mkdir "${PKG_BUILD_DIR}" || return 1; + rtl_fileop cd "${PKG_BUILD_DIR}" || return 1; + fi; + return 0; +}; + +# vim:filetype=sh diff --git a/subr.pkg/pkg_configure_patch.subr b/subr.pkg/pkg_configure_patch.subr new file mode 100644 index 0000000..ba78d46 --- /dev/null +++ b/subr.pkg/pkg_configure_patch.subr @@ -0,0 +1,44 @@ +# +# set +o errexit -o noglob -o nounset is assumed. +# + +pkg_configure_patch() { + local _pcp_group_name="${1}" _pcp_pkg_name="${2}" _pcp_restart_at="${3}" \ + _pcp_patch_cwd="" _pcp_patch_dir="${MIDIPIX_BUILD_PWD}/patches" \ + _pcp_patch_fname="" _pcp_patches_done="" _pcp_pkg_name_full="" \ + _pcp_strip_count=0; + _pcp_pkg_name_full="${_pcp_pkg_name}${PKG_VERSION:+-${PKG_VERSION}}"; + + if [ "${PKG_FNAME:+1}" = 1 ]\ + && [ "${PKG_URLS_GIT:+1}" = 1 ]; + then + _pcp_patch_cwd="${PKG_BASE_DIR}"; + _pcp_strip_count=0; + else + _pcp_patch_cwd="${PKG_BASE_DIR}/${PKG_SUBDIR}"; + _pcp_strip_count=1; + fi; + + set +o noglob; + for _pcp_patch_fname in \ + "${_pcp_patch_dir}/${PKG_NAME}/"*.patch \ + "${_pcp_patch_dir}/${_pcp_pkg_name_full}.local.patch" \ + "${_pcp_patch_dir}/${_pcp_pkg_name_full}.local@${BUILD_HNAME}.patch" \ + ${PKG_PATCHES_EXTRA:-}; + do + if [ -r "${_pcp_patch_fname}" ]\ + && ! rtl_lmatch \$_pcp_patches_done "${_pcp_patch_fname}"; + then + if ! patch -b -d "${_pcp_patch_cwd}" "-p${_pcp_strip_count}" < "${_pcp_patch_fname}"; then + set -o noglob; return 1; + else + rtl_lconcat \$_pcp_patches_done "${_pcp_patch_fname}"; + fi; + fi; + done; + set -o noglob; + + return 0; +}; + +# vim:filetype=sh diff --git a/subr.pkg/pkg_configure_patch_pre.subr b/subr.pkg/pkg_configure_patch_pre.subr new file mode 100644 index 0000000..5435232 --- /dev/null +++ b/subr.pkg/pkg_configure_patch_pre.subr @@ -0,0 +1,48 @@ +# +# set +o errexit -o noglob -o nounset is assumed. +# + +pkgp_configure_patch_pre() { + local _ppcpp_patch_path=""; + + for _ppcpp_patch_path in \ + "${MIDIPIX_BUILD_PWD}/patches/${PKG_NAME}${PKG_VERSION:+-${PKG_VERSION}}_pre.local.patch" \ + "${MIDIPIX_BUILD_PWD}/patches/${PKG_NAME}${PKG_VERSION:+-${PKG_VERSION}}_pre.local@${BUILD_HNAME}.patch"; + do + if [ -r "${_ppcpp_patch_path}" ]\ + && ! patch -b -d "${PKG_BASE_DIR}/${PKG_SUBDIR}" -p1 < "${_ppcpp_patch_path}"; + then + return 1; + fi; + done; + return 0; +}; + +pkgp_configure_patch_pre_chainport() { + local _ppcppc_patch_dname="" _ppcppc_patch_fname="" _ppcppc_oldpwd=""; + _ppcppc_patch_dname="${PKG_BASE_DIR}/${PKG_SUBDIR}/patches/${PKG_NAME%%_ppcppc_*}"; + + if [ "${PKG_VERSION:+1}" = 1 ]; then + _ppcppc_patch_fname="${BUILD_WORKDIR}/chainport/patches/${PKG_NAME%%_ppcppc_*}/${PKG_NAME%%_ppcppc_*}-${PKG_VERSION}.midipix.patch"; + fi; + if [ -e "${_ppcppc_patch_fname}" ]; then + if ! rtl_fileop mkdir "${_ppcppc_patch_dname}"\ + || ! rtl_fileop cp "${_ppcppc_patch_fname}" "${_ppcppc_patch_dname}"; then + return 1; + fi; + fi; + return 0; +}; + +pkg_configure_patch_pre() { + local _pcpp_group_name="${1}" _pcpp_pkg_name="${2}" _pcpp_restart_at="${3}"; + + if ! pkgp_configure_patch_pre_chainport\ + || ! pkgp_configure_patch_pre; + then + return 1; + fi; + return 0; +}; + +# vim:filetype=sh diff --git a/subr.pkg/pkg_fetch_clean.subr b/subr.pkg/pkg_fetch_clean.subr new file mode 100644 index 0000000..6202b18 --- /dev/null +++ b/subr.pkg/pkg_fetch_clean.subr @@ -0,0 +1,25 @@ +# +# set +o errexit -o noglob -o nounset is assumed. +# + +pkg_fetch_clean() { + local _pfc_group_name="${1}" _pfc_pkg_name="${2}" _pfc_restart_at="${3}" \ + _pfc_dname=""; + + if [ "${PKG_URLS_GIT:+1}" = 1 ]; then + if [ "${PKG_SUBDIR:+1}" = 1 ]\ + && [ "${PKG_SUBDIR}" != "${PKG_URLS_GIT%%=*}" ]; then + rtl_fileop rm "${PKG_SUBDIR}"; + fi; + + for _pfc_dname in ${PKG_URLS_GIT}; do + _pfc_dname="${_pfc_dname%%=*}"; rtl_fileop rm "${_pfc_dname}"; + done; + elif [ "${PKG_SUBDIR:+1}" = 1 ]; then + rtl_fileop rm "${PKG_SUBDIR}"; + fi; + + return 0; +}; + +# vim:filetype=sh diff --git a/subr.pkg/pkg_fetch_download.subr b/subr.pkg/pkg_fetch_download.subr new file mode 100644 index 0000000..fe7fff8 --- /dev/null +++ b/subr.pkg/pkg_fetch_download.subr @@ -0,0 +1,43 @@ +# +# set +o errexit -o noglob -o nounset is assumed. +# + +pkg_fetch_download() { + local _pfd_group_name="${1}" _pfd_pkg_name="${2}" _pfd_restart_at="${3}"; + + if [ "${ARG_FETCH_FORCE:-}" != "offline" ]; then + if [ "${PKG_URL:+1}" = 1 ]; then + if ! rtl_fetch_dlcache_subdir \ + "${BUILD_DLCACHEDIR}" "${PKG_NAME}" \ + "${PKG_INHERIT_FROM:-}"; + then + return 1; + elif ! rtl_fetch_url_wget \ + "${PKG_URL}" "${PKG_SHA256SUM}" "${BUILD_DLCACHEDIR}/${PKG_NAME}"\ + "${PKG_FNAME}" "${PKG_NAME}" "${PKG_MIRRORS:-}"; then + return 1; + fi; + fi; + + if [ "${PKG_URLS_GIT:+1}" = 1 ]; then + if ! rtl_fetch_dlcache_subdir \ + "${BUILD_DLCACHEDIR}" "${PKG_NAME}" \ + "${PKG_INHERIT_FROM:-}"; + then + return 1; + elif ! rtl_fetch_urls_git \ + "${BUILD_DLCACHEDIR}/${PKG_NAME}" "${DEFAULT_GIT_ARGS}" "${PKG_BASE_DIR}"\ + "${PKG_NAME}" "${PKG_MIRRORS_GIT:-}" ${PKG_URLS_GIT}; then + return 1; + fi; + fi; + + rtl_fetch_clean_dlcache \ + "${BUILD_DLCACHEDIR}" "${PKG_NAME}" \ + "${PKG_FNAME:-}" "${PKG_URLS_GIT:-}"; + fi; + + return 0; +}; + +# vim:filetype=sh diff --git a/subr.pkg/pkg_fetch_extract.subr b/subr.pkg/pkg_fetch_extract.subr new file mode 100644 index 0000000..ed4bad7 --- /dev/null +++ b/subr.pkg/pkg_fetch_extract.subr @@ -0,0 +1,48 @@ +# +# set +o errexit -o noglob -o nounset is assumed. +# + +pkgp_fetch_extract_type() { + local _ppfet_fname="${1}" _ppfet_rtype="${2#\$}"; + + if [ "${1##*.tar.}" != "${1}" ]; then + eval ${_ppfet_rtype}='${1##*.tar.}'; + elif [ "${1##*.t}" != "${1}" ]; then + eval ${_ppfet_rtype}='${1##*.t}'; + fi; + return 0; +}; + +pkg_fetch_extract() { + local _pfe_group_name="${1}" _pfe_pkg_name="${2}" _pfe_restart_at="${3}" \ + _pfe_type=""; + + if [ "${PKG_URL:+1}" = 1 ]; then + _pfe_oldpwd="${PWD}"; + + if ! rtl_fileop cd "${PKG_BASE_DIR}"\ + || ! rtl_fileop rm "${PKG_BASE_DIR}/${PKG_SUBDIR}"; then + rtl_fileop cd "${_pfe_oldpwd}"; return 1; + else + pkgp_fetch_extract_type "${PKG_NAME}" \$_pfe_type; + + case "${_pfe_type}" in + bz2) bunzip2 -d < "${BUILD_DLCACHEDIR}/${PKG_NAME}/${PKG_FNAME}" | tar -C "${PKG_BASE_DIR}" -xf -; ;; + gz) gunzip -d < "${BUILD_DLCACHEDIR}/${PKG_NAME}/${PKG_FNAME}" | tar -C "${PKG_BASE_DIR}" -xf -; ;; + lz) lzip -d < "${BUILD_DLCACHEDIR}/${PKG_NAME}/${PKG_FNAME}" | tar -C "${PKG_BASE_DIR}" -xf -; ;; + xz) xz -d < "${BUILD_DLCACHEDIR}/${PKG_NAME}/${PKG_FNAME}" | tar -C "${PKG_BASE_DIR}" -xf -; ;; + *) tar -C "${PKG_BASE_DIR}" -xf "${BUILD_DLCACHEDIR}/${PKG_NAME}/${PKG_FNAME}"; ;; + esac; + + if [ "${?}" -ne 0 ]; then + rtl_fileop cd "${_pfe_oldpwd}"; return 1; + else + rtl_fileop cd "${_pfe_oldpwd}"; + fi; + fi; + fi; + + return 0; +}; + +# vim:filetype=sh diff --git a/subr.pkg/pkg_install.subr b/subr.pkg/pkg_install.subr new file mode 100644 index 0000000..6fe420d --- /dev/null +++ b/subr.pkg/pkg_install.subr @@ -0,0 +1,37 @@ +# +# set +o errexit -o noglob -o nounset is assumed. +# + +pkg_install() { + local _group_name="${1}" _pkg_name="${2}" _restart_at="${3}" \ + _destdir="" _destdir_prefix="" _pkglist_name=""; + + if ! rtl_fileop mkdir "${PKG_PREFIX}"; then + return 1; + else for _destdir in "${PKG_DESTDIR}:${PKG_PREFIX}" "${PKG_DESTDIR_HOST}:${PREFIX}"; do + rtl_lassign "_destdir _destdir_prefix" ":" "${_destdir}"; + if [ -e "${_destdir}" ]; then + (set +o errexit -o noglob; rtl_flock_acquire 4 || exit "${?}"; + trap "rm -f \"${BUILD_WORKDIR}/install.lock\"" EXIT; + if ! tar -C "${_destdir}" -cpf - . | tar -C "${_destdir_prefix}" --overwrite -xpf -; then + exit 1; + fi) 4<>"${BUILD_WORKDIR}/install.lock"; + fi; + done; + if [ "${?}" -ne 0 ]; then + return 1; + elif [ "${PKG_PKGLIST_DISABLE:-0}" -eq 0 ]; then + if [ ! -e "${PREFIX}/pkglist.${PKG_BUILD_TYPE}" ]\ + && ! touch "${PREFIX}/pkglist.${PKG_BUILD_TYPE}"; then + return 1; + else + _pkglist_name="${PKG_BASE_DIR##*/}"; _pkglist_name="${_pkglist_name%%-*}"; + if ! printf "%s\n" "${_pkglist_name}" >> "${PREFIX}/pkglist.${PKG_BUILD_TYPE}"; then + return 1; + fi; + fi; + fi; + fi; +}; + +# vim:filetype=sh diff --git a/subr.pkg/pkg_install_clean.subr b/subr.pkg/pkg_install_clean.subr new file mode 100644 index 0000000..bb8df2c --- /dev/null +++ b/subr.pkg/pkg_install_clean.subr @@ -0,0 +1,15 @@ +# +# set +o errexit -o noglob -o nounset is assumed. +# + +pkg_install_clean() { + local _pic_group_name="${1}" _pic_pkg_name="${2}" _pic_restart_at="${3}"; + + if [ "${PKG_DESTDIR:+1}" = 1 ]; then + rtl_fileop rm "${PKG_DESTDIR}" || return 1; + rtl_fileop mkdir "${PKG_DESTDIR}" || return 1; + fi; + return 0; +}; + +# vim:filetype=sh diff --git a/subr.pkg/pkg_install_files.subr b/subr.pkg/pkg_install_files.subr new file mode 100644 index 0000000..364bd36 --- /dev/null +++ b/subr.pkg/pkg_install_files.subr @@ -0,0 +1,133 @@ +# +# set +o errexit -o noglob -o nounset is assumed. +# + +pkgp_install_files() { + if [ "${PKG_INSTALL_FILES:+1}" = 1 ]; then + if ! rtl_install -v "${PKG_DESTDIR}" ${PKG_INSTALL_FILES}; then + return 1; + fi; + fi; + return 0; +}; + +pkgp_install_files_v2() { + local _ppifv2_status="" _ppifv2_vflag=""; + + if [ "${PKG_INSTALL_FILES_V2:+1}" = 1 ]; then + if rtl_lmatch \$ARG_VERBOSE_TAGS "install" ","; then + _ppifv2_vflag="-v"; + fi; + if ! rtl_install_v2 \ + \$_ppifv2_status \ + -p "_builddir=${PKG_BUILD_DIR}" \ + -p "_destdir=${PKG_BASE_DIR}/${PKG_DESTDIR}" \ + -p "_destdir_host=${PKG_BASE_DIR}/${PKG_DESTDIR_HOST}" \ + -p "_files=${MIDIPIX_BUILD_PWD}/files/${PKG_NAME}" \ + -p "_name=${PKG_NAME}" \ + -p "_prefix=${PKG_PREFIX}" \ + -p "_prefix_host=${PREFIX}" \ + -p "_prefix_native=${PREFIX_NATIVE}" \ + -p "_subdir=${PKG_BASE_DIR}/${PKG_SUBDIR}" \ + -p "_target=${PKG_TARGET}" \ + -p "_version=${PKG_VERSION:-}" \ + -p "_workdir=${BUILD_WORKDIR}" \ + ${_ppifv2_vflag} -- "${PKG_DESTDIR}" \ + "${PKG_INSTALL_FILES_V2}"; + then + return 1; + fi; + fi; +}; + +pkgp_install_files_perms() { + local _ppifp_destdir="" _ppifp_fname="" IFS; + + for _ppifp_destdir in "${PKG_DESTDIR}" "${PKG_DESTDIR_HOST}"; do + if [ -e "${_ppifp_destdir}" ]; then + rtl_set_IFS_nl; + + for _ppifp_fname in $(find "${_ppifp_destdir}" -type d); do + if ! rtl_fileop chmod 0755 "${_ppifp_fname}"; then + return 1; + fi; + done; + + for _ppifp_fname in $(find "${_ppifp_destdir}" \( -not -perm /0111 \) -type f); do + if ! rtl_fileop chmod 0644 "${_ppifp_fname}"; then + return 1; + fi; + done; + + for _ppifp_fname in $(find "${_ppifp_destdir}" -perm /0111 -type f); do + if ! rtl_fileop chmod 0755 "${_ppifp_fname}"; then + return 1; + fi; + done; + fi; + done; + return 0; +}; + +pkgp_install_files_pkgconfig() { + local _ppifp2_pc_path=""; + + for _ppifp2_pc_path in $(find "${PKG_DESTDIR}" -name \*.pc); do + if [ -n "$(sed -ne '/^libdir=[^$]*$/p' "${_ppifp2_pc_path}")" ] \ + && ! sed -i"" -e '/^libdir=[^$]*$/s/^libdir=\(.*\)$/libdir=${exec_prefix}\1/' \ + -e '/^exec_prefix=$/s/^.*$/exec_prefix=${prefix}/' \ + "${_ppifp2_pc_path}"; then + return 1; + fi; + + if [ -n "$(sed -ne '/^includedir=[^$]*$/p' "${_ppifp2_pc_path}")" ] \ + && ! sed -i"" -e '/^includedir=[^$]*$/s/^includedir=\(.*\)$/includedir=${prefix}\1/' \ + "${_ppifp2_pc_path}"; then + return 1; + fi; + done; +}; + +pkgp_install_files_strip() { + local _ppifs_bin_path="" _ppifs_stripfl=0 _ppifs_tree_root="${PKG_DESTDIR}"; + + if [ -e "${_ppifs_tree_root}" ]; then + if rtl_match "${PKG_NAME}" "*_ppifs_minipix"; then + : $((_ppifs_stripfl=(${ARG_DEBUG_MINIPIX:-0} ? 0 : 1))); + elif [ "${BUILD_KIND}" = release ]\ + && [ "${PKG_BUILD_TYPE}" = native ]; + then + _ppifs_stripfl=1; + else + _ppifs_stripfl=0; + fi; + + if [ "${_ppifs_stripfl:-0}" -eq 1 ]; then + for _ppifs_bin_path in $(find "${_ppifs_tree_root}" -perm /a=x -type f); do + if objdump -sj .debug_frame -j .debug_info "${_ppifs_bin_path}" >/dev/null 2>&1; then + rtl_log_msg "pkg_strip" "${MSG_pkg_strip}" "${_ppifs_bin_path}"; + if ! "${PKG_TARGET}-strip" "${_ppifs_bin_path}"; then + return 1; + fi; + fi; + done; + fi; + fi; + return 0; +}; + +pkg_install_files() { + local _pif_group_name="${1}" _pif_pkg_name="${2}" _pif_restart_at="${3}"; + + if ! pkgp_install_files\ + || ! pkgp_install_files_v2\ + || ! pkgp_install_files_perms\ + || ! pkgp_install_files_pkgconfig\ + || ! pkgp_install_files_strip; + then + return 1; + fi; + return 0; +}; + +# vim:filetype=sh diff --git a/subr.pkg/pkg_install_libs.subr b/subr.pkg/pkg_install_libs.subr new file mode 100644 index 0000000..e81f3a1 --- /dev/null +++ b/subr.pkg/pkg_install_libs.subr @@ -0,0 +1,94 @@ +# +# set +o errexit -o noglob -o nounset is assumed. +# + +pkgp_install_libs_purge_la() { + local _ppilpl_la_path=""; + + for _ppilpl_la_path in $(find "${PKG_DESTDIR}" -type f -name \*.la); do + if ! rtl_fileop rm "${_ppilpl_la_path}"; then + return 1; + fi; + done; + return 0; +}; + +pkgp_install_libs_shared_link() { + local _ppilsl_lib_name="${1}" _ppilsl_so_dir="${2}" _ppilsl_so_path="${3}" \ + _ppilsl_lib_link_path="${3%.so*}.lib.a" _ppilsl_fname="" _ppilsl_lib_link_tgt=""; + + if _ppilsl_lib_link_tgt="$(find "${_ppilsl_so_dir}" -name "${_ppilsl_lib_name%%.*}.*.lib.a" | sort | tail -1)"\ + && [ "${_ppilsl_lib_link_tgt:+1}" = 1 ]\ + && [ "${_ppilsl_lib_link_tgt}" != "${_ppilsl_lib_link_path}" ]; + then + rtl_basename2 \$_ppilsl_lib_link_tgt \$_ppilsl_fname; + + if ! rtl_fileop rm "${_ppilsl_lib_link_path}"\ + || ! rtl_fileop ln_symbolic "${_ppilsl_fname}" "${_ppilsl_lib_link_path}"; then + return 1; + fi; + fi; + return 0; +}; + +pkgp_install_libs_shared() { + local _ppils_head="" _ppils_lib_dst_path="" _ppils_lib_name="" \ + _ppils_lib_src_path="" _ppils_so_dst_dir="" _ppils_so_src_path=""; + + if [ "${PKG_BUILD_TYPE}" != "host" ]; then + for _ppils_so_src_path in \ + $(find "${PKG_DESTDIR}" \ + \( -name "*.so" -or -name "*.so.*" \) -print); + do + if [ "$(readlink -f "${_ppils_so_src_path}")" != "/dev/null" ]\ + && rtl_head "[0-9.]" "${_ppils_so_src_path##*.so}" \$_ppils_head\ + && [ "${_ppils_head:+1}" != 1 ]; then + case "${_ppils_so_src_path}" in + *.so) _ppils_lib_src_path="${_ppils_so_src_path%%.so}.lib.a"; ;; + *.so.*) _ppils_lib_src_path="${_ppils_so_src_path%%.so.*}.${_ppils_so_src_path##*.so.}.lib.a"; ;; + esac; + + _ppils_so_dst_dir="${_ppils_so_src_path%/*}"; + rtl_basename2 \$_ppils_lib_src_path \$_ppils_lib_name; + _ppils_lib_dst_path="${_ppils_so_dst_dir}/${_ppils_lib_name}"; + + if [ ! -L "${_ppils_lib_src_path}" ]\ + && [ ! -e "${_ppils_lib_dst_path}" ]; then + if ! (rtl_basename2 \$_ppils_so_src_path \$_ppils_fname; \ + rtl_basename2 \$_ppils_lib_dst_path \$_ppils_fname_dst; \ + rtl_dirname2 \$_ppils_so_src_path \$_ppils_dname; \ + rtl_fileop cd "${_ppils_dname}" && \ + perk -e "${_ppils_fname}" |\ + "${PKG_TARGET}-mdso" \ + -i "${_ppils_fname_dst}" \ + -n "${_ppils_fname}" -); + then + return 1; + fi; + fi; + + if ! pkgp_install_libs_shared_link \ + "${_ppils_lib_name}" "${_ppils_so_dst_dir}" \ + "${_ppils_so_src_path}"; + then + return 1; + fi; + fi; + done; + fi; + + return 0; +}; + +pkg_install_libs() { + local _pil_group_name="${1}" _pil_pkg_name="${2}" _pil_restart_at="${3}"; + + if ! pkgp_install_libs_purge_la\ + || ! pkgp_install_libs_shared; + then + return 1; + fi; + return 0; +}; + +# vim:filetype=sh diff --git a/subr.pkg/pkg_install_make.subr b/subr.pkg/pkg_install_make.subr new file mode 100644 index 0000000..a229121 --- /dev/null +++ b/subr.pkg/pkg_install_make.subr @@ -0,0 +1,46 @@ +# +# set +o errexit -o noglob -o nounset is assumed. +# + +pkg_install_make() { + local _pim_group_name="${1}" _pim_pkg_name="${2}" _pim_restart_at="${3}" + _pim_libtool="" _pim_rc=0 _pim_subdir=""; + + case "${PKG_LIBTOOL:-}" in + "") _pim_libtool=""; ;; + none) _pim_libtool=""; ;; + *) _pim_libtool="${PKG_LIBTOOL}"; ;; + esac; + + for _pim_subdir in ${PKG_MAKE_SUBDIRS:-:}; do + if [ "${_pim_subdir}" = ":" ]; then + _pim_subdir=""; + fi; + + if [ "${#_pim_libtool}" -gt 0 ]; then + export MAKE="make LIBTOOL=${_pim_libtool}"; + fi; + + rtl_run_cmd_unsplit "${PKG_MAKE}" \ + ${PKG_MAKEFLAGS_INSTALL:-} \ + ${PKG_MAKEFLAGS_INSTALL_EXTRA:-} \ + AR="${PKG_AR}" CC="${PKG_CC}" RANLIB="${PKG_RANLIB}" \ + "${PKG_RANLIB_INSTALL:+RANLIB=${PKG_RANLIB_INSTALL}}" \ + ${_pim_libtool:+"LIBTOOL=${_pim_libtool}"} \ + "${PKG_MAKE_INSTALL_VNAME:-DESTDIR}=${PKG_DESTDIR}/" \ + ${PKG_INSTALL_TARGET:-install} \ + ${_pim_subdir:+-C "${_pim_subdir}"}; _pim_rc="${?}"; + + if [ "${#_pim_libtool}" -gt 0 ]; then + unset MAKE; + fi; + + if [ "${_pim_rc}" -ne 0 ]; then + return 1; + fi; + done; + + return 0; +}; + +# vim:filetype=sh diff --git a/subr.pkg/pkg_install_rpm.subr b/subr.pkg/pkg_install_rpm.subr new file mode 100644 index 0000000..11cdfd8 --- /dev/null +++ b/subr.pkg/pkg_install_rpm.subr @@ -0,0 +1,66 @@ +# +# set +o errexit -o noglob -o nounset is assumed. +# + +pkg_install_rpm() { + local _pir_group_name="${1}" _pir_pkg_name="${2}" _pir_restart_at="${3}" \ + _pir_pkg_url="" _pir_pkg_version_full="" _pir_pkg_version_rpm="" \ + _pir_rc=0; + + if rtl_lmatch \$ARG_DIST "rpm" ","\ + && [ "${PKG_RPM_DISABLE:-0}" -eq 0 ]\ + && command which rpmbuild >/dev/null 2>&1; + then + if [ "${PKG_URL:+1}" = 1 ]; then + _pir_pkg_url="${PKG_URL%% *}"; _pir_pkg_version_full="${PKG_VERSION}"; _pir_pkg_version_rpm="${PKG_VERSION%%-*}"; + elif [ "${PKG_URLS_GIT:+1}" = 1 ]; then + _pir_pkg_version_rpm="$(cd "${PKG_BASE_DIR}/${PKG_SUBDIR}" && git rev-parse HEAD)"; + _pir_pkg_version_full="${_pir_pkg_version_rpm} ($(cd "${PKG_BASE_DIR}/${PKG_SUBDIR}" && git rev-parse --abbrev-ref HEAD))"; + _pir_pkg_url="${PKG_URLS_GIT%% *}"; _pir_pkg_url="${_pir_pkg_url##*=}"; _pir_pkg_url="${_pir_pkg_url%%@*}"; + + if [ "${_pir_pkg_url#${DEFAULT_GITROOT_HEAD}}" != "${_pir_pkg_url}" ]; then + _pir_pkg_url="Unknown"; + fi; + fi; + + if ! rtl_fileop cp "${MIDIPIX_BUILD_PWD}/etc/package.spec" \ + "${PKG_BASE_DIR}/${PKG_NAME}-${_pir_pkg_version_rpm}.spec"; + then + return 1; + else + while true; do + rpmbuild \ + -bb \ + --define="_tmppath ${BUILD_WORKDIR}" \ + --define="_topdir ${PREFIX_RPM}/${PKG_NAME}-${_pir_pkg_version_rpm}" \ + --define="pkg_destdir ${PKG_DESTDIR}" \ + --define="pkg_name ${PKG_NAME}" \ + --define="pkg_url ${_pir_pkg_url}" \ + --define="pkg_version_full ${_pir_pkg_version_full}" \ + --define="pkg_version_rpm ${_pir_pkg_version_rpm}" \ + --nodeps "${PKG_BASE_DIR}/${PKG_NAME}-${_pir_pkg_version_rpm}.spec"; + _pir_rc="${?}"; + + if [ "${_pir_rc}" -eq 0 ]; then + break; + elif [ "${_pir_rc}" -eq 141 ]; then + continue; + else + return "${_pir_rc}"; + fi; + done; + + if ! find "${PREFIX_RPM}/${PKG_NAME}-${_pir_pkg_version_rpm}/RPMS" \ + -iname \*.rpm -exec cp -pP {} "${PREFIX_RPM}/" \; \ + || ! rtl_fileop rm "${PREFIX_RPM}/${PKG_NAME}-${_pir_pkg_version_rpm}" \ + || ! rtl_fileop cp "${PKG_BASE_DIR}/${PKG_NAME}-${_pir_pkg_version_rpm}.spec" "${PREFIX_RPM}/"; + then + return 1; + fi; + fi; + fi; + + return 0; +}; + +# vim:filetype=sh diff --git a/subr.pkg/pkg_install_subdirs.subr b/subr.pkg/pkg_install_subdirs.subr new file mode 100644 index 0000000..4ea6862 --- /dev/null +++ b/subr.pkg/pkg_install_subdirs.subr @@ -0,0 +1,26 @@ +# +# set +o errexit -o noglob -o nounset is assumed. +# + +pkg_install_subdirs() { + local _pis_group_name="${1}" _pkg_name="${2}" _restart_at="${3}" \ + _pis_gspec=""; + + for _pis_gspec in \ + "${PKG_INSTALL_FILES_DESTDIR:-}" \ + "${PKG_INSTALL_FILES_DESTDIR_EXTRA:-}"; do + if ! rtl_install "${PKG_DESTDIR}" ${_pis_gspec}; then + return 1; + fi; + done; + + if [ "${PKG_PREFIX%/}" = "${PREFIX_NATIVE%/}" ]; then + if ! rtl_install "${PKG_DESTDIR}/${DEFAULT_TARGET}" ${PKG_INSTALL_FILES_DESTDIR}; then + return 1; + fi; + fi; + + return 0; +}; + +# vim:filetype=sh diff --git a/subr.rtl/rtl.subr b/subr.rtl/rtl.subr index 532cb51..7a72b89 100644 --- a/subr.rtl/rtl.subr +++ b/subr.rtl/rtl.subr @@ -2,12 +2,20 @@ # set +o errexit -o noglob -o nounset is assumed. # -rtl_date() { command date "+${1:-${DEFAULT_TIMESTAMP_FMT:-"%Y/%m/%d %H:%M:%S"}}"; }; -rtl_set_IFS_nl() { IFS=" -"; }; -rtl_set_var_unsafe() { [ -n "${2}" ] && eval ${1}=\"${2}\" || return 0; }; +# +RTL_IFS_ORIG=" +"; + +# +RTL_NL=" +"; + +rtl_date() { local _rdate="${1#\$}"; shift; eval ${_rdate}=\"\$\(command date \"+\${1:-\${DEFAULT_TIMESTAMP_FMT:-\"%Y/%m/%d %H:%M:%S\"}}\"\)\"; }; +rtl_set_IFS_nl() { IFS="${RTL_NL}"; }; +rtl_set_var_unsafe() { [ "${2:+1}" = 1 ] && eval ${1}=\"${2}\" || return 0; }; rtl_test_cmd() { command -v "${1}" >/dev/null; }; rtl_uniq() { if [ "${#}" -gt 0 ]; then printf "%s" "${*}" | sed 's/ /\n/g' | awk '!x[$0]++' | paste -s -d" "; fi; }; +rtl_uniq2() { eval set -- \${${1#\$}}; if [ "${#}" -gt 0 ]; then printf "%s" "${*}" | sed 's/ /\n/g' | awk '!x[$0]++' | paste -s -d" "; fi; }; rtl_unset_vars() { while [ ${#} -gt 0 ]; do unset "${1}"; shift; done; }; -# vim:filetype=sh +# vim:filetype=sh textwidth=0 diff --git a/subr.rtl/rtl_complex.subr b/subr.rtl/rtl_complex.subr index 1e13fce..859fd8e 100644 --- a/subr.rtl/rtl_complex.subr +++ b/subr.rtl/rtl_complex.subr @@ -3,81 +3,75 @@ # rtl_export_vars() { - local _unsetfl=0; [ "x${1}" = "x-u" ] && { _unsetfl=1; shift; }; + local _rev_unsetfl=0; + + if [ "x${1}" = "x-u" ]; then + _rev_unsetfl=1; shift; + fi; while [ "${#}" -ge 2 ]; do if [ "${2:+1}" = 1 ]\ - || [ "${_unsetfl}" -eq 1 ]; then - case "${_unsetfl}" in - 0) rtl_set_var_unsafe "${1}" "${2}"; export "${1}"; ;; + || [ "${_rev_unsetfl}" -eq 1 ]; then + case "${_rev_unsetfl}" in + 0) rtl_set_var_unsafe "${1}" "${2}"; + export "${1}"; ;; 1) unset "${1}"; ;; esac; fi; shift 2; done; -}; -rtl_filter_vars() { - local _fn="${1}" _fnfl=0 _qchar="" _var_spec="" _vars="" _vname="" IFS; - rtl_set_IFS_nl; - for _var_spec in $(set); do - case "${_qchar}" in - "\"") if [ "${_var_spec%\"}" != "${_var_spec}" ]; then - _qchar=""; - fi; - if [ "${_fnfl:-0}" -eq 1 ]; then - _vars="$(rtl_lconcat "${_vars}" "${_var_spec}" "\n")"; - fi; - continue; ;; - "\'") if [ "${_var_spec%\'}" != "${_var_spec}" ]; then - _qchar=""; - fi; - if [ "${_fnfl:-0}" -eq 1 ]; then - _vars="$(rtl_lconcat "${_vars}" "${_var_spec}" "\n")"; - fi; - continue; ;; - *) case "${_var_spec}" in - [!=]*=\"*\") _qchar=""; _vname="${_var_spec%%=\"*}"; ;; - [!=]*=\"*) _qchar="\""; _vname="${_var_spec%%=\"*}"; ;; - [!=]*=\'*\') _qchar=""; _vname="${_var_spec%%=\'*}"; ;; - [!=]*=\'*) _qchar="\'"; _vname="${_var_spec%%=\'*}"; ;; - [!=]*=*) _qchar=""; _vname="${_var_spec%%=*}"; ;; - esac; ;; - esac; - if "${_fn}" "${_vname}"; then - _vars="${_vars:+${_vars} -}${_var_spec}"; _fnfl=1; - else - _fnfl=0; - fi; - done; - printf "%s" "${_vars}"; + return 0; }; rtl_head() { - local _pattern="${1}" _s="${2}"; + local _rh_pattern="${1}" _rh_s="${2}" _rh_rs_out="${3#\$}"; + while true; do - if [ "${_s%%${_pattern}}" = "${_s}" ]; then + if [ "${_rh_s%%${_rh_pattern}}" = "${_rh_s}" ]; then break; else - _s="${_s%%${_pattern}}"; + _rh_s="${_rh_s%%${_rh_pattern}}"; fi; done; - printf "%s" "${_s}"; + + eval ${_rh_rs_out}='${_rh_s}'; + return 0; }; rtl_percentage() { - local _in="${1}" _max="${2}" _perc; - _perc="$((100 * ${_in} + ${_max} / 2))"; - _perc="$((${_perc} ? ${_perc} / ${_max} : ${_perc}))"; - printf "%d\n" "${_perc}"; + local _rp_in="${1}" _rp_max="${2}" _rp_rs_out="${3#\$}" \ + _rp_perc; + + _rp_perc=$((100 * ${_rp_in} + ${_rp_max} / 2)); + _rp_perc=$((${_rp_perc} ? ${_rp_perc} / ${_rp_max} : ${_rp_perc})); + + eval ${_rp_rs_out}='${_rp_perc}'; + return 0; +}; + +rtl_percentage2() { + local _rp_rin="${1#\$}" _rp_rmax="${2#\$}" _rp_rs_out="${3#\$}" \ + _rp_in=0 _rp_max=0 _rp_perc; + + eval _rp_in=\"\${${_rp_rin}}\"; + eval _rp_max=\"\${${_rp_rmax}}\"; + + _rp_perc=$((100 * ${_rp_in} + ${_rp_max} / 2)); + _rp_perc=$((${_rp_perc} ? ${_rp_perc} / ${_rp_max} : ${_rp_perc})); + + eval ${_rp_rs_out}='${_rp_perc}'; + return 0; }; rtl_sunset() { local _rs_rset="${1#\$}" _rs_kname="" IFS=" "; - eval set -- '${'"${_rs_rset}"'}'; + + eval set -- "\${${_rs_rset}}"; while [ "${#}" -gt 0 ]; do unset "${_rs_rset}${_rs_kname}"; shift; done; unset "${_rs_rset}"; + + return 0; }; # vim:filetype=sh diff --git a/subr.rtl/rtl_fetch.subr b/subr.rtl/rtl_fetch.subr index 5f55732..b40d11b 100644 --- a/subr.rtl/rtl_fetch.subr +++ b/subr.rtl/rtl_fetch.subr @@ -2,66 +2,53 @@ # set +o errexit -o noglob -o nounset is assumed. # -# N.B. URLs ($1) may contain `?' or '&' characters. -rtl_fetch_url_wget() { - local _urls="${1}" _sha256sum_src="${2}" _target_dname="${3}" _target_fname="${4}" _target_name="${5}" _mirrors="${6:-}"\ - _rc=0 _sha256sum_target="" _target_fname_full="" _url="" _url_base="" _urls_count=0 _urls_full=""; +rtl_fetch_clean_dlcache() { + local _pfdcd_dlcachedir="${1}" _pfdcd_pkg_name="${2}" \ + _pfdcd_pkg_fname="${3}" _pfdcd_pkg_urls_git="${4}" \ + _pfdcd_fname="" _pfdcd_skipfl=0 _pfdcd_url_spec="" \ + _pfdcd_url_subdir=""; - _urls_full="${_urls}"; - for _url_base in ${_mirrors}; do - _urls_full="$(rtl_lconcat "${_urls_full}" "${_url_base%/}/${_target_name}/${_target_fname}")"; - done; - _urls_count="$(rtl_llength "${_urls_full}")"; - for _url in ${_urls_full}; do - if [ -z "${_target_fname}" ]; then - _target_fname="$(rtl_basename "${_url}")"; - fi; - _target_fname_full="${_target_dname}/${_target_fname}"; - (set +o errexit -o noglob -o nounset; - rtl_flock_acquire 4 || exit 1; - trap "_rc=\"\${?}\"; rm -f \"${_target_fname_full}.fetching\"; exit \"\${_rc}\";" EXIT; - if [ -z "${_sha256sum_src}" ]\ - || ! rtl_check_digest_file "${_target_fname_full}" "${_sha256sum_src}" "${_target_fname_full}.fetched"; then - wget ${DEFAULT_WGET_ARGS} -O "${_target_fname_full}" "${_url}"; _rc="${?}"; - if [ "${_rc}" -ne 0 ]; then - exit $((${_rc}+2)); - elif [ -n "${_sha256sum_src}" ]\ - && ! rtl_check_digest "${_target_fname_full}" "${_sha256sum_src}"; then - exit 2; - else - printf "%s" "${RTL_CHECK_DIGEST_DIGEST}" > "${_target_fname_full}.fetched"; exit 0; + for _pfdcd_fname in \ + $(cd "${_pfdcd_dlcachedir}/${_pfdcd_pkg_name}" 2>/dev/null && + find -maxdepth 1 -mindepth 1 \ + ${_pfdcd_pkg_fname:+-not -name "${_pfdcd_pkg_fname}"} \ + ${_pfdcd_pkg_fname:+-not -name "${_pfdcd_pkg_fname}.fetched"}); + do + _pfdcd_fname="${_pfdcd_fname#./}"; _pfdcd_skipfl=0; + + for _pfdcd_url_spec in ${_pfdcd_pkg_urls_git}; do + _pfdcd_url_subdir="${_pfdcd_url_spec%%=*}"; _pfdcd_url_subdir="${_pfdcd_url_subdir##*/}"; + if [ "${_pfdcd_fname%.git}" = "${_pfdcd_url_subdir}" ]; then + _pfdcd_skipfl=1; break; fi; - else - exit 0; - fi;) 4<>"${_target_fname_full}.fetching"; _rc="${?}"; : $((_urls_count-=1)); - case "${_rc}" in - 0) break; ;; - 1) if [ "${_urls_count}" -ge 1 ]; then - rtl_log_msg "warning" "${MSG_rtl_fetch_lockfail_retryurl}" "${_url}"; - else - rtl_log_msg "fatal" "${MSG_rtl_fetch_lockfail}" "${_url}"; - rtl_fileop rm "${_target_fname_full}"; break; - fi; ;; - 2) if [ "${_urls_count}" -ge 1 ]; then - rtl_log_msg "warning" "${MSG_rtl_fetch_hashfail_retryurl}" "${_url}" "${_sha256sum_src}"; - else - if _sha256sum_target="$(sha256sum "${_target_fname_full}" |\ - awk '{print $1}' 2>/dev/null)"; then - rtl_log_msg "fatal" "${MSG_rtl_fetch_hashfail1}" "${_url}" "${_sha256sum_src}" "${_sha256sum_target}"; - else - rtl_log_msg "fatal" "${MSG_rtl_fetch_hashfail2}" "${_url}" "${_sha256sum_src}"; - fi; - rtl_fileop rm "${_target_fname_full}"; break; - fi; ;; - *) if [ "${_urls_count}" -ge 1 ]; then - rtl_log_msg "warning" "${MSG_rtl_fetch_fail_retryurl}" "${_url}" "$((${_rc}-2))"; - else - rtl_log_msg "fatal" "${MSG_rtl_fetch_fail}" "${_url}" "$((${_rc}-2))"; - rtl_fileop rm "${_target_fname_full}"; break; - fi; ;; - esac; + done; + + if [ "${_pfdcd_skipfl}" -eq 0 ]; then + _pfdcd_fname="${_pfdcd_dlcachedir}/${_pfdcd_pkg_name}/${_pfdcd_fname}"; + rtl_log_msg "verbose" "${MSG_rtl_fetch_rm_redundant}" "${_pfdcd_fname}" "${_pfdcd_pkg_name}"; + rtl_fileop rm "${_pfdcd_fname}"; + fi; done; - return "${_rc}"; + + return 0; +}; + +rtl_fetch_dlcache_subdir() { + local _rfds_dlcache_dir="${1}" _rfds_name="${2}" _rfds_pkg_inherit_from="${3}"; + + if [ "${_rfds_pkg_inherit_from:+1}" = 1 ]\ + && ! [ -e "${_rfds_dlcache_dir}/${_rfds_name}" ]\ + && ! rtl_fileop ln_symbolic "${_rfds_pkg_inherit_from}" "${_rfds_dlcache_dir}/${_rfds_name}"; + then + return 1; + elif [ "${_rfds_pkg_inherit_from:+1}" != 1 ]\ + && ! [ -e "${_rfds_dlcache_dir}/${_rfds_name}" ]\ + && ! rtl_fileop mkdir "${_rfds_dlcache_dir}/${_rfds_name}"; + then + return 1; + else + return 0; + fi; }; # vim:filetype=sh diff --git a/subr.rtl/rtl_fetch_git.subr b/subr.rtl/rtl_fetch_git.subr index d86db0d..bacb555 100644 --- a/subr.rtl/rtl_fetch_git.subr +++ b/subr.rtl/rtl_fetch_git.subr @@ -3,68 +3,71 @@ # rtlp_fetch_url_git() { - local _cache_dname="${1}" _git_args="${2}" _git_branch="${3}" _mirrors="${4}" \ - _pkg_name="${5}" _subdir="${6}" _tgtdir="${7}" _url="${8}" _cache_dname_full="" \ - _clonefl=0 _git_pull_log_fname="" _oldpwd="" _url_base=""; + local _rpfug_cache_dname="${1}" _rpfug_git_args="${2}" _rpfug_git_branch="${3}" \ + _rpfug_mirrors="${4}" _rpfug_pkg_name="${5}" _rpfug_subdir="${6}" \ + _rpfug_tgtdir="${7}" _rpfug_url="${8}" \ + _rpfug_cache_dname_full="" _rpfug_clonefl=0 _rpfug_dname="" \ + _rpfug_git_pull_log_fname="" _rpfug_oldpwd="" _rpfug_url_base=""; - _cache_dname_full="${_cache_dname}/${_subdir##*/}"; + _rpfug_cache_dname_full="${_rpfug_cache_dname}/${_rpfug_subdir##*/}"; (set -o errexit -o noglob -o nounset; rtl_flock_acquire 4 || exit "${?}"; - trap "rm -f \"${_cache_dname_full%%[/]}.fetching\"" EXIT; - if [ -e "${_cache_dname_full}" ]; then - (rtl_fileop cd "${_cache_dname_full}" || exit 1; - _git_pull_log_fname="$(mktemp)" || exit 1; - trap 'rm -f "${_git_pull_log_fname}" 2>/dev/null' EXIT HUP INT TERM USR1 USR2; - if ! git pull ${_git_args} origin "${_git_branch:-main}" >"${_git_pull_log_fname}" 2>&1; then - if grep -q '^fatal: refusing to merge unrelated histories$' "${_git_pull_log_fname}"; then - cat "${_git_pull_log_fname}"; printf "Detected forced push(es).\n"; - elif grep -q '^Automatic merge failed; fix conflicts and then commit the result.$' "${_git_pull_log_fname}"; then - cat "${_git_pull_log_fname}"; printf "Detected forced push(es).\n"; git merge --abort; + trap "rm -f \"${_rpfug_cache_dname_full%%[/]}.fetching\"" EXIT; + if [ -e "${_rpfug_cache_dname_full}" ]; then + (rtl_fileop cd "${_rpfug_cache_dname_full}" || exit 1; + _rpfug_git_pull_log_fname="$(mktemp)" || exit 1; + trap 'rm -f "${_rpfug_git_pull_log_fname}" 2>/dev/null' EXIT HUP INT TERM USR1 USR2; + if ! git pull ${_rpfug_git_args} origin "${_rpfug_git_branch:-main}" >"${_rpfug_git_pull_log_fname}" 2>&1; then + if grep -q '^fatal: refusing to merge unrelated histories$' "${_rpfug_git_pull_log_fname}"; then + cat "${_rpfug_git_pull_log_fname}"; printf "Detected forced push(es).\n"; + elif grep -q '^Automatic merge failed; fix conflicts and then commit the result.$' "${_rpfug_git_pull_log_fname}"; then + cat "${_rpfug_git_pull_log_fname}"; printf "Detected forced push(es).\n"; git merge --abort; else - cat "${_git_pull_log_fname}"; exit 1; + cat "${_rpfug_git_pull_log_fname}"; exit 1; fi; while true; do printf "Attempting git-reset(1) --hard HEAD^ and git-pull(1)...\n"; if ! git reset --hard "HEAD^"; then exit 1; - elif git pull ${_git_args} origin "${_git_branch:-main}"; then + elif git pull ${_rpfug_git_args} origin "${_rpfug_git_branch:-main}"; then exit 0; fi; done; else - cat "${_git_pull_log_fname}"; exit 0; + cat "${_rpfug_git_pull_log_fname}"; exit 0; fi;) || return 1; - (rtl_fileop cd "${_cache_dname_full}" &&\ + (rtl_fileop cd "${_rpfug_cache_dname_full}" &&\ git submodule update) || return 1; - else if git clone ${_git_args} -b "${_git_branch:-main}" "${_url}" "${_cache_dname_full}"; then - _clonefl=1; - elif [ "${_mirrors}" = "skip" ]; then + else if git clone ${_rpfug_git_args} -b "${_rpfug_git_branch:-main}" "${_rpfug_url}" "${_rpfug_cache_dname_full}"; then + _rpfug_clonefl=1; + elif [ "${_rpfug_mirrors}" = "skip" ]; then return 1; - else for _url_base in ${_mirrors}; do - if git clone ${_git_args} -b "${_git_branch:-main}" "${_url_base}/${_pkg_name}/${_subdir}" "${_cache_dname_full}"; then - _clonefl=1; break; + else for _rpfug_url_base in ${_rpfug_mirrors}; do + if git clone ${_rpfug_git_args} -b "${_rpfug_git_branch:-main}" "${_rpfug_url_base}/${_rpfug_pkg_name}/${_rpfug_subdir}" "${_rpfug_cache_dname_full}"; then + _rpfug_clonefl=1; break; fi; done; fi; - if [ "${_clonefl}" -eq 0 ]; then + if [ "${_rpfug_clonefl}" -eq 0 ]; then return 1; - else if [ -n "${_git_branch}" ]; then - (rtl_fileop cd "${_cache_dname_full}" &&\ - git checkout "${_git_branch}") || return 1; + else if [ "${_rpfug_git_branch:+1}" = 1 ]; then + (rtl_fileop cd "${_rpfug_cache_dname_full}" &&\ + git checkout "${_rpfug_git_branch}") || return 1; fi; - (rtl_fileop cd "${_cache_dname_full}" &&\ + (rtl_fileop cd "${_rpfug_cache_dname_full}" &&\ git submodule update --init) || return 1; fi; fi; - if [ "${_cache_dname}" != "${_tgtdir}" ]; then - _oldpwd="${PWD}"; rtl_fileop cd "${_tgtdir}" || return 1; - rtl_fileop rm "${_tgtdir}/${_subdir}" || return 1; - if [ ! -e "$(rtl_dirname "${_tgtdir}/${_subdir}")" ]; then - rtl_fileop mkdir "$(rtl_dirname "${_tgtdir}/${_subdir}")"; + if [ "${_rpfug_cache_dname}" != "${_rpfug_tgtdir}" ]; then + _rpfug_oldpwd="${PWD}"; rtl_fileop cd "${_rpfug_tgtdir}" || return 1; + rtl_fileop rm "${_rpfug_tgtdir}/${_rpfug_subdir}" || return 1; + _rpfug_dname="${_rpfug_tgtdir}/${_rpfug_subdir}"; rtl_dirname \$_rpfug_dname; + if ! [ -e "${_rpfug_dname}" ]; then + rtl_fileop mkdir "${_rpfug_dname}"; fi; - rtl_fileop cp "${_cache_dname_full}" "${_tgtdir}/${_subdir}" || return 1; - rtl_fileop cd "${_oldpwd}" || return 1; - fi) 4<>"${_cache_dname_full%%[/]}.fetching"; + rtl_fileop cp "${_rpfug_cache_dname_full}" "${_rpfug_tgtdir}/${_rpfug_subdir}" || return 1; + rtl_fileop cd "${_rpfug_oldpwd}" || return 1; + fi) 4<>"${_rpfug_cache_dname_full%%[/]}.fetching"; if [ "${?}" -eq 0 ]; then cd "$(pwd)"; @@ -74,43 +77,56 @@ rtlp_fetch_url_git() { }; rtl_fetch_mirror_urls_git() { - local _git_args="${1}" _tgtdir="${2}" _rc=0 _repo_dname="" _subdir="" _url="" _url_spec=""; shift 2; + local _rfmug_git_args="${1}" _rfmug_tgtdir="${2}" \ + _rfmug_dname="" _rfmug_rc=0 _rfmug_repo_dname="" _rfmug_subdir="" \ + _rfmug_url="" _rfmug_url_spec=""; shift 2; - for _url_spec in "${@}"; do - _subdir="${_url_spec%=*}"; _subdir="${_subdir##*/}"; _url="${_url_spec#*=}"; _url="${_url%@*}"; - _repo_dname="${_subdir}"; [ "${_repo_dname%.git}" = "${_repo_dname}" ] && _repo_dname="${_repo_dname}.git"; + for _rfmug_url_spec in "${@}"; do + _rfmug_subdir="${_rfmug_url_spec%=*}"; _rfmug_subdir="${_rfmug_subdir##*/}"; _rfmug_url="${_rfmug_url_spec#*=}"; _rfmug_url="${_rfmug_url%@*}"; + _rfmug_repo_dname="${_rfmug_subdir}"; [ "${_rfmug_repo_dname%.git}" = "${_rfmug_repo_dname}" ] && _rfmug_repo_dname="${_rfmug_repo_dname}.git"; - if [ ! -e "$(rtl_dirname "${_tgtdir}")" ]; then - rtl_fileop mkdir "$(rtl_dirname "${_tgtdir}")"; + _rfmug_dname="${_rfmug_tgdir}"; rtl_dirname \$_rfmug_dname; + if ! [ -e "${_rfmug_dname}" ]; then + rtl_fileop mkdir "${_rfmug_dname}"; fi; (set -o errexit -o noglob -o nounset; rtl_flock_acquire 4 || exit "${?}"; - trap "rm -f \"${_tgtdir}/.fetching\"" EXIT; - if [ -e "${_tgtdir}/${_repo_dname}" ]; then - (rtl_fileop cd "${_tgtdir}/${_repo_dname}" && git fetch ${_git_args} --all) || return 1; - else (rtl_fileop cd "${_tgtdir}" && git clone ${_git_args} --mirror "${_url}" "${_repo_dname}") || return 1; - fi) 4<>"${_tgtdir}/.fetching"; + trap "rm -f \"${_rfmug_tgtdir}/.fetching\"" EXIT; + if [ -e "${_rfmug_tgtdir}/${_rfmug_repo_dname}" ]; then + (rtl_fileop cd "${_rfmug_tgtdir}/${_rfmug_repo_dname}" && git fetch ${_rfmug_git_args} --all) || return 1; + else (rtl_fileop cd "${_rfmug_tgtdir}" && git clone ${_rfmug_git_args} --mirror "${_rfmug_url}" "${_rfmug_repo_dname}") || return 1; + fi) 4<>"${_rfmug_tgtdir}/.fetching"; if [ "${?}" -ne 0 ]; then - _rc=1; + _rfmug_rc=1; fi; - done; return "${_rc}"; + done; + + return "${_rfmug_rc}"; }; rtl_fetch_urls_git() { - local _cache_dname="${1}" _git_args="${2}" _tgtdir="${3}" _pkg_name="${4}" _mirrors="${5}"\ - _git_branch="" _subdir="" _url="" _url_spec=""; shift 5; + local _rfug_cache_dname="${1}" _rfug_git_args="${2}" _rfug_tgtdir="${3}" \ + _rfug_pkg_name="${4}" _rfug_mirrors="${5}" \ + _rfug_git_branch="" _rfug_subdir="" _rfug_url="" _rfug_url_spec=""; shift 5; - for _url_spec in "${@}"; do - _subdir="${_url_spec%=*}"; _url="${_url_spec#*=}"; _url="${_url%@*}"; - if [ "${_url_spec#*@}" != "${_url_spec}" ]; then - _git_branch=${_url_spec#*@}; + for _rfug_url_spec in "${@}"; do + _rfug_subdir="${_rfug_url_spec%=*}"; + _rfug_url="${_rfug_url_spec#*=}"; + _rfug_url="${_rfug_url%@*}"; + if [ "${_rfug_url_spec#*@}" != "${_rfug_url_spec}" ]; then + _rfug_git_branch=${_rfug_url_spec#*@}; fi; if ! rtlp_fetch_url_git \ - "${_cache_dname}" "${_git_args}" "${_git_branch}" "${_mirrors}"\ - "${_pkg_name}" "${_subdir}" "${_tgtdir}" "${_url}"; then + "${_rfug_cache_dname}" "${_rfug_git_args}" \ + "${_rfug_git_branch}" "${_rfug_mirrors}" \ + "${_rfug_pkg_name}" "${_rfug_subdir}" \ + "${_rfug_tgtdir}" "${_rfug_url}"; + then return 1; fi; done; + + return 0; }; # vim:filetype=sh diff --git a/subr.rtl/rtl_fetch_wget.subr b/subr.rtl/rtl_fetch_wget.subr new file mode 100644 index 0000000..e5a6067 --- /dev/null +++ b/subr.rtl/rtl_fetch_wget.subr @@ -0,0 +1,79 @@ +# +# set +o errexit -o noglob -o nounset is assumed. +# + +# N.B. URLs ($1) may contain `?' or '&' characters. +rtl_fetch_url_wget() { + local _rfuw_urls="${1}" _rfuw_sha256sum_src="${2}" _rfuw_target_dname="${3}" \ + _rfuw_target_fname="${4}" _rfuw_target_name="${5}" _rfuw_mirrors="${6:-}" \ + _rfuw_rc=0 _rfuw_sha256sum_target="" _rfuw_target_fname_full="" _rfuw_url="" \ + _rfuw_url_base="" _rfuw_urls_count=0 _rfuw_urls_full=""; + + _rfuw_urls_full="${_rfuw_urls}"; + for _rfuw_url_base in ${_rfuw_mirrors}; do + rtl_lconcat \$_rfuw_urls_full "${_rfuw_url_base%/}/${_rfuw_target_name}/${_rfuw_target_fname}"; + done; + rtl_llength \$_rfuw_urls_count \$_rfuw_urls_full; + + for _rfuw_url in ${_rfuw_urls_full}; do + if [ "${_rfuw_target_fname:+1}" != 1 ]; then + rtl_basename2 \$_rfuw_url \$_rfuw_target_fname; + fi; + _rfuw_target_fname_full="${_rfuw_target_dname}/${_rfuw_target_fname}"; + + (set +o errexit -o noglob -o nounset; + rtl_flock_acquire 4 || exit 1; + trap "_rfuw_rc=\"\${?}\"; rm -f \"${_rfuw_target_fname_full}.fetching\"; exit \"\${_rfuw_rc}\";" EXIT; + + if [ "${_rfuw_sha256sum_src:+1}" != 1 ]\ + || ! rtl_check_digest_file "${_rfuw_target_fname_full}" "${_rfuw_sha256sum_src}" "${_rfuw_target_fname_full}.fetched"; then + wget ${DEFAULT_WGET_ARGS} -O "${_rfuw_target_fname_full}" "${_rfuw_url}"; _rfuw_rc="${?}"; + if [ "${_rfuw_rc}" -ne 0 ]; then + exit $((${_rfuw_rc}+2)); + elif [ "${_rfuw_sha256sum_src:+1}" = 1 ]\ + && ! rtl_check_digest \$_digest "${_rfuw_target_fname_full}" "${_rfuw_sha256sum_src}"; then + exit 2; + else + printf "%s" "${_digest}" > "${_rfuw_target_fname_full}.fetched"; exit 0; + fi; + else + exit 0; + fi;) 4<>"${_rfuw_target_fname_full}.fetching"; _rfuw_rc="${?}"; : $((_rfuw_urls_count-=1)); + + case "${_rfuw_rc}" in + + 0) break; ;; + + 1) if [ "${_rfuw_urls_count}" -ge 1 ]; then + rtl_log_msg "warning" "${MSG_rtl_fetch_lockfail_retryurl}" "${_rfuw_url}"; + else + rtl_log_msg "fatal" "${MSG_rtl_fetch_lockfail}" "${_rfuw_url}"; + rtl_fileop rm "${_rfuw_target_fname_full}"; break; + fi; ;; + + 2) if [ "${_rfuw_urls_count}" -ge 1 ]; then + rtl_log_msg "warning" "${MSG_rtl_fetch_hashfail_retryurl}" "${_rfuw_url}" "${_rfuw_sha256sum_src}"; + else + if _rfuw_sha256sum_target="$(sha256sum "${_rfuw_target_fname_full}" |\ + awk '{print $1}' 2>/dev/null)"; then + rtl_log_msg "fatal" "${MSG_rtl_fetch_hashfail1}" "${_rfuw_url}" "${_rfuw_sha256sum_src}" "${_rfuw_sha256sum_target}"; + else + rtl_log_msg "fatal" "${MSG_rtl_fetch_hashfail2}" "${_rfuw_url}" "${_rfuw_sha256sum_src}"; + fi; + rtl_fileop rm "${_rfuw_target_fname_full}"; break; + fi; ;; + + *) if [ "${_rfuw_urls_count}" -ge 1 ]; then + rtl_log_msg "warning" "${MSG_rtl_fetch_fail_retryurl}" "${_rfuw_url}" "$((${_rfuw_rc}-2))"; + else + rtl_log_msg "fatal" "${MSG_rtl_fetch_fail}" "${_rfuw_url}" "$((${_rfuw_rc}-2))"; + rtl_fileop rm "${_rfuw_target_fname_full}"; break; + fi; ;; + + esac; + done; + + return "${_rfuw_rc}"; +}; + +# vim:filetype=sh diff --git a/subr.rtl/rtl_fileop.subr b/subr.rtl/rtl_fileop.subr index 6d258f5..f6eae8f 100644 --- a/subr.rtl/rtl_fileop.subr +++ b/subr.rtl/rtl_fileop.subr @@ -7,10 +7,8 @@ # rtlp_fileop_check() { - local _prefix="${1}" _pname="" _rname=""; shift; - while [ "${#}" -gt 0 ]; do - return 0; - shift; done; + local _rpfc_prefix="${1}" _rpfc_pname="" _rpfc_rname=""; shift; + return 0; }; rtlp_fileop_log() { @@ -22,65 +20,78 @@ rtlp_fileop_log() { # rtl_fileop() { - local _op="${1}" _dst="" _group="" _install_args="" _mode="" _owner="" _rc=0 _src=""; shift; - case "${_op}" in - cd) if [ \( -z "${1}" \) -o ! \( -L "${1}" -o -e "${1}" \) ]; then + local _rf_op="${1}" \ + _rf_dst="" _rf_group="" _rf_install_args="" \ + _rf_mode="" _rf_owner="" _rf_rc=0 _rf_src=""; shift; + + case "${_rf_op}" in + + cd) if [ \( "${1:+1}" != 1 \) -o ! \( -L "${1}" -o -e "${1}" \) ]; then rtl_log_msg "fatalexit" "${MSG_rtl_fileop_invalid_dir}" "${1}"; elif rtlp_fileop_check "${PREFIX:-}" "${1}"; then rtlp_fileop_log "Changing working directory to \`${1}'."; - cd -- "${1}"; _rc="${?}"; + cd -- "${1}"; _rf_rc="${?}"; fi; ;; + chmod) if [ "${#}" -lt 2 ]; then rtl_log_msg "fatalexit" "${MSG_rtl_fileop_invparm_chmod}" "${*}"; - elif _mode="${1}" && shift\ + elif _rf_mode="${1}" && shift\ && rtlp_fileop_check "${PREFIX:-}" "${*}"; then - rtlp_fileop_log "Changing file mode bits of \`${*}' to \`${_mode}'."; - chmod -- "${_mode}" "${@}"; _rc="${?}"; + rtlp_fileop_log "Changing file mode bits of \`${*}' to \`${_rf_mode}'."; + chmod -- "${_rf_mode}" "${@}"; _rf_rc="${?}"; fi; ;; + chgrp) if [ "${#}" -lt 2 ]; then rtl_log_msg "fatalexit" "${MSG_rtl_fileop_invparm_chgrp}" "${*}"; - elif _group="${1}" && shift\ + elif _rf_group="${1}" && shift\ && rtlp_fileop_check "${PREFIX:-}" "${*}"; then - rtlp_fileop_log "Changing file group of \`${*}' to \`${_group}'."; - chgrp -- "${_group}" "${@}"; _rc="${?}"; + rtlp_fileop_log "Changing file group of \`${*}' to \`${_rf_group}'."; + chgrp -- "${_rf_group}" "${@}"; _rf_rc="${?}"; fi; ;; + chown) if [ "${#}" -lt 2 ]; then rtl_log_msg "fatalexit" "${MSG_rtl_fileop_invparm_chown}" "${*}"; - elif _owner="${1}" && shift\ + elif _rf_owner="${1}" && shift\ && rtlp_fileop_check "${PREFIX:-}" "${*}"; then - rtlp_fileop_log "Changing file owner of \`${*}' to \`${_owner}'."; - chown -- "${_owner}" "${@}"; _rc="${?}"; + rtlp_fileop_log "Changing file owner of \`${*}' to \`${_rf_owner}'."; + chown -- "${_rf_owner}" "${@}"; _rf_rc="${?}"; fi; ;; + cp_follow) if [ "${#}" -lt 2 ]; then rtl_log_msg "fatalexit" "${MSG_rtl_fileop_invparm_cp_follow}" "${*}"; elif rtlp_fileop_check "${PREFIX:-}" "${*}"; then - _src="${*}"; _src="${_src% *}"; - _dst="${*}"; _dst="${_dst##* }"; - rtlp_fileop_log "Copying \`${_src}' into \`${_dst}' w/ -pLR."; - cp -pLR -- "${@}"; _rc="${?}"; + _rf_src="${*}"; _rf_src="${_rf_src% *}"; + _rf_dst="${*}"; _rf_dst="${_rf_dst##* }"; + rtlp_fileop_log "Copying \`${_rf_src}' into \`${_rf_dst}' w/ -pLR."; + cp -pLR -- "${@}"; _rf_rc="${?}"; fi; ;; + cp) if [ "${#}" -lt 2 ]; then rtl_log_msg "fatalexit" "${MSG_rtl_fileop_invparm_cp}" "${*}"; elif rtlp_fileop_check "${PREFIX:-}" "${*}"; then - _src="${*}"; _src="${_src% *}"; - _dst="${*}"; _dst="${_dst##* }"; - rtlp_fileop_log "Copying \`${_src}' into \`${_dst}' w/ -pPR."; - cp -pPR -- "${@}"; _rc="${?}"; + _rf_src="${*}"; _rf_src="${_rf_src% *}"; + _rf_dst="${*}"; _rf_dst="${_rf_dst##* }"; + rtlp_fileop_log "Copying \`${_rf_src}' into \`${_rf_dst}' w/ -pPR."; + cp -pPR -- "${@}"; _rf_rc="${?}"; fi; ;; + install) if [ "${#}" -lt 2 ]; then rtl_log_msg "fatalexit" "${MSG_rtl_fileop_invparm_install}" "${*}"; - else _dst="$(while [ ""${#}"" -gt 2 ]; do shift; done; printf "%s" "${2}")"; - _install_args="$(while [ ""${#}"" -gt 2 ]; do printf "%s" "${1}"; shift; done)"; - _src="$(while [ ""${#}"" -gt 2 ]; do shift; done; printf "%s" "${1}")"; - if rtlp_fileop_check "${PREFIX:-}" "${_dst}" "${_src}"; then - rtlp_fileop_log "Installing \`${_src}' into \`${_dst}' w/ ${_install_args}."; - install "${@}"; _rc="${?}"; + else + rtl_lindexV \$_rf_dst -1 "${@}"; + rtl_lrangeV \$_rf_install_args 0 1 "${@}"; + rtl_lindexV \$_rf_install_args -2 "${@}"; + + if rtlp_fileop_check "${PREFIX:-}" "${_rf_dst}" "${_rf_src}"; then + rtlp_fileop_log "Installing \`${_rf_src}' into \`${_rf_dst}' w/ ${_rf_install_args}."; + install "${@}"; _rf_rc="${?}"; fi; fi; ;; + ln_symbolic) - if [ \( -z "${1}" \) -o \( -z "${2}" \) ]; then + if [ \( "${1:+1}" != 1 \) -o \( "${2:+1}" != 1 \) ]; then rtl_log_msg "fatalexit" "${MSG_rtl_fileop_invparm_ln_symbolic}" "${*}"; elif rtlp_fileop_check "${PREFIX:-}" "${2}"; then if rtl_fileop test "${2}"; then @@ -88,63 +99,70 @@ rtl_fileop() { fi; if [ "${?}" -eq 0 ]; then rtlp_fileop_log "Linking \`${1}' to \`${2}' w/ -fs"; - ln -fs -- "${1}" "${2}"; _rc="${?}"; + ln -fs -- "${1}" "${2}"; _rf_rc="${?}"; fi; fi; ;; - mv) if [ \( -z "${1}" \) -o \( -z "${2}" \) ]; then + + mv) if [ \( "${1:+1}" != 1 \) -o \( "${2:+1}" != 1 \) ]; then rtl_log_msg "fatalexit" "${MSG_rtl_fileop_invparm_mv}" "${*}"; elif rtlp_fileop_check "${PREFIX:-}" "${1}" "${2}"; then rtlp_fileop_log "Moving \`${1}' to \`${2}' w/ -fs"; - mv -f -- "${1}" "${2}"; _rc="${?}"; + mv -f -- "${1}" "${2}"; _rf_rc="${?}"; fi; ;; - touch) if [ -z "${1}" ]; then + + touch) if [ "${1:+1}" != 1 ]; then rtl_log_msg "fatalexit" "${MSG_rtl_fileop_invparm_touch}" "${*}"; elif rtlp_fileop_check "${PREFIX:-}" "${1}"; then rtlp_fileop_log "Touching file \`${1}'${2:+ w/ timestamp \`${2}\'}."; - touch ${2:+-t "${2}"} -- "${1}"; _rc="${?}"; + touch ${2:+-t "${2}"} -- "${1}"; _rf_rc="${?}"; fi; ;; + mkdir|mkfifo|rm|source|source_opt|test) while [ \( "${?}" -eq 0 \) -a \( ""${#}"" -gt 0 \) ]; do - if [ -z "${1}" ]; then - rtl_log_msg "fatalexit" "${MSG_rtl_fileop_invparm}" "${_op}" "${*}"; - elif [ "${_op}" = mkdir ]\ + if [ "${1:+1}" != 1 ]; then + rtl_log_msg "fatalexit" "${MSG_rtl_fileop_invparm}" "${_rf_op}" "${*}"; + elif [ "${_rf_op}" = mkdir ]\ && [ ! -d "${1}" ]\ && rtlp_fileop_check "${PREFIX:-}" "${1}"; then if rtl_fileop test "${1}"; then rtl_fileop rm "${1}"; fi; rtlp_fileop_log "Making directory \`${1}'."; - mkdir -p -- "${1}"; _rc="${?}"; - elif [ "${_op}" = mkfifo ]\ + mkdir -p -- "${1}"; _rf_rc="${?}"; + elif [ "${_rf_op}" = mkfifo ]\ && rtlp_fileop_check "${PREFIX:-}" "${1}"; then if rtl_fileop test "${1}"; then rtl_fileop rm "${1}"; fi; rtlp_fileop_log "Creating FIFO \`${1}'."; rtlp_fileop_check "${PREFIX:-}" "${1}"; - mkfifo -- "${1}"; _rc="${?}"; - elif [ "${_op}" = rm ]\ + mkfifo -- "${1}"; _rf_rc="${?}"; + elif [ "${_rf_op}" = rm ]\ && rtl_fileop test "${1}"\ && rtlp_fileop_check "${PREFIX:-}" "${1}"; then rtlp_fileop_log "Removing directory or file \`${1}'."; - rm -rf -- "${1}"; _rc="${?}"; - elif [ "${_op}" = source ]\ + rm -rf -- "${1}"; _rf_rc="${?}"; + elif [ "${_rf_op}" = source ]\ && rtlp_fileop_check "${PREFIX:-}" "${1}"; then rtlp_fileop_log "Sourcing file \`${1}'."; - . "${1}"; _rc="${?}"; - elif [ "${_op}" = source_opt ]\ + . "${1}"; _rf_rc="${?}"; + elif [ "${_rf_op}" = source_opt ]\ && rtl_fileop test "${1}"\ && rtlp_fileop_check "${PREFIX:-}" "${1}"; then rtlp_fileop_log "Sourcing file \`${1}'."; - . "${1}"; _rc="${?}"; - elif [ "${_op}" = test ]\ + . "${1}"; _rf_rc="${?}"; + elif [ "${_rf_op}" = test ]\ && rtlp_fileop_check "${PREFIX:-}" "${1}"\ && ! [ \( -L "${1}" \) -o \( -e "${1}" \) ]; then return 1; fi; shift; done; ;; + *) rtl_log_msg "fatalexit" "${MSG_rtl_fileop_invparm_fileop}" "${*}"; ;; - esac; return "${_rc}"; + + esac; + + return "${_rf_rc}"; }; # vim:filetype=sh diff --git a/subr.rtl/rtl_filepath.subr b/subr.rtl/rtl_filepath.subr index 671f853..a2b5bf4 100644 --- a/subr.rtl/rtl_filepath.subr +++ b/subr.rtl/rtl_filepath.subr @@ -3,16 +3,28 @@ # rtl_basename() { - local _fname="${1##*/}"; printf "%s" "${_fname}"; + rtl_basename2 "${1}" "${1}"; +}; + +rtl_basename2() { + local _rb2_rfname="${1#\$}" _rb2_rfname_out="${2#\$}" \ + _rb2_fname=""; + + eval _rb2_fname="\${${_rb2_rfname}}"; + eval ${_rb2_rfname_out}='${_rb2_fname##*/}'; + return 0; }; rtl_check_digest() { - local _fname="${1}" _digest_check="${2}" _digest=""; RTL_CHECK_DIGEST_DIGEST=""; - if ! [ -e "${_fname}" ]; then + local _rcd_rdigest="${1#\$}" _rcd_fname="${2}" _rcd_digest_check="${3}" \ + _rcd_digest=""; + + if ! [ -e "${_rcd_fname}" ]; then return 1; - else set -- $(sha256sum "${_fname}"); - RTL_CHECK_DIGEST_DIGEST="${1}"; - if [ "${RTL_CHECK_DIGEST_DIGEST}" = "${_digest_check}" ]; then + else set -- $(sha256sum "${_rcd_fname}"); + _rcd_digest="${1}"; + eval ${_rcd_rdigest}='${_rcd_digest}'; + if [ "${_rcd_digest}" = "${_rcd_digest_check}" ]; then return 0; else return 1; @@ -21,57 +33,88 @@ rtl_check_digest() { }; rtl_check_digest_file() { - local _fname="${1}" _digest_check="${2}" _digest_fname="${3}" _digest="" RTL_CHECK_DIGEST_DIGEST=""; - if ! [ -e "${_digest_fname}" ]; then + local _rcdf_fname="${1}" _rcdf_digest_check="${2}" _rcdf_digest_fname="${3}" \ + _rcdf_digest="" _rcdf_digest_file=""; + + if ! [ -e "${_rcdf_digest_fname}" ]; then return 1; - else _digest="$(cat "${_digest_fname}")"; - if [ "${_digest}" != "${_digest_check}" ]\ - || ! rtl_check_digest "${_fname}" "${_digest_check}"; then + else _rcdf_digest_file="$(cat "${_rcdf_digest_fname}")"; + if [ "${_rcdf_digest_file}" != "${_rcdf_digest_check}" ]\ + || ! rtl_check_digest \$_rcdf_digest "${_rcdf_fname}" \ + "${_rcdf_digest_check}"; + then return 1; + else + return 0; fi; fi; }; 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; + local _rcpv_rstatus="${1#\$}" _rcpv_vnames="${2}" \ + _rcpv_rc=0 _rcpv_vname="" _rcpv_vname_val=""; + + for _rcpv_vname in ${_rcpv_vnames}; do + rtl_get_var_unsafe \$_rcpv_vname_val "${_rcpv_vname}"; + if [ "${_rcpv_vname_val:+1}" != 1 ]; then + _rcpv_rc=1; + rtl_setrstatus "${_rcpv_rstatus}" 'Error: variable \`'"${_rcpv_vname}'"' is empty or unset.'; + break; + elif [ "${_rcpv_vname_val#* *}" != "${_rcpv_vname_val}" ]; then + _rcpv_rc=2; + rtl_setrstatus "${_rcpv_rstatus}" 'Error: variable \`'"${_rcpv_vname}'"' contains one or more whitespace characters.'; + break; fi; done; - return "${_rc}"; + return "${_rcpv_rc}"; }; rtl_dirname() { - local _dname="${1%/*}"; - case "${_dname}" in - "") _dname="."; ;; - *) while rtl_matchr "${_dname}" "*/"; do - _dname="${_dname%/}"; + rtl_dirname2 "${1}" "${1}"; +}; + +rtl_dirname2() { + local _rdname="${1#\$}" _rdname_out="${2#\$}" \ + _rd2_dname=""; + + eval _rd2_dname="\${${_rdname}}"; + _rd2_dname="${_rd2_dname%/*}"; + + case "${_rd2_dname}" in + "") _rd2_dname="."; ;; + *) while rtl_matchr "${_rd2_dname}" "*/"; do + _rd2_dname="${_rd2_dname%/}"; done; ;; - esac; printf "%s" "${_dname:-/}"; + esac; + + eval ${_rdname_out}='${_rd2_dname}'; + return 0; }; rtl_exists_any() { - local _subdir="${1}"; shift; + local _rea_subdir="${1}"; shift; + while [ "${#}" -gt 0 ]; do - if [ -e "${_subdir}/${1}" ]; then + if [ -e "${_rea_subdir}/${1}" ]; then return 0; else shift; fi; - done; return 1; + done; + return 1; }; rtl_flock_acquire() { - local _fd="${1}" _conflict_exit_code="${2:-253}" _wait="${3:-3600}" + local _rfa_fd="${1}" _rfa_conflict_exit_code="${2:-253}" _rfa_wait="${3:-3600}"; + while true; do - if flock -E "${_conflict_exit_code}" -w "${_wait}" "${_fd}"; then - break; - elif [ "${?}" -eq "${_conflict_exit_code}" ]; then + if flock \ + -E "${_rfa_conflict_exit_code}" \ + -w "${_rfa_wait}" \ + "${_rfa_fd}"; + then + return 0; + elif [ "${?}" -eq "${_rfa_conflict_exit_code}" ]; then continue; else return "${?}"; @@ -80,12 +123,16 @@ rtl_flock_acquire() { }; rtl_is_newer() { - local _new_fname="${1}" _old_fname="${2}" _new_ts="" _old_ts=""; - if ! [ -e "${_old_fname}" ]; then + local _ris_new_fname="${1}" _ris_old_fname="${2}" \ + _ris_new_ts="" _ris_old_ts=""; + + if ! [ -e "${_ris_old_fname}" ]; then return 0; - else _new_ts="$(stat -c %Y "${_new_fname}" 2>/dev/null)"; - _old_ts="$(stat -c %Y "${_old_fname}" 2>/dev/null)"; - if [ "${_new_ts:-0}" -gt "${_old_ts:-0}" ]; then + else + _ris_new_ts="$(stat -c %Y "${_ris_new_fname}" 2>/dev/null)"; + _ris_old_ts="$(stat -c %Y "${_ris_old_fname}" 2>/dev/null)"; + + if [ "${_ris_new_ts:-0}" -gt "${_ris_old_ts:-0}" ]; then return 0; else return 1; diff --git a/subr.rtl/rtl_install.subr b/subr.rtl/rtl_install.subr index db305cd..36f5f28 100644 --- a/subr.rtl/rtl_install.subr +++ b/subr.rtl/rtl_install.subr @@ -3,81 +3,89 @@ # rtl_install() { - local _verbose="" _prefix="" _chmod_mode="" _dname="" _file_fname_dst="" \ - _file_fname_src="" _fname="" _ln_fname="" _ln_target="" _owner_spec="" \ - _pname=""; - [ "${1}" = "-v" ] && { _verbose=1; shift; }; _prefix="${1}"; shift; + local _ri_verbose="" _ri_prefix="" \ + _ri_chmod_mode="" _ri_dname="" _ri_file_fname_dst="" _ri_file_fname_src="" \ + _ri_fname="" _ri_ln_fname="" _ri_ln_target="" _ri_owner_spec="" _ri_pname=""; + + if [ "${1}" = "-v" ]; then + _ri_verbose=1; shift; + fi; + _ri_prefix="${1}"; shift; while [ ${#} -gt 0 ]; do case "${1}" in + -*) - _pname="${1#-}"; - if [ "${_pname#/}" = "${_pname}" ]; then - _pname="${_prefix:+${_prefix}/}${_pname}"; + _ri_pname="${1#-}"; + if [ "${_ri_pname#/}" = "${_ri_pname}" ]; then + _ri_pname="${_ri_prefix:+${_ri_prefix}/}${_ri_pname}"; fi; - if ! rtl_fileop rm "${_pname}"; then + if ! rtl_fileop rm "${_ri_pname}"; then return 1; fi; ;; !*=*) - _file_fname_src="${1#!}"; _file_fname_src="${_file_fname_src%=*}"; - _file_fname_dst="${1#!}"; _file_fname_dst="${_file_fname_dst#*=}"; - if [ "${_file_fname_src#/}" = "${_file_fname_src}" ]; then - _file_fname_src="${_prefix:+${_prefix}/}${_file_fname_src}"; + _ri_file_fname_src="${1#!}"; _ri_file_fname_src="${_ri_file_fname_src%=*}"; + _ri_file_fname_dst="${1#!}"; _ri_file_fname_dst="${_ri_file_fname_dst#*=}"; + if [ "${_ri_file_fname_src#/}" = "${_ri_file_fname_src}" ]; then + _ri_file_fname_src="${_ri_prefix:+${_ri_prefix}/}${_ri_file_fname_src}"; fi; - if [ "${_file_fname_dst#/}" = "${_file_fname_dst}" ]; then - _file_fname_dst="${_prefix:+${_prefix}/}${_file_fname_dst}"; + if [ "${_ri_file_fname_dst#/}" = "${_ri_file_fname_dst}" ]; then + _ri_file_fname_dst="${_ri_prefix:+${_ri_prefix}/}${_ri_file_fname_dst}"; fi; - if ! rtl_fileop mv "${_file_fname_src}" "${_file_fname_dst}"; then + if ! rtl_fileop mv "${_ri_file_fname_src}" "${_ri_file_fname_dst}"; then return 1; fi; ;; /=*) - _dname="${1#/=}"; - if [ "${_dname#/}" = "${_dname}" ]; then - _dname="${_prefix:+${_prefix}/}${_dname}"; + _ri_dname="${1#/=}"; + if [ "${_ri_dname#/}" = "${_ri_dname}" ]; then + _ri_dname="${_ri_prefix:+${_ri_prefix}/}${_ri_dname}"; fi; - if ! rtl_fileop mkdir "${_dname}"; then + if ! rtl_fileop mkdir "${_ri_dname}"; then return 1; fi; ;; @*=*) - _ln_target="${1%=*}"; _ln_target="${_ln_target#@}"; _ln_fname="${1#*=}"; - if [ "${_ln_fname#/}" = "${_ln_fname}" ]; then - _ln_fname="${_prefix:+${_prefix}/}${_ln_fname}"; + _ri_ln_target="${1%=*}"; _ri_ln_target="${_ri_ln_target#@}"; _ri_ln_fname="${1#*=}"; + if [ "${_ri_ln_fname#/}" = "${_ri_ln_fname}" ]; then + _ri_ln_fname="${_ri_prefix:+${_ri_prefix}/}${_ri_ln_fname}"; fi; - if [ -e "${_ln_fname}" ]; then - rtl_fileop rm "${_ln_fname}"; + if [ -e "${_ri_ln_fname}" ]; then + rtl_fileop rm "${_ri_ln_fname}"; fi; - if ! rtl_fileop ln_symbolic "${_ln_target}" "${_ln_fname}"; then + if ! rtl_fileop ln_symbolic "${_ri_ln_target}" "${_ri_ln_fname}"; then return 1; fi; ;; m[0-7][0-7][0-7][0-7]=*) - _fname="${1#m[0-7][0-7][0-7][0-7]=}"; _chmod_mode="${1%%=*}"; _chmod_mode="${_chmod_mode#m}"; - if ! rtl_fileop chmod "${_chmod_mode}" "${_fname}"; then + _ri_fname="${1#m[0-7][0-7][0-7][0-7]=}"; _ri_chmod_mode="${1%%=*}"; _ri_chmod_mode="${_ri_chmod_mode#m}"; + if ! rtl_fileop chmod "${_ri_chmod_mode}" "${_ri_fname}"; then return 1; fi; ;; o*=*) - _fname="${1#o*=}"; _owner_spec="${1%%=*}"; _owner_spec="${_owner_spec#o}"; - if ! rtl_fileop chown "${_owner_spec}" "${_fname}"; then + _ri_fname="${1#o*=}"; _ri_owner_spec="${1%%=*}"; _ri_owner_spec="${_ri_owner_spec#o}"; + if ! rtl_fileop chown "${_ri_owner_spec}" "${_ri_fname}"; then return 1; fi; ;; *=*) - _file_fname_src="${1%=*}"; _file_fname_dst="${1#*=}"; - if [ "${_file_fname_src#/}" = "${_file_fname_src}" ]; then - _file_fname_src="${_prefix:+${_prefix}/}${_file_fname_src}"; + _ri_file_fname_src="${1%=*}"; _ri_file_fname_dst="${1#*=}"; + if [ "${_ri_file_fname_src#/}" = "${_ri_file_fname_src}" ]; then + _ri_file_fname_src="${_ri_prefix:+${_ri_prefix}/}${_ri_file_fname_src}"; fi; - if [ "${_file_fname_dst#/}" = "${_file_fname_dst}" ]; then - _file_fname_dst="${_prefix:+${_prefix}/}${_file_fname_dst}"; + if [ "${_ri_file_fname_dst#/}" = "${_ri_file_fname_dst}" ]; then + _ri_file_fname_dst="${_ri_prefix:+${_ri_prefix}/}${_ri_file_fname_dst}"; fi; - if ! rtl_fileop cp "${_file_fname_src}" "${_file_fname_dst}"; then + if ! rtl_fileop cp "${_ri_file_fname_src}" "${_ri_file_fname_dst}"; then return 1; fi; ;; + esac; shift; done; + + return 0; }; # vim:filetype=sh diff --git a/subr.rtl/rtl_install_v2.subr b/subr.rtl/rtl_install_v2.subr index 0efeaac..d498255 100644 --- a/subr.rtl/rtl_install_v2.subr +++ b/subr.rtl/rtl_install_v2.subr @@ -2,7 +2,7 @@ # set +o errexit -o noglob -o nounset is assumed. # -RTLP_INSTALL_NL=" +RTL_NL=" "; # XXX optimise @@ -14,264 +14,305 @@ RTLP_INSTALL_NL=" # # DSL functor implementation # -# {{{ rtlp_install_fmap($_rparams, $_prefix, $_spec, $_fn, [$_param[...], --, [$_spec[...]]]) -rtlp_install_fmap() { - local _rif_rparams="${1#\$}" _rif_prefix="${2}" _rif_spec="${3}" \ - _rif_fn="${4}" _rif_IFS0="${IFS:- }" _rif_paramsc=0 \ - _rif_spec_cur="" _rif_spec_list="" _rif_spec0="" _rif_specsc=0 \ - _rif_nspec=0 _rif_rc=0 IFS; shift 4; +# {{{ rtlp_install_v2_fmap($_rstatus, $_rparams, $_prefix, $_spec, $_fn, [$_param[...], --, [$_spec[...]]]) +rtlp_install_v2_fmap() { + local _ri2f_rstatus="${1#\$}" _ri2f_rparams="${2#\$}" _ri2f_prefix="${3}" _ri2f_spec="${4}" _ri2f_fn="${5}" \ + _ri2f_IFS0="${IFS:- }" _ri2f_paramsc=0 _ri2f_spec_cur="" _ri2f_spec_list="" _ri2f_spec0="" \ + _ri2f_specsc=0 _ri2f_nspec=0 _ri2f_rc=0 IFS; + shift 5; + while [ "${#}" -gt 0 ] && [ "x${1}" != "x--" ]; do - : $((_rif_paramsc+=1)); local "${_rif_rparams}${_rif_paramsc}=${1}"; shift; + : $((_ri2f_paramsc+=1)); local "${_ri2f_rparams}${_ri2f_paramsc}=${1}"; shift; done; shift; while [ "${#}" -gt 0 ] && [ "x${1}" != "x--" ]; do - : $((_rif_specsc+=1)); local "_rif_specs${_rif_specsc}=${1}"; shift; + : $((_ri2f_specsc+=1)); local "_ri2f_specs${_ri2f_specsc}=${1}"; shift; done; - if rtlp_install_fmap_params "${_rif_rparams}" \$_rif_spec ""\ - && rtlp_install_fmap_patterns "${_rif_rparams}" "${_rif_prefix}" "${_rif_spec}" \$_rif_spec_list; then - IFS="${RTLP_INSTALL_NL}"; for _rif_spec_cur in ${_rif_spec_list}; do - IFS="${_rif_IFS0}"; set --; - _rif_nspec=1; while [ "${_rif_nspec}" -le "${_rif_specsc}" ]; do - eval _rif_spec0=\"\${_rif_specs${_rif_nspec}}\"; - rtlp_install_fmap_params \ - "${_rif_rparams}" \ - \$_rif_spec0 "${_rif_spec_cur}"; - eval set -- '"${@}"' '"${_rif_spec0}"'; : $((_rif_nspec+=1)); + if rtlp_install_v2_fmap_params "${_ri2f_rstatus}" "${_ri2f_rparams}" \$_ri2f_spec ""\ + && rtlp_install_v2_fmap_patterns "${_ri2f_rstatus}" "${_ri2f_rparams}" "${_ri2f_prefix}" "${_ri2f_spec}" \$_ri2f_spec_list; then + IFS="${RTL_NL}"; for _ri2f_spec_cur in ${_ri2f_spec_list}; do + IFS="${_ri2f_IFS0}"; set --; + _ri2f_nspec=1; while [ "${_ri2f_nspec}" -le "${_ri2f_specsc}" ]; do + eval _ri2f_spec0=\"\${_ri2f_specs${_ri2f_nspec}}\"; + rtlp_install_v2_fmap_params \ + "${_ri2f_rstatus}" \ + "${_ri2f_rparams}" \ + \$_ri2f_spec0 "${_ri2f_spec_cur}"; + eval set -- '"${@}"' '"${_ri2f_spec0}"'; : $((_ri2f_nspec+=1)); done; - eval "${_rif_fn}" \"\$\{@\}\"; _rif_rc=$((${?} ? ${?} : ${_rif_rc})); - [ "${_rif_rc}" -ne 0 ] && break; - done; IFS="${_rif_IFS0}"; + eval "${_ri2f_fn}" \"\$\{@\}\"; _ri2f_rc=$((${?} ? ${?} : ${_ri2f_rc})); + [ "${_ri2f_rc}" -ne 0 ] && break; + done; IFS="${_ri2f_IFS0}"; else - _rif_rc=1; + _ri2f_rc=1; fi; - return "${_rif_rc}"; + return "${_ri2f_rc}"; }; # }}} -# {{{ rtlp_install_fmap_params($_rparams, $_rspec, $_item) +# {{{ rtlp_install_v2_fmap_params($_rstatus, $_rparams, $_rspec, $_item) RTLP_INSTALL_FMAP_PARAMS_LEVEL=0; -rtlp_install_fmap_params() { - local _rifp_rparams="${1#\$}" _rifp_rspec="${2#\$}" _rifp_item="${3}" \ - _rifp_expr="" _rifp_expr_="" _rifp_expr_sub="" _rifp_expr_op="" \ - _rifp_lhs="" _rifp_rc=0 _rifp_rhs="" _rifp_subexpr=""; _status=""; - eval _rifp_lhs='${'"${_rifp_rspec}"'}'\; ${_rifp_rspec}=; +rtlp_install_v2_fmap_params() { + local _ri2fp_rstatus="${1#\$}" _ri2fp_rparams="${2#\$}" _ri2fp_rspec="${3#\$}" _ri2fp_item="${4}" \ + _ri2fp_expr="" _ri2fp_expr_="" _ri2fp_expr_sub="" _ri2fp_expr_op="" _ri2fp_lhs="" _ri2fp_rc=0 \ + _ri2fp_rhs="" _ri2fp_subexpr=""; + eval _ri2fp_lhs='${'"${_ri2fp_rspec}"'}'\; ${_ri2fp_rspec}=; while true; do - if ! rtlp_install_splitl_ref \$_rifp_expr \$_rifp_lhs \$_rifp_rhs '%[' ']'; then - eval ${_rifp_rspec}='${'"${_rifp_rspec}"'}${_rifp_lhs}'; break; - else case "${_rifp_expr}" in + if ! rtlp_install_v2_splitl_ref \$_ri2fp_expr \$_ri2fp_lhs \$_ri2fp_rhs '%[' ']'; then + eval ${_ri2fp_rspec}='${'"${_ri2fp_rspec}"'}${_ri2fp_lhs}'; break; + else + case "${_ri2fp_expr}" in + [0-9]*) - eval _rifp_expr='${'"${_rifp_rparams}${_rifp_expr}"'}'; ;; + eval _ri2fp_expr='${'"${_ri2fp_rparams}${_ri2fp_expr}"'}'; ;; + @[0-9]*) : $((RTLP_INSTALL_FMAP_PARAMS_LEVEL+=1)); - eval _rifp_expr${RTLP_INSTALL_FMAP_PARAMS_LEVEL}='${'"${_rifp_rparams}${_rifp_expr#@}"'}'; - rtlp_install_fmap_params "${_rifp_rparams}" \ - \$_rifp_expr${RTLP_INSTALL_FMAP_PARAMS_LEVEL} \ - "${_rifp_item}"; _rifp_rc="${?}"; - eval _rifp_expr='${_rifp_expr'"${RTLP_INSTALL_FMAP_PARAMS_LEVEL}"'}'; + eval _ri2fp_expr${RTLP_INSTALL_FMAP_PARAMS_LEVEL}='${'"${_ri2fp_rparams}${_ri2fp_expr#@}"'}'; + rtlp_install_v2_fmap_params "${_ri2fp_rstatus}" "${_ri2fp_rparams}" \ + \$_ri2fp_expr${RTLP_INSTALL_FMAP_PARAMS_LEVEL} \ + "${_ri2fp_item}"; _ri2fp_rc="${?}"; + eval _ri2fp_expr='${_ri2fp_expr'"${RTLP_INSTALL_FMAP_PARAMS_LEVEL}"'}'; + unset '_ri2fp_expr'"${RTLP_INSTALL_FMAP_PARAMS_LEVEL}"; : $((RTLP_INSTALL_FMAP_PARAMS_LEVEL-=1)); - [ "${_rifp_rc}" -eq 1 ] && break; ;; + [ "${_ri2fp_rc}" -eq 1 ] && break; ;; [_0-9a-zA-Z]*) - case "${_rifp_expr}" in - DNAME*) _rifp_subexpr="${_rifp_expr#DNAME}"; _rifp_expr="${_rifp_item%/*}"; ;; - FNAME*) _rifp_subexpr="${_rifp_expr#FNAME}"; _rifp_expr="${_rifp_item##*/}"; ;; - ITEM*) _rifp_subexpr="${_rifp_expr#ITEM}"; _rifp_expr="${_rifp_item}"; ;; - "") _rifp_rc=1; _status="zero-length parameter name in expression"; ;; + case "${_ri2fp_expr}" in + + DNAME*) _ri2fp_subexpr="${_ri2fp_expr#DNAME}"; _ri2fp_expr="${_ri2fp_item%/*}"; ;; + FNAME*) _ri2fp_subexpr="${_ri2fp_expr#FNAME}"; _ri2fp_expr="${_ri2fp_item##*/}"; ;; + ITEM*) _ri2fp_subexpr="${_ri2fp_expr#ITEM}"; _ri2fp_expr="${_ri2fp_item}"; ;; + + "") _ri2fp_rc=1; + rtl_setrstatus "${_ri2fp_rstatus}" 'zero-length parameter name in expression'; + ;; + *) - _rifp_expr_="${_rifp_expr%%[!_0-9a-zA-Z]*}"; - _rifp_subexpr="${_rifp_expr#${_rifp_expr_}}"; - _rifp_expr="${_rifp_expr_}"; - if eval [ '"${'"${_rifp_rparams}${_rifp_expr}"':+1}"' = 1 ]; then - eval _rifp_expr='${'"${_rifp_rparams}${_rifp_expr}"'}'; - else _rifp_rc=1; _status="unknown parameter name \`${_rifp_expr}' in expression"; - fi; ;; + _ri2fp_expr_="${_ri2fp_expr%%[!_0-9a-zA-Z]*}"; + _ri2fp_subexpr="${_ri2fp_expr#${_ri2fp_expr_}}"; + _ri2fp_expr="${_ri2fp_expr_}"; + if eval [ '"${'"${_ri2fp_rparams}${_ri2fp_expr}"':+1}"' = 1 ]; then + eval _ri2fp_expr='${'"${_ri2fp_rparams}${_ri2fp_expr}"'}'; + else _ri2fp_rc=1; + rtl_setrstatus "${_ri2fp_rstatus}" 'unknown parameter name \`'"${_ri2fp_expr}"''\'' in expression'; + fi; + ;; + esac; - if [ "${_rifp_rc}" -eq 0 ]; then + if [ "${_ri2fp_rc}" -eq 0 ]; then while true; do - if ! rtlp_install_splitl_subexpr \ - \$_rifp_subexpr_ \ - \$_rifp_subexpr \ + if ! rtlp_install_v2_splitl_subexpr \ + \$_ri2fp_subexpr_ \ + \$_ri2fp_subexpr \ '## # %% %'; then break; - else case "${_rifp_subexpr_}" in + else case "${_ri2fp_subexpr_}" in + /*) ;; - \#\#*) _rifp_expr="${_rifp_expr##${_rifp_subexpr_#\#\#}}"; ;; - \#*) _rifp_expr="${_rifp_expr#${_rifp_subexpr_#\#}}"; ;; - %%*) _rifp_expr="${_rifp_expr%%${_rifp_subexpr_#%%}}"; ;; - %*) _rifp_expr="${_rifp_expr%${_rifp_subexpr_#%}}"; ;; - "") _rifp_rc=1; _status="zero-length subexpression in expression"; ;; - *) _rifp_rc=1; _status="invalid subexpression \`${_rifp_subexpr_}' in expression"; ;; + \#\#*) _ri2fp_expr="${_ri2fp_expr##${_ri2fp_subexpr_#\#\#}}"; ;; + \#*) _ri2fp_expr="${_ri2fp_expr#${_ri2fp_subexpr_#\#}}"; ;; + %%*) _ri2fp_expr="${_ri2fp_expr%%${_ri2fp_subexpr_#%%}}"; ;; + %*) _ri2fp_expr="${_ri2fp_expr%${_ri2fp_subexpr_#%}}"; ;; + + "") _ri2fp_rc=1; + rtl_setrstatus "${_ri2fp_rstatus}" 'zero-length subexpression in expression'; + ;; + + *) _ri2fp_rc=1; + rtl_setrstatus "${_ri2fp_rstatus}" 'invalid subexpression \`'"${_ri2fp_subexpr_}"''\'' in expression'; + ;; + esac; fi; done; fi; ;; - "") _rifp_rc=1; _status="zero-length expression"; break; ;; - *) _rifp_rc=1; _status="invalid expression \`${_rifp_expr}'"; break; ;; + "") _ri2fp_rc=1; + rtl_setrstatus "${_ri2fp_rstatus}" 'zero-length expression'; + break; ;; + + *) _ri2fp_rc=1; + rtl_setrstatus "${_ri2fp_rstatus}" 'invalid expression \`'"${_ri2fp_expr}"''\'; + break; ;; + esac; fi; - eval ${_rifp_rspec}='${'"${_rifp_rspec}"'}${_rifp_lhs}${_rifp_expr}'; _rifp_lhs="${_rifp_rhs}"; - done; return "${_rifp_rc}"; + + eval ${_ri2fp_rspec}='${'"${_ri2fp_rspec}"'}${_ri2fp_lhs}${_ri2fp_expr}'; _ri2fp_lhs="${_ri2fp_rhs}"; + done; + + return "${_ri2fp_rc}"; }; # }}} -# {{{ rtlp_install_fmap_patterns($_rparams, $_prefix, $_spec, $_rspec_list) -rtlp_install_fmap_patterns() { - local _rifp2_rparams="${1#\$}" _rifp2_prefix="${2}" _rifp2_spec="${3}" \ - _rifp2_rspec_list="${4#\$}" _rifp2_expr="" _rifp2_lhs="" _rifp2_rc=0 \ - _rifp2_rhs="" IFS="${RTLP_INSTALL_NL}"; _status=""; - _rifp2_lhs="${_rifp2_spec}"; +# {{{ rtlp_install_v2_fmap_patterns($_rstatus, $_rparams, $_prefix, $_spec, $_rspec_list) +rtlp_install_v2_fmap_patterns() { + local _ri2fp2_rstatus="${1#\$}" _ri2fp2_rparams="${2#\$}" _ri2fp2_prefix="${3}" \ + _ri2fp2_spec="${4}" _ri2fp2_rspec_list="${5#\$}" \ + _ri2fp2_expr="" _ri2fp2_lhs="" _ri2fp2_rc=0 _ri2fp2_rhs="" \ + IFS="${RTL_NL}"; + _ri2fp2_lhs="${_ri2fp2_spec}"; while true; do - if rtlp_install_splitl_ref \$_rifp2_expr \$_rifp2_lhs \$_rifp2_rhs '%<' '>'; then - case "${_rifp2_expr}" in + if rtlp_install_v2_splitl_ref \$_ri2fp2_expr \$_ri2fp2_lhs \$_ri2fp2_rhs '%<' '>'; then + case "${_ri2fp2_expr}" in + *\**) - if [ "${_rifp2_lhs#/}" = "${_rifp2_lhs}" ]; then - _rifp2_lhs_full="${_rifp2_prefix:+${_rifp2_prefix%}/}${_rifp2_lhs:+${_rifp2_lhs%/}/}"; + if [ "${_ri2fp2_lhs#/}" = "${_ri2fp2_lhs}" ]; then + _ri2fp2_lhs_full="${_ri2fp2_prefix:+${_ri2fp2_prefix%}/}${_ri2fp2_lhs:+${_ri2fp2_lhs%/}/}"; else - _rifp2_lhs_full="${_rifp2_lhs:+${_rifp2_lhs%/}/}"; + _ri2fp2_lhs_full="${_ri2fp2_lhs:+${_ri2fp2_lhs%/}/}"; fi; - set +o noglob; for _rifp2_pname in ${_rifp2_lhs_full}${_rifp2_expr}; do - set -o noglob; _rifp2_pname="${_rifp2_pname%/}${_rifp2_rhs:+/${_rifp2_rhs}}"; - if [ -e "${_rifp2_pname}" ]; then - eval ${_rifp2_rspec_list}='${'"${_rifp2_rspec_list}"':+${'"${_rifp2_rspec_list}"'}${RTLP_INSTALL_NL}}${_rifp2_pname}'; + set +o noglob; for _ri2fp2_pname in ${_ri2fp2_lhs_full}${_ri2fp2_expr}; do + set -o noglob; _ri2fp2_pname="${_ri2fp2_pname%/}${_ri2fp2_rhs:+/${_ri2fp2_rhs}}"; + if [ -e "${_ri2fp2_pname}" ]; then + eval ${_ri2fp2_rspec_list}='${'"${_ri2fp2_rspec_list}"':+${'"${_ri2fp2_rspec_list}"'}${RTL_NL}}${_ri2fp2_pname}'; fi; done; set -o noglob; ;; - "") _rifp2_rc=1; _status="zero-length pattern"; break; ;; - *) _rifp2_rc=1; _status="invalid pattern \`${_rifp2_expr}'"; break; ;; - esac; _rifp2_lhs="${_rifp2_rhs}"; + "") _ri2fp2_rc=1; + rtl_setrstatus "${_ri2fp2_rstatus}" 'zero-length pattern'; + break; ;; + + *) _ri2fp2_rc=1; + rtl_setrstatus "${_ri2fp2_rstatus}" 'invalid pattern \`'"${_ri2fp2_expr}"''\'; + break; ;; + + esac; _ri2fp2_lhs="${_ri2fp2_rhs}"; else - eval ${_rifp2_rspec_list}='${'"${_rifp2_rspec_list}"':+${'"${_rifp2_rspec_list}"'}${RTLP_INSTALL_NL}}${_rifp2_lhs}'; + eval ${_ri2fp2_rspec_list}='${'"${_ri2fp2_rspec_list}"':+${'"${_ri2fp2_rspec_list}"'}${RTL_NL}}${_ri2fp2_lhs}'; break; fi; - done; return "${_rifp2_rc}"; + done; + + return "${_ri2fp2_rc}"; }; # }}} # # Install OPeration functions # -# {{{ rtlp_install_op_chmod($_nflag, $_prefix, $_vflag, $_fname, $_mode) -rtlp_install_op_chmod() { - local _rioc_nflag="${1}" _rioc_prefix="${2}" _rioc_vflag="${3}" _rioc_fname="${4}" _rioc_mode="${5}"; +# {{{ rtlp_install_v2_op_chmod($_nflag, $_prefix, $_vflag, $_fname, $_mode) +rtlp_install_v2_op_chmod() { + local _ri2oc_nflag="${1}" _ri2oc_prefix="${2}" _ri2oc_vflag="${3}" _ri2oc_fname="${4}" _ri2oc_mode="${5}"; - rtlp_install_fixup_fname \$_rioc_fname "${_rioc_prefix}"; - rtlp_install_rc "${_rioc_nflag}" "${_rioc_vflag}" rtl_fileop chmod "${_rioc_mode}" "${_rioc_fname}"; + rtlp_install_v2_fixup_fname \$_ri2oc_fname "${_ri2oc_prefix}"; + rtlp_install_v2_rc "${_ri2oc_nflag}" "${_ri2oc_vflag}" rtl_fileop chmod "${_ri2oc_mode}" "${_ri2oc_fname}"; }; # }}} -# {{{ rtlp_install_op_chgrp($_nflag, $_prefix, $_vflag, $_fname, $_group) -rtlp_install_op_chgrp() { - local _rioc2_nflag="${1}" _rioc2_prefix="${2}" _rioc2_vflag="${3}" _rioc2_fname="${4}" _rioc2_group="${5}"; +# {{{ rtlp_install_v2_op_chgrp($_nflag, $_prefix, $_vflag, $_fname, $_group) +rtlp_install_v2_op_chgrp() { + local _ri2oc2_nflag="${1}" _ri2oc2_prefix="${2}" _ri2oc2_vflag="${3}" _ri2oc2_fname="${4}" _ri2oc2_group="${5}"; - rtlp_install_fixup_fname \$_rioc2_fname "${_rioc2_prefix}"; - rtlp_install_rc "${_rioc2_nflag}" "${_rioc2_vflag}" rtl_fileop chgrp "${_rioc2_group}" "${_rioc2_fname}"; + rtlp_install_v2_fixup_fname \$_ri2oc2_fname "${_ri2oc2_prefix}"; + rtlp_install_v2_rc "${_ri2oc2_nflag}" "${_ri2oc2_vflag}" rtl_fileop chgrp "${_ri2oc2_group}" "${_ri2oc2_fname}"; }; # }}} -# {{{ rtlp_install_op_chown($_nflag, $_prefix, $_vflag, $_fname, $_owner) -rtlp_install_op_chown() { - local _rioc3_nflag="${1}" _rioc3_prefix="${2}" _rioc3_vflag="${3}" _rioc3_fname="${4}" _rioc3_owner="${5}"; +# {{{ rtlp_install_v2_op_chown($_nflag, $_prefix, $_vflag, $_fname, $_owner) +rtlp_install_v2_op_chown() { + local _ri2oc3_nflag="${1}" _ri2oc3_prefix="${2}" _ri2oc3_vflag="${3}" _ri2oc3_fname="${4}" _ri2oc3_owner="${5}"; - rtlp_install_fixup_fname \$_rioc3_fname "${_rioc3_prefix}"; - rtlp_install_rc "${_rioc3_nflag}" "${_rioc3_vflag}" rtl_fileop chown "${_rioc3_owner}" "${_rioc3_fname}"; + rtlp_install_v2_fixup_fname \$_ri2oc3_fname "${_ri2oc3_prefix}"; + rtlp_install_v2_rc "${_ri2oc3_nflag}" "${_ri2oc3_vflag}" rtl_fileop chown "${_ri2oc3_owner}" "${_ri2oc3_fname}"; }; # }}} -# {{{ rtlp_install_op_cp($_nflag, $_prefix, $_vflag, $_file_fname_dst, $_file_fname_src) -rtlp_install_op_cp() { - local _rioc4_nflag="${1}" _rioc4_prefix="${2}" _rioc4_vflag="${3}" _rioc4_fname_dst="${4}" _rioc4_fname_src="${5}"; +# {{{ rtlp_install_v2_op_cp($_nflag, $_prefix, $_vflag, $_file_fname_dst, $_file_fname_src) +rtlp_install_v2_op_cp() { + local _ri2oc4_nflag="${1}" _ri2oc4_prefix="${2}" _ri2oc4_vflag="${3}" _ri2oc4_fname_dst="${4}" _ri2oc4_fname_src="${5}"; - rtlp_install_fixup_fname \$_rioc4_fname_dst "${_rioc4_prefix}"; - rtlp_install_fixup_fname \$_rioc4_fname_src "${_rioc4_prefix}"; - rtlp_install_rc "${_rioc4_nflag}" "${_rioc4_vflag}" rtl_fileop cp "${_rioc4_fname_src}" "${_rioc4_fname_dst}"; + rtlp_install_v2_fixup_fname \$_ri2oc4_fname_dst "${_ri2oc4_prefix}"; + rtlp_install_v2_fixup_fname \$_ri2oc4_fname_src "${_ri2oc4_prefix}"; + rtlp_install_v2_rc "${_ri2oc4_nflag}" "${_ri2oc4_vflag}" rtl_fileop cp "${_ri2oc4_fname_src}" "${_ri2oc4_fname_dst}"; }; # }}} -# {{{ rtlp_install_op_cp_follow_if_newer($_nflag, $_prefix, $_vflag, $_file_fname_dst, $_file_fname_src) -rtlp_install_op_cp_follow_if_newer() { - local _riocfin_nflag="${1}" _riocfin_prefix="${2}" _riocfin_vflag="${3}" _riocfin_fname_dst="${4}" _riocfin_fname_src="${5}"; - - rtlp_install_fixup_fname \$_riocfin_fname_dst "${_riocfin_prefix}"; - rtlp_install_fixup_fname \$_riocfin_fname_src "${_riocfin_prefix}"; - if [ -e "${_riocfin_fname_dst}" ]\ - && rtl_is_newer "${_riocfin_fname_src}" "${_riocfin_fname_dst}"; then +# {{{ rtlp_install_v2_op_cp_follow_if_newer($_nflag, $_prefix, $_vflag, $_file_fname_dst, $_file_fname_src) +rtlp_install_v2_op_cp_follow_if_newer() { + local _ri2ocfin_nflag="${1}" _ri2ocfin_prefix="${2}" _ri2ocfin_vflag="${3}" _ri2ocfin_fname_dst="${4}" _ri2ocfin_fname_src="${5}"; + + rtlp_install_v2_fixup_fname \$_ri2ocfin_fname_dst "${_ri2ocfin_prefix}"; + rtlp_install_v2_fixup_fname \$_ri2ocfin_fname_src "${_ri2ocfin_prefix}"; + if [ -e "${_ri2ocfin_fname_dst}" ]\ + && rtl_is_newer "${_ri2ocfin_fname_src}" "${_ri2ocfin_fname_dst}"; then return 0; else - rtlp_install_rc "${_riocfin_nflag}" "${_riocfin_vflag}" rtl_fileop cp_follow "${_riocfin_fname_src}" "${_riocfin_fname_dst}"; + rtlp_install_v2_rc "${_ri2ocfin_nflag}" "${_ri2ocfin_vflag}" rtl_fileop cp_follow "${_ri2ocfin_fname_src}" "${_ri2ocfin_fname_dst}"; fi; }; # }}} -# {{{ rtlp_install_op_ln_symbolic($_nflag, $_prefix, $_vflag, $_ln_fname, $_ln_target) -rtlp_install_op_ln_symbolic() { - local _riols_nflag="${1}" _riols_prefix="${2}" _riols_vflag="${3}" _riols_ln_fname="${4}" _riols_ln_target="${5}"; +# {{{ rtlp_install_v2_op_ln_symbolic($_nflag, $_prefix, $_vflag, $_ln_fname, $_ln_target) +rtlp_install_v2_op_ln_symbolic() { + local _ri2ols_nflag="${1}" _ri2ols_prefix="${2}" _ri2ols_vflag="${3}" _ri2ols_ln_fname="${4}" _ri2ols_ln_target="${5}"; - rtlp_install_fixup_fname \$_riols_ln_fname "${_riols_prefix}"; - if [ -e "${_riols_ln_fname}" ]; then - rtlp_install_rc "${_riols_nflag}" "${_riols_vflag}" rtl_fileop rm "${_riols_ln_fname}"; + rtlp_install_v2_fixup_fname \$_ri2ols_ln_fname "${_ri2ols_prefix}"; + if [ -e "${_ri2ols_ln_fname}" ]; then + rtlp_install_v2_rc "${_ri2ols_nflag}" "${_ri2ols_vflag}" rtl_fileop rm "${_ri2ols_ln_fname}"; fi; - rtlp_install_rc "${_riols_nflag}" "${_riols_vflag}" rtl_fileop ln_symbolic "${_riols_ln_target}" "${_riols_ln_fname}"; + rtlp_install_v2_rc "${_ri2ols_nflag}" "${_ri2ols_vflag}" rtl_fileop ln_symbolic "${_ri2ols_ln_target}" "${_ri2ols_ln_fname}"; }; # }}} -# {{{ rtlp_install_op_mkdir($_nflag, $_prefix, $_vflag, $_dname) -rtlp_install_op_mkdir() { - local _riom_nflag="${1}" _riom_prefix="${2}" _riom_vflag="${3}" _riom_dname="${4}"; +# {{{ rtlp_install_v2_op_mkdir($_nflag, $_prefix, $_vflag, $_dname) +rtlp_install_v2_op_mkdir() { + local _ri2om_nflag="${1}" _ri2om_prefix="${2}" _ri2om_vflag="${3}" _ri2om_dname="${4}"; - rtlp_install_fixup_fname \$_riom_dname "${_riom_prefix}"; - rtlp_install_rc "${_riom_nflag}" "${_riom_vflag}" rtl_fileop mkdir "${_riom_dname}"; + rtlp_install_v2_fixup_fname \$_ri2om_dname "${_ri2om_prefix}"; + rtlp_install_v2_rc "${_ri2om_nflag}" "${_ri2om_vflag}" rtl_fileop mkdir "${_ri2om_dname}"; }; # }}} -# {{{ rtlp_install_op_mv($_nflag, $_prefix, $_vflag, $_file_fname_dst, $_file_fname_src) -rtlp_install_op_mv() { - local _riom2_nflag="${1}" _riom2_prefix="${2}" _riom2_vflag="${3}" _riom2_fname_dst="${4}" _riom2_fname_src="${5}"; +# {{{ rtlp_install_v2_op_mv($_nflag, $_prefix, $_vflag, $_file_fname_dst, $_file_fname_src) +rtlp_install_v2_op_mv() { + local _ri2om2_nflag="${1}" _ri2om2_prefix="${2}" _ri2om2_vflag="${3}" _ri2om2_fname_dst="${4}" _ri2om2_fname_src="${5}"; - rtlp_install_fixup_fname \$_riom2_fname_dst "${_riom2_prefix}"; - rtlp_install_fixup_fname \$_riom2_fname_src "${_riom2_prefix}"; - rtlp_install_rc "${_riom2_nflag}" "${_riom2_vflag}" rtl_fileop mv "${_riom2_fname_src}" "${_riom2_fname_dst}"; + rtlp_install_v2_fixup_fname \$_ri2om2_fname_dst "${_ri2om2_prefix}"; + rtlp_install_v2_fixup_fname \$_ri2om2_fname_src "${_ri2om2_prefix}"; + rtlp_install_v2_rc "${_ri2om2_nflag}" "${_ri2om2_vflag}" rtl_fileop mv "${_ri2om2_fname_src}" "${_ri2om2_fname_dst}"; }; # }}} -# {{{ rtlp_install_op_rm($_nflag, $_prefix, $_vflag, $_pname) -rtlp_install_op_rm() { - local _rior_nflag="${1}" _rior_prefix="${2}" _rior_vflag="${3}" _rior_pname="${4}"; +# {{{ rtlp_install_v2_op_rm($_nflag, $_prefix, $_vflag, $_pname) +rtlp_install_v2_op_rm() { + local _ri2or_nflag="${1}" _ri2or_prefix="${2}" _ri2or_vflag="${3}" _ri2or_pname="${4}"; - rtlp_install_fixup_fname \$_rior_pname "${_rior_prefix}"; - rtlp_install_rc "${_rior_nflag}" "${_rior_vflag}" rtl_fileop rm "${_rior_pname}"; + rtlp_install_v2_fixup_fname \$_ri2or_pname "${_ri2or_prefix}"; + rtlp_install_v2_rc "${_ri2or_nflag}" "${_ri2or_vflag}" rtl_fileop rm "${_ri2or_pname}"; }; # }}} -# {{{ rtlp_install_op_touch($_nflag, $_prefix, $_vflag, $_fname, $_ts) -rtlp_install_op_touch() { - local _riot_nflag="${1}" _riot_prefix="${2}" _riot_vflag="${3}" _riot_fname="${4}" _riot_ts="${5:-}"; +# {{{ rtlp_install_v2_op_touch($_nflag, $_prefix, $_vflag, $_fname, $_ts) +rtlp_install_v2_op_touch() { + local _ri2ot_nflag="${1}" _ri2ot_prefix="${2}" _ri2ot_vflag="${3}" _ri2ot_fname="${4}" _ri2ot_ts="${5:-}"; - rtlp_install_fixup_fname \$_riot_fname "${_riot_prefix}"; - rtlp_install_rc "${_riot_nflag}" "${_riot_vflag}" rtl_fileop touch "${_riot_fname}" "${_riot_ts}"; + rtlp_install_v2_fixup_fname \$_ri2ot_fname "${_ri2ot_prefix}"; + rtlp_install_v2_rc "${_ri2ot_nflag}" "${_ri2ot_vflag}" rtl_fileop touch "${_ri2ot_fname}" "${_ri2ot_ts}"; }; # }}} # # Ancillary functions # -# {{{ rtlp_install_fixup_fname($_rfname, $_prefix) -rtlp_install_fixup_fname() { - local _riff_rfname="${1#\$}" __riff_prefix="${2}" _riff_fname=""; - eval _riff_fname='${'"${_riff_rfname}"'}'; +# {{{ rtlp_install_v2_fixup_fname($_rfname, $_prefix) +rtlp_install_v2_fixup_fname() { + local _ri2ff_rfname="${1#\$}" _ri2ff_prefix="${2}" _ri2ff_fname=""; + eval _ri2ff_fname='${'"${_ri2ff_rfname}"'}'; - if [ "${_riff_fname#/}" = "${_riff_fname}" ]; then - eval ${_riff_rfname}='${__riff_prefix:+${__riff_prefix}/}${_riff_fname}'; + if [ "${_ri2ff_fname#/}" = "${_ri2ff_fname}" ]; then + eval ${_ri2ff_rfname}='${_ri2ff_prefix:+${_ri2ff_prefix}/}${_ri2ff_fname}'; fi; }; # }}} -# {{{ rtlp_install_rc($_nflag, $_vflag, $_fn, [...]) -rtlp_install_rc() { - local _rir_nflag="${1}" _rir_vflag="${2}" _rir_fn="${3}" _rir_rc=0; shift 3; +# {{{ rtlp_install_v2_rc($_nflag, $_vflag, $_fn, [...]) +rtlp_install_v2_rc() { + local _ri2r_nflag="${1}" _ri2r_vflag="${2}" _ri2r_fn="${3}" _ri2r_rc=0; shift 3; - if [ "${_rir_nflag}" -eq 1 ]\ - || [ "${_rir_vflag}" -gt 0 ]; then - rtl_log_msg "install" "${MSG_rtl_install_v2_rc}" "${_rir_fn}${_rir_fn:+ ${*}}"; + if [ "${_ri2r_nflag}" -eq 1 ]\ + || [ "${_ri2r_vflag}" -gt 0 ]; then + rtl_log_msg "install" "${MSG_rtl_install_v2_rc}" "${_ri2r_fn}${_ri2r_fn:+ ${*}}"; fi; - if [ "${_rir_nflag}" -eq 0 ]; then - "${_rir_fn}" "${@}"; _rir_rc="${?}"; + if [ "${_ri2r_nflag}" -eq 0 ]; then + "${_ri2r_fn}" "${@}"; _ri2r_rc="${?}"; fi; - return "${_rir_rc}"; + return "${_ri2r_rc}"; }; # }}} -# {{{ rtlp_install_splitl($_rlhs, $_rrhs, $_sep) +# {{{ rtlp_install_v2_splitl($_rlhs, $_rrhs, $_sep) # -# rtlp_install_splitl() +# rtlp_install_v2_splitl() # Split @_rlhs from left-hand side into left-hand and right-hand side # according to @_sep w/ backslash escaping # @@ -283,29 +324,30 @@ rtlp_install_rc() { # Notate bene: @_sep is a shell pattern # Returns: zero (0) on success, non-zero (>0) on absence of unescaped @_sep in @_rlhs # -rtlp_install_splitl() { - local _ris_rlhs="${1#\$}" _ris_rrhs="${2#\$}" _ris_sep="${3}" _ris_lhs="" \ - _ris_lhs_new="" _ris_rc=1 _ris_rhs="" _ris_rhs_new=""; - - eval _ris_rhs='${'"${_ris_rlhs}"'}'; - while [ "${_ris_rhs:+1}" = 1 ]; do - _ris_lhs_new="${_ris_rhs%%${_ris_sep}*}"; - if [ "${_ris_lhs_new}" != "${_ris_rhs}" ]; then - _ris_rhs_new="${_ris_rhs#*${_ris_sep}}"; - if [ "${_ris_lhs_new%\\}" = "${_ris_lhs_new}" ]; then - eval ${_ris_rlhs}='${_ris_lhs}${_ris_lhs_new}' \ - ${_ris_rrhs}='${_ris_rhs_new}'; _ris_rc=0; break; +rtlp_install_v2_splitl() { + local _ri2s_rlhs="${1#\$}" _ri2s_rrhs="${2#\$}" _ri2s_sep="${3}" _ri2s_lhs="" \ + _ri2s_lhs_new="" _ri2s_rc=1 _ri2s_rhs="" _ri2s_rhs_new=""; + + eval _ri2s_rhs='${'"${_ri2s_rlhs}"'}'; + while [ "${_ri2s_rhs:+1}" = 1 ]; do + _ri2s_lhs_new="${_ri2s_rhs%%${_ri2s_sep}*}"; + if [ "${_ri2s_lhs_new}" != "${_ri2s_rhs}" ]; then + _ri2s_rhs_new="${_ri2s_rhs#*${_ri2s_sep}}"; + if [ "${_ri2s_lhs_new%\\}" = "${_ri2s_lhs_new}" ]; then + eval ${_ri2s_rlhs}='${_ri2s_lhs}${_ri2s_lhs_new}' \ + ${_ri2s_rrhs}='${_ri2s_rhs_new}'; _ri2s_rc=0; break; else - _ris_lhs="${_ris_lhs}${_ris_lhs_new%\\}${_ris_sep}"; - _ris_rhs="${_ris_rhs_new}"; + _ri2s_lhs="${_ri2s_lhs}${_ri2s_lhs_new%\\}${_ri2s_sep}"; + _ri2s_rhs="${_ri2s_rhs_new}"; fi; else break; fi; - done; return "${_ris_rc}"; + done; + return "${_ri2s_rc}"; }; # }}} -# {{{ rtlp_install_splitl_ref($_ritem, $_rlhs, $_rrhs, $_sepl, $_sepr) +# {{{ rtlp_install_v2_splitl_ref($_ritem, $_rlhs, $_rrhs, $_sepl, $_sepr) # -# rtlp_install_splitl_ref() +# rtlp_install_v2_splitl_ref() # Split @_rlhs from left-hand side into left-hand, reference, and # right-hand side according to left-hand (beginning) and right-hand # (ending) side separators w/ backslash escaping @@ -320,48 +362,48 @@ rtlp_install_splitl() { # Notate bene: @_sepl and @_sepr are shell patterns # Returns: zero (0) on success, non-zero (>0) on absence of unescaped references in @_rlhs # -rtlp_install_splitl_ref() { - local _risr_rref="${1#\$}" _risr_rlhs="${2#\$}" _risr_rrhs="${3#\$}" _risr_sepl="${4}" \ - _risr_sepr="${5}" _risr_item="" _risr_item_lhs="" _risr_item_lhs_new="" \ - _risr_item_rhs="" _risr_item_rhs_new="" _risr_lhs="" _risr_lhs_new="" _risr_rc=1 \ - _risr_rhs="" _risr_rhs_new=""; - - eval _risr_rhs='${'"${_risr_rlhs}"'}'; - while [ "${_risr_rhs:+1}" = 1 ]; do - _risr_lhs_new="${_risr_rhs%%${_risr_sepl}*}"; - if [ "${_risr_lhs_new}" != "${_risr_rhs}" ]; then - _risr_rhs_new="${_risr_rhs#*${_risr_sepl}}"; - if [ "${_risr_lhs_new%\\}" = "${_risr_lhs_new}" ]; then - _risr_item=""; _risr_item_lhs=""; _risr_item_rhs="${_risr_rhs_new}"; - while [ "${_risr_item_rhs:+1}" = 1 ]; do - _risr_item_lhs_new="${_risr_item_rhs%%${_risr_sepr}*}"; - if [ "${_risr_item_lhs_new}" != "${_risr_item_rhs}" ]; then - _risr_item_rhs_new="${_risr_item_rhs#*${_risr_sepr}}"; - if [ "${_risr_item_lhs_new%\\}" = "${_risr_item_lhs_new}" ]; then - _risr_item="${_risr_item_lhs}${_risr_item_lhs_new}"; - _risr_item_rhs="${_risr_item_rhs_new}"; - _risr_rc=0; break; +rtlp_install_v2_splitl_ref() { + local _ri2sr_rref="${1#\$}" _ri2sr_rlhs="${2#\$}" _ri2sr_rrhs="${3#\$}" _ri2sr_sepl="${4}" \ + _ri2sr_sepr="${5}" _ri2sr_item="" _ri2sr_item_lhs="" _ri2sr_item_lhs_new="" \ + _ri2sr_item_rhs="" _ri2sr_item_rhs_new="" _ri2sr_lhs="" _ri2sr_lhs_new="" _ri2sr_rc=1 \ + _ri2sr_rhs="" _ri2sr_rhs_new=""; + + eval _ri2sr_rhs='${'"${_ri2sr_rlhs}"'}'; + while [ "${_ri2sr_rhs:+1}" = 1 ]; do + _ri2sr_lhs_new="${_ri2sr_rhs%%${_ri2sr_sepl}*}"; + if [ "${_ri2sr_lhs_new}" != "${_ri2sr_rhs}" ]; then + _ri2sr_rhs_new="${_ri2sr_rhs#*${_ri2sr_sepl}}"; + if [ "${_ri2sr_lhs_new%\\}" = "${_ri2sr_lhs_new}" ]; then + _ri2sr_item=""; _ri2sr_item_lhs=""; _ri2sr_item_rhs="${_ri2sr_rhs_new}"; + while [ "${_ri2sr_item_rhs:+1}" = 1 ]; do + _ri2sr_item_lhs_new="${_ri2sr_item_rhs%%${_ri2sr_sepr}*}"; + if [ "${_ri2sr_item_lhs_new}" != "${_ri2sr_item_rhs}" ]; then + _ri2sr_item_rhs_new="${_ri2sr_item_rhs#*${_ri2sr_sepr}}"; + if [ "${_ri2sr_item_lhs_new%\\}" = "${_ri2sr_item_lhs_new}" ]; then + _ri2sr_item="${_ri2sr_item_lhs}${_ri2sr_item_lhs_new}"; + _ri2sr_item_rhs="${_ri2sr_item_rhs_new}"; + _ri2sr_rc=0; break; else - _risr_item_lhs="${_risr_item_lhs}${_risr_item_lhs_new%\\}${_risr_sepr}"; - _risr_item_rhs="${_risr_item_rhs_new}"; + _ri2sr_item_lhs="${_ri2sr_item_lhs}${_ri2sr_item_lhs_new%\\}${_ri2sr_sepr}"; + _ri2sr_item_rhs="${_ri2sr_item_rhs_new}"; fi; else break; fi; done; break; else - _risr_lhs="${_risr_lhs}${_risr_lhs_new%\\}${_risr_sepl}"; _risr_rhs="${_risr_rhs_new}"; + _ri2sr_lhs="${_ri2sr_lhs}${_ri2sr_lhs_new%\\}${_ri2sr_sepl}"; _ri2sr_rhs="${_ri2sr_rhs_new}"; fi; else break; fi; done; - eval ${_risr_rref}='${_risr_item}' \ - ${_risr_rlhs}='${_risr_lhs}${_risr_lhs_new}' \ - ${_risr_rrhs}='${_risr_item_rhs}'; - return "${_risr_rc}"; + eval ${_ri2sr_rref}='${_ri2sr_item}' \ + ${_ri2sr_rlhs}='${_ri2sr_lhs}${_ri2sr_lhs_new}' \ + ${_ri2sr_rrhs}='${_ri2sr_item_rhs}'; + return "${_ri2sr_rc}"; }; # }}} -# {{{ rtlp_install_splitl_subexpr($_rexpr, $_rlhs, $_lsep) +# {{{ rtlp_install_v2_splitl_subexpr($_rexpr, $_rlhs, $_lsep) # -# rtlp_install_splitl_subexpr() +# rtlp_install_v2_splitl_subexpr() # Split @_rlhs from left-hand side into left-hand (subexpression) and right-hand # side according to list of expression operator prefixes w/ backslash escaping # @@ -373,69 +415,77 @@ rtlp_install_splitl_ref() { # Notate bene: @_lsep list items are shell patterns # Returns: zero (0) on success, non-zero (>0) on absence of unescaped expressions in @_rlhs # -rtlp_install_splitl_subexpr() { - local _riss_rexpr="${1#\$}" _riss_rlhs="${2#\$}" _riss_lsep="${3}" _riss_lhs="" \ - _riss_matchfl="" _riss_nsep="" _riss_rc=1 _riss_sep="" _riss_sexpr="" \ - _riss_sexpr_lhs="" _riss_sexpr_lhs_new="" _riss_sexpr_rhs="" \ - _riss_sexpr_rhs_new="" _riss_sexpr_rhs_new_min="" _riss_sexpr_rhs_new_min_new="" \ - _riss_sexpr_sep="" _riss_sexpr_sep_new="" - - eval _riss_lhs='${'"${_riss_rlhs}"'}'; set -- ${_riss_lsep}; - if [ "${_riss_lhs:+1}" = 1 ]; then - _riss_matchfl=0; _riss_nsep=1; while [ "${_riss_nsep}" -le "${#}" ]; do - eval _riss_sep='${'"${_riss_nsep}"'}'; - case "${_riss_lhs}" in - ${_riss_sep}*) _riss_matchfl=1; break; ;; - *) : $((_riss_nsep+=1)); ;; +rtlp_install_v2_splitl_subexpr() { + local _ri2ss_rexpr="${1#\$}" _ri2ss_rlhs="${2#\$}" _ri2ss_lsep="${3}" _ri2ss_lhs="" \ + _ri2ss_matchfl="" _ri2ss_nsep="" _ri2ss_rc=1 _ri2ss_sep="" _ri2ss_sexpr="" \ + _ri2ss_sexpr_lhs="" _ri2ss_sexpr_lhs_new="" _ri2ss_sexpr_rhs="" \ + _ri2ss_sexpr_rhs_new="" _ri2ss_sexpr_rhs_new_min="" _ri2ss_sexpr_rhs_new_min_new="" \ + _ri2ss_sexpr_sep="" _ri2ss_sexpr_sep_new="" + + eval _ri2ss_lhs='${'"${_ri2ss_rlhs}"'}'; set -- ${_ri2ss_lsep}; + + if [ "${_ri2ss_lhs:+1}" = 1 ]; then + _ri2ss_matchfl=0; _ri2ss_nsep=1; while [ "${_ri2ss_nsep}" -le "${#}" ]; do + eval _ri2ss_sep='${'"${_ri2ss_nsep}"'}'; + case "${_ri2ss_lhs}" in + ${_ri2ss_sep}*) _ri2ss_matchfl=1; break; ;; + *) : $((_ri2ss_nsep+=1)); ;; esac; done; - if [ "${_riss_matchfl}" -eq 1 ]; then - _riss_sexpr=""; _riss_sexpr_lhs="${_riss_sep}"; - _riss_sexpr_rhs="${_riss_lhs#${_riss_sep}}"; - while [ "${_riss_sexpr_rhs:+1}" = 1 ]; do - _riss_sexpr_rhs_new_min=-1; _riss_sexpr_sep=""; _riss_nsep=1; - while [ "${_riss_nsep}" -le "${#}" ]; do - eval _riss_sexpr_sep_new='${'"${_riss_nsep}"'}'; - _riss_sexpr_rhs_new="${_riss_sexpr_rhs%%${_riss_sexpr_sep_new}*}"; - if [ "${_riss_sexpr_rhs_new}" != "${_riss_sexpr_rhs}" ]; then - _riss_sexpr_rhs_new_min_new="${#_riss_sexpr_rhs_new}"; - if [ "${_riss_sexpr_rhs_new_min_new}" -le "${_riss_sexpr_rhs_new_min}" ]\ - || [ "${_riss_sexpr_rhs_new_min}" -eq -1 ]; then - _riss_sexpr_rhs_new_min="${_riss_sexpr_rhs_new_min_new}"; - _riss_sexpr_sep="${_riss_sexpr_sep_new}"; + + if [ "${_ri2ss_matchfl}" -eq 1 ]; then + _ri2ss_sexpr=""; _ri2ss_sexpr_lhs="${_ri2ss_sep}"; + _ri2ss_sexpr_rhs="${_ri2ss_lhs#${_ri2ss_sep}}"; + + while [ "${_ri2ss_sexpr_rhs:+1}" = 1 ]; do + _ri2ss_sexpr_rhs_new_min=-1; _ri2ss_sexpr_sep=""; _ri2ss_nsep=1; + while [ "${_ri2ss_nsep}" -le "${#}" ]; do + eval _ri2ss_sexpr_sep_new='${'"${_ri2ss_nsep}"'}'; + _ri2ss_sexpr_rhs_new="${_ri2ss_sexpr_rhs%%${_ri2ss_sexpr_sep_new}*}"; + if [ "${_ri2ss_sexpr_rhs_new}" != "${_ri2ss_sexpr_rhs}" ]; then + _ri2ss_sexpr_rhs_new_min_new="${#_ri2ss_sexpr_rhs_new}"; + if [ "${_ri2ss_sexpr_rhs_new_min_new}" -le "${_ri2ss_sexpr_rhs_new_min}" ]\ + || [ "${_ri2ss_sexpr_rhs_new_min}" -eq -1 ]; then + _ri2ss_sexpr_rhs_new_min="${_ri2ss_sexpr_rhs_new_min_new}"; + _ri2ss_sexpr_sep="${_ri2ss_sexpr_sep_new}"; fi; - fi; : $((_riss_nsep+=1)); + fi; : $((_ri2ss_nsep+=1)); done; - if [ "${_riss_sexpr_sep:+1}" = 1 ]; then - _riss_sexpr_lhs_new="${_riss_sexpr_rhs%%${_riss_sexpr_sep}*}"; - if [ "${_riss_sexpr_lhs_new%\\}" = "${_riss_sexpr_lhs_new}" ]; then - _riss_sexpr_lhs="${_riss_sexpr_lhs}${_riss_sexpr_lhs_new}"; - _riss_sexpr_rhs="${_riss_sexpr_sep}${_riss_sexpr_rhs#*${_riss_sexpr_sep}}"; break; + if [ "${_ri2ss_sexpr_sep:+1}" = 1 ]; then + _ri2ss_sexpr_lhs_new="${_ri2ss_sexpr_rhs%%${_ri2ss_sexpr_sep}*}"; + if [ "${_ri2ss_sexpr_lhs_new%\\}" = "${_ri2ss_sexpr_lhs_new}" ]; then + _ri2ss_sexpr_lhs="${_ri2ss_sexpr_lhs}${_ri2ss_sexpr_lhs_new}"; + _ri2ss_sexpr_rhs="${_ri2ss_sexpr_sep}${_ri2ss_sexpr_rhs#*${_ri2ss_sexpr_sep}}"; break; else - _riss_sexpr_lhs="${_riss_sexpr_lhs}${_riss_sexpr_rhs%%\\${_riss_sexpr_sep}*}${_riss_sexpr_sep}"; - _riss_sexpr_rhs="${_riss_sexpr_rhs#*\\${_riss_sexpr_sep}}"; + _ri2ss_sexpr_lhs="${_ri2ss_sexpr_lhs}${_ri2ss_sexpr_rhs%%\\${_ri2ss_sexpr_sep}*}${_ri2ss_sexpr_sep}"; + _ri2ss_sexpr_rhs="${_ri2ss_sexpr_rhs#*\\${_ri2ss_sexpr_sep}}"; fi; else - _riss_sexpr_lhs="${_riss_sexpr_lhs}${_riss_sexpr_rhs}"; _riss_sexpr_rhs=""; break; + _ri2ss_sexpr_lhs="${_ri2ss_sexpr_lhs}${_ri2ss_sexpr_rhs}"; _ri2ss_sexpr_rhs=""; break; fi; done; - eval ${_riss_rexpr}='${_riss_sexpr_lhs}' ${_riss_rlhs}='${_riss_sexpr_rhs}'; _riss_rc=0; + + eval ${_ri2ss_rexpr}='${_ri2ss_sexpr_lhs}' ${_ri2ss_rlhs}='${_ri2ss_sexpr_rhs}'; _ri2ss_rc=0; fi; - fi; return "${_riss_rc}"; + fi; + + return "${_ri2ss_rc}"; }; # }}} rtl_install_v2() { - local _ri_prefix="" _ri_spec_flag="" _ri_spec_list="" _ri_iflag=0 _ri_IFS="${IFS:- }" \ - _ri_nflag=0 _ri_paramsc=0 _ri_vflag=0 _ri_IFS0 _ri_nparam=0 _ri_opt="" _ri_param="" \ - _ri_rc=0 _ri_spec="" _ri_spec_dst="" _ri_spec_src="" IFS OPTARG="" OPTIND=1; _status=""; + local _ri2_rstatus="${1#\$}" \ + _ri2_prefix="" _ri2_spec_flag="" _ri2_spec_list="" _ri2_iflag=0 _ri2_IFS="${IFS:- }" \ + _ri2_nflag=0 _ri2_paramsc=0 _ri2_vflag=0 _ri2_IFS0 _ri2_nparam=0 _ri2_opt="" _ri2_param="" \ + _ri2_rc=0 _ri2_spec="" _ri2_spec_dst="" _ri2_spec_src="" IFS OPTARG="" OPTIND=1; + shift; while true; do if [ "${1:-}" = "--" ]; then : $((OPTIND+=1)); break; - elif ! getopts hiI:np:v _ri_opt; then + elif ! getopts hiI:np:v _ri2_opt; then break; - else case "${_ri_opt}" in + else case "${_ri2_opt}" in h) printf "usage: rtl_install [-i] [-I ifs] [-n] [-p name=val] [-v] prefix spec_list\n" >&2; printf " -i...........: continue on soft errors\n" >&2; printf " -I ifs.......: process spec_list with ifs instead of NL\n" >&2; @@ -444,102 +494,107 @@ rtl_install_v2() { printf " -v...........: increase verbosity\n" >&2; printf " prefix.......: pathname prefix\n" >&2; printf " spec_list....: ifs-separated list of specs\n" >&2; return 1; ;; - i) _ri_iflag=1; ;; - I) _ri_IFS="${OPTARG}"; ;; - n) _ri_nflag=1; ;; - p) : $((_ri_paramsc+=1)); local _ri_params${OPTARG%%=*}="${OPTARG#*=}"; ;; - v) : $((_ri_vflag+=1)); ;; + i) _ri2_iflag=1; ;; + I) _ri2_IFS="${OPTARG}"; ;; + n) _ri2_nflag=1; ;; + p) : $((_ri2_paramsc+=1)); local _ri2_params${OPTARG%%=*}="${OPTARG#*=}"; ;; + v) : $((_ri2_vflag+=1)); ;; *) return 1; ;; esac; fi; done; shift $((${OPTIND}-1)); - _ri_prefix="${1:-}"; _ri_spec_list="${2:-}"; shift 2; - _ri_IFS0="${IFS:- }"; IFS="${_ri_IFS}"; set -- ${_ri_spec_list}; IFS="${_ri_IFS0}"; + _ri2_prefix="${1:-}"; _ri2_spec_list="${2:-}"; shift 2; + _ri2_IFS0="${IFS:- }"; IFS="${_ri2_IFS}"; set -- ${_ri2_spec_list}; IFS="${_ri2_IFS0}"; while [ ${#} -gt 0 ]; do - _ri_spec_src="${1}"; - case "${_ri_spec_src}" in - \?*) _ri_spec_flag="?"; ;; - *) _ri_spec_flag=""; ;; + _ri2_spec_src="${1}"; + case "${_ri2_spec_src}" in + \?*) _ri2_spec_flag="?"; ;; + *) _ri2_spec_flag=""; ;; esac; - if ! rtlp_install_splitl \$_ri_spec_src \$_ri_spec_dst "="; then - _ri_rc=1; _status="zero-length or invalid specification \`${1}'"; - else case "${_ri_spec_src}" in + if ! rtlp_install_v2_splitl \$_ri2_spec_src \$_ri2_spec_dst "="; then + _ri2_rc=1; + rtl_setrstatus "${_ri2_rstatus}" 'zero-length or invalid specification \`'"${1}"''\'; + else case "${_ri2_spec_src}" in + -) - rtlp_install_fmap \$_ri_params "${_ri_prefix}" "${_ri_spec_dst}" \ - rtlp_install_op_rm "${_ri_nflag}" "${_ri_prefix}" "${_ri_vflag}" \ - "" \ + rtlp_install_v2_fmap "${_ri2_rstatus}" \$_ri2_params "${_ri2_prefix}" "${_ri2_spec_dst}" \ + rtlp_install_v2_op_rm "${_ri2_nflag}" "${_ri2_prefix}" "${_ri2_vflag}" \ + "" \ -- "%[1]" "%[2]" "%[3]" "%[ITEM]"; ;; /) - rtlp_install_fmap \$_ri_params "${_ri_prefix}" "${_ri_spec_dst}" \ - rtlp_install_op_mkdir "${_ri_nflag}" "${_ri_prefix}" "${_ri_vflag}" \ - "" \ + rtlp_install_v2_fmap "${_ri2_rstatus}" \$_ri2_params "${_ri2_prefix}" "${_ri2_spec_dst}" \ + rtlp_install_v2_op_mkdir "${_ri2_nflag}" "${_ri2_prefix}" "${_ri2_vflag}" \ + "" \ -- "%[1]" "%[2]" "%[3]" "%[ITEM]"; ;; t*) - rtlp_install_fmap \$_ri_params "${_ri_prefix}" "${_ri_spec_dst}" \ - rtlp_install_op_touch "${_ri_nflag}" "${_ri_prefix}" "${_ri_vflag}" \ - "" "" \ + rtlp_install_v2_fmap "${_ri2_rstatus}" \$_ri2_params "${_ri2_prefix}" "${_ri2_spec_dst}" \ + rtlp_install_v2_op_touch "${_ri2_nflag}" "${_ri2_prefix}" "${_ri2_vflag}" \ + "" "" \ -- "%[1]" "%[2]" "%[3]" "%[ITEM]" "%[5]"; ;; :*) - rtlp_install_fmap \$_ri_params "${_ri_prefix}" "${_ri_spec_src#:}" \ - rtlp_install_op_cp "${_ri_nflag}" "${_ri_prefix}" "${_ri_vflag}" \ - "${_ri_spec_dst}" "" \ + rtlp_install_v2_fmap "${_ri2_rstatus}" \$_ri2_params "${_ri2_prefix}" "${_ri2_spec_src#:}" \ + rtlp_install_v2_op_cp "${_ri2_nflag}" "${_ri2_prefix}" "${_ri2_vflag}" \ + "${_ri2_spec_dst}" "" \ -- "%[1]" "%[2]" "%[3]" "%[@4]" "%[ITEM]"; ;; !*) - rtlp_install_fmap \$_ri_params "${_ri_prefix}" "${_ri_spec_src#!}" \ - rtlp_install_op_mv "${_ri_nflag}" "${_ri_prefix}" "${_ri_vflag}" \ - "${_ri_spec_dst}" "" \ + rtlp_install_v2_fmap "${_ri2_rstatus}" \$_ri2_params "${_ri2_prefix}" "${_ri2_spec_src#!}" \ + rtlp_install_v2_op_mv "${_ri2_nflag}" "${_ri2_prefix}" "${_ri2_vflag}" \ + "${_ri2_spec_dst}" "" \ -- "%[1]" "%[2]" "%[3]" "%[@4]" "%[ITEM]"; ;; @*) - rtlp_install_fmap \$_ri_params "${_ri_prefix}" "${_ri_spec_dst}" \ - rtlp_install_op_ln_symbolic "${_ri_nflag}" "${_ri_prefix}" \ - "${_ri_vflag}" "" "${_ri_spec_src#@}" "" \ + rtlp_install_v2_fmap "${_ri2_rstatus}" \$_ri2_params "${_ri2_prefix}" "${_ri2_spec_dst}" \ + rtlp_install_v2_op_ln_symbolic "${_ri2_nflag}" "${_ri2_prefix}" \ + "${_ri2_vflag}" "" "${_ri2_spec_src#@}" "" \ -- "%[1]" "%[2]" "%[3]" "%[ITEM]" "%[@5]"; ;; +*) - rtlp_install_fmap \$_ri_params "${_ri_prefix}" "${_ri_spec_src#+}" \ - rtlp_install_op_cp_follow_if_newer "${_ri_nflag}" "${_ri_prefix}" \ - "${_ri_vflag}" "${_ri_spec_dst}" "" \ + rtlp_install_v2_fmap "${_ri2_rstatus}" \$_ri2_params "${_ri2_prefix}" "${_ri2_spec_src#+}" \ + rtlp_install_v2_op_cp_follow_if_newer "${_ri2_nflag}" "${_ri2_prefix}" \ + "${_ri2_vflag}" "${_ri2_spec_dst}" "" \ -- "%[1]" "%[2]" "%[3]" "%[@4]" "%[ITEM]"; ;; g*) - rtlp_install_fmap \$_ri_params "${_ri_prefix}" "${_ri_spec_dst}" \ - rtlp_install_op_chgrp "${_ri_nflag}" "${_ri_prefix}" "${_ri_vflag}" \ - "" "${_ri_spec_src#g}" \ + rtlp_install_v2_fmap "${_ri2_rstatus}" \$_ri2_params "${_ri2_prefix}" "${_ri2_spec_dst}" \ + rtlp_install_v2_op_chgrp "${_ri2_nflag}" "${_ri2_prefix}" "${_ri2_vflag}" \ + "" "${_ri2_spec_src#g}" \ -- "%[1]" "%[2]" "%[3]" "%[ITEM]" "%[5]"; ;; m[0-7][0-7][0-7][0-7]) - rtlp_install_fmap \$_ri_params "${_ri_prefix}" "${_ri_spec_dst}" \ - rtlp_install_op_chmod "${_ri_nflag}" "${_ri_prefix}" "${_ri_vflag}" \ - "" "${_ri_spec_src#m}" \ + rtlp_install_v2_fmap "${_ri2_rstatus}" \$_ri2_params "${_ri2_prefix}" "${_ri2_spec_dst}" \ + rtlp_install_v2_op_chmod "${_ri2_nflag}" "${_ri2_prefix}" "${_ri2_vflag}" \ + "" "${_ri2_spec_src#m}" \ -- "%[1]" "%[2]" "%[3]" "%[ITEM]" "%[5]"; ;; o*) - rtlp_install_fmap \$_ri_params "${_ri_prefix}" "${_ri_spec_dst}" \ - rtlp_install_op_chown "${_ri_nflag}" "${_ri_prefix}" "${_ri_vflag}" \ - "" "${_ri_spec_src#o}" \ + rtlp_install_v2_fmap "${_ri2_rstatus}" \$_ri2_params "${_ri2_prefix}" "${_ri2_spec_dst}" \ + rtlp_install_v2_op_chown "${_ri2_nflag}" "${_ri2_prefix}" "${_ri2_vflag}" \ + "" "${_ri2_spec_src#o}" \ -- "%[1]" "%[2]" "%[3]" "%[ITEM]" "%[5]"; ;; T*) - rtlp_install_fmap \$_ri_params "${_ri_prefix}" "${_ri_spec_dst}" \ - rtlp_install_op_touch "${_ri_nflag}" "${_ri_prefix}" "${_ri_vflag}" \ - "" "${_ri_spec_src#T}" \ + rtlp_install_v2_fmap "${_ri2_rstatus}" \$_ri2_params "${_ri2_prefix}" "${_ri2_spec_dst}" \ + rtlp_install_v2_op_touch "${_ri2_nflag}" "${_ri2_prefix}" "${_ri2_vflag}" \ + "" "${_ri2_spec_src#T}" \ -- "%[1]" "%[2]" "%[3]" "%[ITEM]" "%[5]"; ;; \#*|"") ;; - esac; _ri_rc="${?}"; fi; + + esac; _ri2_rc="${?}"; fi; shift; - if [ "${_ri_rc}" -ne 0 ]\ - && [ "${_ri_iflag}" -eq 0 ]; then + + if [ "${_ri2_rc}" -ne 0 ]\ + && [ "${_ri2_iflag}" -eq 0 ]; then break; fi; done; - return "${_ri_rc}"; + + return "${_ri2_rc}"; }; # vim:filetype=sh diff --git a/subr.rtl/rtl_list.subr b/subr.rtl/rtl_list.subr index 07d401b..5b518da 100644 --- a/subr.rtl/rtl_list.subr +++ b/subr.rtl/rtl_list.subr @@ -5,173 +5,280 @@ # rtl_lassign() { - local _vnames="${1}" _sep="${2}" _vname="" _vval=""\ - IFS RTL_LFIRST_HEAD="" RTL_LFIRST_TAIL=""; - IFS="${_sep}"; shift 2; - for _vval in ${@}; do - if ! rtl_lfirst "${_vnames}" " "; then + local _rla_vnames="${1}" _rla_sep="${2}" \ + _rla_head="" _rla_tail="" _rla_vname="" _rla_vval="" IFS; + IFS="${_rla_sep}"; shift 2; + + for _rla_vval in ${@}; do + if ! rtl_lfirst \$_rla_head \$_rla_tail "${_rla_vnames}" " "; then return 1; else - _vname="${RTL_LFIRST_HEAD}"; _vnames="${RTL_LFIRST_TAIL}"; - rtl_set_var_unsafe "${_vname}" "${_vval}"; + _rla_vname="${_rla_head}"; _rla_vnames="${_rla_tail}"; + rtl_set_var_unsafe "${_rla_vname}" "${_rla_vval}"; fi; done; + return 0; }; 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}"; + rtl_lconcat2 "${1}" "${1}" "${2}" "${3:-}"; +}; + +rtl_lconcat2() { + local _rlc2_rlist_new="${1#\$}" _rlc2_rlist="${2#\$}" _rlc2_litem_new="${3}" \ + _rlc2_sep="${4:- }" IFS="${4:-${IFS:- }}"; + + if eval [ \"'${'${_rlc2_rlist}':+1}'\" = 1 ]; then + eval ${_rlc2_rlist_new}='${'"${_rlc2_rlist}"'}${_rlc2_sep}${_rlc2_litem_new}'; else - printf "%s" "${_litem_new}"; + eval ${_rlc2_rlist_new}='${_rlc2_litem_new}'; fi; + return 0; }; rtl_lfilter() { - local _list="${1}" _filter="${2}" _sep="${3:- }" IFS="${3:-${IFS:- }}"\ - _filterfl="" _litem="" _litem_filter="" _lnew=""; - if [ -z "${_filter}" ]; then - printf "%s" "${_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; - printf "%s" "${_lnew}"; + rtl_lfilter2 "${1}" "${1}" "${2}" "${3:-}"; }; rtl_lfilter2() { - local _rlist="${1#\$}" _rlist_new="${2#\$}" _filter="${3}" _sep="${4:- }" IFS="${4:-${IFS:- }}"\ - _filterfl="" _litem="" _litem_filter="" _lnew=""; - - if [ "${_filter:+1}" != 1 ]; then - eval ${_rlist_new}=; return 0; - else eval set -- '${'"${_rlist}"'}'\; ${_rlist_new}=; - while [ "${#}" -gt 0 ]; do - _litem="${1}"; shift; _filterfl=0; - for _litem_filter in ${_filter}; do - if [ "${_litem_filter}" = "${_litem}" ]; then - _filterfl=1; break; + local _rlf2_rlist="${1#\$}" _rlf2_rlist_new="${2#\$}" _rlf2_filter="${3}" _rlf2_sep="${4:-}"\ + _rlf2_filterfl="" _rlf2_list="" _rlf2_litem="" _rlf2_litem_filter="" _rlf2_lnew=""; + + if [ "${_rlf2_sep:+1}" = 1 ]; then + local IFS="${_rlf2_sep}"; + else + local _rlf2_sep=" " IFS="${RTL_IFS_ORIG}"; + fi; + + if [ "${_rlf2_filter:+1}" != 1 ]; then + eval ${_rlf2_rlist_new}=; + else + eval _rlf2_list='${'"${_rlf2_rlist}"'}'; + eval ${_rlf2_rlist_new}=; + for _rlf2_litem in ${_rlf2_list}; do + _rlf2_filterfl=0; + for _rlf2_litem_filter in ${_rlf2_filter}; do + if [ "${_rlf2_litem_filter}" = "${_rlf2_litem}" ]; then + _rlf2_filterfl=1; break; fi; done; - if [ "${_filterfl:-0}" -eq 0 ]; then - eval ${_rlist_new}='${'"${_rlist_new}"':+${'"${_rlist_new}"'}${_sep}}${_litem}'; + if [ "${_rlf2_filterfl:-0}" -eq 0 ]; then + eval ${_rlf2_rlist_new}='${'"${_rlf2_rlist_new}"':+${'"${_rlf2_rlist_new}"'}${_rlf2_sep}}${_rlf2_litem}'; fi; done; fi; -}; - -rtl_lfilter3() { - rtl_lfilter2 "${1}" "${1}" "${2}" "${3:-}"; + return 0; }; rtl_lfirst() { - local _list="${1}" _sep="${2}" IFS; IFS="${_sep}"; - set -- ${_list}; RTL_LFIRST_HEAD="${1}"; + local _rlf_rhead="${1#\$}" _rlf_rtail="${2#\$}" _rlf_list="${3}" _rlf_sep="${4}" IFS="${4}"; + + set -- ${_rlf_list}; eval ${_rlf_rhead}='${1}'; if [ "${#}" -ge 0 ]; then - shift; RTL_LFIRST_TAIL="${*}"; + shift; eval ${_rlf_rtail}=\"'${*}'\"; else - RTL_LFIRST_TAIL=""; + eval ${_rlf_rtail}=; fi; + return 0; }; -rtl_llength() { - local _list="${1}" _sep="${2:- }" IFS="${2:-${IFS:- }}" _litem="" _llength=0; - for _litem in ${_list}; do - : $((_llength+=1)); - done; - printf "%s" "${_llength}"; +rtl_lindexV() { + local _rliV_rlout="${1#\$}" _rliV_idx="${2}" \ + _rliV_limit=0; shift 2; + + if [ "${_rliV_idx#-}" != "${_rliV_idx}" ]; then + _rliV_idx="${_rliV_idx#-}"; + while [ "${#}" -gt "${_rliV_idx}" ]; do + shift; + done; + _rliV_limit=$((${#} + 1)); + else + _rliV_limit="${#}"; + shift "${_rliV_idx}"; + fi; + + if [ "${#}" -ge 1 ]\ + && [ "${_rliV_idx}" -lt "${_rliV_limit}" ]; then + eval ${_rliV_rlout}='${1}'; + else + eval ${_rliV_rlout}=; + fi; + return 0; }; -rtl_llength2() { - local _rlist="${1#\$}" _rlen="${2#\$}" _sep="${3:- }" IFS="${3:-${IFS:- }}"; - eval set -- '${'"${_rlist}"'}'\; ${_rlen}='${#}'; +rtl_llength() { + local _rll_rlen="${1#\$}" _rll_rlist="${2#\$}" _rll_sep="${3:- }" IFS="${3:-${IFS:- }}"; + + eval set -- '${'"${_rll_rlist}"'}'\; ${_rll_rlen}='${#}'; + return 0; }; rtl_llift() { - local _list="${1}" _sep="${2}" _sep_new="${3}" IFS; IFS="${_sep}"; - set -- ${_list}; IFS="${_sep_new}"; - printf "%s" "${*}"; + rtl_llift2 "${1}" "${1}" "${2}" "${3}"; }; rtl_llift2() { - local _rlist="${1#\$}" _rlist_new="${2#\$}" _sep="${3}" \ - _sep_new="${4}" IFS; IFS="${_sep}"; + local _rl2_rlist="${1#\$}" _rl2_rlist_new="${2#\$}" _rl2_sep="${3:-}" \ + _rl2_sep_new="${4}"; - eval set -- '${'"${_rlist}"'}'; IFS="${_sep_new}"; - eval ${_rlist_new}='"${*}"'; -}; + if [ "${_rl2_sep:+1}" = 1 ]; then + local IFS="${_rl2_sep}"; + else + local _rl2_sep=" " IFS="${RTL_IFS_ORIG}"; + fi; -rtl_llift3() { - rtl_llift2 "${1}" "${1}" "${2}" "${3}"; + eval set -- '${'"${_rl2_rlist}"'}'; IFS="${_rl2_sep_new}"; + eval ${_rl2_rlist_new}='"${*}"'; + return 0; }; rtl_lmatch() { - local _list="${1}" _item="${2}" _sep="${3:- }"; - [ -n "$(rtl_lsearch "${_list}" "${_item}" "${_sep}")" ]; + local _rlm_rlist="${1#\$}" _rlm_item="${2}" _rlm_sep="${3:-}" _rlm_list_=""; + + rtl_lsearch2 "${_rlm_rlist}" \$_rlm_list_ "${_rlm_item}" "${_rlm_sep}"; + [ "${_rlm_list_:+1}" = 1 ]; }; rtl_lmax() { - local _len=0 _len_max=0; + local _rlm2_rlist="${1#\$}" _rlm2_rmax="${2#\$}" \ + _rlm2_len=0 _rlm2_len_max=0; + + eval set -- '${'"${_rlm2_rlist}"'}'; while [ "${#}" -gt 0 ]; do - _len="${#1}"; - if [ "${_len}" -gt "${_len_max}" ]; then - _len_max="${_len}"; + _rlm2_len="${#1}"; + if [ "${_rlm2_len}" -gt "${_rlm2_len_max}" ]; then + _rlm2_len_max="${_rlm2_len}"; fi; shift; - done; printf "%s" "${_len_max}"; + done; + eval ${_rlm2_rmax}='${_rlm2_len_max}'; + return 0; +}; + +rtl_lrangeV() { + local _rlrV_rlout="${1#\$}" _rlrV_idx0="${2}" _rlrV_idx1="${3}" _rlrV_sep="${4}" \ + _rlrV_limit=0; shift 4; + + if [ "${_rlrV_idx0#-}" != "${_rlrV_idx0}" ]; then + eval ${_rlrV_rlout}=; + + return 1; + elif [ "${_rlrV_idx1#-}" != "${_rlrV_idx1}" ]; then + _rlrV_idx1="${_rlrV_idx1#-}"; + + _rlrV_limit="${#}"; + shift "${_rlrV_idx0}"; + + eval ${_rlrV_rlout}=; + while [ "${#}" -gt 0 ]\ + && [ "${_rlrV_idx1}" -lt "${#}" ]; + do + eval ${_rlrV_rlout}='${'"${_rlrV_rlout}"':+${'"${_rlrV_rlout}"'}${_rlrV_sep}}${1}'; + shift; + done; + + return 0; + elif [ "${_rlrV_idx1}" -ge "${_rlrV_idx0}" ]; then + _rlrV_limit="${#}"; + shift "${_rlrV_idx0}"; + : $((_rlrV_idx1 -= ${_rlrV_idx0})); + : $((_rlrV_idx1 += 1)); + + eval ${_rlrV_rlout}=; + while [ "${_rlrV_idx1}" -gt 0 ]\ + && [ "${#}" -gt 0 ]; + do + eval ${_rlrV_rlout}='${'"${_rlrV_rlout}"':+${'"${_rlrV_rlout}"'}${_rlrV_sep}}${1}'; + : $((_rlrV_idx1 -= 1)); + shift; + done; + + return 0; + fi; }; rtl_lsearch() { - local _list="${1}" _filter="${2}" _sep="${3:- }" IFS="${3:-${IFS:- }}"\ - _litem="" _litem_filter="" _lnew=""; - if [ -z "${_filter}" ]; then - printf "%s" "${_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; + rtl_lsearch2 "${1}" "${1}" "${2}" "${3:-}"; +} + +rtl_lsearch2() { + local _rls2_rlist="${1#\$}" _rls2_rlist_new="${2#\$}" \ + _rls2_filter="${3}" _rls2_sep="${4:-}" \ + _rls2_list="" _rls2_litem="" _rls2_litem_filter="" \ + _rls2_lnew=""; + + if [ "${_rls2_sep:+1}" = 1 ]; then + local IFS="${_rls2_sep}"; + else + local _rls2_sep=" " IFS="${RTL_IFS_ORIG}"; + fi; + if [ "${_rls2_filter:+1}" != 1 ]; then + eval ${_rls2_rlist_new}='${_rls2_list}'; return 0; + else + eval _rls2_list='${'"${_rls2_rlist}"'}'; + for _rls2_litem in ${_rls2_list}; do + for _rls2_litem_filter in ${_rls2_filter}; do + if [ "${_rls2_litem_filter}" = "${_rls2_litem}" ]; then + _rls2_lnew="${_rls2_lnew:+${_rls2_lnew}${_rls2_sep}}${_rls2_litem}"; + break; + fi; + done; done; - done; fi; - printf "%s" "${_lnew}"; + fi; + + eval ${_rls2_rlist_new}='${_rls2_lnew}'; + return 0; }; rtl_lsearch_patternl() { - local _list="${1}" _pattern="${2}" _sep="${3:- }" IFS="${3:-${IFS:- }}"\ - _litem="" _lnew=""; - if [ -n "${_pattern}" ]; then - for _litem in ${_list}; do - if [ "${_litem#${_pattern}}" != "${_litem}" ]; then - _lnew="${_lnew:+${_lnew}${_sep}}${_litem}"; + rtl_lsearch_patternl2 "${1}" "${1}" "${2}" "${3:-}"; +}; + +rtl_lsearch_patternl2() { + local _rlsp2_rlist="${1#\$}" _rlsp2_rlist_new="${2#\$}" \ + _rlsp2_pattern="${3}" _rlsp2_sep="${4:- }" \ + IFS="${4:-${IFS:- }}" \ + _rlsp2_litem="" _rlsp2_lnew=""; + + if [ "${_rlsp2_pattern:+1}" = 1 ]; then + eval _rlsp2_list='${'"${_rlsp2_rlist}"'}'; + for _rlsp2_litem in ${_rlsp2_list}; do + if [ "${_rlsp2_litem#${_rlsp2_pattern}}" != "${_rlsp2_litem}" ]; then + _rlsp2_lnew="${_rlsp2_lnew:+${_rlsp2_lnew}${_rlsp2_sep}}${_rlsp2_litem}"; fi; done; fi; - printf "%s" "${_lnew}"; + eval ${_rlsp2_rlist_new}='${_rlsp2_lnew}'; + return 0; }; rtl_lsort() { - local _list="${1}" _sep="${2:- }"; - printf "%s" "${_list}" | tr "${_sep}" "\n" | sort | paste -s -d "${_sep}"; + printf "%s" "${*}" | tr " " "\n" | sort | paste -s -d " "; + return 0; }; +RTL_LUNFOLD_DEPENDS_LEVEL=0; 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}")"; + local _rld_vname_template="${1}" _rld_rlist="${2#\$}" \ + _rld_depends="" _rld_list="" _rld_name="" _rld_names="" \ + _rld_vname_template_=""; + shift 2; + + for _rld_name in "${@}"; do + eval _rld_vname_template_=\"${_rld_vname_template}\"; + if rtl_get_var_unsafe \$_rld_depends -u "${_rld_vname_template_}"\ + && [ "${_rld_depends:+1}" = 1 ]; then + : $((RTL_LUNFOLD_DEPENDS_LEVEL+=1)); + eval _rld_depends${RTL_LUNFOLD_DEPENDS_LEVEL}='${_rld_depends}'; + rtl_lunfold_depends "${_rld_vname_template}" \$_rld_depends${RTL_LUNFOLD_DEPENDS_LEVEL} ${_rld_depends}; + eval _rld_depends='${_rld_depends'"${RTL_LUNFOLD_DEPENDS_LEVEL}"'}'; + unset '_rld_depends'"${RTL_LUNFOLD_DEPENDS_LEVEL}"; + : $((RTL_LUNFOLD_DEPENDS_LEVEL-=1)); + rtl_lconcat \$_rld_names "${_rld_depends}"; fi; - _names="$(rtl_lconcat "${_names}" "${_name}")"; + rtl_lconcat \$_rld_names "${_rld_name}"; done; - printf "%s" "${_names}"; + eval ${_rld_rlist}='${_rld_names}'; + return 0; }; # vim:filetype=sh diff --git a/subr.rtl/rtl_log.subr b/subr.rtl/rtl_log.subr index 3a7560a..3e224e8 100644 --- a/subr.rtl/rtl_log.subr +++ b/subr.rtl/rtl_log.subr @@ -11,24 +11,28 @@ RTLP_LOG_NO_ATTR=0; RTLP_LOG_TAGS=""; rtlp_log_printf() { - local _attr="${1}" _fmt_pfx="${2}" _fmt="${3#*;}" _fmt_argc="${3%%;*}"; shift 3; - if [ "${#}" -ne "${_fmt_argc}" ]; then - if [ "${_fmt_argc}" -eq 0 ]; then + local _rplp_attr="${1}" _rplp_fmt_pfx="${2}" \ + _rplp_fmt="${3#*;}" _rplp_fmt_argc="${3%%;*}"; + shift 3; + + if [ "${#}" -ne "${_rplp_fmt_argc}" ]; then + if [ "${_rplp_fmt_argc}" -eq 0 ]; then shift "${#}"; else rtlp_log_printf "" "" "0;==> FIXME TODO XXX MESSAGE STRING ARGUMENT COUNT MISMATCH\n"; fi; fi; - _msg="$(printf "${_fmt_pfx}${_fmt}" "${@}")"; + _rplp_msg="$(printf "${_rplp_fmt_pfx}${_rplp_fmt}" "${@}")"; - if [ -n "${RTLP_LOG_FNAME}" ]; then - printf "%s\n" "${_msg}" >> "${RTLP_LOG_FNAME}"; + if [ "${RTLP_LOG_FNAME:+1}" = 1 ]; then + printf "%s\n" "${_rplp_msg}" >> "${RTLP_LOG_FNAME}"; fi; if [ "${RTLP_LOG_NO_ATTR:-0}" -eq 0 ]; then - printf "\033[0m\033[${_attr}m%s\033[0m\n" "${_msg}"; + printf "\033[0m\033[${_rplp_attr}m%s\033[0m\n" "${_rplp_msg}"; else - printf "%s\n" "${_msg}"; - fi; return 0; + printf "%s\n" "${_rplp_msg}"; + fi; + return 0; }; # @@ -41,48 +45,64 @@ rtl_log_clear_tags() { rtl_log_enable_tags() { local IFS=","; set -- ${*}; + while [ "${#}" -gt 0 ]; do - if ! rtl_lmatch "${RTLP_LOG_TAGS}" "${1}" ","; then + if ! rtl_lmatch \$RTLP_LOG_TAGS "${1}" ","; then RTLP_LOG_TAGS="${RTLP_LOG_TAGS:+${RTLP_LOG_TAGS},}${1}"; fi; shift; - done; return 0; + done; + return 0; }; rtl_log_env_vars() { - local _tag="${1}" _type="${2}" _arg_len_max=0; shift 2; + local _rlev_tag="${1}" _rlev_type="${2}" \ + _rlev_arg_len_max=0 _rlev_list="" _rlev_msg="" _rlev_msg_=""; + shift 2; - rtl_log_msg "${_tag}" "${MSG_rtl_log_vars_header}" "${_type}"; - _arg_len_max="$(rtl_lmax "${@}")"; + rtl_log_msg "${_rlev_tag}" "${MSG_rtl_log_vars_header}" "${_rlev_type}"; + _rlev_list="${@}"; rtl_lmax \$_rlev_list \$_rlev_arg_len_max; while [ "${#}" -gt 0 ]; do - rtl_log_msg "${_tag}" \ - "2;%${_arg_len_max}.${_arg_len_max}s=%s" \ - "${1%%=*}" "$(rtl_get_var_unsafe "${1#*=}")"; + rtl_get_var_unsafe \$_rlev_msg "${1#*=}"; + rtl_llift2 \$_rlev_msg \$_rlev_msg_ "" " "; + rtl_log_msg "${_rlev_tag}" \ + "2;%${_rlev_arg_len_max}.${_rlev_arg_len_max}s=%s" \ + "${1%%=*}" "${_rlev_msg_}"; shift; - done; return 0; + done; + return 0; }; rtl_log_msg() { - local _tag="${1}" _fmt="${2}" _attr="" _exitfl=0; shift 2; + local _rlm3_tag="${1}" _rlm3_fmt="${2}" \ + _rlm3_attr="" _rlm3_date_now=0 _rlm3_exitfl=0; + shift 2; - [ "x${_tag}" = "xfatalexit" ] && { _tag="fatal"; _exitfl=1; }; - if rtl_lmatch "${RTLP_LOG_TAGS}" "${_tag}" ","; then - eval _attr='${LOG_TAG_'"${_tag}"':-}'; - if [ "${#_attr}" -eq 0 ]; then - rtlp_log_printf "" "" "0;==> FIXME TODO XXX UNKNOWN TAG \`${_tag}' PASSED TO rtl_log_msg()\n"; + if [ "x${_rlm3_tag}" = "xfatalexit" ]; then + _rlm3_tag="fatal"; _rlm3_exitfl=1; + fi; + + if rtl_lmatch \$RTLP_LOG_TAGS "${_rlm3_tag}" ","; then + eval _rlm3_attr='${LOG_TAG_'"${_rlm3_tag}"':-}'; + if [ "${#_rlm3_attr}" -eq 0 ]; then + rtlp_log_printf "" "" "0;==> FIXME TODO XXX UNKNOWN TAG \`${_rlm3_tag}' PASSED TO rtl_log_msg()\n"; fi; - rtlp_log_printf "${_attr}" "==> $(rtl_date) " "${_fmt}" "${@}"; - if [ "${_exitfl}" -eq 1 ]; then + rtl_date \$_rlm3_date_now; + rtlp_log_printf "${_rlm3_attr}" "==> ${_rlm3_date_now} " "${_rlm3_fmt}" "${@}"; + if [ "${_rlm3_exitfl}" -eq 1 ]; then exit 1; fi; - fi; return 0; + fi; + return 0; }; rtl_log_set_fname() { - RTLP_LOG_FNAME="${1}"; return 0; + RTLP_LOG_FNAME="${1}"; + return 0; }; rtl_log_set_no_attr() { - RTLP_LOG_NO_ATTR="${1}"; return 0; + RTLP_LOG_NO_ATTR="${1}"; + return 0; }; # vim:filetype=sh diff --git a/subr.rtl/rtl_platform.subr b/subr.rtl/rtl_platform.subr index dd50852..2580521 100644 --- a/subr.rtl/rtl_platform.subr +++ b/subr.rtl/rtl_platform.subr @@ -3,122 +3,164 @@ # rtl_check_prereqs() { - local _cmd="" _cmds_missing="" _rc=0; _status=""; - for _cmd in "${@}"; do - if ! which "${_cmd}" >/dev/null 2>&1; then - _cmds_missing="${_cmds_missing:+${_cmds_missing} }${_cmd}"; + local _rcp_rstatus="${1#\$}" \ + _rcp_cmd="" _rcp_cmds_missing="" _rcp_rc=0; + shift; + + for _rcp_cmd in "${@}"; do + if ! which "${_rcp_cmd}" >/dev/null 2>&1; then + _rcp_cmds_missing="${_rcp_cmds_missing:+${_rcp_cmds_missing} }${_rcp_cmd}"; fi; done; - if [ -n "${_cmds_missing}" ]; then - _rc=1; _status="Error: missing prerequisite package(s): ${_cmds_missing}"; + if [ "${_rcp_cmds_missing:+1}" = 1 ]; then + _rcp_rc=1; + rtl_setrstatus "${_rcp_rstatus}" 'Error: missing prerequisite package(s): '"${_rcp_cmds_missing}"; fi; - return "${_rc}"; + return "${_rcp_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="$(rtl_lconcat "${_env_vars_except}" "${_env_var}")"; + local _rce_env_vars_except="${1}" \ + _rce_env_var="" _rce_env_vars="" _rce_env_vars_unset=""; + + _rce_env_vars="$(export | sed -ne '/^export/{s/^export //;s/=.*$//p}')"; + + for _rce_env_var in ${_rce_env_vars}; do + if [ "${_rce_env_var#DEFAULT_}" != "${_rce_env_var}" ]\ + || [ "${_rce_env_var#PKG_}" != "${_rce_env_var}" ]; then + rtl_lconcat \$_rce_env_vars_except "${_rce_env_var}"; fi; done; - rtl_unset_vars $(rtl_lfilter "${_env_vars}" "${_env_vars_except}"); + rtl_lfilter2 \$_rce_env_vars \$_rce_env_vars_unset "${_rce_env_vars_except}"; + rtl_unset_vars ${_rce_env_vars_unset}; + + return 0; }; rtl_get_cpu_count() { - local _line="" _ncpus=0 _rc=0 _sname="$(uname -s 2>/dev/null)"; _status=""; - case "${_sname}" in + local _rgcc_rstatus="${1#\$}" _rgcc_rcount="${2#\$}" \ + _rgcc_line="" _rgcc_ncpus=0 _rgcc_rc=0 _rgcc_sname=""; + + _rgcc_sname="$(uname -s 2>/dev/null)" || return 1; + case "${_rgcc_sname}" in + Linux) if [ ! -e "/proc/cpuinfo" ]; then - _rc=1; _status="Error: /proc/cpuinfo non-existent."; - else while read -r _line; do - if rtl_match "${_line}" "processor*:"; then - : $((_ncpus+=1)); + _rgcc_rc=1; + rtl_setrstatus "${_rgcc_rstatus}" 'Error: /proc/cpuinfo non-existent.'; + else while read -r _rgcc_line; do + if rtl_match "${_rgcc_line}" "processor*:"; then + : $((_rgcc_ncpus+=1)); fi; - done < /proc/cpuinfo; printf "%s" "${_ncpus}"; + done < /proc/cpuinfo; + _rgcc_rc=0; + rtl_setrstatus "${_rgcc_rstatus}" ""; fi; ;; - *) _rc=1; _status="Error: unknown platform \`${_sname}'."; ;; - esac; return "${_rc}"; + + *) _rgcc_rc=1; + rtl_setrstatus "${_rgcc_rstatus}" 'Error: unknown platform \`'"${_rgcc_sname}"''\''.'; + ;; + + esac; + eval ${_rgcc_rcount}='${_rgcc_ncpus}'; + return "${_rgcc_rc}"; }; rtl_get_var_unsafe() { - local _vname=""; + local _rgvu_rvname_out="${1#\$}" \ + _rgvu_vname=""; + shift; + if [ "x${1}" = "x-u" ]; then - shift; _vname="$(rtl_toupper "${1}")"; + shift; _rgvu_vname="${1}"; rtl_toupper \$_rgvu_vname; else - _vname="${1}"; + _rgvu_vname="${1}"; fi; - eval echo \${${_vname}} 2>/dev/null; + eval ${_rgvu_rvname_out}="\${${_rgvu_vname}:-}"; + return 0; }; rtl_get_vars_fast() { - local _pattern="${1}"; - set | awk -F= '/'"${_pattern}"'/{print $1}' | sort; + local _rgvf_pattern="${1}"; + + set | awk -F= '/'"${_rgvf_pattern}"'/{print $1}' | sort; + return 0; }; rtl_kill_tree() { - local _pid="${1}" _signal="${2:-TERM}" _pid_child="" _pids=""; - if _pids="$(pgrep -P "${_pid}")"\ - && [ -n "${_pids}" ]; then - for _pid_child in ${_pids}; do - rtl_kill_tree "${_pid_child}" "${_signal}"; + local _rkt_rpids="${1#\$}" _rkt_pid="${2}" _rkt_signal="${3:-TERM}" \ + _rkt_pid_child="" _rkt_pids=""; + + if _rkt_pids="$(pgrep -P "${_rkt_pid}")"\ + && [ "${_rkt_pids:+1}" = 1 ]; then + for _rkt_pid_child in ${_rkt_pids}; do + rtl_kill_tree "${_rkt_rpids}" "${_rkt_pid_child}" "${_rkt_signal}"; done; fi; - if [ "${_pid:-0}" -ne "${$}" ]\ - && kill "-${_signal}" "${_pid}" 2>/dev/null; then - RTL_KILL_TREE_PIDS="$(rtl_lconcat "${RTL_KILL_TREE_PIDS}" "${_pid}")"; + if [ "${_rkt_pid:-0}" -ne "${$}" ]\ + && kill "-${_rkt_signal}" "${_rkt_pid}" 2>/dev/null; then + rtl_lconcat "${_rkt_rpids}" "${_rkt_pid}"; fi; + return 0; }; rtl_prompt() { - local _fmt="${1}" _choice=""; shift; - printf "${_fmt}? (y|N) " "${@}"; - read -r _choice; - case "${_choice}" in - [yY]) _choice=1; ;; - *) _choice=0; ;; + local rp_fmt="${1}" rp_choice=""; shift; + + printf "${rp_fmt}? (y|N) " "${@}"; + read -r rp_choice; + case "${rp_choice}" in + [yY]) rp_choice=1; ;; + *) rp_choice=0; ;; esac; - return "${_choice}"; + return "${rp_choice}"; }; rtl_rc() { - local _nflag="${1}" _cmd="${2}"; shift 2; - case "${_nflag}" in + local _rr_nflag="${1}" _rr_cmd="${2}"; + shift 2; + + case "${_rr_nflag}" in 1) if [ "${#}" -gt 0 ]; then - rtl_log_msg "verbose" "${MSG_rtl_platform_rc1}" "${_cmd}" "${*}"; + rtl_log_msg "verbose" "${MSG_rtl_platform_rc1}" "${_rr_cmd}" "${*}"; else - rtl_log_msg "verbose" "${MSG_rtl_platform_rc2}" "${_cmd}"; + rtl_log_msg "verbose" "${MSG_rtl_platform_rc2}" "${_rr_cmd}"; fi; ;; - *) "${_cmd}" "${@}"; + *) "${_rr_cmd}" "${@}"; ;; esac; + return 0; }; rtl_run_cmd_unsplit() { - local _cmd="${1}" _cmdline="" _rc="" IFS; shift; + local _rrcu_cmd="${1}" \ + _rrcu_cmdline="" _rrcu_rc="" IFS; + shift; + while [ ${#} -gt 0 ]; do - [ -n "${1}" ] &&\ - _cmdline="${_cmdline:+${_cmdline}:}${1}"; + [ "${1:+1}" = 1 ] &&\ + _rrcu_cmdline="${_rrcu_cmdline:+${_rrcu_cmdline}:}${1}"; shift; done; - IFS=:; ${_cmd} ${_cmdline}; _rc=$?; - return ${_rc}; + IFS=:; ${_rrcu_cmd} ${_rrcu_cmdline}; _rrcu_rc=$?; + return ${_rrcu_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}"; - eval _vval_src='${'"${_vname_src}"':-}'; - if [ "${_vval_src:+1}" = 1 ]; then - eval PKG_${_vname_dst}='${_vval_src}'; - _vars_set_tmp="${_vars_set_tmp:+${_vars_set_tmp} }PKG_${_vname_dst}"; + local _rsv_vars_set_vname="${1}" _rsv_vname_dst="${2}" _rsv_vname_src_tmpls="${3}" \ + _rsv_vars_set_old="" _rsv_vars_set_tmp="" _rsv_vname_src="" _rsv_vnames_src=""; + + rtl_toupper2 \$_rsv_vname_src_tmpls \$_rsv_vnames_src; + for _rsv_vname_src in ${_rsv_vnames_src}; do + _rsv_vname_src="${_rsv_vname_src}_${_rsv_vname_dst}"; + eval _rsv_vval_src="\${${_rsv_vname_src}:-}"; + if [ "${_rsv_vval_src:+1}" = 1 ]; then + eval PKG_${_rsv_vname_dst}='${_rsv_vval_src}'; + _rsv_vars_set_tmp="${_rsv_vars_set_tmp:+${_rsv_vars_set_tmp} }PKG_${_rsv_vname_dst}"; fi; done; - eval _vars_set_old='${'"${_vars_set_vname}"'}'; - rtl_set_var_unsafe "${_vars_set_vname}" "${_vars_set_old:+${_vars_set_old} }${_vars_set_tmp}"; + eval _rsv_vars_set_old="\${${_rsv_vars_set_vname}}"; + rtl_set_var_unsafe "${_rsv_vars_set_vname}" "${_rsv_vars_set_old:+${_rsv_vars_set_old} }${_rsv_vars_set_tmp}"; + + return 0; }; # vim:filetype=sh diff --git a/subr.rtl/rtl_state.subr b/subr.rtl/rtl_state.subr index da091e9..fdf58a6 100644 --- a/subr.rtl/rtl_state.subr +++ b/subr.rtl/rtl_state.subr @@ -3,42 +3,53 @@ # 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}"; + local _rsc_workdir="${1}" _rsc_pkg_name="${2}" \ + _rsc_pkg_fname=""; + + for _rsc_pkg_fname in $( + find "${_rsc_workdir}" \ + -maxdepth 1 \ + -mindepth 1 \ + -name .${_rsc_pkg_name}.\* \ + -type f); + do + rtl_fileop rm "${_rsc_pkg_fname}"; done; + return 0; }; rtl_state_set() { - local _workdir="${1}" _pkg_fname="${2}" _build_step="${3}" \ - _done_fname_pfx="${1}/.${2}"; shift 3; + local _rss_workdir="${1}" _rss_pkg_fname="${2}" _rss_build_step="${3}" \ + _rss_done_fname_pfx="${1}/.${2}"; + shift 3; - rtl_fileop touch "${_done_fname_pfx}.${_build_step}"; + rtl_fileop touch "${_rss_done_fname_pfx}.${_rss_build_step}"; while [ ${#} -ge 1 ]; do if [ "${#1}" -gt 0 ]; then - rtl_fileop rm "${_done_fname_pfx}.${1}"; + rtl_fileop rm "${_rss_done_fname_pfx}.${1}"; fi; shift; done; + return 0; }; rtl_state_test() { - local _workdir="${1}" _pkg_name="${2}" _build_steps="${3}" \ - _restart_at="${4:-}" _build_step="" _done_fname="" \ - IFS="," _rc=0; + local _rst_workdir="${1}" _rst_pkg_name="${2}" _rst_build_steps="${3}" \ + _rst_restart_at="${4:-}" _rst_build_step="" _rst_done_fname="" \ + IFS="," _rst_rc=0; - for _build_step in ${_build_steps}; do - _done_fname="${_workdir}/.${_pkg_name}.${_build_step}"; - if [ "${_restart_at:+1}" != 1 ]\ - || [ "${_restart_at}" = "LAST" ]; then - rtl_fileop test "${_done_fname}"; _rc="${?}"; - elif [ "${_restart_at}" = "ALL" ]; then - _rc=1; + for _rst_build_step in ${_rst_build_steps}; do + _rst_done_fname="${_rst_workdir}/.${_rst_pkg_name}.${_rst_build_step}"; + if [ "${_rst_restart_at:+1}" != 1 ]\ + || [ "${_rst_restart_at}" = "LAST" ]; then + rtl_fileop test "${_rst_done_fname}"; _rst_rc="${?}"; + elif [ "${_rst_restart_at}" = "ALL" ]; then + _rst_rc=1; else - rtl_lmatch "${_restart_at}" "${_build_step}" ","; - _rc=$((${?} ? 0 : 1)); - fi; [ "${_rc}" -eq 0 ] && break; - done; return "${_rc}"; + rtl_lmatch \$_rst_restart_at "${_rst_build_step}" ","; + _rst_rc=$((${?} ? 0 : 1)); + fi; [ "${_rst_rc}" -eq 0 ] && break; + done; + return "${_rst_rc}"; }; # vim:filetype=sh diff --git a/subr.rtl/rtl_string.subr b/subr.rtl/rtl_string.subr index e3e9860..75c5169 100644 --- a/subr.rtl/rtl_string.subr +++ b/subr.rtl/rtl_string.subr @@ -3,18 +3,22 @@ # rtl_isnumber() { - local _s="${1}" _rc=0; - while [ -n "${_s}" ]; do - case "${_s}" in - [0-9]*) _s="${_s#[0-9]}"; ;; - *) _rc=1; break; ;; + local _ri_s="${1}" \ + _ri_rc=0; + + while [ "${_ri_s:+1}" = 1 ]; do + case "${_ri_s}" in + [0-9]*) _ri_s="${_ri_s#[0-9]}"; ;; + *) _ri_rc=1; break; ;; esac; done; - return "${_rc}"; + + return "${_ri_rc}"; }; rtl_match() { - local _s="${1}" _find="${2}"; - if [ "${_s#${_find}}" != "${_s}" ]; then + local _rm_s="${1}" _rm_find="${2}"; + + if [ "${_rm_s#${_rm_find}}" != "${_rm_s}" ]; then return 0; else return 1; @@ -22,101 +26,135 @@ rtl_match() { }; rtl_matchr() { - local _s="${1}" _find="${2}"; - if [ "${_s%${_find}}" != "${_s}" ]; then + local _rmr_s="${1}" _rmr_find="${2}"; + + if [ "${_rmr_s%${_rmr_find}}" != "${_rmr_s}" ]; then return 0; else return 1; fi; }; +rtl_setrstatus() { + local _rsrs_rstatus="${1#\$}" _rsrs_status="${2}"; + eval ${_rsrs_rstatus}=\"${_rsrs_status}\"; + return 0; +}; + rtl_subst() { - local _s="${1}" _find="${2}" _replace="${3}" _prefix="" _s_new=""; - while [ -n "${_s}" ]; do - case "${_s}" in - *${_find}*) _prefix="${_s%%${_find}*}"; _s="${_s#*${_find}}"; - _s_new="${_s_new:+${_s_new}}${_prefix}${_replace}"; ;; - *) _s_new="${_s_new:+${_s_new}}${_s}"; _s=""; ;; + rtl_subst2 "${1}" "${1}" "${2}" "${3}"; +}; + +rtl_subst2() { + local _rs2_rs="${1#\$}" _rs2_rs_out="${2#\$}" _rs2_find="${3}" _rs2_replace="${4}" \ + _rs2_prefix="" _rs2_s="" _rs2_s_new=""; + + eval _rs2_s="\${${_rs2_rs}}"; + while [ "${_rs2_s:+1}" = 1 ]; do + case "${_rs2_s}" in + *${_rs2_find}*) _rs2_prefix="${_rs2_s%%${_rs2_find}*}"; _rs2_s="${_rs2_s#*${_rs2_find}}"; + _rs2_s_new="${_rs2_s_new:+${_rs2_s_new}}${_rs2_prefix}${_rs2_replace}"; ;; + *) _rs2_s_new="${_rs2_s_new:+${_rs2_s_new}}${_rs2_s}"; _rs2_s=""; ;; esac; done; - printf "%s" "${_s_new}"; + eval ${_rs2_rs_out}='${_rs2_s_new}'; + return 0; }; 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}"; ;; + rtl_tolower2 "${1}" "${1}"; +}; + +rtl_tolower2() { + local _rtl2_rs="${1#\$}" _rtl2_rs_out="${2#\$}" \ + _rtl2_s="" _rtl2_s_new=""; + + eval _rtl2_s="\${${_rtl2_rs}}"; + + while [ "${_rtl2_s:+1}" = 1 ]; do + case "${_rtl2_s}" in + A*) _rtl2_s_new="${_rtl2_s_new:+${_rtl2_s_new}}a"; _rtl2_s="${_rtl2_s#A}"; ;; + B*) _rtl2_s_new="${_rtl2_s_new:+${_rtl2_s_new}}b"; _rtl2_s="${_rtl2_s#B}"; ;; + C*) _rtl2_s_new="${_rtl2_s_new:+${_rtl2_s_new}}c"; _rtl2_s="${_rtl2_s#C}"; ;; + D*) _rtl2_s_new="${_rtl2_s_new:+${_rtl2_s_new}}d"; _rtl2_s="${_rtl2_s#D}"; ;; + E*) _rtl2_s_new="${_rtl2_s_new:+${_rtl2_s_new}}e"; _rtl2_s="${_rtl2_s#E}"; ;; + F*) _rtl2_s_new="${_rtl2_s_new:+${_rtl2_s_new}}f"; _rtl2_s="${_rtl2_s#F}"; ;; + G*) _rtl2_s_new="${_rtl2_s_new:+${_rtl2_s_new}}g"; _rtl2_s="${_rtl2_s#G}"; ;; + H*) _rtl2_s_new="${_rtl2_s_new:+${_rtl2_s_new}}h"; _rtl2_s="${_rtl2_s#H}"; ;; + I*) _rtl2_s_new="${_rtl2_s_new:+${_rtl2_s_new}}i"; _rtl2_s="${_rtl2_s#I}"; ;; + J*) _rtl2_s_new="${_rtl2_s_new:+${_rtl2_s_new}}j"; _rtl2_s="${_rtl2_s#J}"; ;; + K*) _rtl2_s_new="${_rtl2_s_new:+${_rtl2_s_new}}k"; _rtl2_s="${_rtl2_s#K}"; ;; + L*) _rtl2_s_new="${_rtl2_s_new:+${_rtl2_s_new}}l"; _rtl2_s="${_rtl2_s#L}"; ;; + M*) _rtl2_s_new="${_rtl2_s_new:+${_rtl2_s_new}}m"; _rtl2_s="${_rtl2_s#M}"; ;; + N*) _rtl2_s_new="${_rtl2_s_new:+${_rtl2_s_new}}n"; _rtl2_s="${_rtl2_s#N}"; ;; + O*) _rtl2_s_new="${_rtl2_s_new:+${_rtl2_s_new}}o"; _rtl2_s="${_rtl2_s#O}"; ;; + P*) _rtl2_s_new="${_rtl2_s_new:+${_rtl2_s_new}}p"; _rtl2_s="${_rtl2_s#P}"; ;; + Q*) _rtl2_s_new="${_rtl2_s_new:+${_rtl2_s_new}}q"; _rtl2_s="${_rtl2_s#Q}"; ;; + R*) _rtl2_s_new="${_rtl2_s_new:+${_rtl2_s_new}}r"; _rtl2_s="${_rtl2_s#R}"; ;; + S*) _rtl2_s_new="${_rtl2_s_new:+${_rtl2_s_new}}s"; _rtl2_s="${_rtl2_s#S}"; ;; + T*) _rtl2_s_new="${_rtl2_s_new:+${_rtl2_s_new}}t"; _rtl2_s="${_rtl2_s#T}"; ;; + U*) _rtl2_s_new="${_rtl2_s_new:+${_rtl2_s_new}}u"; _rtl2_s="${_rtl2_s#U}"; ;; + V*) _rtl2_s_new="${_rtl2_s_new:+${_rtl2_s_new}}v"; _rtl2_s="${_rtl2_s#V}"; ;; + W*) _rtl2_s_new="${_rtl2_s_new:+${_rtl2_s_new}}w"; _rtl2_s="${_rtl2_s#W}"; ;; + X*) _rtl2_s_new="${_rtl2_s_new:+${_rtl2_s_new}}x"; _rtl2_s="${_rtl2_s#X}"; ;; + Y*) _rtl2_s_new="${_rtl2_s_new:+${_rtl2_s_new}}y"; _rtl2_s="${_rtl2_s#Y}"; ;; + Z*) _rtl2_s_new="${_rtl2_s_new:+${_rtl2_s_new}}z"; _rtl2_s="${_rtl2_s#Z}"; ;; [!ABCDEFGHIJKLMNOPQRSTUVWXYZ]*) - _s_new="${_s_new:+${_s_new}}${_s%%[ABCDEFGHIJKLMNOPQRSTUVWXYZ]*}"; - while [ "${_s#[!ABCDEFGHIJKLMNOPQRSTUVWXYZ]}" != "${_s}" ]; do - _s="${_s#[!ABCDEFGHIJKLMNOPQRSTUVWXYZ]}"; + _rtl2_s_new="${_rtl2_s_new:+${_rtl2_s_new}}${_rtl2_s%%[ABCDEFGHIJKLMNOPQRSTUVWXYZ]*}"; + while [ "${_rtl2_s#[!ABCDEFGHIJKLMNOPQRSTUVWXYZ]}" != "${_rtl2_s}" ]; do + _rtl2_s="${_rtl2_s#[!ABCDEFGHIJKLMNOPQRSTUVWXYZ]}"; done; ;; esac; done; - printf "%s" "${_s_new}"; + eval ${_rtl2_rs_out}='${_rtl2_s_new}'; + + return 0; }; 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}"; ;; + rtl_toupper2 "${1}" "${1}"; +}; + +rtl_toupper2() { + local _rtu2_rs="${1#\$}" _rtu2_rs_out="${2#\$}" _rtu2_s="" _rtu2_s_new=""; + + eval _rtu2_s="\${${_rtu2_rs}}"; + + while [ "${_rtu2_s:+1}" = 1 ]; do + case "${_rtu2_s}" in + a*) _rtu2_s_new="${_rtu2_s_new:+${_rtu2_s_new}}A"; _rtu2_s="${_rtu2_s#a}"; ;; + b*) _rtu2_s_new="${_rtu2_s_new:+${_rtu2_s_new}}B"; _rtu2_s="${_rtu2_s#b}"; ;; + c*) _rtu2_s_new="${_rtu2_s_new:+${_rtu2_s_new}}C"; _rtu2_s="${_rtu2_s#c}"; ;; + d*) _rtu2_s_new="${_rtu2_s_new:+${_rtu2_s_new}}D"; _rtu2_s="${_rtu2_s#d}"; ;; + e*) _rtu2_s_new="${_rtu2_s_new:+${_rtu2_s_new}}E"; _rtu2_s="${_rtu2_s#e}"; ;; + f*) _rtu2_s_new="${_rtu2_s_new:+${_rtu2_s_new}}F"; _rtu2_s="${_rtu2_s#f}"; ;; + g*) _rtu2_s_new="${_rtu2_s_new:+${_rtu2_s_new}}G"; _rtu2_s="${_rtu2_s#g}"; ;; + h*) _rtu2_s_new="${_rtu2_s_new:+${_rtu2_s_new}}H"; _rtu2_s="${_rtu2_s#h}"; ;; + i*) _rtu2_s_new="${_rtu2_s_new:+${_rtu2_s_new}}I"; _rtu2_s="${_rtu2_s#i}"; ;; + j*) _rtu2_s_new="${_rtu2_s_new:+${_rtu2_s_new}}J"; _rtu2_s="${_rtu2_s#j}"; ;; + k*) _rtu2_s_new="${_rtu2_s_new:+${_rtu2_s_new}}K"; _rtu2_s="${_rtu2_s#k}"; ;; + l*) _rtu2_s_new="${_rtu2_s_new:+${_rtu2_s_new}}L"; _rtu2_s="${_rtu2_s#l}"; ;; + m*) _rtu2_s_new="${_rtu2_s_new:+${_rtu2_s_new}}M"; _rtu2_s="${_rtu2_s#m}"; ;; + n*) _rtu2_s_new="${_rtu2_s_new:+${_rtu2_s_new}}N"; _rtu2_s="${_rtu2_s#n}"; ;; + o*) _rtu2_s_new="${_rtu2_s_new:+${_rtu2_s_new}}O"; _rtu2_s="${_rtu2_s#o}"; ;; + p*) _rtu2_s_new="${_rtu2_s_new:+${_rtu2_s_new}}P"; _rtu2_s="${_rtu2_s#p}"; ;; + q*) _rtu2_s_new="${_rtu2_s_new:+${_rtu2_s_new}}Q"; _rtu2_s="${_rtu2_s#q}"; ;; + r*) _rtu2_s_new="${_rtu2_s_new:+${_rtu2_s_new}}R"; _rtu2_s="${_rtu2_s#r}"; ;; + s*) _rtu2_s_new="${_rtu2_s_new:+${_rtu2_s_new}}S"; _rtu2_s="${_rtu2_s#s}"; ;; + t*) _rtu2_s_new="${_rtu2_s_new:+${_rtu2_s_new}}T"; _rtu2_s="${_rtu2_s#t}"; ;; + u*) _rtu2_s_new="${_rtu2_s_new:+${_rtu2_s_new}}U"; _rtu2_s="${_rtu2_s#u}"; ;; + v*) _rtu2_s_new="${_rtu2_s_new:+${_rtu2_s_new}}V"; _rtu2_s="${_rtu2_s#v}"; ;; + w*) _rtu2_s_new="${_rtu2_s_new:+${_rtu2_s_new}}W"; _rtu2_s="${_rtu2_s#w}"; ;; + x*) _rtu2_s_new="${_rtu2_s_new:+${_rtu2_s_new}}X"; _rtu2_s="${_rtu2_s#x}"; ;; + y*) _rtu2_s_new="${_rtu2_s_new:+${_rtu2_s_new}}Y"; _rtu2_s="${_rtu2_s#y}"; ;; + z*) _rtu2_s_new="${_rtu2_s_new:+${_rtu2_s_new}}Z"; _rtu2_s="${_rtu2_s#z}"; ;; [!abcdefghijklmnopqrstuvwxyz]*) - _s_new="${_s_new:+${_s_new}}${_s%%[abcdefghijklmnopqrstuvwxyz]*}"; - while [ "${_s#[!abcdefghijklmnopqrstuvwxyz]}" != "${_s}" ]; do - _s="${_s#[!abcdefghijklmnopqrstuvwxyz]}"; + _rtu2_s_new="${_rtu2_s_new:+${_rtu2_s_new}}${_rtu2_s%%[abcdefghijklmnopqrstuvwxyz]*}"; + while [ "${_rtu2_s#[!abcdefghijklmnopqrstuvwxyz]}" != "${_rtu2_s}" ]; do + _rtu2_s="${_rtu2_s#[!abcdefghijklmnopqrstuvwxyz]}"; done; ;; esac; done; - printf "%s" "${_s_new}"; + eval ${_rtu2_rs_out}='${_rtu2_s_new}'; + + return 0; }; # vim:filetype=sh diff --git a/subr/build_init.subr b/subr/build_init.subr deleted file mode 100644 index 71e57e4..0000000 --- a/subr/build_init.subr +++ /dev/null @@ -1,323 +0,0 @@ -# -# set +o errexit -o noglob -o nounset is assumed. -# - -buildp_init_args() { - local _foundfl=0 _group="" _pkg_names_unknown="" _rc=0 \ - EX_PKG_BUILD_GROUPS EX_PKG_BUILD_GROUPS_NOAUTO; _status=""; - - case "${ARG_FETCH_FORCE}" in - ipv4) DEFAULT_GIT_ARGS="$(rtl_lconcat "-4" "${DEFAULT_GIT_ARGS}")"; - DEFAULT_WGET_ARGS="$(rtl_lconcat "-4" "${DEFAULT_WGET_ARGS}")"; ;; - ipv6) DEFAULT_GIT_ARGS="$(rtl_lconcat "-6" "${DEFAULT_GIT_ARGS}")"; - DEFAULT_WGET_ARGS="$(rtl_lconcat "-6" "${DEFAULT_WGET_ARGS}")"; ;; - esac; - if [ "${BUILD_HNAME:+1}" != 1 ]\ - && ! BUILD_HNAME="$(hostname)"; then - _rc=1; _status="failed to obtain hostname."; - elif [ "${ARG_DUMP_ON_ABORT:-0}" -eq 1 ]\ - && [ "${ARG_RELAXED:-0}" -eq 1 ]; then - _rc=1; _status="--dump-on-abort excludes -R."; - elif [ "${ARG_AS_NEEDED:-0}" -eq 1 ]\ - && [ -e "${PREFIX}/build.gitref" ]\ - && [ "$(git rev-parse HEAD)" = "$(cat "${PREFIX}/build.gitref")" ]; then - _rc=0; _status="Git repository has not changed since last build and --as-needed was specified."; - elif ! ex_pkg_process_restart_spec \$ARG_RESTART \$ARG_RESTART_AT \$ARG_RESTART_RECURSIVE; then - _rc=1; _status="failed to process -r specification: ${_status}."; - elif ! ex_pkg_load_groups; then - _rc=1; _status="failed to load build groups."; - else if ! rtl_lmatch "${ARG_DIST:-}" "rpm" ","\ - && [ "${ARG_DUMP_IN:+1}" != 1 ]\ - && [ "${ARG_DUMP_ON_ABORT:-0}" -eq 0 ]; then - EX_PKG_BUILD_GROUPS="$(rtl_lfilter "${EX_PKG_BUILD_GROUPS}" "host_deps_rpm")"; - fi; - if [ "${BUILD_GROUPS:+1}" != 1 ]; then - BUILD_GROUPS="${EX_PKG_BUILD_GROUPS}"; - else _foundfl=0; for _group in ${BUILD_GROUPS}; do - if rtl_lmatch "${EX_PKG_BUILD_GROUPS}" "${_group}"; then - _foundfl=1; break; - fi; - done; - if [ "${_foundfl}" -eq 0 ]; then - _foundfl=0; for _group in ${BUILD_GROUPS}; do - if rtl_lmatch "${EX_PKG_BUILD_GROUPS}" "${_group}"; then - _rc=1; _status="unknown build group \`${_group}'."; break; - fi; - done; - fi; - fi; - if [ "${_rc:-0}" -eq 0 ]; then - if rtl_lmatch "${ARG_DIST}" "zipdist" ","\ - && ! rtl_lmatch "${ARG_DIST}" "minipix" ","; then - ARG_DIST="$(rtl_lconcat "${ARG_DIST}" "minipix" ",")"; - fi; - if [ "${ARG_DIST:+1}" = 1 ]; then - BUILD_GROUPS="$(rtl_lconcat "$(rtl_lfilter "${BUILD_GROUPS}" "dist")" "dist")"; - fi; - if [ "${ARG_RESTART:+1}" = 1 ]\ - && ! rtl_lmatch "${ARG_RESTART}" "ALL LAST"; then - for _pkg_name in ${ARG_RESTART}; do - if ! ex_pkg_find_package "${BUILD_GROUPS}" "${_pkg_name}" >/dev/null; then - _pkg_names_unknown="$(rtl_lconcat "${_pkg_names_unknown}" "${_pkg_name}")"; - fi; - done; - case "$(rtl_llength "${_pkg_names_unknown}")" in - 0) ;; - 1) _rc=1; _status="unknown package \`${_pkg_names_unknown}'."; ;; - *) _rc=1; _status="unknown packages: $(rtl_subst "${_pkg_names_unknown}" " " ", ")"; ;; - esac; - fi; - fi; - fi; return "${_rc}"; -}; - -buildp_init_env() { - local _fname="" _lang="${LANG:-C}" _lang_="" _name="" _rc=0; _status=""; _lang="${_lang%%_*}"; - - if ! cd "${0%/*}"; then - printf "Error: failed to change working directory to \`${0%/*}'." >&2; exit 1; - elif ! umask 022; then - printf "Error: failed to set umask(2).\n" >&2; exit 1; - elif ! BUILD_USER="$(id -nu)"; then - printf "Error: failed to obtain username." >&2; exit 1; - else for _fname in \ - $(find subr.rtl -name *.subr) \ - $(find subr -name *.subr) \ - etc/build.theme \ - ; - do - if ! . "${_fname}"; then - printf "Error: failed to source \`%s'.\n" "${_fname}" >&2; exit 1; - fi; - done; - if [ -e "etc/build.theme.local" ]; then - if ! . "etc/build.theme.local"; then - printf "Error: failed to source \`%s'.\n" "etc/build.theme.local" >&2; exit 1; - fi; - fi; - for _name in build rtl; do - for _lang_ in ${_lang} C; do - _fname="etc/${_name}.msgs.${_lang_}"; - if [ -e "${_fname}" ]; then - if ! . "${_fname}"; then - printf "Error: failed to source \`%s'.\n" "${_fname}" >&2; exit 1; - fi; - if [ -e "${_fname}.local" ]; then - if ! . "${_fname}.local"; then - printf "Error: failed to source \`%s'.\n" "${_fname}.local" >&2; exit 1; - fi; - fi; break; - fi; - done; - done; - fi; export LANG=C LC_ALL=C; return "${_rc}"; -}; - -buildp_init_files() { - local _log_last_fname="" _log_last_num=1 _rc=0; _status="" - - if ! rtl_fileop mkdir "${BUILD_DLCACHEDIR}" "${BUILD_WORKDIR}"\ - || rtl_lmatch "${ARG_DIST}" "rpm" ","\ - && ! rtl_fileop mkdir "${PREFIX_RPM}"; then - _rc=1; _status="cannot create build directories."; - elif [ -e "${DEFAULT_BUILD_STATUS_IN_PROGRESS_FNAME}" ]; then - _rc=1; _status="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="failed to clean environment."; - elif ! rtl_check_path_vars "${DEFAULT_CHECK_PATH_VARS}"; then - _rc=1; _status="${_status}"; - else export TMP="${BUILD_WORKDIR}" TMPDIR="${BUILD_WORKDIR}"; - touch "${DEFAULT_BUILD_STATUS_IN_PROGRESS_FNAME}"; - if [ -e "${DEFAULT_BUILD_LOG_FNAME}" ]; then - while [ -e "${DEFAULT_BUILD_LOG_FNAME}.${_log_last_num}" ]; do - : $((_log_last_num+=1)); - done; - _log_last_fname="${DEFAULT_BUILD_LOG_FNAME}.${_log_last_num}"; - 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}"; rtl_log_set_fname "${DEFAULT_BUILD_LOG_FNAME}"; - if rtl_lmatch "${ARG_CLEAN_BUILDS}" "prefix" ","; then - trap "rm -f \"${DEFAULT_BUILD_STATUS_IN_PROGRESS_FNAME}\" 2>/dev/null; rtl_log_msg \"fatalexit\" \"${MSG_build_aborted}\"" HUP INT TERM USR1 USR2; - rtl_log_msg "info" "${MSG_build_clean_prefix}"; - for _pname in ${DEFAULT_CLEAR_PREFIX_PATHS}; do - if ! rtl_fileop rm "${PREFIX}/${_pname}"; then - _rc=1; _status="failed to remove \`${PREFIX}/${_pname}'."; break; - fi; - done; - trap - HUP INT TERM USR1 USR2; - fi; - export PATH="${PREFIX}/bin${PATH:+:${PATH}}"; - fi; - return "${_rc}"; -}; - -buildp_init_getopts() { - local _arg="" _opt="" _rc=0 _shiftfl=0 OPTIND=0; _status=""; - - : ${ARCH:="nt64"}; : ${BUILD_KIND:="debug"}; - ARG_AS_NEEDED=0; ARG_CLEAN_BUILDS=""; ARG_DEBUG_MINIPIX=0; ARG_DIST=""; ARG_DUMP_IN=""; - ARG_DUMP_ON_ABORT=0; ARG_FETCH_FORCE=""; ARG_PARALLEL=1; ARG_RELAXED=0; ARG_RESET_PKG=0; - ARG_RESTART=""; ARG_RESTART_AT=""; ARG_RESTART_RECURSIVE=""; ARG_VERBOSE=0; ARG_VERBOSE_TAGS=""; - - while [ "${#}" -gt 0 ]; do - case "${1}" in - --as-needed) ARG_AS_NEEDED=1; _shiftfl=1; ;; - --dump-in) if [ "${#}" -ge 2 ]; then - ARG_DUMP_IN="${2}"; ARG_DUMP_ON_ABORT=1; _shiftfl=2; - else - _rc=1; _status="missing argument to option --dump-in."; - fi; ;; - --dump-on-abort) - ARG_DUMP_ON_ABORT=1; _shiftfl=1; ;; - --debug-minipx) ARG_DEBUG_MINIPIX=1; _shiftfl=1; ;; - --help) - if [ -t 1 ]; then - cat etc/build.usage; - else - sed 's/\[[0-9]\+m//g' etc/build.usage; - fi; exit 0; ;; - --reset-state) ARG_RESET_PKG=1; _shiftfl=1; ;; - -v*) _opt="${1#-}"; while [ -n "${_opt}" ]; do - : $((ARG_VERBOSE+=1)); _opt="${_opt#?}"; - done; _shiftfl=1; ;; - # {{{ --roar - --roar) printf "%s\n" ' - ▃▃▃▃ - ▟ ▙ -▟▙▃▟▙  /\ /\  roar! -▜▒▓▒▛  ▛ """ ▜  / - ▜ ▛   ^ _ ^   / - ▀   (__y_)   - ▟▙ ▁▂▃▟▐▙▜`\_/▛▟▌ - ▟▙ ▟ ▓▓▓| |▍▓▓▓ - ▜\▙ ▟ ▓▓▓▓▓ |▓▓▓▓▓ - ▜\\ \ ▒▒▒| | ▒▒▒ - ▜\ ) ▒_| |▙ ▒ - ( / ))))))'; exit 0; ;; - # }}} - *) _shiftfl=0; ;; - esac; - if [ "${_rc}" -ne 0 ]; then - break; - elif [ "${_shiftfl}" -gt 0 ]; then - shift "${_shiftfl}"; continue; - elif getopts a:b:C:D:F:hp:Pr:RxV: _opt; then - case "${_opt}" in - a) ARCH="${OPTARG}"; ;; - b) BUILD_KIND="${OPTARG}"; ;; - C) ARG_CLEAN_BUILDS="${OPTARG}"; ;; - D) ARG_DIST="${OPTARG}"; ;; - F) ARG_FETCH_FORCE="${OPTARG}"; ;; - h) - if [ -t 1 ]; then - cat etc/build.usage.short; - else - sed 's/\[[0-9]\+m//g' etc/build.usage.short; - fi; exit 0; ;; - p) ARG_PARALLEL="${OPTARG}"; ;; - P) ARG_PARALLEL="auto"; - if [ -n "${2:-}" ]\ - && rtl_isnumber "${2}"; then - _rc=1; _status="maximum parallelisation job count is set with the \`-p jobs' option."; break - fi; ;; - r) ARG_RESTART="${OPTARG}"; ;; - R) ARG_RELAXED=1; ;; - x) ARG_VERBOSE_TAGS="${ARG_VERBOSE_TAGS:+${ARG_VERBOSE_TAGS},}xtrace"; ;; - V) ARG_VERBOSE_TAGS="${OPTARG}"; ;; - *) cat etc/build.usage.short; exit 1; ;; - esac; shift $((${OPTIND}-1)); OPTIND=1; - else if rtl_match "${1}" "=*"; then - BUILD_GROUPS_INHIBIT_DEPS=1; _arg="${1#=}"; - else - _arg="${1}"; - fi; - case "${_arg}" in - *=*) rtl_set_var_unsafe "${_arg%%=*}" "${_arg#*=}"; ;; - [!a-zA-Z]*) _rc=1; _status="build group names must start with [a-zA-Z] (in argument \`${_arg}'.)"; ;; - *[!_a-zA-Z]*) _rc=1; _status="build group names must not contain [!_a-zA-Z] (in argument \`${_arg}'.)"; ;; - *) BUILD_GROUPS="$(rtl_lconcat "${BUILD_GROUPS}" "${_arg}")"; ;; - esac; shift; - fi; - done; - if [ "${_rc:-0}" -eq 0 ]; then - case "${ARG_PARALLEL}" in - auto) if ! ARG_PARALLEL="$(rtl_get_cpu_count)"; then - _rc=1; _status="failed to get CPU count."; - else - ARG_PARALLEL=$((${ARG_PARALLEL}/2)); - fi; ;; - max) if ! ARG_PARALLEL="$(rtl_get_cpu_count)"; then - _rc=1; _status="failed to get CPU count."; - fi; ;; - "") ARG_PARALLEL=1; ;; - *) if ! rtl_isnumber "${ARG_PARALLEL}"; then - _rc=1; _status="invalid jobs count \`${ARG_PARALLEL}'."; - fi; ;; - esac; - if [ "${_rc:-0}" -eq 0 ]; then - DEFAULT_BUILD_CPUS="${ARG_PARALLEL}"; - fi; - fi; - return "${_rc}"; -}; - -buildp_init_logging() { - local _tag="" _tags="" _rc=0; _status=""; - - rtl_log_clear_tags; - case "${ARG_VERBOSE}" in - 0) [ "${#ARG_VERBOSE_TAGS}" -eq 0 ] && rtl_log_enable_tags "${LOG_TAGS_normal}"; ;; - 1) rtl_log_enable_tags "${LOG_TAGS_verbose}"; ;; - *) _rc=1; _status="invalid verbosity level (max. -v)"; ;; - esac; - if [ "${_rc}" -eq 0 ]; then - case "${ARG_VERBOSE_TAGS}" in - +*) rtl_log_enable_tags "${LOG_TAGS_normal}"; - ARG_VERBOSE_TAGS="${ARG_VERBOSE_TAGS#+}"; ;; - *) ;; - esac; - for _tag in $(rtl_llift "${ARG_VERBOSE_TAGS}" "," " "); do - case "${_tag}" in - all) rtl_log_enable_tags "${LOG_TAGS_all}"; ;; - clear|none) rtl_log_clear_tags; ;; - normal) rtl_log_enable_tags "${LOG_TAGS_normal}"; ;; - verbose) rtl_log_enable_tags "${LOG_TAGS_verbose}"; ;; - *) - _tags="$(rtl_lsearch_patternl "${LOG_TAGS_all}" "${_tag}" ",")"; - if [ "${#_tags}" -gt 0 ]; then - rtl_log_enable_tags "${_tags}"; - else - _rc=1; _status="invalid log tag or tag pattern \`${_tag}'"; break; - fi; ;; - esac; - done; - fi; - return "${_rc}"; -}; - -buildp_init_prereqs() { - if ! rtl_check_prereqs ${DEFAULT_PREREQS}; then - printf "%s\n" "${_status}" >&2; exit 1; - elif ! awk -V 2>/dev/null | grep -q "^GNU Awk "; then - printf "Error: awk(1) in \$PATH must be GNU Awk." >&2; exit 1; - elif ! (FNAME="$(mktemp)" && { trap "rm -f \"\${FNAME}\"" EXIT; \ - sed -i'' -e '' "${FNAME}" >/dev/null 2>&1; }); then - printf "Error: sed(1) in \${PATH} does not support the \`-i' option.\n" >&2; exit 1; - fi; -}; - -build_init() { - local _rc=0; _status=""; - if ! buildp_init_env \ - || ! buildp_init_getopts "${@}" \ - || ! buildp_init_logging \ - || ! ex_pkg_load_vars \ - || ! buildp_init_prereqs \ - || ! buildp_init_args \ - || ! buildp_init_files; then - _rc=1; _status="${_status}"; - fi; return "${_rc}"; -}; - -# vim:filetype=sh foldmethod=marker diff --git a/subr/ex_pkg.subr b/subr/ex_pkg.subr deleted file mode 100644 index ac03670..0000000 --- a/subr/ex_pkg.subr +++ /dev/null @@ -1,287 +0,0 @@ -# -# set +o errexit -o noglob -o nounset is assumed. -# - -# -# ex_pkg_check_depends() - check single named package for unsatisfied dependencies -# @_checkfl: enable (1) or inhibit (0) dependency expansion -# @_pkg_disabled: list of disabled packages -# @_pkg_finished: list of finished packages -# @_pkg_name: single package name -# @_pkg_names: list of package names -# -# Return: zero (0) given no outstanding dependencies, non-zero (>0) otherwise -# -ex_pkg_check_depends() { - local _checkfl="${1}" _pkg_disabled="${2}" _pkg_finished="${3}" _pkg_name="${4}" _pkg_names="${5}"\ - _dependfl=0 _pkg_depends="" _pkg_name_depend=""; - if [ "${_checkfl:-0}" -eq 1 ]\ - && _pkg_depends="$(rtl_uniq $(rtl_lunfold_depends 'PKG_${_name}_DEPENDS' $(rtl_get_var_unsafe -u "PKG_"${_pkg_name}"_DEPENDS")))"; then - for _pkg_name_depend in $(rtl_uniq ${_pkg_depends}); do - if ! rtl_lmatch "${_pkg_disabled}" "${_pkg_name_depend}"\ - && ! rtl_lmatch "${_pkg_finished}" "${_pkg_name_depend}"\ - && ! ex_pkg_state_test "${_pkg_name_depend}" finish; then - if ! rtl_lmatch "${_pkg_names}" "${_pkg_name_depend}"; then - rtl_log_msg "fatalexit" "${MSG_build_unknown_dep}" "${_pkg_name_depend}" "${_pkg_name}"; - else - _dependfl=1; break; - fi; - fi; - done; - fi; - return "${_dependfl}"; -}; - -# -# ex_pkg_find_package() - find build group a single named package belongs to -# @_group_names: build group names -# @_pkg_name: single named package -# -# Return: zero (0) on success, non-zero (>0) if package not found, group name on stdout if package was found. -# -ex_pkg_find_package() { - local _group_names="${1}" _pkg_name="${2}" _foundfl=0 _group_name="" _pkg_names=""; - for _group_name in ${_group_names}; do - if _pkg_names="$(rtl_get_var_unsafe -u "${_group_name}_PACKAGES")"\ - && [ -n "${_pkg_names}" ]\ - && rtl_lmatch "${_pkg_names}" "${_pkg_name}"; then - _foundfl=1; break; - fi; - done; - case "${_foundfl:-0}" in - 0) return 1; ;; - 1) printf "%s" "${_group_name}"; return 0; ;; - esac; -}; - -# -# ex_pkg_get_packages() - get list of packages belonging to single named build group -# @_group_name: build group name -# -# Return: zero (0) on success, non-zero (>0) on failure, list of package names on stdout on success. -# -ex_pkg_get_packages() { - local _group_name="${1}" _pkg_names=""; - if _pkg_names="$(rtl_get_var_unsafe -u "${_group_name}_PACKAGES")"\ - && [ -n "${_pkg_names}" ]; then - printf "%s" "${_pkg_names}"; return 0; - else - return 1; - fi; -}; - -# -# ex_pkg_load_dump() - load package dump -# @_pkg_name: package name -# -# Return: zero (0) on success, non-zero (>0) on failure, package dump post-return on success. -# -ex_pkg_load_dump() { - local _pkg_name="${1}" _workdir="${2}" _rc=0; _status=""; - if [ ! -e "${_workdir}/${_pkg_name}.dump" ]; then - rtl_log_msg "warning" "${MSG_pkgtool_no_env_dump}" "${_pkg_name}" "${_workdir}"; - rtl_log_msg "info" "${MSG_pkgtool_rebuilding_pkg}" "${_pkg_name}"; - (export ARCH BUILD_KIND BUILD_DLCACHEDIR BUILD_WORKDIR \ - PREFIX PREFIX_CROSS PREFIX_MINGW32 PREFIX_MINIPIX \ - PREFIX_NATIVE PREFIX_ROOT PREFIX_RPM; - ./build.sh --dump-in _build -P -r "${_pkg_name}" -v); - if [ ! -e "${_workdir}/${_pkg_name}.dump" ]; then - _rc=1; _status="Error: failed to locate environment dump for package \`${_pkg_name}' in \`${_workdir}'."; - fi; - else - _rc=0; - fi; - if [ "${_rc:-0}" -eq 0 ]\ - && ! . "${_workdir}/${_pkg_name}.dump"; then - _rc=1; _status="Error: failed to source environment dump for package \`${_pkg_name}' from \`${_workdir}'."; - elif [ "${_rc:-0}" -eq 0 ]\ - && ! rtl_fileop cd "${PKG_BUILD_DIR}"; then - _rc=1; _status="Error: failed to change working directory to \`${PKG_BUILD_DIR}'."; - fi; return "${_rc}"; -}; - -# -# ex_pkg_load_vars() - load build variables -# -# Return: zero (0) on success, non-zero (>0) on failure, build variables post-return on success. -# -ex_pkg_load_vars() { - local _rc=0 _fname=""; _status=""; - if ! rtl_lmatch "${ARCH}" "nt32 nt64"; then - _rc=1; _status="Error: invalid architecture \`${ARCH}'."; - elif ! rtl_lmatch "${BUILD_KIND}" "debug release"; then - _rc=1; _status="Error: unknown build type \`${BUILD_KIND}'."; - else case "${ARCH}" in - nt32) DEFAULT_TARGET="i686-nt32-midipix"; ;; - nt64) DEFAULT_TARGET="x86_64-nt64-midipix"; ;; - esac; - for _fname in \ - "${HOME}/midipix_build.vars" \ - "${HOME}/.midipix_build.vars" \ - ../midipix_build.vars \ - ./midipix.env; do - if [ -r "${_fname}" ]; then - rtl_fileop source "${_fname}"; - fi; - done; - if [ -z "${PREFIX}" ]; then - _rc=1; _status="Error: \${PREFIX} empty or unset."; - fi; - fi; return "${_rc}"; -}; - -# -# ex_pkg_load_groups() - load all available build groups -# -# Return: zero (0) on success, non-zero (>0) on failure, build groups loaded and ${EX_PKG_BUILD_GROUPS} and ${EX_PKG_BUILD_GROUPS_NOAUTO} set post-return. -# -ex_pkg_load_groups() { - local _build_groups="" _build_groups_noauto="" _fname="" _group="" _groups=""; - for _fname in $(find ./groups -name *.group | sort); do - rtl_fileop source_opt "${_fname}"; - if [ -n "${GROUP_TARGET:-}" ]; then - _group="${GROUP_TARGET}"; unset GROUP_TARGET; - else - _group="${_fname##*/}"; _group="${_group%.group}"; _group="${_group#*.}"; - fi; - if ! rtl_lmatch "${_groups}" "${_group}"; then - _groups="$(rtl_lconcat "${_groups}" "${_group}")"; - if [ -n "${GROUP_AUTO:-}" ]; then - if [ "${GROUP_AUTO:-0}" -ne 0 ]; then - _build_groups="$(rtl_lconcat "${_build_groups}" "${_group}")"; - else - _build_groups_noauto="$(rtl_lconcat "${_build_groups_noauto}" "${_group}")"; - fi; - unset GROUP_AUTO; - else - _build_groups="$(rtl_lconcat "${_build_groups}" "${_group}")"; - fi; - fi; - done; - EX_PKG_BUILD_GROUPS="$(rtl_uniq "${_build_groups}")"; - EX_PKG_BUILD_GROUPS_NOAUTO="$(rtl_uniq "${_build_groups_noauto}")"; -}; - -# -# ex_pkg_unfold_depends() - unfold list of package names into dependency-expanded set of complete, disabled, finished, and outstanding package names -# @_checkfl: enable (1) or inhibit (0) dependency expansion -# @_forcefl: enable (1) or inhibit (0) forcibly rebuilding finished packages -# @_group_name: build group name -# @_pkg_names: list of package names -# @_restart: optional whitespace-separated list of package names to rebuild -# @_test_finished: only exclude disabled packages from ${EX_PKG_NAMES} (0,) split finished packages into ${EX_PKG_FINISHED} -# -# Return: zero (0) on success, non-zero (>0) on failure, ${EX_PKG_DISABLED}, ${EX_PKG_FINISHED}, and ${EX_PKG_NAMES} set post-return. -# -ex_pkg_unfold_depends() { - local _checkfl="${1}" _forcefl="${2}" _group_name="${3}" _pkg_names="${4}" _restart="${5}" _test_finished="${6}"\ - _pkg_name="" _restartfl=0; - if [ -n "${_restart}" ] && ! rtl_lmatch "${_restart}" "ALL LAST"; then - _pkg_names="$(rtl_lsearch "${_pkg_names}" "${_restart}")"; - fi; - if [ -n "${_restart}" ] && [ "${_checkfl:-0}" -eq 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 - _restartfl=1; - else - _restartfl=0; - fi; - if [ "x$(rtl_get_var_unsafe -u "PKG_${_pkg_name}_DISABLED")" = "x1" ]; then - EX_PKG_DISABLED="$(rtl_lconcat "${EX_PKG_DISABLED}" "${_pkg_name}")"; - _pkg_names="$(rtl_lfilter "${_pkg_names}" "${_pkg_name}")"; - elif [ "${_test_finished:-1}" -eq 1 ]\ - && ex_pkg_state_test "${_pkg_name}" finish\ - && [ "${_restartfl:-0}" -eq 0 ]\ - && [ "${_forcefl:-0}" -ne 1 ]\ - && [ "x$(rtl_get_var_unsafe -u "${_group_name}_FORCE")" != "x1" ]; then - EX_PKG_FINISHED="$(rtl_lconcat "${EX_PKG_FINISHED}" "${_pkg_name}")"; - _pkg_names="$(rtl_lfilter "${_pkg_names}" "${_pkg_name}")"; - fi; - done; - EX_PKG_DISABLED="$(rtl_uniq ${EX_PKG_DISABLED})"; - EX_PKG_FINISHED="$(rtl_uniq ${EX_PKG_FINISHED})"; - EX_PKG_NAMES="$(rtl_uniq ${_pkg_names})"; -}; - -# -# ex_pkg_unfold_rdepends() - unfold list of package names into reverse dependency-expanded set of complete, disabled, finished, and outstanding package names -# @_group_name: build group name -# @_pkg_names: list of package names -# @_restart: optional whitespace-separated list of package names to rebuild -# @_test_finished: only exclude disabled packages from ${EX_PKG_NAMES} (0,) split finished packages into ${EX_PKG_FINISHED} -# -# Return: zero (0) on success, non-zero (>0) on failure, ${EX_PKG_DISABLED}, ${EX_PKG_FINISHED}, and ${EX_PKG_NAMES} set post-return. -# -ex_pkg_unfold_rdepends() { - local _group_name="${1}" _pkg_names="${2}" _restart="${3}" _test_finished="${4}"\ - _pkg_depends="" _pkg_name="" _pkg_name_depend="" _pkg_rdepends=""; - for _pkg_name_depend in ${_restart}; do - for _pkg_name in ${_pkg_names}; do - if [ "${_pkg_name}" != "${_pkg_name_depend}" ]\ - && [ "x$(rtl_get_var_unsafe -u "PKG_${_pkg_name}_DISABLED")" != "x1" ]\ - && _pkg_depends="$(rtl_lunfold_depends 'PKG_${_name}_DEPENDS' $(rtl_get_var_unsafe -u "PKG_"${_pkg_name}"_DEPENDS"))"\ - && [ -n "${_pkg_depends}" ]\ - && rtl_lmatch "${_pkg_depends}" "${_pkg_name_depend}"; then - _pkg_rdepends="$(rtl_lconcat "${_pkg_rdepends}" "${_pkg_name}")"; - fi; - done; - done; - _pkg_names=""; - for _pkg_name in ${_pkg_rdepends}; do - if _pkg_depends="$(rtl_lunfold_depends 'PKG_${_name}_DEPENDS' $(rtl_get_var_unsafe -u "PKG_"${_pkg_name}"_DEPENDS"))"\ - && [ -n "${_pkg_depends}" ]; then - for _pkg_name_depend in ${_pkg_depends}; do - if [ "x$(rtl_get_var_unsafe -u "PKG_${_pkg_name_depend}_DISABLED")" = "x1" ]; then - EX_PKG_DISABLED="$(rtl_lconcat "${EX_PKG_DISABLED}" "${_pkg_name_depend}")"; - elif [ "${_test_finished:-1}" -eq 1 ]\ - && ex_pkg_state_test "${_pkg_name_depend}" finish\ - && [ "x$(rtl_get_var_unsafe -u "${_group_name}_FORCE")" != "x1" ]\ - && ! rtl_lmatch "${_pkg_rdepends}" "${_pkg_name_depend}"; then - EX_PKG_FINISHED="$(rtl_lconcat "${EX_PKG_FINISHED}" "${_pkg_name_depend}")"; - elif [ "${_test_finished:-1}" -eq 0 ]\ - || ! ex_pkg_state_test "${_pkg_name_depend}" finish\ - || [ "x$(rtl_get_var_unsafe -u "${_group_name}_FORCE")" = "x1" ]; then - _pkg_names="$(rtl_lconcat "${_pkg_names}" "${_pkg_name_depend}")"; - fi; - done; - fi; - _pkg_names="$(rtl_lconcat "${_pkg_names}" "${_pkg_name}")"; - done; - EX_PKG_DISABLED="$(rtl_uniq ${EX_PKG_DISABLED})"; - EX_PKG_FINISHED="$(rtl_uniq ${EX_PKG_FINISHED})"; - EX_PKG_NAMES="$(rtl_uniq ${_pkg_names})"; -}; - -# -# ex_pkg_unfold_rdepends_direct() - unfold list of package names into direct reverse dependency-expanded set of disabled and outstanding package names -# @_group_name: build group name -# @_pkg_names: list of package names -# @_restart: optional whitespace-separated list of package names to rebuild -# -# Return: zero (0) on success, non-zero (>0) on failure, ${EX_PKG_DISABLED} and ${EX_PKG_RDEPENDS_DIRECT} set post-return. -# -ex_pkg_unfold_rdepends_direct() { - local _group_name="${1}" _pkg_names="${2}" _restart="${3}"\ - _pkg_depends="" _pkg_disabled="" _pkg_name="" _pkg_name_depend="" _pkg_rdepends=""; - for _pkg_name_depend in ${_restart}; do - for _pkg_name in ${_pkg_names}; do - if [ "${_pkg_name}" != "${_pkg_name_depend}" ]\ - && _pkg_depends="$(rtl_get_var_unsafe -u "PKG_${_pkg_name}_DEPENDS")"\ - && [ -n "${_pkg_depends}" ]\ - && rtl_lmatch "${_pkg_depends}" "${_pkg_name_depend}"; then - if [ "x$(rtl_get_var_unsafe -u "PKG_${_pkg_name}_DISABLED")" != "x1" ]; then - _pkg_rdepends="$(rtl_lconcat "${_pkg_rdepends}" "${_pkg_name}")"; - else - _pkg_disabled="$(rtl_lconcat "${_pkg_disabled}" "${_pkg_name}")"; - fi; - fi; - done; - done; - EX_PKG_DISABLED="$(rtl_uniq ${_pkg_disabled})"; - EX_PKG_RDEPENDS_DIRECT="$(rtl_uniq ${_pkg_rdepends})"; -}; - -# vim:filetype=sh textwidth=0 diff --git a/subr/ex_pkg_dispatch.subr b/subr/ex_pkg_dispatch.subr deleted file mode 100644 index 139cf94..0000000 --- a/subr/ex_pkg_dispatch.subr +++ /dev/null @@ -1,255 +0,0 @@ -# -# set +o errexit -o noglob -o nounset is assumed. -# - -# -# 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_expand_packages() - expand build group name to list of packages ordered and filtered according to dependency and restart constraints -# @_checkfl: enable (1) or inhibit (0) dependency expansion -# @_forcefl: enable (1) or inhibit (0) forcibly rebuilding finished packages -# @_group_name: build group name -# @_restart: optional whitespace-separated list of package names to rebuild -# @_reversefl: unfold reverse dependencies (1) or dependencies (0) -# -# Return: zero (0) on success, non-zero (>0) on failure, ${EX_PKG_DISABLED}, ${EX_PKG_FINISHED}, and ${EX_PKG_NAMES} set post-return. -# -exp_pkg_dispatch_expand_packages() { - local _checkfl="${1}" _forcefl="${2}" _group_name="${3}" _restart="${4}" _reversefl="${5}"\ - _pkg_names=""; EX_PKG_DISABLED=""; EX_PKG_FINISHED=""; EX_PKG_NAMES=""; - if _pkg_names="$(rtl_get_var_unsafe -u "${_group_name}_PACKAGES")"\ - && [ -n "${_pkg_names}" ]; then - if [ "${_reversefl:-0}" -eq 0 ]; then - ex_pkg_unfold_depends "${_checkfl}" "${_forcefl}" "${_group_name}" "${_pkg_names}" "${_restart}" 1; - else ex_pkg_unfold_rdepends "${_group_name}" "${_pkg_names}" "${_restart}" 1; - fi; - fi; - return 0; -}; - -# -# 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 -# @_checkfl: enable (1) or inhibit (0) dependency expansion -# @_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 or LAST -# @_workdir: pathname to build-specific temporary directory -# -# Return: zero (0) on success, non-zero (>0) on failure, ${EXP_PKG_DISPATCH_COUNT_CUR} may be mutated post-return. -# -exp_pkg_dispatch_group() { - local _build_steps_default="${1}" _build_vars_default="${2}" _checkfl="${3}"\ - _dispatch_fn="${4}" _group_name="${5}" _njobs_max="${6}" _pipe_path="${7}"\ - _restart_at="${8}" _workdir="${9}" _perc_group=0 _perc_pkg=0 _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) _pkg_name="${_pipe_msg#done * }"; : $((EXP_PKG_DISPATCH_COUNT_CUR+=1)); : $((EXP_PKG_DISPATCH_NJOBS-=1)); - EX_PKG_FINISHED="$(rtl_lconcat "${EX_PKG_FINISHED}" "${_pkg_name}")"; - _perc_group="$(rtl_percentage "${EXP_PKG_DISPATCH_GROUP_CUR}" "${EXP_PKG_DISPATCH_GROUP_MAX}")"; - _perc_pkg="$(rtl_percentage "${EXP_PKG_DISPATCH_COUNT_CUR}" "${EXP_PKG_DISPATCH_COUNT_MAX}")"; - "${_dispatch_fn}" finish_pkg ${_pipe_msg#done } "${EXP_PKG_DISPATCH_COUNT_MAX}" "${_perc_group}" "${_perc_pkg}"; - EX_PKG_NAMES="$(rtl_lfilter "${EX_PKG_NAMES}" "${_pkg_name}")"; - EX_PKG_DISPATCH_WAIT="$(rtl_lfilter "${EX_PKG_DISPATCH_WAIT}" "${_pkg_name}")"; - if [ -n "${EX_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}" "${_checkfl}" \ - "${_dispatch_fn}" "${_group_name}" \ - "${_njobs_max}" "${_pipe_path}" \ - "${EX_PKG_DISABLED}" "${EX_PKG_FINISHED}" \ - "${_restart_at}" "${_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 } "${EXP_PKG_DISPATCH_COUNT_MAX}"; ;; - msg_pkg) - "${_dispatch_fn}" msg_pkg ${_pipe_msg#msg_pkg }; ;; - step) "${_dispatch_fn}" step_pkg ${_pipe_msg#step }; ;; - esac; done <>"${_pipe_path}"; - if [ -n "${EX_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}" "${_checkfl}" \ - "${_dispatch_fn}" "${_group_name}" \ - "${_njobs_max}" "${_pipe_path}" \ - "${EX_PKG_DISABLED}" "${EX_PKG_FINISHED}" \ - "${_restart_at}" "${_workdir}"; - fi; - 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 -# @_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 or LAST -# @_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}, ${EX_PKG_NAMES}, and ${EX_PKG_DISPATCH_WAIT} may be mutated post-return. -# -exp_pkg_dispatch_package() { - local _build_steps_default="${1}" _build_vars_default="${2}" _dispatch_fn="${3}"\ - _group_name="${4}" _pkg_name="${5}" _restart_at="${6}" _workdir="${7}"\ - _perc_group=0 _perc_pkg=0; - _perc_group="$(rtl_percentage "${EXP_PKG_DISPATCH_GROUP_CUR}" "${EXP_PKG_DISPATCH_GROUP_MAX}")"; - _perc_pkg="$(rtl_percentage "${EXP_PKG_DISPATCH_COUNT_CUR}" "${EXP_PKG_DISPATCH_COUNT_MAX}")"; - if "${_dispatch_fn}" start_pkg "${_group_name}" "${_pkg_name}" "$((${EXP_PKG_DISPATCH_COUNT}+1))" "${EXP_PKG_DISPATCH_COUNT_MAX}" "${_perc_group}" "${_perc_pkg}"; then - : $((EXP_PKG_DISPATCH_NJOBS+=1)); : $((EXP_PKG_DISPATCH_COUNT+=1)); EX_PKG_DISPATCH_WAIT="$(rtl_lconcat "${EX_PKG_DISPATCH_WAIT}" "${_pkg_name}")"; - (trap "if [ \${?} -eq 0 ]; then \ - printf \"done %s %s %d\n\" \"${_group_name}\" \"${_pkg_name}\" \"${EXP_PKG_DISPATCH_COUNT}\" >&3; \ - else \ - printf \"fail %s %s %d\n\" \"${_group_name}\" \"${_pkg_name}\" \"${EXP_PKG_DISPATCH_COUNT}\" >&3; \ - pkill -U "${$}"; \ - fi;" EXIT HUP INT TERM USR1 USR2; - set +o errexit -o noglob -o nounset; BUILD_IS_PARENT=0; rtl_log_set_fname ""; rtl_log_set_no_attr 1; - if ex_pkg_env "${_build_steps_default}" "${_build_vars_default}" \ - "${_group_name}" 0 "${_pkg_name}" "${_restart_at}" "${_workdir}"; then - ex_pkg_exec "${_dispatch_fn}" "${_group_name}" "${_pkg_name}" "${_restart_at}"; - else - return 1; - fi;) 1>"${_workdir}/${_pkg_name}_stderrout.log" 2>&1 3>"${_pipe_path}" & - else - return 1; - fi; -}; - -# -# exp_pkg_dispatch_packages() - dispatch set of packages -# @_build_steps_default: list of default build steps -# @_build_vars_default: list of default build variables -# @_checkfl: enable (1) or inhibit (0) dependency expansion -# @_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_disabled: list of disabled packages -# @_pkg_finished: list of finished packages -# @_restart_at: optional comma-separated list of build steps at which to rebuild or ALL or LAST -# @_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}, ${EX_PKG_NAMES}, and ${EX_PKG_DISPATCH_WAIT} may be mutated post-return. -# -exp_pkg_dispatch_packages() { - local _build_steps_default="${1}" _build_vars_default="${2}" _checkfl="${3}"\ - _dispatch_fn="${4}" _group_name="${5}" _njobs_max="${6}" _pipe_path="${7}"\ - _pkg_disabled="${8}" _pkg_finished="${9}" _restart_at="${10}" _workdir="${11}"\ - _foundfl=0 _njob=0 _pkg_depends="" _pkg_name=""; - while [ "${EXP_PKG_DISPATCH_NJOBS:-0}" -lt "${_njobs_max}" ]; do - _foundfl=0; - for _pkg_name in ${EX_PKG_NAMES}; do - if ! rtl_lmatch "${_pkg_disabled}" "${_pkg_name}"\ - && ! rtl_lmatch "${_pkg_finished}" "${_pkg_name}"\ - && ! rtl_lmatch "${EX_PKG_DISPATCH_WAIT}" "${_pkg_name}"\ - && ex_pkg_check_depends "${_checkfl}" "${_pkg_disabled}" "${_pkg_finished}" \ - "${_pkg_name}" "${EX_PKG_NAMES}"; then - exp_pkg_dispatch_package "${_build_steps_default}" \ - "${_build_vars_default}" "${_dispatch_fn}" \ - "${_group_name}" "${_pkg_name}" "${_restart_at}" \ - "${_workdir}"; _foundfl=1; break; - fi; - done; - if [ "${_foundfl:-0}" -eq 0 ]; then - break; - fi; - done; -}; - -# -# 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) -# @_groups_inhibit_deps: inhibit group-group dependency expansion -# @_njobs_max: maximum count of simultaneous jobs -# @_pipe_path: pathname to build FIFO -# @_restart: optional whitespace-separated list of package names to rebuild -# @_restart_at: optional comma-separated list of build steps at which to rebuild or ALL or LAST -# @_restart_recursive: optional flag specifiying either no dependency expansion (0,) dependency expansion (1,) dependency expansion and forcibly rebuild (2,) forcibly rebuild reverse dependencies (3.) -# @_workdir: pathname to build-specific temporary directory -# -# Return: zero (0) on success, non-zero (>0) on failure, ${EX_PKG_DISPATCH_WAIT} mutated post-return. -# -ex_pkg_dispatch() { - local _build_steps_default="${1}" _build_vars_default="${2}" _dispatch_fn="${3}" \ - _group_names="${4}" _groups_inhibit_deps="${5}" _njobs_max="${6}" _pipe_path="${7}" \ - _restart="${8}" _restart_at="${9}" _restart_recursive="${10}" _workdir="${11}" \ - _checkfl=1 _forcefl=0 _perc_group=0 _pkg_name="" _pkg_names="" _rc=0 _reversefl=0 \ - EX_PKG_DISABLED EX_PKG_FINISHED EX_PKG_NAMES EXP_PKG_DISPATCH_COUNT \ - EXP_PKG_DISPATCH_COUNT_CUR EXP_PKG_DISPATCH_COUNT_MAX EXP_PKG_DISPATCH_GROUP_CUR \ - EXP_PKG_DISPATCH_GROUP_MAX EXP_PKG_DISPATCH_NJOBS; EX_PKG_DISPATCH_WAIT=""; - case "${_groups_inhibit_deps:-0}" in - 0) _group_names="$(rtl_uniq $(rtl_lunfold_depends '${_name}_GROUP_DEPENDS' ${_group_names}))"; - esac; - if [ -n "${_restart}" ]; then - case "${_restart_recursive:-0}" in - 0) _checkfl=0; _forcefl=0; _reversefl=0; ;; - 1) _checkfl=1; _forcefl=0; _reversefl=0; ;; - 2) _checkfl=1; _forcefl=1; _reversefl=0; ;; - 3) _checkfl=1; _forcefl=1; _reversefl=1; ;; - esac; - fi; - EXP_PKG_DISPATCH_GROUP_CUR=0; EXP_PKG_DISPATCH_GROUP_MAX="$(rtl_llength "${_group_names}")"; - for _group_name in ${_group_names}; do - EX_PKG_DISABLED=""; EX_PKG_DISPATCH_WAIT=""; EX_PKG_FINISHED=""; EX_PKG_NAMES=""; - EXP_PKG_DISPATCH_COUNT=0; EXP_PKG_DISPATCH_COUNT_CUR=0; EXP_PKG_DISPATCH_COUNT_MAX=0; EXP_PKG_DISPATCH_NJOBS=0; - _perc_group="$(rtl_percentage "${EXP_PKG_DISPATCH_GROUP_CUR}" "${EXP_PKG_DISPATCH_GROUP_MAX}")"; - if "${_dispatch_fn}" start_group "${_group_name}" "" "${EXP_PKG_DISPATCH_GROUP_CUR}" "${EXP_PKG_DISPATCH_GROUP_MAX}" "${_perc_group}"; then - if rtl_fileop mkdir "${_workdir}"\ - && rtl_log_msg "verbose" "${MSG_build_resolving_deps}" "${_group_name}"\ - && exp_pkg_dispatch_expand_packages "${_checkfl}" "${_forcefl}" "${_group_name}" "${_restart}" "${_reversefl}"\ - && exp_pkg_dispatch_complete "${_dispatch_fn}" "${_group_name}" "${EX_PKG_DISABLED}" "${EX_PKG_FINISHED}"\ - && rtl_log_msg "verbose" "${MSG_build_resolved_deps}" "${_group_name}"\ - && EXP_PKG_DISPATCH_COUNT_MAX="$(rtl_llength "${EX_PKG_NAMES}")"\ - && [ "${EXP_PKG_DISPATCH_COUNT_MAX}" -gt 0 ]; then - _pkg_names="$(rtl_lconcat "${_pkg_names}" "${EX_PKG_NAMES}")"; - exp_pkg_dispatch_group "${_build_steps_default}" \ - "${_build_vars_default}" "${_checkfl}" "${_dispatch_fn}" \ - "${_group_name}" "${_njobs_max}" "${_pipe_path}" \ - "${_restart_at}" "${_workdir}"; _rc="${?}"; - fi; - : $((EXP_PKG_DISPATCH_GROUP_CUR+=1)); - _perc_group="$(rtl_percentage "${EXP_PKG_DISPATCH_GROUP_CUR}" "${EXP_PKG_DISPATCH_GROUP_MAX}")"; - "${_dispatch_fn}" finish_group "${_group_name}" "" "${EXP_PKG_DISPATCH_GROUP_CUR}" "${EXP_PKG_DISPATCH_GROUP_MAX}" "${_perc_group}"; - if [ "${_rc}" -ne 0 ]; then - break; - fi; - fi; - done; return "${_rc}"; -}; - -# vim:filetype=sh textwidth=0 diff --git a/subr/ex_pkg_env.subr b/subr/ex_pkg_env.subr deleted file mode 100644 index c13cfdf..0000000 --- a/subr/ex_pkg_env.subr +++ /dev/null @@ -1,157 +0,0 @@ -# -# set +o errexit -o noglob -o nounset is assumed. -# - -# -# exp_pkg_env_defaults() - set package variable defaults for single named package -# @_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 _build_steps_default="${1}" _pkg_name="${2}" _workdir="${3}"; - : ${PKG_NAME:="${_pkg_name}"}; - : ${MIDIPIX_BUILD_PWD:="$(pwd)"}; - : ${PKG_BASE_DIR:="${_workdir}/${_pkg_name}-${PKG_BUILD_TYPE}-${PKG_TARGET}"}; - if [ -n "${PKG_BUILD_STEPS_DISABLE:-}" ]; then - : ${PKG_BUILD_STEPS:="$(rtl_lfilter "${_build_steps_default}" "${PKG_BUILD_STEPS_DISABLE:-}")"}; - else - : ${PKG_BUILD_STEPS:="${_build_steps_default}"}; - fi; - if [ -n "${PKG_URL:-}" ]; then - : ${PKG_FNAME:="${PKG_URL##*/}"}; - fi; - if [ -z "${PKG_SUBDIR:-}" ]; then - if [ -n "${PKG_URLS_GIT:-}" ]\ - && [ -n "${PKG_FNAME:-}" ]; then - rtl_log_msg "fatalexit" "${MSG_pkg_fail_missing_vars}"; - elif [ -n "${PKG_URLS_GIT:-}" ]; then - PKG_SUBDIR="${PKG_URLS_GIT%%=*}"; - else case "${PKG_FNAME:-}" in - *.t*) PKG_SUBDIR="${PKG_FNAME%%.t*}"; ;; - *) PKG_SUBDIR="${_pkg_name}"; ;; - esac; fi; - fi; - if [ -z "${PKG_BUILD_DIR:-}" ]; then - case "${PKG_IN_TREE:-0}" in - 0) PKG_BUILD_DIR="obj"; ;; - 1) PKG_BUILD_DIR="${PKG_SUBDIR}"; ;; - esac; - fi; - PKG_BUILD_DIR="${PKG_BASE_DIR}/${PKG_BUILD_DIR}"; - PKG_CONFIGURE="${PKG_BASE_DIR}/${PKG_CONFIGURE:-${PKG_SUBDIR}/configure}"; - PKG_DESTDIR="${PKG_BASE_DIR}/${PKG_DESTDIR:-destdir}"; - PKG_DESTDIR_HOST="${PKG_BASE_DIR}/${PKG_DESTDIR_HOST:-destdir_host}"; -}; - -# -# exp_pkg_env_set() - set package variables for single named package -# @_build_vars_default: list of default build variables -# @_group_name: build group name -# @_nounset: don't clear package variable namespace -# @_pkg_name: single package name -# -# Sets package variables from either defaults, defaults specific to build type, -# build group, package to inherit from if any, or package for a single named -# package, exports variables optionally named in ${PKG_ENV_VARS_EXTRA}, and -# clears the package variable namespace. -# -# Return: zero (0) on success, non-zero (>0) on failure -# -exp_pkg_env_set() { - local _build_vars_default="${1}" _group_name="${2}" _nounset="${3}" \ - _pkg_name="${4}" _cmd_name="" _var_prefixes="" _vars_set="" \ - _vname="" IFS IFS0; - - 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 - rtl_set_vars _vars_set "${_vname}" \ - "$(rtl_lconcat "${_var_prefixes}" \ - "$(rtl_toupper "PKG_${PKG_INHERIT_FROM} PKG_${PKG_INHERIT_FROM}_${BUILD_KIND} PKG_${_pkg_name} PKG_${_pkg_name}_${BUILD_KIND}")")"; - else - rtl_set_vars _vars_set "${_vname}" \ - "$(rtl_lconcat "${_var_prefixes}" \ - "$(rtl_toupper "PKG_${_pkg_name} PKG_${_pkg_name}_${BUILD_KIND}")")"; - fi; - done; - IFS0="${IFS:- }"; IFS=":"; for _vname in ${PKG_ENV_VARS_EXTRA:-}; do - export "${_vname}"; - done; IFS="${IFS0}"; - if [ "${_nounset:-0}" -eq 0 ]; then - rtl_unset_vars $(rtl_lfilter \ - "$(set | sed -ne '/^PKG_[^=]*=/s/=.*$//p' | paste -s -d " ")" \ - "${_vars_set}"); - fi; - - for _vname in AR CC CXX PKG_CONFIG RANLIB; do - if eval [ '"${PKG_'"${_vname}"':+1}"' = 1 ]\ - && eval [ '"${PKG_'"${_vname}"'#/}"' = '"${_cmd_name:=${PKG_'"${_vname}"'}}"' ]; then - eval PKG_${_vname}='$(which "${_cmd_name}")'; - fi; _cmd_name=""; - done; -}; - -# -# ex_pkg_env() - set package variables for single named package -# @_build_steps_default: list of default build steps -# @_build_vars_default: list of default build variables -# @_group_name: build group name -# @_nounset: don't clear package variable namespace -# @_pkg_name: single package name -# @_restart_at: optional comma-separated list of build steps at which to rebuild or ALL or LAST -# @_workdir: pathname to build-specific temporary directory -# -# Return: zero (0) on success, non-zero (>0) on failure -# -ex_pkg_env() { - local _build_steps_default="${1}" _build_vars_default="${2}" _group_name="${3}" \ - _nounset="${4}" _pkg_name="${5}" _restart_at="${6}" _workdir="${7}" \ - _inherit_from="" _vars_file="" _vname=""; - - if _inherit_from="$(rtl_get_var_unsafe -u "PKG_${_pkg_name}_INHERIT_FROM")"\ - && [ "${#_inherit_from}" -gt 0 ]; then - _vars_file="$(rtl_get_var_unsafe -u "PKG_${_inherit_from}_VARS_FILE")"; - else - _vars_file="$(rtl_get_var_unsafe -u "PKG_${_pkg_name}_VARS_FILE")"; - fi; - if [ "${#_vars_file}" -eq 0 ]; then - _vars_file="vars/${_pkg_name}.vars"; - fi; - - rtl_fileop source_opt "${_vars_file}" "${_group_name}/${_pkg_name}.${_group_name}"; - if ! exp_pkg_env_set "${_build_vars_default}" "${_group_name}" "${_nounset}" "${_pkg_name}"\ - || ! exp_pkg_env_defaults "${_build_steps_default}" "${_pkg_name}" "${_workdir}"; then - return 1; - fi; -}; - -# -# ex_pkg_state_set() - update build step status for single named package -# @_pkg_name: single package name -# @_build_step: build step set status of -# [@${@}]: optional list of build steps to invalidate status of -# -# Return: zero (0) on success, non-zero (>0) on failure -# -ex_pkg_state_set() { - rtl_state_set "${_workdir}" "${@}"; -}; - -# -# ex_pkg_state_test() - test build step status of single named package -# @_pkg_name: single package name -# @_build_step: build step to test status of -# @_restart_at: optional comma-separated list of build steps at which to rebuild or ALL or LAST -# -# Return: zero (0) on success, non-zero (>0) on failure -# -ex_pkg_state_test() { - rtl_state_test "${_workdir}" "${@}"; -}; - -# vim:filetype=sh diff --git a/subr/ex_pkg_exec.subr b/subr/ex_pkg_exec.subr deleted file mode 100644 index cd82756..0000000 --- a/subr/ex_pkg_exec.subr +++ /dev/null @@ -1,136 +0,0 @@ -# -# set +o errexit -o noglob -o nounset is assumed. -# - -exp_pkg_exec_filter_vars_fn() { - local _vname="${1}"; - case "${_vname}" in - DEFAULT|PKG_*) - return 0; ;; - BUILD_DLCACHEDIR|BUILD_WORKDIR|MIDIPIX_BUILD_PWD) - return 0; ;; - CONFIG_CACHE_GNULIB) - return 0; ;; - PREFIX|PREFIX_CROSS|PREFIX_MINGW32|PREFIX_MINIPIX|PREFIX_NATIVE|PREFIX_RPM) - return 0; ;; - *) return 1; ;; - esac; -}; - -# -# exp_pkg_exec_pre() - XXX -# @_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 or LAST -# -# Return: zero (0) on success, non-zero (>0) on failure -# -exp_pkg_exec_pre() { - local _group_name="${1}" _pkg_name="${2}" _restart_at="${3}"; - if [ -z "${PKG_URL:-}" ]\ - && [ -z "${PKG_URLS_GIT:-}" ]\ - && [ -z "${PKG_VERSION:-}" ]\ - && [ -z "${PKG_INSTALL_FILES:-}" ]\ - && [ -z "${PKG_INSTALL_FILES_V2:-}" ]\ - && ! 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 ]\ - && ! rtl_fileop rm "${PKG_BASE_DIR}" "${PKG_BUILD_DIR}" "${PKG_DESTDIR}" "${PKG_DESTDIR_HOST}"\ - || ! rtl_fileop mkdir "${PKG_BASE_DIR}"; then - return 1; - fi; - if ! rtl_fileop mkdir "${PKG_BUILD_DIR}" "${PKG_DESTDIR}"\ - || ! ex_pkg_state_set "${_pkg_name}" "start"; then - return 1; - fi; - elif ! rtl_exists_any "${PKG_BASE_DIR}" "${PKG_BUILD_DIR}" "${PKG_DESTDIR}" "${PKG_DESTDIR_HOST}"\ - && ! rtl_fileop mkdir "${PKG_BASE_DIR}" "${PKG_BUILD_DIR}" "${PKG_DESTDIR}" "${PKG_DESTDIR_HOST}"; then - return 1 - fi; - rtl_fileop cd "${PKG_BUILD_DIR}"; -}; - -# -# exp_pkg_exec_step() - XXX -# @_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 or LAST -# @_step: build step to execute -# -# Return: zero (0) on success, non-zero (>0) on failure -# -exp_pkg_exec_step() { - local _group_name="${1}" _pkg_name="${2}" _restart_at="${3}" _step="${4}" \ - _fn_name="" _pkg_step_fn="" _rc=0; - if rtl_test_cmd "pkg_${_pkg_name}_${_step}"; then - _pkg_step_fn="pkg_${_pkg_name}_${_step}"; - else - _pkg_step_fn="pkg_${_step}"; - fi; - for _fn_name in \ - "pkg_${_pkg_name}_${_step}_pre" \ - "${_pkg_step_fn}" \ - "pkg_${_pkg_name}_${_step}_post"; do - if rtl_test_cmd "${_fn_name}"\ - && ! "${_fn_name}" "${_group_name}" "${_pkg_name}" "${_restart_at}"; then - _rc=1; break; - fi; - done; - return "${_rc}"; -}; - -# -# exp_pkg_exec() - XXX -# @_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 or LAST -# -# Return: zero (0) on success, non-zero (>0) on failure -# -ex_pkg_exec() { - local _dispatch_fn="${1}" _group_name="${2}" _pkg_name="${3}" _restart_at="${4}" \ - _build_step_last="" _rc=0 _step=""; - - if ! exp_pkg_exec_pre "${_group_name}" "${_pkg_name}" "${_restart_at}"\ - || ! "${_dispatch_fn}" start_pkg_child "${_group_name}" "${_pkg_name}"; then - _rc=1; - elif rtl_test_cmd "pkg_${_pkg_name}_all"; then - "pkg_${_pkg_name}_all" "${_restart_at}"; _rc="${?}"; - else set -- ${PKG_BUILD_STEPS}; - while [ ${#} -gt 0 ]; do - _step="${1}"; shift; - if [ "${#_restart_at}" -gt 0 ]\ - && [ "${_restart_at}" != "ALL" ]\ - && [ "${_restart_at}" != "LAST" ]\ - && ! rtl_lmatch "${_restart_at}" "${_step}" ","; then - continue; - fi; - if [ "${_step}" = "${ARG_DUMP_IN}" ]; then - printf "" > "${BUILD_WORKDIR}/${_pkg_name}.dump"; - rtl_filter_vars exp_pkg_exec_filter_vars_fn >> "${BUILD_WORKDIR}/${_pkg_name}.dump"; - export >> "${BUILD_WORKDIR}/${_pkg_name}.dump"; exit 1; - elif [ "${_step}" = "finish" ]; then - ex_pkg_state_set "${_pkg_name}" finish; break; - elif [ "${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 printf "step %s %s %s\n" "${_group_name}" "${_pkg_name}" "${_step}" >&3; - ex_pkg_state_set "${_pkg_name}" "${_step}" "${@}"; - fi; - done; - fi; - if [ "${_rc:-0}" -ne 0 ]\ - && [ "${ARG_DUMP_ON_ABORT:-0}" -eq 1 ]; then - printf "" > "${BUILD_WORKDIR}/${_pkg_name}.dump"; - rtl_filter_vars exp_pkg_exec_filter_vars_fn >> "${BUILD_WORKDIR}/${_pkg_name}.dump"; - export >> "${BUILD_WORKDIR}/${_pkg_name}.dump"; - fi; - return "${_rc}"; -}; - -# vim:filetype=sh diff --git a/subr/ex_pkg_restart.subr b/subr/ex_pkg_restart.subr deleted file mode 100644 index 9e51df8..0000000 --- a/subr/ex_pkg_restart.subr +++ /dev/null @@ -1,293 +0,0 @@ -# -# set +o errexit -o noglob -o nounset is assumed. -# - -# -# exp_pkg_check_restart_at() - XXX -# @_rspec_at: in reference to restart build step list -# -# Calling convention: in ref. @_rspec_at -# Returns: zero (0) on success, non-zero (>0) on failure -# -exp_pkg_check_restart_at() { - local _epcra_rspec_at="${1#\$}" _epcra_len="" _epcra_rc=0 _epcra_spec_at=""; _status="" - - if ! rtl_llift2 "${_epcra_rspec_at}" \$_epcra_spec_at "," " "\ - || ! rtl_lfilter3 \$_epcra_spec_at "${DEFAULT_BUILD_STEPS} ALL LAST"\ - || ! rtl_llength2 \$_epcra_spec_at \$_epcra_len; then - _epcra_rc=1; - elif [ "${_epcra_len}" -gt 0 ]; then - _status="unknown build step(s) \`${_epcra_spec_at}'"; _epcra_rc=1; - fi; return "${_epcra_rc}"; -}; - -# -# exp_pkg_expand_restart_at_spec() - XXX -# @_rset: in reference to restart virtual build step set -# @_rspec_at: inout reference to restart build step list -# -# Calling convention: in ref. @_rset, inout ref. @_rspec_at -# Returns: zero (0) on success, non-zero (>0) on failure -# -exp_pkg_expand_restart_at_spec() { - local _eperas_rset="${1#\$}" _eperas_rspec_at="${2#\$}" _eperas_at="" \ - _eperas_rc=0 _eperas_spec_at="" _eperas_spec_at_=""; _status=""; - eval _eperas_spec_at='${'"${_eperas_rspec_at}"'}'; - - case "${_eperas_spec_at}" in - ALL|LAST|"") - ;; - - ^*) - _eperas_spec_at="${_eperas_spec_at#^}"; - if exp_pkg_expand_restart_at_virtual \ - "${_eperas_spec_at}" \$_eperas_spec_at \ - "${_eperas_rset}" \ - && exp_pkg_check_restart_at \$_eperas_spec_at; then - rtl_llift2 \$DEFAULT_BUILD_STEPS "${_eperas_rspec_at}" " " ","; - rtl_llift2 \$_eperas_spec_at \$_eperas_spec_at_ "," " "; - for _eperas_at in ${_eperas_spec_at_}; do - rtl_lfilter3 "${_eperas_rspec_at}" "${_eperas_at}" ","; - done; rtl_lfilter3 "${_eperas_rspec_at}" "finish" ","; - else - _eperas_rc=1; - fi; ;; - - \<=*|\<*|\>=*|\>*) - exp_pkg_expand_restart_at_spec_cmp \ - "${_eperas_rset}" "${_eperas_rspec_at}"; _eperas_rc="${?}"; ;; - - *) - if ! exp_pkg_expand_restart_at_virtual \ - "${_eperas_spec_at}" "${_eperas_rspec_at}" \ - "${_eperas_rset}"; then - _eperas_rc=1; - fi; ;; - esac; - - if [ "${_eperas_rc}" -eq 0 ]; then - if ! exp_pkg_check_restart_at "${_eperas_rspec_at}"; then - _epprs_rc=1; - elif eval [ '"${'"${_eperas_rspec_at}"':+1}"' != 1 ]; then - _status="zero-length build step list"; _epprs_rc=1; - fi; - fi; - return "${_eperas_rc}"; -}; - -# -# exp_pkg_expand_restart_at_spec_cmp() - XXX -# @_rset: in reference to restart virtual build step set -# @_rspec_at: inout reference to restart build step list -# -# Calling convention: in ref. @_rset, inout ref. @_rspec_at -# Returns: zero (0) on success, non-zero (>0) on failure -# -exp_pkg_expand_restart_at_spec_cmp() { - local _eperasc_rset="${1#\$}" _eperasc_rspec_at="${2#\$}" _eperasc_at="" \ - _eperasc_eqfl="" _eperasc_foundfl="" _eperasc_ltfl="" _eperasc_rc=0 \ - _eperasc_spec_at="" _eperasc_spec_at0=""; - eval _eperasc_spec_at0='${'"${_eperasc_rspec_at}"'}'; - - [ "${_eperasc_spec_at0#<}" = "${_eperasc_spec_at0}" ]; _eperasc_ltfl="${?}"; - if [ "${_eperasc_spec_at0#[<>]=}" != "${_eperasc_spec_at0}" ]; then - _eperasc_spec_at0="${_eperasc_spec_at0#[<>]=}"; _eperasc_eqfl=1; - else - _eperasc_spec_at0="${_eperasc_spec_at0#[<>]}"; _eperasc_eqfl=0; - fi; _eperasc_spec_at=""; - - if exp_pkg_expand_restart_at_virtual \ - "${_eperasc_spec_at0%%,*}" \$_eperasc_spec_at0 \ - "${_eperasc_rset}" \ - && exp_pkg_check_restart_at \$_eperasc_spec_at0; then - if [ \( "${_eperasc_eqfl}" -eq 1 \) -a \( "${_eperasc_ltfl}" -eq 1 \) ]\ - || [ \( "${_eperasc_eqfl}" -eq 0 \) -a \( "${_eperasc_ltfl}" -eq 0 \) ]; then - _eperasc_spec_at0="${_eperasc_spec_at0##*,}"; - elif [ \( "${_eperasc_eqfl}" -eq 1 \) -a \( "${_eperasc_ltfl}" -eq 0 \) ]\ - || [ \( "${_eperasc_eqfl}" -eq 0 \) -a \( "${_eperasc_ltfl}" -eq 1 \) ]; then - _eperasc_spec_at0="${_eperasc_spec_at0%%,*}"; - fi; - - _eperasc_foundfl=0; for _eperasc_at in ${DEFAULT_BUILD_STEPS}; do - if [ "${_eperasc_ltfl}" -eq 1 ]; then - if [ "${_eperasc_at}" = "${_eperasc_spec_at0%%,*}" ]; then - if [ "${_eperasc_eqfl}" -eq 1 ]; then - _eperasc_spec_at="${_eperasc_spec_at:+${_eperasc_spec_at},}${_eperasc_at}"; - fi; break; - fi; - else - if [ "${_eperasc_at}" = "${_eperasc_spec_at0%%,*}" ]; then - _eperasc_foundfl=1; [ "${_eperasc_eqfl}" -eq 0 ] && continue; - fi; [ "${_eperasc_foundfl}" -eq 0 ] && continue; - fi; - _eperasc_spec_at="${_eperasc_spec_at:+${_eperasc_spec_at},}${_eperasc_at}"; - done; - else - _eperasc_rc=1; - fi; - - eval ${_eperasc_rspec_at}='${_eperasc_spec_at}'; - return "${_eperasc_rc}"; -}; - -# -# exp_pkg_expand_restart_at_virtual() - XXX -# @_spec_at: restart build step list -# @_rspec_at_new: out reference to new restart build step list -# @_rset: inout reference to restart virtual build step set -# -# Calling convention: inout ref. @_rspec_recursive -# Returns: zero (0) on success, non-zero (>0) on failure -# -exp_pkg_expand_restart_at_virtual() { - local _epera_spec_at="${1}" _epera_rspec_at_new="${2#\$}" _epera_rset="${3#\$}" \ - _epera_at="" _epera_IFS0="${IFS:- }" _epera_rc=0 _epera_spec_at_new="" \ - IFS; _status=""; - - eval ${_epera_rspec_at_new}=; - IFS=","; set -- ${_epera_spec_at}; IFS="${_epera_IFS0}"; - while [ "${#}" -gt 0 ]; do - _epera_at="${1}"; shift; - if [ "${_epera_at#@}" != "${_epera_at}" ]; then - _epera_at="${_epera_at#@}"; - if [ "${_epera_at%[!0-9a-zA-Z_]*}" != "${_epera_at}" ]; then - _status="invalid virtual build step \`${_epera_at}'"; _epera_rc=1; - elif eval [ '"${'"${_epera_rset}${_epera_at}"':+1}"' = 1 ]; then - eval _epera_at='${'"${_epera_rset}${_epera_at}"'}'; - else - _status="unknown virtual build step \`${_epera_at}'"; _epera_rc=1; - fi; - fi; - eval ${_epera_rspec_at_new}='${'"${_epera_rspec_at_new}"':+${'"${_epera_rspec_at_new}"'},}${_epera_at}'; - done; - return "${_epera_rc}"; -}; - -# -# exp_pkg_expand_restart_recursive() - XXX -# @_rspec: inout reference to restart {specification,package name list} -# @_rrecursive: out reference to recursion flag -# -# Calling convention: inout ref. @_rspec, out ref. @_rrecursive -# Returns: zero (0) on success, non-zero (>0) on failure -# -exp_pkg_expand_restart_recursive() { - local _eperr_rspec="${1#\$}" _eperr_rrecursive="${2#\$}" _eperr_spec=""; _status="" - eval _eperr_spec='${'"${_eperr_rspec}"'}'; - - case "${_eperr_spec}" in - \*\*\*[a-zA-Z]*) - eval ${_eperr_rspec}='${_eperr_spec#\*\*\*}' ${_eperr_rrecursive}=3; ;; - \*\*[a-zA-Z]*) eval ${_eperr_rspec}='${_eperr_spec#\*\*}' ${_eperr_rrecursive}=2; ;; - \*[a-zA-Z]*) eval ${_eperr_rspec}='${_eperr_spec#\*}' ${_eperr_rrecursive}=1; ;; - ALL) eval ${_eperr_rrecursive}=2; ;; - LAST) eval ${_eperr_rrecursive}=0; ;; - esac; - return 0; -}; - -# -# exp_pkg_expand_restart_spec() - XXX -# @_rspec: inout reference to restart {specification,package name list} -# @_rspec_at: out reference to restart build step list -# -# Calling convention: inout ref. @_rspec, out ref. @_rspec_at, out ref. @_rrecursive -# Returns: zero (0) on success, non-zero (>0) on failure -# -exp_pkg_expand_restart_spec() { - local _epers_rspec="${1#\$}" _epers_rspec_at="${2#\$}" _epers_last_pkg="" \ - _epers_rc=0 _epers_spec="" _epers_spec_at="" _epers_spec_at0=""; - eval _epers_spec='${'"${_epers_rspec}"'}'; - - case "${_epers_spec}" in - "") eval ${_epers_rspec_at}=; ;; - ALL) eval ${_epers_rspec_at}=ALL; ;; - LAST|LAST:*) - case "${_epers_spec}" in - LAST) eval ${_epers_rspec_at}=LAST; ;; - LAST:*) eval ${_epers_rspec_at}='${_epers_spec#LAST:}'; ;; - esac; - if [ "${DEFAULT_BUILD_LAST_FAILED_PKG_FNAME:+1}" = 1 ]\ - && [ -e "${DEFAULT_BUILD_LAST_FAILED_PKG_FNAME}" ]; then - if read -r _epers_last_pkg <"${DEFAULT_BUILD_LAST_FAILED_PKG_FNAME}"\ - && rtl_fileop rm "${DEFAULT_BUILD_LAST_FAILED_PKG_FNAME}"; then - eval ${_epers_rspec}='${_epers_last_pkg}'; - else - _status="failed to read or clear status of last failed package \`${_epers_last_pkg}'"; _epers_rc=1; - fi; - else - _status="cannot rebuild last failed package"; _epers_rc=1; - fi; ;; - - *:*) eval ${_epers_rspec}='${_epers_spec%:*}' ${_epers_rspec_at}='${_epers_spec#*:}'; ;; - *) eval ${_epers_rspec_at}= ${_epers_rspec_at}=ALL; ;; - esac; - return "${_epers_rc}"; -}; - -# -# exp_pkg_init_restart_at_virtual() - XXX -# @_rset: out reference to restart virtual build step set -# -# Calling convention: out ref. @_rset -# Returns: zero (0) on success, non-zero (>0) on failure -# -exp_pkg_init_restart_at_virtual() { - local _eperav_rset="${1#\$}" _eperav_step="" _eperav_step_virtual="" _epera_steps=""; - - rtl_lfilter2 \$DEFAULT_BUILD_STEPS \$_epera_steps "finish"; - for _eperav_step in ${_epera_steps}; do - _eperav_step_virtual="${_eperav_step%%_*}"; - if eval [ '"${'"${_eperav_rset}${_eperav_step_virtual}"':+1}"' != 1 ]; then - eval ${_eperav_rset}='"${'"${_eperav_rset}"':+${'"${_eperav_rset}"'},}${_eperav_step_virtual}"'; - fi; - eval ${_eperav_rset}${_eperav_step_virtual}='"${'"${_eperav_rset}${_eperav_step_virtual}"':+${'"${_eperav_rset}${_eperav_step_virtual}"'},}${_eperav_step}"'; - done; return 0; -}; - -# -# ex_pkg_process_restart_spec() - XXX -# @_rspec: inout reference to restart {specification,package name list} -# @_rspec_at: out reference to restart build step list -# @_rrecursive: out reference to restart recursion flag -# -# Calling convention: inout ref. @_rspec, out ref. @_rspec_at -# Returns: zero (0) on success, non-zero (>0) on failure -# -ex_pkg_process_restart_spec() { - local _epprs_rspec="${1#\$}" _epprs_rspec_at="${2#\$}" _epprs_rrecursive="${3#\$}" \ - _epprs_at="" _epprs_rc=0 _epprs_spec_at_new="" _epprs_step="" _epprs_step1="" \ - _epprs_virtual_set=""; _status=""; - - if eval [ '"${'"${_epprs_rspec}"':+1}"' = 1 ]; then - if exp_pkg_init_restart_at_virtual \$_epprs_virtual_set \ - && exp_pkg_expand_restart_spec "${_epprs_rspec}" \$_epprs_spec_at_new \ - && exp_pkg_expand_restart_recursive "${_epprs_rspec}" "${_epprs_rrecursive}" \ - && exp_pkg_expand_restart_at_spec \$_epprs_virtual_set \$_epprs_spec_at_new; then - eval ${_epprs_rspec_at}=; - case "${_epprs_spec_at_new}" in - ALL|LAST) - eval ${_epprs_rspec_at}='${_epprs_spec_at_new}'; ;; - *) - for _epprs_at in ${DEFAULT_BUILD_STEPS}; do - if rtl_lmatch "${_epprs_at}" "${_epprs_spec_at_new}" ","; then - eval ${_epprs_rspec_at}='${'"${_epprs_rspec_at}"':+${'"${_epprs_rspec_at}"'},}${_epprs_at}'; - fi; - done; - if eval [ '"${'"${_epprs_rspec_at}"'##*,}"' != "finish" ]; then - rtl_lfilter2 "${_epprs_rspec_at}" \$_epprs_step "clean,finish" ","; _epprs_step="${_epprs_step##*,}"; - rtl_lfilter2 \$DEFAULT_BUILD_STEPS \$_epprs_step1 "clean finish"; _epprs_step1="${_epprs_step1##* }"; - if [ "${_epprs_step}" = "${_epprs_step1}" ]; then - eval ${_epprs_rspec_at}='${'"${_epprs_rspec_at}"':+${'"${_epprs_rspec_at}"'},}finish'; - fi; - fi; ;; - esac; rtl_llift3 "${_epprs_rspec}" "," " " || _epprs_rc=1; - else - _epprs_rc=1; - fi; - rtl_sunset \$_epprs_virtual_set; - fi; - return "${_epprs_rc}"; -}; - -# vim:filetype=sh diff --git a/subr/pkg_build.subr b/subr/pkg_build.subr deleted file mode 100644 index 1c6712f..0000000 --- a/subr/pkg_build.subr +++ /dev/null @@ -1,54 +0,0 @@ -# -# set +o errexit -o noglob -o nounset is assumed. -# - -pkg_build() { - local _libtool="" _makeflags_verbosity="${PKG_MAKEFLAGS_VERBOSITY:-none}" _no_autoconf="" _rc=0 _subdir=""; - case "${PKG_LIBTOOL:-}" in - "") _libtool=""; ;; - none) _libtool=""; ;; - *) _libtool="${PKG_LIBTOOL}"; ;; - esac; - if [ "${_makeflags_verbosity}" = "none" ]; then - _makeflags_verbosity=""; - fi; - if [ ! -x "${PKG_CONFIGURE:-}" ]; then - _no_autoconf=1; - fi; - for _subdir in ${PKG_MAKE_SUBDIRS:-:}; do - if [ "${_subdir}" = ":" ]; then - _subdir=""; - fi; - if [ "${#_libtool}" -gt 0 ]; then - export MAKE="make LIBTOOL=${_libtool}"; - fi; - # 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. - rtl_run_cmd_unsplit "${PKG_MAKE}" \ - ${PKG_MAKEFLAGS_BUILD:-} \ - ${PKG_MAKEFLAGS_BUILD_EXTRA:-} \ - "AR=${PKG_AR}" "${_no_autoconf:+CC=${PKG_CC}}" "RANLIB=${PKG_RANLIB}" \ - "${PKG_CFLAGS_BUILD:+CFLAGS=${PKG_CFLAGS_BUILD}}" \ - "${PKG_CFLAGS_BUILD_EXTRA:+CFLAGS+=${PKG_CFLAGS_BUILD_EXTRA}}" \ - "${PKG_CPPFLAGS_BUILD:+CPPFLAGS=${PKG_CPPFLAGS_BUILD}}" \ - "${PKG_CPPFLAGS_BUILD_EXTRA:+CPPFLAGS+=${PKG_CPPFLAGS_BUILD_EXTRA}}" \ - "${PKG_CXXFLAGS_BUILD:+CXXFLAGS=${PKG_CXXFLAGS_BUILD}}" \ - "${PKG_CXXFLAGS_BUILD_EXTRA:+CXXFLAGS+=${PKG_CXXFLAGS_BUILD_EXTRA}}" \ - "${PKG_LDFLAGS_BUILD:+LDFLAGS=${PKG_LDFLAGS_BUILD}}" \ - "${PKG_LDFLAGS_BUILD_EXTRA:+LDFLAGS+=${PKG_LDFLAGS_BUILD_EXTRA}}" \ - "${PKG_PKG_CONFIG:+PKG_CONFIG=${PKG_PKG_CONFIG}}" \ - "${PKG_PKG_CONFIG_LIBDIR:+PKG_CONFIG_LIBDIR=${PKG_PKG_CONFIG_LIBDIR}}" \ - ${_libtool:+"LIBTOOL=${_libtool}"} \ - ${_makeflags_verbosity} \ - ${_subdir:+-C "${_subdir}"}; _rc="${?}"; - if [ "${#_libtool}" -gt 0 ]; then - unset MAKE; - fi; - if [ "${_rc}" -ne 0 ]; then - return 1; - fi; - done; -}; - -# vim:filetype=sh diff --git a/subr/pkg_build_clean.subr b/subr/pkg_build_clean.subr deleted file mode 100644 index 55dc19c..0000000 --- a/subr/pkg_build_clean.subr +++ /dev/null @@ -1,33 +0,0 @@ -# -# set +o errexit -o noglob -o nounset is assumed. -# - -pkg_build_clean() { - local _libtool="" _makeflags_verbosity="${PKG_MAKEFLAGS_VERBOSITY:-}" \ - _no_autoconf="" _rc=0 _subdir=""; - - if ex_pkg_state_test "${_pkg_name}" "build" "${_restart_at}"; then - case "${PKG_LIBTOOL:-}" in - "") _libtool=""; ;; - none) _libtool=""; ;; - *) _libtool="${PKG_LIBTOOL}"; ;; - esac; - [ ! -x "${PKG_CONFIGURE:-}" ] && _no_autoconf=1; - - for _subdir in ${PKG_MAKE_SUBDIRS:-:}; do - [ "${_subdir}" = ":" ] && _subdir=""; - [ "${#_libtool}" -gt 0 ] && export MAKE="make LIBTOOL=${_libtool}"; - rtl_run_cmd_unsplit "${PKG_MAKE}" \ - ${PKG_MAKEFLAGS_BUILD:-} \ - ${PKG_MAKEFLAGS_BUILD_EXTRA:-} \ - ${_libtool:+"LIBTOOL=${_libtool}"} \ - ${_makeflags_verbosity} \ - ${_subdir:+-C "${_subdir}"} \ - clean; _rc="${?}"; - [ "${#_libtool}" -gt 0 ] && unset MAKE; - [ "${_rc}" -ne 0 ] && return 1; - done; return 0; - fi; -}; - -# vim:filetype=sh diff --git a/subr/pkg_clean.subr b/subr/pkg_clean.subr deleted file mode 100644 index e8f1899..0000000 --- a/subr/pkg_clean.subr +++ /dev/null @@ -1,29 +0,0 @@ -# -# set +o errexit -o noglob -o nounset is assumed. -# - -pkg_clean() { - if [ "${PKG_NO_CLEAN:-0}" -eq 0 ]; then - if rtl_lmatch "${ARG_CLEAN_BUILDS}" "build" ","\ - && [ "${PKG_NO_CLEAN_BUILD_DIR:-0}" -eq 0 ]; then - if ! rtl_fileop rm "${PKG_BUILD_DIR}"; then - return 1; - fi; - fi; - if rtl_lmatch "${ARG_CLEAN_BUILDS}" "dest" ","; then - if ! rtl_fileop rm "${PKG_DESTDIR}"; then - return 1; - elif [ -e "${PKG_DESTDIR_HOST}" ]\ - && ! rtl_fileop rm "${PKG_DESTDIR_HOST}"; then - return 1; - fi; - fi; - if rtl_lmatch "${ARG_CLEAN_BUILDS}" "src" ","; then - if ! rtl_fileop rm "${PKG_BASE_DIR}/${PKG_SUBDIR}"; then - return 1; - fi; - fi; - fi; -}; - -# vim:filetype=sh diff --git a/subr/pkg_configure.subr b/subr/pkg_configure.subr deleted file mode 100644 index ea26507..0000000 --- a/subr/pkg_configure.subr +++ /dev/null @@ -1,184 +0,0 @@ -# -# set +o errexit -o noglob -o nounset is assumed. -# - -pkgp_configure_autotools() { - local _libtool="" _rc=0; - - if ! [ -x "${PKG_CONFIGURE:-}" ]; then - return 2; - elif [ -d "${PKG_BASE_DIR}/${PKG_SUBDIR}/sofort" ]\ - || [ "${PKG_CONFIGURE_TYPE:-}" = "sofort" ]; then - return 2; - else - case "${PKG_LIBTOOL:-}" in - "") _libtool=""; ;; - none) _libtool=""; ;; - *) _libtool="${PKG_LIBTOOL}"; ;; - esac; - - rtl_export_vars \ - PKG_CONFIG "${PKG_PKG_CONFIG:-}" \ - PKG_CONFIG_LIBDIR "${PKG_PKG_CONFIG_LIBDIR:-}" \ - PYTHON "${PKG_PYTHON:-}" \ - ${_libtool:+MAKE} ${_libtool:+"make LIBTOOL=${_libtool}"}; - - AR="${PKG_AR}" \ - CC="${PKG_CC}" \ - RANLIB="${PKG_RANLIB}" \ - CFLAGS="${PKG_CFLAGS_CONFIGURE:-}${PKG_CFLAGS_CONFIGURE_EXTRA:+ ${PKG_CFLAGS_CONFIGURE_EXTRA}}" \ - CPPFLAGS="${PKG_CFLAGS_CONFIGURE:-}${PKG_CFLAGS_CONFIGURE_EXTRA:+ ${PKG_CFLAGS_CONFIGURE_EXTRA}}" \ - 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=$((${?} ? 1 : ${_rc})); - - rtl_export_vars -u \ - PKG_CONFIG "${PKG_PKG_CONFIG:-}" \ - PKG_CONFIG_LIBDIR "${PKG_PKG_CONFIG_LIBDIR:-}" \ - PYTHON "${PKG_PYTHON:-}" \ - ${_libtool:+MAKE} ${_libtool:+"make LIBTOOL=${_libtool}"}; - return "${_rc}"; - fi; -}; - -pkgp_configure_cmake() { - local _cmake_args_auto"" _build_type="" _IFS0="${IFS:- }" _rc=0 IFS; - - if [ "${PKG_CMAKE_LISTFILE:+1}" != 1 ]\ - || ! [ -e "${PKG_BASE_DIR}/${PKG_SUBDIR}/${PKG_CMAKE_LISTFILE}" ]; then - _rc=2; - else - rtl_fileop rm config.cache || return 1; - rtl_export_vars \ - PKG_CONFIG "${PKG_PKG_CONFIG:-}" \ - PKG_CONFIG_LIBDIR "${PKG_PKG_CONFIG_LIBDIR:-}" \ - PYTHON "${PKG_PYTHON:-}"; - - case "${BUILD_KIND}" in - debug) _build_type="debug"; ;; - release|*) _build_type="release"; ;; - esac; - - _cmake_args_auto=" - -DCMAKE_AR=${PKG_AR} - -DCMAKE_BUILD_TYPE=${_build_type} - -DCMAKE_C_COMPILER=${PKG_CC} - -DCMAKE_C_FLAGS=${PKG_CFLAGS_CONFIGURE:-}${PKG_CFLAGS_CONFIGURE_EXTRA:+ ${PKG_CFLAGS_CONFIGURE_EXTRA}} - -DCMAKE_CPP_FLAGS=${PKG_CPPFLAGS_CONFIGURE:-}${PKG_CPPFLAGS_CONFIGURE_EXTRA:+ ${PKG_CPPFLAGS_CONFIGURE_EXTRA}} - -DCMAKE_CXX_COMPILER=${PKG_CXX} - -DCMAKE_CXX_FLAGS=${PKG_CXXFLAGS_CONFIGURE:-}${PKG_CXXFLAGS_CONFIGURE_EXTRA:+ ${PKG_CXXFLAGS_CONFIGURE_EXTRA}} - -DCMAKE_EXE_LINKER_FLAGS=${PKG_LDFLAGS_CONFIGURE:-}${PKG_LDFLAGS_CONFIGURE_EXTRA:+ ${PKG_LDFLAGS_CONFIGURE_EXTRA}} - -DCMAKE_FIND_ROOT_PATH=${PKG_PREFIX} - -DCMAKE_INSTALL_PREFIX= - -DCMAKE_LINKER=$(which "ld") - -DCMAKE_MODULE_LINKER_FLAGS=${PKG_LDFLAGS_CONFIGURE:-}${PKG_LDFLAGS_CONFIGURE_EXTRA:+ ${PKG_LDFLAGS_CONFIGURE_EXTRA}} - -DCMAKE_RANLIB=${PKG_RANLIB} - -DCMAKE_SHARED_LINKER_FLAGS=${PKG_LDFLAGS_CONFIGURE:-}${PKG_LDFLAGS_CONFIGURE_EXTRA:+ ${PKG_LDFLAGS_CONFIGURE_EXTRA}} - -DPKG_CONFIG_EXECUTABLE=${PKG_PKG_CONFIG}" || return 1; - - case "${PKG_BUILD_TYPE}" in - host|cross) - ;; - native) - _cmake_args_auto="${_cmake_args_auto:+${_cmake_args_auto}} - -DCMAKE_LINKER=$(which "${PKG_TARGET}-ld") - -DCMAKE_SYSROOT=${PKG_PREFIX} - -DCMAKE_SYSTEM_NAME=Midipix" || return 1; - - case "${ARCH}" in - nt32) _cmake_args_auto="${_cmake_args_auto:+${_cmake_args_auto}} - -DCMAKE_SYSTEM_PROCESSOR=i686"; ;; - nt64) _cmake_args_auto="${_cmake_args_auto:+${_cmake_args_auto}} - -DCMAKE_SYSTEM_PROCESSOR=x86_64"; ;; - esac; ;; - esac; - - IFS=" - "; "${PKG_CMAKE}" \ - ${_cmake_args_auto} \ - ${PKG_CMAKE_ARGS:-} \ - ${PKG_CMAKE_ARGS_EXTRA:-} \ - "${PKG_BASE_DIR}/${PKG_SUBDIR}"; - _rc=$((${?} ? ${?} : ${_rc})); IFS="${_IFS0}"; - - rtl_export_vars -u \ - PKG_CONFIG "${PKG_PKG_CONFIG:-}" \ - PKG_CONFIG_LIBDIR "${PKG_PKG_CONFIG_LIBDIR:-}" \ - PYTHON "${PKG_PYTHON:-}"; - fi; - return "${_rc}"; -}; - -pkgp_configure_sofort() { - local _rc=0 _vname="" _vnames="" _vval=""; - - if ! [ -x "${PKG_CONFIGURE:-}" ]; then - return 2; - elif ! [ -d "${PKG_BASE_DIR}/${PKG_SUBDIR}/sofort" ]\ - && ! [ "${PKG_CONFIGURE_TYPE:-}" = "sofort" ]; then - return 2; - else - for _vname in AR CC CXX LD RANLIB; do - if eval [ '"${PKG_'"${_vname}"':+1}"' = 1 ]; then - _vnames="${_vnames:+${_vnames} }${_vname}"; - eval ${_vname}='${PKG_'"${_vname}"'}'; export ${_vname}; - fi; - if eval [ '"${PKG_SOFORT_NATIVE_'"${_vname}"':+1}"' = 1 ]; then - _vnames="${_vnames:+${_vnames} }NATIVE_${_vname}"; - eval NATIVE_${_vname}='${PKG_SOFORT_NATIVE_'"${_vname}"'}'; export NATIVE_${_vname}; - fi; - done; - for _vname in CFLAGS CPPFLAGS CXXFLAGS LDFLAGS; do - if eval [ '"${PKG_'"${_vname}"'_CONFIGURE:+1}"' = 1 ]; then - eval _vval='${PKG_'"${_vname}"'_CONFIGURE}'; - if eval [ '"${PKG_'"${_vname}"'_CONFIGURE_EXTRA:+1}"' = 1 ]; then - eval _vval='${_vval:+${_vval} }${PKG_'"${_vname}"'_CONFIGURE_EXTRA}'; - fi; - _vnames="${_vnames:+${_vnames} }${_vname} ${_vname}_SHARED ${_vname}_STATIC"; - eval ${_vname}='${_vval}'\; ${_vname}_SHARED='${_vval}'\; ${_vname}_STATIC='${_vval}'; - export ${_vname} ${_vname}_SHARED ${_vname}_STATIC; - fi; - if eval [ '"${PKG_SOFORT_NATIVE_'"${_vname}"':+1}"' = 1 ]; then - eval _vval='${PKG_SOFORT_NATIVE_'"${_vname}"'}'; - if eval [ '"${PKG_SOFORT_NATIVE_'"${_vname}"'_EXTRA:+1}"' = 1 ]; then - eval _vval='${_vval:+${_vval} }${PKG_SOFORT_NATIVE_'"${_vname}"'_EXTRA}'; - fi; - _vnames="${_vnames:+${_vnames} }NATIVE_${_vname}"; - eval NATIVE_${_vname}='${_vval}'; export NATIVE_${_vname}; - fi; - done; - - RANLIB="${PKG_RANLIB}" \ - "${PKG_CONFIGURE}" \ - ${PKG_CONFIGURE_ARGS:-} \ - ${PKG_CONFIGURE_ARGS_EXTRA:-} \ - ${PKG_CONFIGURE_ARGS_EXTRA_DEBUG:-}; - _rc=$((${?} ? 1 : ${_rc})); - - for _vname in ${_vnames}; do - unset "${_vname}"; - done; - return "${_rc}"; - fi; -}; - -pkg_configure() { - local _rc=0 _type=""; - - for _type in autotools sofort cmake; do - if [ "${PKG_CONFIGURE_TYPE:+1}" = 1 ]\ - && [ "${PKG_CONFIGURE_TYPE}" != "${_type}" ]; then - continue; - else - pkgp_configure_${_type} "${@}"; _rc="${?}"; - case "${_rc}" in - 0|1) return "${_rc}"; ;; - 2) _rc=0; continue; ;; - esac; - fi; - done; - return "${_rc}"; -}; - -# vim:filetype=sh textwidth=0 diff --git a/subr/pkg_configure_autotools.subr b/subr/pkg_configure_autotools.subr deleted file mode 100644 index 15d7656..0000000 --- a/subr/pkg_configure_autotools.subr +++ /dev/null @@ -1,99 +0,0 @@ -# -# set +o errexit -o noglob -o nounset is assumed. -# - -pkg_configure_autotools() { - local _config_cache="" _config_guest_fname="" _fname="" _subdir_tgt=""; - - if [ "${PKG_CONFIGURE_TYPE:+1}" = 1 ]\ - && [ "${PKG_CONFIGURE_TYPE}" != "autotools" ]; then - return 0; - fi; - - if [ "${PKG_AUTOCONF_CONFIG_GUESS:-midipix}" = "midipix" ]; then - _config_guest_fname="config.guess"; - else - _config_guest_fname=""; - fi; - - if rtl_exists_any "${PKG_BASE_DIR}/${PKG_SUBDIR}" \ - ${_config_guest_fname:+"${_config_guest_fname}"} \ - "configure.ac" "configure.in" "configure"; - then rtl_export_vars PKG_CONFIG "${PKG_PKG_CONFIG:-}" PKG_CONFIG_LIBDIR "${PKG_PKG_CONFIG_LIBDIR:-}"; - if [ "${PKG_FORCE_AUTORECONF:-0}" -eq 1 ]\ - && ! (cd "${PKG_BASE_DIR}/${PKG_SUBDIR}" && autoreconf -fiv); then - return 1; - fi; - 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 - if [ -e "${PKG_BASE_DIR}/${PKG_SUBDIR}/${_fname}" ]; then - for _subdir_tgt in \ - "${PKG_BASE_DIR}/${PKG_SUBDIR}/build-aux" \ - "${PKG_BASE_DIR}/${PKG_SUBDIR}"; - do if [ -e "${_subdir_tgt}" ]; then - if ! rtl_fileop install -m 0700 \ - "${MIDIPIX_BUILD_PWD}/etc/config.sub" \ - "${_subdir_tgt}/config.sub"; then - return 1; - fi; - if [ "${PKG_AUTOCONF_CONFIG_GUESS:-midipix}" = "midipix" ]; then - if ! rtl_fileop install -m 0700 \ - "${MIDIPIX_BUILD_PWD}/etc/config.guess"\ - "${_subdir_tgt}/config.guess"; then - return 1; - else - break; - fi; - fi; - fi; - done; - if ! (rtl_fileop cd "${PKG_BASE_DIR}/${PKG_SUBDIR}" && \ - /bin/sh "${_fname}"); then - return 1; - else - break; - fi; - fi; - done; - if ! (rtl_fileop cd "${PKG_BASE_DIR}/${PKG_SUBDIR}" && autoconf); then - return 1; - fi; - fi; - for _fname in $(find "${PKG_BASE_DIR}/${PKG_SUBDIR}" -name config.sub); do - 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_AUTOCONF_CONFIG_GUESS:-midipix}" = "midipix" ]; then - for _fname in $(find "${PKG_BASE_DIR}/${PKG_SUBDIR}" -name config.guess); do - if ! rtl_fileop mv "${_fname}" "${_fname}.orig"\ - || ! rtl_fileop install -m 0700 "${MIDIPIX_BUILD_PWD}/etc/config.guess" "${_fname}"; then - return 1; - fi; - done; - fi; - if [ "${PKG_BUILD_TYPE}" != host ]; then - if ! rtl_fileop touch "${PKG_BUILD_DIR}/config.cache"; then - return 1; - else for _config_cache in \ - "${PKG_CONFIG_CACHE:-}" \ - "${PKG_CONFIG_CACHE_LOCAL:-}" \ - "${PKG_CONFIG_CACHE_EXTRA:-}"; - do if [ -n "${_config_cache}" ]\ - && ! printf "%s\n" "${_config_cache}" |\ - tr " " "\n" >> "${PKG_BUILD_DIR}/config.cache"; then - return 1; - fi; - done; - if ! sed -i"" "s,%PREFIX%,${PKG_PREFIX},g" "${PKG_BUILD_DIR}/config.cache"; then - return 1; - fi; - fi; - fi; - rtl_export_vars -u PKG_CONFIG "${PKG_PKG_CONFIG:-}" PKG_CONFIG_LIBDIR "${PKG_PKG_CONFIG_LIBDIR:-}"; - fi; -}; - -# vim:filetype=sh diff --git a/subr/pkg_configure_clean.subr b/subr/pkg_configure_clean.subr deleted file mode 100644 index 48549a9..0000000 --- a/subr/pkg_configure_clean.subr +++ /dev/null @@ -1,20 +0,0 @@ -# -# set +o errexit -o noglob -o nounset is assumed. -# - -pkg_configure_clean() { - local _group_name="${1}" _pkg_name="${2}" _restart_at="${3}"; - - if ex_pkg_state_test \ - "${_pkg_name}" \ - "configure_patch_pre,configure_autotools,configure_patch,configure" \ - "${_restart_at}"; then - if [ "${PKG_BUILD_DIR:-}" != "${PKG_SUBDIR:-}" ]; then - rtl_fileop rm "${PKG_BUILD_DIR}" || return 1; - rtl_fileop mkdir "${PKG_BUILD_DIR}" || return 1; - rtl_fileop cd "${PKG_BUILD_DIR}" || return 1; - fi; - fi; -}; - -# vim:filetype=sh diff --git a/subr/pkg_configure_patch.subr b/subr/pkg_configure_patch.subr deleted file mode 100644 index d7c8401..0000000 --- a/subr/pkg_configure_patch.subr +++ /dev/null @@ -1,33 +0,0 @@ -# -# set +o errexit -o noglob -o nounset is assumed. -# - -pkg_configure_patch() { - local _patch_cwd="" _patch_dir="${MIDIPIX_BUILD_PWD}/patches" _patch_fname=""\ - _patches_done="" _pkg_name_full="${PKG_NAME}${PKG_VERSION:+-${PKG_VERSION}}"\ - _strip_count=0; - - if [ -n "${PKG_FNAME:-}" ]\ - && [ -n "${PKG_URLS_GIT:-}" ]; then - _patch_cwd="${PKG_BASE_DIR}"; _strip_count=0; - else - _patch_cwd="${PKG_BASE_DIR}/${PKG_SUBDIR}"; _strip_count=1; - fi; - set +o noglob; - for _patch_fname in \ - "${_patch_dir}/${_pkg_name}/"*.patch \ - "${_patch_dir}/${_pkg_name_full}.local.patch" \ - "${_patch_dir}/${_pkg_name_full}.local@${BUILD_HNAME}.patch" \ - ${PKG_PATCHES_EXTRA:-}; do - if [ -r "${_patch_fname}" ]\ - && ! rtl_lmatch "${_patches_done}" "${_patch_fname}"; then - if ! patch -b -d "${_patch_cwd}" "-p${_strip_count}" < "${_patch_fname}"; then - set -o noglob; return 1; - else - _patches_done="$(rtl_lconcat "${_patches_done}" "${_patch_fname}")"; - fi; - fi; - done; set -o noglob; -}; - -# vim:filetype=sh diff --git a/subr/pkg_configure_patch_pre.subr b/subr/pkg_configure_patch_pre.subr deleted file mode 100644 index c78b65b..0000000 --- a/subr/pkg_configure_patch_pre.subr +++ /dev/null @@ -1,38 +0,0 @@ -# -# set +o errexit -o noglob -o nounset is assumed. -# - -pkgp_configure_patch_pre() { - local _patch_path=""; - for _patch_path in \ - "${MIDIPIX_BUILD_PWD}/patches/${PKG_NAME}${PKG_VERSION:+-${PKG_VERSION}}_pre.local.patch" \ - "${MIDIPIX_BUILD_PWD}/patches/${PKG_NAME}${PKG_VERSION:+-${PKG_VERSION}}_pre.local@${BUILD_HNAME}.patch"; do - if [ -r "${_patch_path}" ]\ - && ! patch -b -d "${PKG_BASE_DIR}/${PKG_SUBDIR}" -p1 < "${_patch_path}"; then - return 1; - fi; - done; -}; - -pkgp_configure_patch_pre_chainport() { - local _chainport_patch_dname="" _chainport_patch_fname="" _oldpwd=""; - _chainport_patch_dname="${PKG_BASE_DIR}/${PKG_SUBDIR}/patches/${PKG_NAME%%_*}"; - if [ -n "${PKG_VERSION:-}" ]; then - _chainport_patch_fname="${BUILD_WORKDIR}/chainport/patches/${PKG_NAME%%_*}/${PKG_NAME%%_*}-${PKG_VERSION}.midipix.patch"; - fi; - if [ -e "${_chainport_patch_fname}" ]; then - if ! rtl_fileop mkdir "${_chainport_patch_dname}"\ - || ! rtl_fileop cp "${_chainport_patch_fname}" "${_chainport_patch_dname}"; then - return 1; - fi; - fi; -}; - -pkg_configure_patch_pre() { - if ! pkgp_configure_patch_pre_chainport\ - || ! pkgp_configure_patch_pre; then - return 1; - fi; -}; - -# vim:filetype=sh diff --git a/subr/pkg_fetch_clean.subr b/subr/pkg_fetch_clean.subr deleted file mode 100644 index 5279706..0000000 --- a/subr/pkg_fetch_clean.subr +++ /dev/null @@ -1,21 +0,0 @@ -# -# set +o errexit -o noglob -o nounset is assumed. -# - -pkg_fetch_clean() { - local _dname=""; - - if [ -n "${PKG_URLS_GIT:-}" ]; then - if [ -n "${PKG_SUBDIR:-}" ]\ - && [ "${PKG_SUBDIR}" != "${PKG_URLS_GIT%%=*}" ]; then - rtl_fileop rm "${PKG_SUBDIR}"; - fi; - for _dname in ${PKG_URLS_GIT}; do - _dname="${_dname%%=*}"; rtl_fileop rm "${_dname}"; - done; - elif [ -n "${PKG_SUBDIR}" ]; then - rtl_fileop rm "${PKG_SUBDIR}"; - fi; return 0; -}; - -# vim:filetype=sh diff --git a/subr/pkg_fetch_download.subr b/subr/pkg_fetch_download.subr deleted file mode 100644 index 7a33394..0000000 --- a/subr/pkg_fetch_download.subr +++ /dev/null @@ -1,67 +0,0 @@ -# -# set +o errexit -o noglob -o nounset is assumed. -# - -pkg_fetch_download_clean_dlcache() { - local _dlcachedir="${1}" _pkg_name="${2}" _pkg_fname="${3}" _pkg_urls_git="${4}"\ - _fname="" _skipfl=0 _url_spec="" _url_subdir=""; - - for _fname in $(cd "${_dlcachedir}/${_pkg_name}" 2>/dev/null && find \ - -maxdepth 1 \ - -mindepth 1 \ - ${_pkg_fname:+-not -name "${_pkg_fname}"} \ - ${_pkg_fname:+-not -name "${_pkg_fname}.fetched"}); do - _fname="${_fname#./}"; _skipfl=0; - for _url_spec in ${_pkg_urls_git}; do - _url_subdir="${_url_spec%%=*}"; _url_subdir="${_url_subdir##*/}"; - if [ "${_fname%.git}" = "${_url_subdir}" ]; then - _skipfl=1; break; - fi; - done; - if [ "${_skipfl}" -eq 0 ]; then - _fname="${_dlcachedir}/${_pkg_name}/${_fname}"; - rtl_log_msg "verbose" "${MSG_rtl_fetch_rm_redundant}" "${_fname}" "${_pkg_name}"; - rtl_fileop rm "${_fname}"; - fi; - done; -}; - -pkg_fetch_download_dlcache_subdir() { - if [ -n "${PKG_INHERIT_FROM:-}" ]\ - && ! [ -e "${BUILD_DLCACHEDIR}/${PKG_NAME}" ]\ - && ! rtl_fileop ln_symbolic "${PKG_INHERIT_FROM}" "${BUILD_DLCACHEDIR}/${PKG_NAME}"; then - return 1; - elif [ -z "${PKG_INHERIT_FROM:-}" ]\ - && ! [ -e "${BUILD_DLCACHEDIR}/${PKG_NAME}" ]\ - && ! rtl_fileop mkdir "${BUILD_DLCACHEDIR}/${PKG_NAME}"; then - return 1; - else - return 0; - fi; -}; - -pkg_fetch_download() { - if [ "${ARG_FETCH_FORCE:-}" != "offline" ]; then - if [ -n "${PKG_URL:-}" ]; then - if ! pkg_fetch_download_dlcache_subdir; then - return 1; - elif ! rtl_fetch_url_wget \ - "${PKG_URL}" "${PKG_SHA256SUM}" "${BUILD_DLCACHEDIR}/${PKG_NAME}"\ - "${PKG_FNAME}" "${PKG_NAME}" "${PKG_MIRRORS:-}"; then - return 1; - fi; - fi; - if [ -n "${PKG_URLS_GIT:-}" ]; then - if ! pkg_fetch_download_dlcache_subdir; then - return 1; - elif ! rtl_fetch_urls_git \ - "${BUILD_DLCACHEDIR}/${PKG_NAME}" "${DEFAULT_GIT_ARGS}" "${PKG_BASE_DIR}"\ - "${PKG_NAME}" "${PKG_MIRRORS_GIT:-}" ${PKG_URLS_GIT}; then - return 1; - fi; - fi; - pkg_fetch_download_clean_dlcache "${BUILD_DLCACHEDIR}" "${PKG_NAME}" "${PKG_FNAME:-}" "${PKG_URLS_GIT:-}"; - fi; -}; - -# vim:filetype=sh diff --git a/subr/pkg_fetch_extract.subr b/subr/pkg_fetch_extract.subr deleted file mode 100644 index b86c490..0000000 --- a/subr/pkg_fetch_extract.subr +++ /dev/null @@ -1,37 +0,0 @@ -# -# set +o errexit -o noglob -o nounset is assumed. -# - -pkgp_fetch_extract_type() { - local _fname="${1}"; - if [ "${1##*.tar.}" != "${1}" ]; then - printf "%s" "${1##*.tar.}"; - elif [ "${1##*.t}" != "${1}" ]; then - printf "%s" "${1##*.t}"; - fi; -}; - -pkg_fetch_extract() { - if [ -n "${PKG_URL:-}" ]; then - _oldpwd="${PWD}"; - if ! rtl_fileop cd "${PKG_BASE_DIR}"\ - || ! rtl_fileop rm "${PKG_BASE_DIR}/${PKG_SUBDIR}"; then - rtl_fileop cd "${_oldpwd}"; return 1; - else - case "$(pkgp_fetch_extract_type "${PKG_NAME}")" in - bz2) bunzip2 -d < "${BUILD_DLCACHEDIR}/${PKG_NAME}/${PKG_FNAME}" | tar -C "${PKG_BASE_DIR}" -xf -; ;; - gz) gunzip -d < "${BUILD_DLCACHEDIR}/${PKG_NAME}/${PKG_FNAME}" | tar -C "${PKG_BASE_DIR}" -xf -; ;; - lz) lzip -d < "${BUILD_DLCACHEDIR}/${PKG_NAME}/${PKG_FNAME}" | tar -C "${PKG_BASE_DIR}" -xf -; ;; - xz) xz -d < "${BUILD_DLCACHEDIR}/${PKG_NAME}/${PKG_FNAME}" | tar -C "${PKG_BASE_DIR}" -xf -; ;; - *) tar -C "${PKG_BASE_DIR}" -xf "${BUILD_DLCACHEDIR}/${PKG_NAME}/${PKG_FNAME}"; ;; - esac; - if [ "${?}" -ne 0 ]; then - rtl_fileop cd "${_oldpwd}"; return 1; - else - rtl_fileop cd "${_oldpwd}"; - fi; - fi; - fi; -}; - -# vim:filetype=sh diff --git a/subr/pkg_install.subr b/subr/pkg_install.subr deleted file mode 100644 index e6e2497..0000000 --- a/subr/pkg_install.subr +++ /dev/null @@ -1,35 +0,0 @@ -# -# set +o errexit -o noglob -o nounset is assumed. -# - -pkg_install() { - local _destdir="" _destdir_prefix="" _pkglist_name=""; - if ! rtl_fileop mkdir "${PKG_PREFIX}"; then - return 1; - else for _destdir in "${PKG_DESTDIR}:${PKG_PREFIX}" "${PKG_DESTDIR_HOST}:${PREFIX}"; do - rtl_lassign "_destdir _destdir_prefix" ":" "${_destdir}"; - if [ -e "${_destdir}" ]; then - (set +o errexit -o noglob; rtl_flock_acquire 4 || exit "${?}"; - trap "rm -f \"${BUILD_WORKDIR}/install.lock\"" EXIT; - if ! tar -C "${_destdir}" -cpf - . | tar -C "${_destdir_prefix}" --overwrite -xpf -; then - exit 1; - fi) 4<>"${BUILD_WORKDIR}/install.lock"; - fi; - done; - if [ "${?}" -ne 0 ]; then - return 1; - elif [ "${PKG_PKGLIST_DISABLE:-0}" -eq 0 ]; then - if [ ! -e "${PREFIX}/pkglist.${PKG_BUILD_TYPE}" ]\ - && ! touch "${PREFIX}/pkglist.${PKG_BUILD_TYPE}"; then - return 1; - else - _pkglist_name="${PKG_BASE_DIR##*/}"; _pkglist_name="${_pkglist_name%%-*}"; - if ! printf "%s\n" "${_pkglist_name}" >> "${PREFIX}/pkglist.${PKG_BUILD_TYPE}"; then - return 1; - fi; - fi; - fi; - fi; -}; - -# vim:filetype=sh diff --git a/subr/pkg_install_clean.subr b/subr/pkg_install_clean.subr deleted file mode 100644 index 3d99f32..0000000 --- a/subr/pkg_install_clean.subr +++ /dev/null @@ -1,12 +0,0 @@ -# -# set +o errexit -o noglob -o nounset is assumed. -# - -pkg_install_clean() { - if [ -n "${PKG_DESTDIR:-}" ]; then - rtl_fileop rm "${PKG_DESTDIR}" || return 1; - rtl_fileop mkdir "${PKG_DESTDIR}" || return 1; - fi; return 0; -}; - -# vim:filetype=sh diff --git a/subr/pkg_install_files.subr b/subr/pkg_install_files.subr deleted file mode 100644 index 0cd03e4..0000000 --- a/subr/pkg_install_files.subr +++ /dev/null @@ -1,115 +0,0 @@ -# -# set +o errexit -o noglob -o nounset is assumed. -# - -pkgp_install_files() { - if [ -n "${PKG_INSTALL_FILES:-}" ]; then - if ! rtl_install -v "${PKG_DESTDIR}" ${PKG_INSTALL_FILES}; then - return 1; - fi; - fi; -}; - -pkgp_install_files_v2() { - local _vflag=""; _status=""; - - if [ -n "${PKG_INSTALL_FILES_V2:-}" ]; then - if rtl_lmatch "${ARG_VERBOSE_TAGS}" "install" ","; then - _vflag="-v"; - fi; - if ! rtl_install_v2 \ - -p "_builddir=${PKG_BUILD_DIR}" \ - -p "_destdir=${PKG_BASE_DIR}/${PKG_DESTDIR}" \ - -p "_destdir_host=${PKG_BASE_DIR}/${PKG_DESTDIR_HOST}" \ - -p "_files=${MIDIPIX_BUILD_PWD}/files/${PKG_NAME}" \ - -p "_name=${PKG_NAME}" \ - -p "_prefix=${PKG_PREFIX}" \ - -p "_prefix_host=${PREFIX}" \ - -p "_prefix_native=${PREFIX_NATIVE}" \ - -p "_subdir=${PKG_BASE_DIR}/${PKG_SUBDIR}" \ - -p "_target=${PKG_TARGET}" \ - -p "_version=${PKG_VERSION:-}" \ - -p "_workdir=${BUILD_WORKDIR}" \ - ${_vflag} -- "${PKG_DESTDIR}" \ - "${PKG_INSTALL_FILES_V2}"; then - return 1; - fi; - fi; -}; - -pkgp_install_files_perms() { - local _destdir="" _fname="" IFS; - for _destdir in "${PKG_DESTDIR}" "${PKG_DESTDIR_HOST}"; do - if [ -e "${_destdir}" ]; then - rtl_set_IFS_nl; - for _fname in $(find "${_destdir}" -type d); do - if ! rtl_fileop chmod 0755 "${_fname}"; then - return 1; - fi; - done; - for _fname in $(find "${_destdir}" \( -not -perm /0111 \) -type f); do - if ! rtl_fileop chmod 0644 "${_fname}"; then - return 1; - fi; - done; - for _fname in $(find "${_destdir}" -perm /0111 -type f); do - if ! rtl_fileop chmod 0755 "${_fname}"; then - return 1; - fi; - done; - fi; - done; -}; - -pkgp_install_files_pkgconfig() { - local _pc_path=""; - for _pc_path in $(find "${PKG_DESTDIR}" -name \*.pc); do - if [ -n "$(sed -ne '/^libdir=[^$]*$/p' "${_pc_path}")" ] \ - && ! sed -i"" -e '/^libdir=[^$]*$/s/^libdir=\(.*\)$/libdir=${exec_prefix}\1/' \ - -e '/^exec_prefix=$/s/^.*$/exec_prefix=${prefix}/' \ - "${_pc_path}"; then - return 1; - fi; - if [ -n "$(sed -ne '/^includedir=[^$]*$/p' "${_pc_path}")" ] \ - && ! sed -i"" -e '/^includedir=[^$]*$/s/^includedir=\(.*\)$/includedir=${prefix}\1/' \ - "${_pc_path}"; then - return 1; - fi; - done; -}; - -pkgp_install_files_strip() { - local _bin_path="" _stripfl=0 _tree_root="${PKG_DESTDIR}"; - if [ -e "${_tree_root}" ]; then - if rtl_match "${PKG_NAME}" "*_minipix"; then - : $((_stripfl=(${ARG_DEBUG_MINIPIX:-0} ? 0 : 1))); - elif [ "${BUILD_KIND}" = release ]\ - && [ "${PKG_BUILD_TYPE}" = native ]; then - _stripfl=1; - else - _stripfl=0; - fi; - if [ "${_stripfl:-0}" -eq 1 ]; then - for _bin_path in $(find "${_tree_root}" -perm /a=x -type f); do - if objdump -sj .debug_frame -j .debug_info "${_bin_path}" >/dev/null 2>&1; then - rtl_log_msg "pkg_strip" "${MSG_pkg_strip}" "${_bin_path}"; - if ! "${PKG_TARGET}-strip" "${_bin_path}"; then - return 1; - fi; - fi; - done; - fi; - fi; -}; - -pkg_install_files() { - if ! pkgp_install_files\ - || ! pkgp_install_files_v2\ - || ! pkgp_install_files_perms\ - || ! pkgp_install_files_pkgconfig\ - || ! pkgp_install_files_strip; then - return 1; - fi; -}; - -# vim:filetype=sh diff --git a/subr/pkg_install_libs.subr b/subr/pkg_install_libs.subr deleted file mode 100644 index 3dcc0ac..0000000 --- a/subr/pkg_install_libs.subr +++ /dev/null @@ -1,66 +0,0 @@ -# -# set +o errexit -o noglob -o nounset is assumed. -# - -pkgp_install_libs_purge_la() { - local _la_path=""; - for _la_path in $(find "${PKG_DESTDIR}" -type f -name \*.la); do - if ! rtl_fileop rm "${_la_path}"; then - return 1; - fi; - done; -}; - -pkgp_install_libs_shared_link() { - local _lib_name="${1}" _so_dir="${2}" _so_path="${3}" _lib_link_path="${3%.so*}.lib.a" _lib_link_tgt=""; - 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 ! rtl_fileop rm "${_lib_link_path}"\ - || ! rtl_fileop ln_symbolic "$(rtl_basename "${_lib_link_tgt}")" "${_lib_link_path}"; then - return 1; - fi; - fi; -}; - -pkgp_install_libs_shared() { - local _lib_dst_path="" _lib_name="" _lib_src_path="" _so_dst_dir="" _so_src_path=""; - if [ "${PKG_BUILD_TYPE}" != "host" ]; then - for _so_src_path in \ - $(find "${PKG_DESTDIR}" \ - \( -name "*.so" -or -name "*.so.*" \) -print); - do if [ "$(readlink -f "${_so_src_path}")" != "/dev/null" ]\ - && [ -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="$(rtl_basename "${_lib_src_path}")"; - _lib_dst_path="${_so_dst_dir}/${_lib_name}"; - if [ ! -L "${_lib_src_path}" ]\ - && [ ! -e "${_lib_dst_path}" ]; then - if ! (rtl_fileop cd "$(rtl_dirname "${_so_src_path}")" && \ - perk -e "$(rtl_basename "${_so_src_path}")" |\ - "${PKG_TARGET}-mdso" \ - -i "$(rtl_basename "${_lib_dst_path}")" \ - -n "$(rtl_basename "${_so_src_path}")" -); then - return 1; - fi; - fi; - if ! pkgp_install_libs_shared_link "${_lib_name}" "${_so_dst_dir}" "${_so_src_path}"; then - return 1; - fi; - fi; - done; - fi; -}; - -pkg_install_libs() { - if ! pkgp_install_libs_purge_la\ - || ! pkgp_install_libs_shared; then - return 1; - fi; -}; - -# vim:filetype=sh diff --git a/subr/pkg_install_make.subr b/subr/pkg_install_make.subr deleted file mode 100644 index f7ac464..0000000 --- a/subr/pkg_install_make.subr +++ /dev/null @@ -1,37 +0,0 @@ -# -# set +o errexit -o noglob -o nounset is assumed. -# - -pkg_install_make() { - local _libtool="" _rc=0 _subdir=""; - case "${PKG_LIBTOOL:-}" in - "") _libtool=""; ;; - none) _libtool=""; ;; - *) _libtool="${PKG_LIBTOOL}"; ;; - esac; - for _subdir in ${PKG_MAKE_SUBDIRS:-:}; do - if [ "${_subdir}" = ":" ]; then - _subdir=""; - fi; - if [ "${#_libtool}" -gt 0 ]; then - export MAKE="make LIBTOOL=${_libtool}"; - fi; - rtl_run_cmd_unsplit "${PKG_MAKE}" \ - ${PKG_MAKEFLAGS_INSTALL:-} \ - ${PKG_MAKEFLAGS_INSTALL_EXTRA:-} \ - AR="${PKG_AR}" CC="${PKG_CC}" RANLIB="${PKG_RANLIB}" \ - "${PKG_RANLIB_INSTALL:+RANLIB=${PKG_RANLIB_INSTALL}}" \ - ${_libtool:+"LIBTOOL=${_libtool}"} \ - "${PKG_MAKE_INSTALL_VNAME:-DESTDIR}=${PKG_DESTDIR}/" \ - ${PKG_INSTALL_TARGET:-install} \ - ${_subdir:+-C "${_subdir}"}; _rc="${?}"; - if [ "${#_libtool}" -gt 0 ]; then - unset MAKE; - fi; - if [ "${_rc}" -ne 0 ]; then - return 1; - fi; - done; -}; - -# vim:filetype=sh diff --git a/subr/pkg_install_rpm.subr b/subr/pkg_install_rpm.subr deleted file mode 100644 index 776034b..0000000 --- a/subr/pkg_install_rpm.subr +++ /dev/null @@ -1,52 +0,0 @@ -# -# set +o errexit -o noglob -o nounset is assumed. -# - -pkg_install_rpm() { - local _pkg_url="" _pkg_version_full="" _pkg_version_rpm="" _rc=0; - if rtl_lmatch "${ARG_DIST}" "rpm" ","\ - && [ "${PKG_RPM_DISABLE:-0}" -eq 0 ]\ - && [ -x "$(which rpmbuild 2>/dev/null)" ]; then - if [ -n "${PKG_URL:-}" ]; then - _pkg_url="${PKG_URL%% *}"; _pkg_version_full="${PKG_VERSION}"; _pkg_version_rpm="${PKG_VERSION%%-*}"; - elif [ -n "${PKG_URLS_GIT:-}" ]; then - _pkg_version_rpm="$(cd "${PKG_BASE_DIR}/${PKG_SUBDIR}" && git rev-parse HEAD)"; - _pkg_version_full="${_pkg_version_rpm} ($(cd "${PKG_BASE_DIR}/${PKG_SUBDIR}" && git rev-parse --abbrev-ref HEAD))"; - _pkg_url="${PKG_URLS_GIT%% *}"; _pkg_url="${_pkg_url##*=}"; _pkg_url="${_pkg_url%%@*}"; - if [ "${_pkg_url#${DEFAULT_GITROOT_HEAD}}" != "${_pkg_url}" ]; then - _pkg_url="Unknown"; - fi; - fi; - 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 - rpmbuild \ - -bb \ - --define="_tmppath ${BUILD_WORKDIR}" \ - --define="_topdir ${PREFIX_RPM}/${PKG_NAME}-${_pkg_version_rpm}" \ - --define="pkg_destdir ${PKG_DESTDIR}" \ - --define="pkg_name ${PKG_NAME}" \ - --define="pkg_url ${_pkg_url}" \ - --define="pkg_version_full ${_pkg_version_full}" \ - --define="pkg_version_rpm ${_pkg_version_rpm}" \ - --nodeps "${PKG_BASE_DIR}/${PKG_NAME}-${_pkg_version_rpm}.spec"; _rc="${?}"; - if [ "${_rc}" -eq 0 ]; then - break; - elif [ "${_rc}" -eq 141 ]; then - continue; - else - return "${_rc}"; - fi; - done; - if ! find "${PREFIX_RPM}/${PKG_NAME}-${_pkg_version_rpm}/RPMS" \ - -iname \*.rpm -exec cp -pP {} "${PREFIX_RPM}/" \; \ - || ! 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 1; - fi; - fi; - fi; -}; - -# vim:filetype=sh diff --git a/subr/pkg_install_subdirs.subr b/subr/pkg_install_subdirs.subr deleted file mode 100644 index c9e4cd3..0000000 --- a/subr/pkg_install_subdirs.subr +++ /dev/null @@ -1,21 +0,0 @@ -# -# set +o errexit -o noglob -o nounset is assumed. -# - -pkg_install_subdirs() { - local _spec=""; - for _spec in \ - "${PKG_INSTALL_FILES_DESTDIR:-}" \ - "${PKG_INSTALL_FILES_DESTDIR_EXTRA:-}"; do - if ! rtl_install "${PKG_DESTDIR}" ${_spec}; then - return 1; - fi; - done; - if [ "${PKG_PREFIX%/}" = "${PREFIX_NATIVE%/}" ]; then - if ! rtl_install "${PKG_DESTDIR}/${DEFAULT_TARGET}" ${PKG_INSTALL_FILES_DESTDIR}; then - return 1; - fi; - fi; -}; - -# vim:filetype=sh diff --git a/subr/pkgtool_init.subr b/subr/pkgtool_init.subr deleted file mode 100644 index 9d77d8d..0000000 --- a/subr/pkgtool_init.subr +++ /dev/null @@ -1,153 +0,0 @@ -# -# set +o errexit -o noglob -o nounset is assumed. -# - -pkgtoolp_init_args() { - local _rc=0; _status=""; - if [ "$((${ARG_INFO:-0} + ${ARG_MIRROR:-0} + ${ARG_RDEPENDS:-0} + ${ARG_SHELL:-0} + ${ARG_TARBALL:-0}))" -gt 1 ]; then - cat etc/pkgtool.usage; _rc=1; _status="Error: only one of -i, -m and/or -M, -r, -s, or -t must be specified."; - elif [ "$((${ARG_INFO:-0} + ${ARG_MIRROR:-0} + ${ARG_RDEPENDS:-0} + ${ARG_SHELL:-0} + ${ARG_TARBALL:-0}))" -eq 0 ]\ - && [ -z "${ARG_RESTART_AT}" ]\ - && [ "${ARG_UPDATE_DIFF:-0}" -eq 0 ]; then - cat etc/pkgtool.usage; _rc=1; _status="Error: one of -i, -m and/or -M, -r, -s, or -t must be specified."; - elif [ "${BUILD_HNAME:+1}" != 1 ]\ - && ! BUILD_HNAME="$(hostname)"; then - _rc=1; _status="failed to obtain hostname."; - else _rc=0; export TMP="${BUILD_WORKDIR}" TMPDIR="${BUILD_WORKDIR}"; - fi; return "${_rc}"; -}; - -pkgtoolp_init_env() { - local _fname="" _lang="${LANG:-C}" _name="" _rc=0; _status=""; _lang="${_lang%%_*}"; - - if ! cd "${0%/*}"; then - printf "Error: failed to change working directory to \`${0%/*}'." >&2; exit 1; - elif ! umask 022; then - printf "Error: failed to set umask(2).\n" >&2; exit 1; - else for _fname in \ - $(find subr.rtl -name *.subr) \ - $(find subr -name *.subr) \ - etc/pkgtool.theme \ - ; - do - if ! . "${_fname}"; then - printf "Error: failed to source \`%s'.\n" "${_fname}" >&2; exit 1; - fi; - done; - if [ -e "etc/pkgtool.theme.local" ]; then - if ! . "etc/pkgtool.theme.local"; then - printf "Error: failed to source \`%s'.\n" "etc/pkgtool.theme.local" >&2; exit 1; - fi; - fi; - for _name in pkgtool rtl; do - for _lang_ in ${_lang} C; do - _fname="etc/${_name}.msgs.${_lang_}"; - if [ -e "${_fname}" ]; then - if ! . "${_fname}"; then - printf "Error: failed to source \`%s'.\n" "${_fname}" >&2; exit 1; - fi; - if [ -e "${_fname}.local" ]; then - if ! . "${_fname}.local"; then - printf "Error: failed to source \`%s'.\n" "${_fname}.local" >&2; exit 1; - fi; - fi; break; - fi; - done; - done; - - fi; export LANG=C LC_ALL=C; return "${_rc}"; -}; - -pkgtoolp_init_getopts() { - local _opt="" _shiftfl=0 _rc=0 OPTIND=0; _status=""; : ${ARCH:="nt64"}; : ${BUILD_KIND:="debug"}; - ARG_INFO=0; ARG_MIRROR=0; ARG_MIRROR_DNAME=""; ARG_MIRROR_DNAME_GIT=""; ARG_RESTART_AT=""; - ARG_RDEPENDS=0; ARG_UPDATE_DIFF=0; ARG_SHELL=0; ARG_TARBALL=0; ARG_VERBOSE=0; - while [ "${#}" -gt 0 ]; do - case "${1}" in - --update-diff) - ARG_UPDATE_DIFF=1; _shiftfl=1; ;; - --restart-at) - if [ "${#}" -lt 2 ]\ - || [ -z "${2}" ]; then - _rc=1; _status="Error: missing argument for option --restart-at."; - else - ARG_RESTART_AT="${2}"; _shiftfl=2; - fi; ;; - *) _shiftfl=0; ;; - esac; - if [ "${_rc:-0}" -ne 0 ]; then - break; - elif [ "${_shiftfl:-0}" -gt 0 ]; then - shift "${_shiftfl}"; continue; - elif getopts a:b:him:M:rstv _opt; then - case "${_opt}" in - a) ARCH="${OPTARG}"; ;; - b) BUILD_KIND="${OPTARG}"; ;; - h) cat etc/pkgtool.usage; exit 0; ;; - i) ARG_INFO=1; ;; - m) ARG_MIRROR=1; ARG_MIRROR_DNAME="${OPTARG}"; ;; - M) ARG_MIRROR=1; ARG_MIRROR_DNAME_GIT="${OPTARG}"; ;; - r) ARG_RDEPENDS=1; ;; - s) ARG_SHELL=1; ;; - t) ARG_TARBALL=1; ;; - v) ARG_VERBOSE=1; ;; - *) cat etc/pkgtool.usage; exit 1; ;; - esac; shift $((${OPTIND}-1)); OPTIND=1; - else case "${1}" in - *=*) rtl_set_var_unsafe "${1%%=*}" "${1#*=}"; ;; - *) PKGTOOL_PKG_NAME="${1}"; ;; - esac; shift; - fi; - done; - if [ "${_rc}" -eq 0 ]; then - if [ -z "${PKGTOOL_PKG_NAME:-}" ]\ - && [ "${ARG_MIRROR:-0}" -eq 0 ]; then - _rc=1; _status="Error: missing package name."; - else export PKGTOOL_PKG_NAME; - case "${ARG_VERBOSE:-0}" in - 0) rtl_log_enable_tags "${LOG_TAGS_normal}"; ;; - 1) rtl_log_enable_tags "${LOG_TAGS_verbose}"; ;; - *) _rc=1; _status="Error: invalid verbosity level (max. -v)"; ;; - esac; - fi; - fi; return "${_rc}"; -}; - -pkgtoolp_init_getopts_help() { - local _opt=""; - while getopts a:b:hirst _opt 2>/dev/null; do - case "${_opt}" in - h) - if [ -t 1 ]; then - cat etc/pkgtool.usage; - else - sed 's/\[[0-9]\+m//g' etc/pkgtool.usage; - fi; exit 0; ;; - esac; done; shift $((${OPTIND}-1)); -}; - -pkgtoolp_init_prereqs() { - if ! rtl_check_prereqs \ - awk bzip2 cat chmod cp date find grep hostname mkdir \ - mktemp mv paste printf readlink rm sed sort tar test \ - touch tr uniq; then - printf "%s\n" "${_status}" >&2; exit 1; - elif ! (FNAME="$(mktemp)" && { trap "rm -f \"\${FNAME}\"" EXIT; \ - sed -i'' -e '' "${FNAME}" >/dev/null 2>&1; }); then - printf "Error: sed(1) in \${PATH} does not support the \`-i' option.\n" >&2; exit 1; - fi; -}; - -pkgtool_init() { - local _fname="" _rc=0; _status=""; - if ! pkgtoolp_init_env \ - || ! pkgtoolp_init_getopts_help "${@}" \ - || ! pkgtoolp_init_prereqs \ - || ! pkgtoolp_init_getopts "${@}" \ - || ! ex_pkg_load_vars \ - || ! pkgtoolp_init_args; then - _rc=1; _status="${_status}"; - fi; return "${_rc}"; -}; - -# vim:filetype=sh diff --git a/vars/ca_certificates.vars b/vars/ca_certificates.vars index dfe0c9b..3260334 100644 --- a/vars/ca_certificates.vars +++ b/vars/ca_certificates.vars @@ -17,11 +17,12 @@ pkg_ca_certificates_install_make_post() { }; pkg_ca_certificates_host_configure_patch_post() { - local _vname="" _vspec="" _vval=""; + local _vname="" _vspec="" _vpsec_="" _vval=""; for _vspec in \ CERTSCONF:/etc/ca-certificates.conf \ ETCCERTSDIR:/etc/ssl/certs/; do - set -- $(rtl_llift "${_vspec}" : " "); _vname="${1}"; _vval="${2}"; + rtl_llift2 \$_vspec \$_vspec_ : " "; + set -- ${_vspec_}; _vname="${1}"; _vval="${2}"; sed -i"" -e's,^#define '"${_vname}"' ".\+"$,#define '"${_vname}"' "'"${PKG_DESTDIR%/}${_vval}"'",' update-ca.c; done; sed -i"" -e's,^#define CERTSDIR ".\+"$,#define CERTSDIR "../../../usr/share/ca-certificates/",' update-ca.c; diff --git a/vars/gcc.vars b/vars/gcc.vars index 388b7ad..fa87f86 100644 --- a/vars/gcc.vars +++ b/vars/gcc.vars @@ -7,10 +7,12 @@ # # Private subroutines # -pkgp_gcc_build_dir() { PKG_BUILD_DIR="${1}-${2}-${PKG_TARGET}"; }; + +pkgp_gcc_build_dir() { PKG_BUILD_DIR="${1}-${2}-${PKG_TARGET}"; return 0; }; pkgp_gcc_state_set() { printf "step unknown %s %s\n" "${PKG_NAME}" "${1}" >&3; ex_pkg_state_set "${PKG_NAME}" "${1}" ${2:+"${2}"}; + return 0; }; pkgp_gcc_configure() { @@ -43,10 +45,12 @@ pkgp_gcc_configure() { else pkgp_gcc_state_set "configure" "build"; fi; + return 0; }; pkgp_gcc_setup_env() { local _vname=""; + for _vname in CFLAGS CFLAGS_FOR_BUILD CPPFLAGS_FOR_BUILD \ CXXFLAGS CXXFLAGS_FOR_BUILD; do export "${_vname}=${GCCFLAGS}"; @@ -59,70 +63,98 @@ pkgp_gcc_setup_env() { cbb_cflags_for_stage3 cbb_cflags_for_stage4; do export "${_vname}=${CFLAGS_FOR_BUILD}" ; done; + return 0; }; pkgp_gcc_setup_vars() { local _unwind_midipix_h=""; export cbb_target="${PKG_TARGET}" MAKE="make LIBTOOL=slibtool"; _unwind_midipix_h="$(readlink -f "${PKG_BASE_DIR}/cbb-gcc-${PKG_VERSION}/gcc/unwind-midipix.h")"; + case "${PKG_NAME}" in + gcc_full) GCCTARGET_FLAGS="-DIN_TARGET_LIBRARY_BUILD --sysroot=${PKG_PREFIX}"; - GCCTARGET_FLAGS="$(rtl_lconcat "${GCCTARGET_FLAGS}" "--include=${_unwind_midipix_h}")"; - GCCTARGET_FLAGS="$(rtl_lconcat "${GCCTARGET_FLAGS}" "-DTARGET_PERSONALITY_FUNCTION")"; - GCCTARGET_FLAGS="$(rtl_lconcat "${GCCTARGET_FLAGS}" "-DTARGET_PERSONALITY_FUNCTION_MIDIPIX")"; - GCCTARGET_FLAGS="$(rtl_lconcat "${GCCTARGET_FLAGS}" "${DEFAULT_CFLAGS_DEBUG_RUNTIME}")"; - export cbb_ldflags_for_target=--sysroot="${PKG_PREFIX}" \ - cbb_sysroot_for_libgcc="${PKG_PREFIX}" \ - cbb_xgcc_for_specs="${PKG_TARGET}-gcc" \ - sysroot_headers_suffix="${PKG_PREFIX}"; ;; + rtl_lconcat \$GCCTARGET_FLAGS "--include=${_unwind_midipix_h}"; + rtl_lconcat \$GCCTARGET_FLAGS "-DTARGET_PERSONALITY_FUNCTION"; + rtl_lconcat \$GCCTARGET_FLAGS "-DTARGET_PERSONALITY_FUNCTION_MIDIPIX"; + rtl_lconcat \$GCCTARGET_FLAGS "${DEFAULT_CFLAGS_DEBUG_RUNTIME}"; + export cbb_ldflags_for_target=--sysroot="${PKG_PREFIX}" \ + cbb_sysroot_for_libgcc="${PKG_PREFIX}" \ + cbb_xgcc_for_specs="${PKG_TARGET}-gcc" \ + sysroot_headers_suffix="${PKG_PREFIX}"; + ;; + gcc_stage1_cross_mingw32) GCCTARGET_FLAGS="-DIN_TARGET_LIBRARY_BUILD --sysroot=${PREFIX_MINGW32} -midata"; - export cbb_ldflags_for_target=--sysroot="${PREFIX_MINGW32}" \ - cbb_neutral_libiberty=no \ - cbb_sysroot_for_libgcc="${PREFIX_MINGW32}" \ - cbb_xgcc_for_specs="${PKG_BASE_DIR}/${PKG_BUILD_DIR}/gcc/xgcc"; ;; + export cbb_ldflags_for_target=--sysroot="${PREFIX_MINGW32}" \ + cbb_neutral_libiberty=no \ + cbb_sysroot_for_libgcc="${PREFIX_MINGW32}" \ + cbb_xgcc_for_specs="${PKG_BASE_DIR}/${PKG_BUILD_DIR}/gcc/xgcc"; + ;; + gcc_stage1_host) GCCTARGET_FLAGS="-DIN_TARGET_LIBRARY_BUILD --sysroot=${PREFIX_CROSS}"; - GCCTARGET_FLAGS="$(rtl_lconcat "${GCCTARGET_FLAGS}" "--include=${_unwind_midipix_h}")"; - GCCTARGET_FLAGS="$(rtl_lconcat "${GCCTARGET_FLAGS}" "-DTARGET_PERSONALITY_FUNCTION")"; - GCCTARGET_FLAGS="$(rtl_lconcat "${GCCTARGET_FLAGS}" "-DTARGET_PERSONALITY_FUNCTION_MIDIPIX")"; - GCCTARGET_FLAGS="$(rtl_lconcat "${GCCTARGET_FLAGS}" "${DEFAULT_CFLAGS_DEBUG_RUNTIME}")"; - export cbb_ldflags_for_target="--sysroot=${PREFIX_CROSS}" \ - cbb_neutral_libiberty="no" \ - cbb_sysroot_for_libgcc="${PREFIX_CROSS}" \ - cbb_xgcc_for_specs="${PKG_BASE_DIR}/${PKG_BUILD_DIR}/gcc/xgcc" \ - LDFLAGS="${PKG_LDFLAGS_CONFIGURE}"; ;; + rtl_lconcat \$GCCTARGET_FLAGS "--include=${_unwind_midipix_h}"; + rtl_lconcat \$GCCTARGET_FLAGS "-DTARGET_PERSONALITY_FUNCTION"; + rtl_lconcat \$GCCTARGET_FLAGS "-DTARGET_PERSONALITY_FUNCTION_MIDIPIX"; + rtl_lconcat \$GCCTARGET_FLAGS "${DEFAULT_CFLAGS_DEBUG_RUNTIME}"; + export cbb_ldflags_for_target="--sysroot=${PREFIX_CROSS}" \ + cbb_neutral_libiberty="no" \ + cbb_sysroot_for_libgcc="${PREFIX_CROSS}" \ + cbb_xgcc_for_specs="${PKG_BASE_DIR}/${PKG_BUILD_DIR}/gcc/xgcc" \ + LDFLAGS="${PKG_LDFLAGS_CONFIGURE}"; + ;; + gcc_stage1_native_mingw32) GCCTARGET_FLAGS="-DIN_TARGET_LIBRARY_BUILD --sysroot=${PKG_PREFIX} -midata"; - export cbb_ldflags_for_target=--sysroot="${PKG_PREFIX}" \ - cbb_neutral_libiberty=no \ - cbb_sysroot_for_libgcc="${PKG_PREFIX}" \ - cbb_xgcc_for_specs="${PKG_TARGET}-gcc"; ;; + export cbb_ldflags_for_target=--sysroot="${PKG_PREFIX}" \ + cbb_neutral_libiberty=no \ + cbb_sysroot_for_libgcc="${PKG_PREFIX}" \ + cbb_xgcc_for_specs="${PKG_TARGET}-gcc"; + ;; + esac; - GCCFLAGS="$(rtl_lconcat "${PKG_CFLAGS_CONFIGURE}" \ - "--include $(readlink -f "${PKG_BASE_DIR}/cbb-gcc-${PKG_VERSION}/libc/cbb-musl-pe.h")")"; + + rtl_lconcat2 \ + \$GCCFLAGS \ + \$PKG_CFLAGS_CONFIGURE \ + "--include $(readlink -f "${PKG_BASE_DIR}/cbb-gcc-${PKG_VERSION}/libc/cbb-musl-pe.h")"; }; pkgp_gcc_stage1_all() { - local _restart_at="${1}" _rc=0; + local _group_name="${1}" _pkg_name="${2}" _restart_at="${3}" \ + _rc=0; + case "${PKG_NAME}" in + gcc_stage1_cross_mingw32) - pkgp_gcc_build_dir "cbb-gcc-${PKG_VERSION}" mingw32; ;; + pkgp_gcc_build_dir "cbb-gcc-${PKG_VERSION}" mingw32; + ;; + gcc_stage1_host) if ! rtl_fileop ln_symbolic . "${PREFIX_CROSS}/usr"\ || ! rtl_fileop mkdir "${PREFIX_CROSS}/usr/include"\ || ! pkgp_gcc_build_dir "cbb-gcc-${PKG_VERSION}" cross; then _rc=1; - fi; ;; + fi; + ;; + gcc_stage1_native_mingw32) - pkgp_gcc_build_dir "cbb-gcc-${PKG_VERSION}" native; ;; + pkgp_gcc_build_dir "cbb-gcc-${PKG_VERSION}" native; + ;; + esac; + if [ "${_rc}" -ne 0 ]; then return 1; fi; + if ! ex_pkg_state_test "${PKG_NAME}" fetch "${_restart_at}"; then - if ! pkg_fetch_download_dlcache_subdir; then + if ! rtl_fetch_dlcache_subdir \ + "${BUILD_DLCACHEDIR}" "${PKG_NAME}" \ + "${PKG_INHERIT_FROM:-}"; + then return 1; elif ! rtl_fetch_urls_git \ "${BUILD_DLCACHEDIR}/${PKG_NAME}" "${DEFAULT_GIT_ARGS}" "${PKG_BASE_DIR}" \ @@ -133,15 +165,20 @@ pkgp_gcc_stage1_all() { pkgp_gcc_state_set "fetch" "patch"; fi; fi; + if ! ex_pkg_state_test "${PKG_NAME}" patch "${_restart_at}"; then if [ -e "${MIDIPIX_BUILD_PWD}/patches/${PKG_NAME}.local.patch" ]; then patch -b -d "${PKG_BASE_DIR}" -p0 < "${MIDIPIX_BUILD_PWD}/patches/${PKG_NAME}.local.patch" || return 1; fi; pkgp_gcc_state_set "patch" "configure"; fi; - pkgp_gcc_setup_vars; pkgp_gcc_setup_env; + + pkgp_gcc_setup_vars; + pkgp_gcc_setup_env; + if ! ex_pkg_state_test "${PKG_NAME}" configure "${_restart_at}"; then case "${PKG_NAME}" in + gcc_stage1_cross_mingw32) pkgp_gcc_configure \ --enable-sjlj-exceptions \ @@ -150,7 +187,9 @@ pkgp_gcc_stage1_all() { --with-mpc="${PREFIX}" \ --with-mpfr="${PREFIX}" \ --with-sysroot="${PREFIX_MINGW32}" \ - --without-headers; ;; + --without-headers; + ;; + gcc_stage1_host) pkgp_gcc_configure \ --disable-sjlj-exceptions \ @@ -158,7 +197,9 @@ pkgp_gcc_stage1_all() { --with-gmp="${PREFIX}" \ --with-mpc="${PREFIX}" \ --with-mpfr="${PREFIX}" \ - --with-sysroot="${PREFIX_CROSS}"; ;; + --with-sysroot="${PREFIX_CROSS}"; + ;; + gcc_stage1_native_mingw32) pkgp_gcc_configure \ --build=x86_64-unknown-linux-gnu \ @@ -170,33 +211,46 @@ pkgp_gcc_stage1_all() { --with-mpc="${PKG_PREFIX}" \ --with-mpfr="${PKG_PREFIX}" \ --with-sysroot= \ - --without-headers; ;; + --without-headers; + ;; + esac; + if [ "${?}" -ne 0 ]; then return 1; fi; - else rtl_fileop cd "${PKG_BASE_DIR}/${PKG_BUILD_DIR}" || return 1; + else + rtl_fileop cd "${PKG_BASE_DIR}/${PKG_BUILD_DIR}" || return 1; fi; + if ! ex_pkg_state_test "${PKG_NAME}" build "${_restart_at}"; then make ${PKG_MAKEFLAGS_BUILD} "all-gcc" || return 1; pkgp_gcc_state_set "build" "install_subdirs"; fi; + if ! ex_pkg_state_test "${PKG_NAME}" install_subdirs "${_restart_at}"; then - pkg_install_subdirs || return 1; + pkg_install_subdirs "${_group_name}" "${_pkg_name}" "${_restart_at}" || return 1; pkgp_gcc_state_set "install_subdirs" "install_make"; fi; + if ! ex_pkg_state_test "${PKG_NAME}" install_make "${_restart_at}"; then case "${PKG_NAME}" in + gcc_stage1_cross_mingw32) make ${PKG_MAKEFLAGS_BUILD} "prefix=${PKG_DESTDIR}" "install-gcc"; ;; + gcc_stage1_host) make ${PKG_MAKEFLAGS_BUILD} "prefix=${PKG_DESTDIR}" "install-gcc"; ;; + gcc_stage1_native_mingw32) make ${PKG_MAKEFLAGS_BUILD} "prefix=${PKG_DESTDIR}" "install-gcc"; ;; + esac; + if [ "${?}" -ne 0 ]; then return 1; - else case "$(uname -s)" in + else + case "$(uname -s)" in CYGWIN_*) if ! rtl_fileop ln_symbolic "${PKG_DESTDIR}/libexec/gcc/${PKG_TARGET}/${PKG_VERSION}/liblto_plugin.dll.a"\ || ! rtl_fileop ln_symbolic "${PKG_DESTDIR}/libexec/gcc/${PKG_TARGET}/${PKG_VERSION}/liblto_plugin.so"; then @@ -206,20 +260,30 @@ pkgp_gcc_stage1_all() { pkgp_gcc_state_set "install_make" "install"; fi; fi; + if ! ex_pkg_state_test "${PKG_NAME}" install "${_restart_at}"; then - pkg_install || return 1; + pkg_install "${_group_name}" "${_pkg_name}" "${_restart_at}" || return 1; pkgp_gcc_state_set "install"; fi; + pkgp_gcc_state_set "finish"; + + return 0; }; pkg_gcc_full_all() { - local _restart_at="${1}" _configure_host="" _vis_hide="vis_hide=-fvisibility=hidden"; + local _group_name="${1}" _pkg_name="${2}" _restart_at="${3}" \ + _configure_host="" _vis_hide="vis_hide=-fvisibility=hidden"; export MAKE="make LIBTOOL=slibtool ${_vis_hide}"; + pkgp_gcc_build_dir "cbb-gcc-${PKG_VERSION}" native; + if ! ex_pkg_state_test "${PKG_NAME}" fetch "${_restart_at}"; then - if ! pkg_fetch_download_dlcache_subdir; then + if ! rtl_fetch_dlcache_subdir \ + "${BUILD_DLCACHEDIR}" "${PKG_NAME}" \ + "${PKG_INHERIT_FROM:-}"; + then return 1; elif ! rtl_fetch_urls_git \ "${BUILD_DLCACHEDIR}/${PKG_NAME}" "${DEFAULT_GIT_ARGS}" \ @@ -231,22 +295,28 @@ pkg_gcc_full_all() { pkgp_gcc_state_set "fetch" "patch"; fi; fi; + if ! ex_pkg_state_test "${PKG_NAME}" patch "${_restart_at}"; then if [ -e "${MIDIPIX_BUILD_PWD}/patches/${PKG_NAME}.local.patch" ]; then patch -b -d "${PKG_BASE_DIR}" -p0 < "${MIDIPIX_BUILD_PWD}/patches/${PKG_NAME}.local.patch" || return 1; fi; pkgp_gcc_state_set "patch" "configure"; fi; - pkgp_gcc_setup_vars; pkgp_gcc_setup_env; + + pkgp_gcc_setup_vars; + pkgp_gcc_setup_env; + if ! ex_pkg_state_test "${PKG_NAME}" configure "${_restart_at}"; then rtl_fileop mkdir "${PKG_PREFIX}/${PKG_TARGET}" || return 1; if [ \! -d "${PKG_PREFIX}/${PKG_TARGET}/usr" ]; then rtl_fileop ln_symbolic . "${PKG_PREFIX}/${PKG_TARGET}/usr" || return 1; fi; + case "${ARCH}" in nt32) _configure_host="i686-nt32-midipix"; ;; nt64) _configure_host="x86_64-nt64-midipix"; ;; esac; + pkgp_gcc_configure \ --disable-sjlj-exceptions \ --host="${_configure_host}" \ @@ -256,8 +326,10 @@ pkg_gcc_full_all() { --with-mpc="${PKG_PREFIX}" \ --with-mpfr="${PKG_PREFIX}" \ --with-sysroot="" || return 1; - else rtl_fileop cd "${PKG_BASE_DIR}/${PKG_BUILD_DIR}" || return 1; + else + rtl_fileop cd "${PKG_BASE_DIR}/${PKG_BUILD_DIR}" || return 1; fi; + if ! ex_pkg_state_test "${PKG_NAME}" build "${_restart_at}"; then if ! make ${PKG_MAKEFLAGS_BUILD} "all-gcc"\ || ! make ${PKG_MAKEFLAGS_BUILD} "all-target-libgcc" ${_vis_hide}\ @@ -268,97 +340,128 @@ pkg_gcc_full_all() { else pkgp_gcc_state_set "build" "install_subdirs"; fi; fi; + if ! ex_pkg_state_test "${PKG_NAME}" install_subdirs "${_restart_at}"; then - pkg_install_subdirs || return 1; + pkg_install_subdirs "${_group_name}" "${_pkg_name}" "${_restart_at}" || return 1; pkgp_gcc_state_set "install_subdirs" "install_make"; fi; + if ! ex_pkg_state_test "${PKG_NAME}" install_make "${_restart_at}"; then make ${PKG_MAKEFLAGS_BUILD} "prefix=${PKG_DESTDIR}" "install" || return 1; pkgp_gcc_state_set "install_make" "install"; fi; + if ! ex_pkg_state_test "${PKG_NAME}" install "${_restart_at}"; then - pkg_install || return 1; + pkg_install "${_group_name}" "${_pkg_name}" "${_restart_at}" || return 1; pkgp_gcc_state_set "install"; fi; + pkgp_gcc_state_set "finish"; + + return 0; }; pkg_gcc_full_host_all() { - local _restart_at="${1}"; + local _group_name="${1}" _pkg_name="${2}" _restart_at="${3}"; export MAKE="make LIBTOOL=slibtool"; + if ! pkgp_gcc_build_dir "cbb-gcc-${PKG_VERSION}" cross\ || ! rtl_fileop cd "${PKG_BASE_DIR}/${PKG_BUILD_DIR}"; then return 1; - else if ! ex_pkg_state_test "${PKG_NAME}" build "${_restart_at}"; then + else + if ! ex_pkg_state_test "${PKG_NAME}" build "${_restart_at}"; then make ${PKG_MAKEFLAGS_BUILD} || return 1; pkgp_gcc_state_set "build" "install_subdirs"; fi; + if ! ex_pkg_state_test "${PKG_NAME}" install_subdirs "${_restart_at}"; then - pkg_install_subdirs || return 1; + pkg_install_subdirs "${_group_name}" "${_pkg_name}" "${_restart_at}" || return 1; pkgp_gcc_state_set "install_subdirs" "install_make"; fi; + if ! ex_pkg_state_test "${PKG_NAME}" install_make "${_restart_at}"; then make ${PKG_MAKEFLAGS_BUILD} "prefix=${PKG_DESTDIR}" "install" || return 1; pkgp_gcc_state_set "install_make" "install"; fi; + if ! ex_pkg_state_test "${PKG_NAME}" install "${_restart_at}"; then - pkg_install || return 1; + pkg_install "${_group_name}" "${_pkg_name}" "${_restart_at}" || return 1; pkgp_gcc_state_set "install"; fi; + pkgp_gcc_state_set "finish"; fi; + + return 0; }; pkg_gcc_libstdcpp_v3_host_all() { - local _restart_at="${1}"; + local _group_name="${1}" _pkg_name="${2}" _restart_at="${3}"; export MAKE="make LIBTOOL=slibtool"; + if ! pkgp_gcc_build_dir "cbb-gcc-${PKG_VERSION}" cross\ || ! rtl_fileop cd "${PKG_BASE_DIR}/${PKG_BUILD_DIR}"; then return 1; - else if ! ex_pkg_state_test "${PKG_NAME}" build "${_restart_at}"; then + else + if ! ex_pkg_state_test "${PKG_NAME}" build "${_restart_at}"; then make ${PKG_MAKEFLAGS_BUILD} "all-target-libstdc++-v3" || return 1; pkgp_gcc_state_set "build" "install_subdirs"; fi; + if ! ex_pkg_state_test "${PKG_NAME}" install_subdirs "${_restart_at}"; then - pkg_install_subdirs || return 1; + pkg_install_subdirs "${_group_name}" "${_pkg_name}" "${_restart_at}" || return 1; pkgp_gcc_state_set "install_subdirs" "install_make"; fi; + if ! ex_pkg_state_test "${PKG_NAME}" install_make "${_restart_at}"; then make ${PKG_MAKEFLAGS_BUILD} "prefix=${PKG_DESTDIR}" "install-target-libstdc++-v3" || return 1; pkgp_gcc_state_set "install_make" "install"; fi; + if ! ex_pkg_state_test "${PKG_NAME}" install "${_restart_at}"; then - pkg_install || return 1; + pkg_install "${_group_name}" "${_pkg_name}" "${_restart_at}" || return 1; pkgp_gcc_state_set "install"; fi; + pkgp_gcc_state_set "finish"; fi; + + return 0; }; pkg_gcc_runtime_host_all() { - local _restart_at="${1}" _vis_hide="vis_hide=-fvisibility=hidden"; + local _group_name="${1}" _pkg_name="${2}" _restart_at="${3}" \ + _vis_hide="vis_hide=-fvisibility=hidden"; export MAKE="make LIBTOOL=slibtool ${_vis_hide}"; + if ! pkgp_gcc_build_dir "cbb-gcc-${PKG_VERSION}" cross\ || ! rtl_fileop cd "${PKG_BASE_DIR}/${PKG_BUILD_DIR}"; then return 1; - else if ! ex_pkg_state_test "${PKG_NAME}" build "${_restart_at}"; then + else + if ! ex_pkg_state_test "${PKG_NAME}" build "${_restart_at}"; then make ${PKG_MAKEFLAGS_BUILD} "all-target-libgcc" ${_vis_hide} || return 1; pkgp_gcc_state_set "build" "install_subdirs"; fi; + if ! ex_pkg_state_test "${PKG_NAME}" install_subdirs "${_restart_at}"; then - pkg_install_subdirs || return 1; + pkg_install_subdirs "${_group_name}" "${_pkg_name}" "${_restart_at}" || return 1; pkgp_gcc_state_set "install_subdirs" "install_make"; fi; + if ! ex_pkg_state_test "${PKG_NAME}" install_make "${_restart_at}"; then make ${PKG_MAKEFLAGS_BUILD} "prefix=${PKG_DESTDIR}" "install-target-libgcc" || return 1; pkgp_gcc_state_set "install_make" "install"; fi; + if ! ex_pkg_state_test "${PKG_NAME}" install "${_restart_at}"; then - pkg_install || return 1; + pkg_install "${_group_name}" "${_pkg_name}" "${_restart_at}" || return 1; pkgp_gcc_state_set "install"; fi; + pkgp_gcc_state_set "finish"; fi; + + return 0; }; pkg_gcc_stage1_all() { @@ -373,6 +476,7 @@ pkg_gcc_stage1_cross_mingw32_all() { || ! pkgp_gcc_stage1_all "${@}"; then return 1; fi; + return 0; }; pkg_gcc_stage1_host_all() { @@ -387,6 +491,7 @@ pkg_gcc_stage1_native_mingw32_all() { || ! pkgp_gcc_stage1_all "${@}"; then return 1; fi; + return 0; }; # vim:filetype=sh textwidth=0 diff --git a/vars/git.vars b/vars/git.vars index bcdda80..73255a6 100644 --- a/vars/git.vars +++ b/vars/git.vars @@ -5,7 +5,7 @@ pkg_git_install_make_post() { local _fname="" _fname_new=""; for _fname in $(find "${PKG_DESTDIR}" -name "Git*::*" -type f); do - _fname_new="$(rtl_subst "${_fname}" "::" ".")"; + rtl_subst2 \$_fname \$_fname_new "::" "."; if ! rtl_fileop mv "${_fname}" "${_fname_new}"; then return 1; fi; diff --git a/vars/perl.vars b/vars/perl.vars index 3ff7b94..b634a3e 100644 --- a/vars/perl.vars +++ b/vars/perl.vars @@ -3,7 +3,7 @@ # pkg_perl_fetch_extract_post() { - local _cflag="" _fname_dst="" _fname_src=""; + local _cflag="" _dname_dst="" _fname_dst="" _fname_src=""; if ! ( if ! rtl_fileop cd "${PKG_BASE_DIR}"; then return 1; else @@ -14,8 +14,9 @@ pkg_perl_fetch_extract_post() { return 1; fi; fi; - if [ ! -d "$(rtl_dirname "${_fname_dst}")" ]; then - if ! rtl_fileop mkdir "$(rtl_dirname "${_fname_dst}")"; then + rtl_dirname2 \$_fname_dst \$_dname_dst; + if ! [ -d "${_dname_dst}" ]; then + if ! rtl_fileop mkdir "${_dname_dst}"; then return 1; fi; fi; @@ -27,7 +28,7 @@ pkg_perl_fetch_extract_post() { return 1; else for _cflag in ${PKG_CFLAGS_CONFIGURE}; do - PKG_CONFIGURE_ARGS="$(rtl_lconcat "${PKG_CONFIGURE_ARGS}" "-A ccflags=${_cflag}")"; + rtl_lconcat \$PKG_CONFIGURE_ARGS "-A ccflags=${_cflag}"; done; fi; };