summaryrefslogtreecommitdiffhomepage
path: root/subr
diff options
context:
space:
mode:
Diffstat (limited to 'subr')
-rw-r--r--subr/build_init.subr18
-rw-r--r--subr/ex_pkg_exec.subr20
-rw-r--r--subr/pkgtool_init.subr133
-rw-r--r--subr/rtl_complex.subr35
-rw-r--r--subr/rtl_string.subr11
5 files changed, 209 insertions, 8 deletions
diff --git a/subr/build_init.subr b/subr/build_init.subr
index 95641d5d..e3bf7b3c 100644
--- a/subr/build_init.subr
+++ b/subr/build_init.subr
@@ -48,14 +48,14 @@ buildp_init_defaults() {
local _rc=0; _status="";
# Command-line arguments
- ARCH="nt64"; BUILD="debug";
- ARG_AS_NEEDED=0; ARG_CLEAN_BUILDS=""; ARG_DEBUG_MINIPIX=0; ARG_DIST="";
- ARG_FETCH_FORCE=0; ARG_PARALLEL=1; ARG_RELAXED=0; ARG_RESTART=""; ARG_VERBOSE=0;
+ : ${ARCH:="nt64"}; : ${BUILD:="debug"};
+ ARG_AS_NEEDED=0; ARG_CLEAN_BUILDS=""; ARG_DEBUG_MINIPIX=0; ARG_DUMP_ON_ABORT=0;
+ ARG_DIST=""; ARG_FETCH_FORCE=0; ARG_PARALLEL=1; ARG_RELAXED=0; ARG_RESTART="";
+ ARG_VERBOSE=0;
# Build parameters & state
- BUILD_DLCACHEDIR=""; BUILD_HNAME=""; BUILD_IS_PARENT=1; BUILD_GROUPS="";
- BUILD_GROUPS_INHIBIT_DEPS=0; BUILD_TARGET=""; BUILD_USER=""; BUILD_WORKDIR="";
- MIDIPIX_BUILD_PWD=""; PREFIX=""; PREFIX_RPM="";
+ BUILD_HNAME=""; BUILD_IS_PARENT=1; BUILD_GROUPS=""; BUILD_GROUPS_INHIBIT_DEPS=0;
+ BUILD_TARGET=""; BUILD_USER=""; MIDIPIX_BUILD_PWD="";
# Global defaults
DEFAULT_BUILD_CPUS=1;
@@ -76,7 +76,7 @@ buildp_init_defaults() {
buildp_init_env() {
local _fname="" _rc=0; _status="";
- if ! cd "$(dirname "${0}")" || ! umask 022; then
+ if ! umask 022; then
printf "Error: failed to setup environment.\n"; exit 1;
else for _fname in $(find subr -name *.subr); do
if ! . "${_fname}"; then
@@ -97,7 +97,7 @@ buildp_init_files() {
elif ! rtl_clean_env "${DEFAULT_CLEAR_ENV_VARS_EXCEPT}"; then
_rc=1; _status="Error: failed to clean environment.";
elif ! rtl_check_path_vars "${DEFAULT_CHECK_PATH_VARS}"; then
- _rc=1; _status="Error: one or more variable containing pathname(s) contains whitespace character(s).";
+ _rc=1; _status="${_status}";
else
touch "${DEFAULT_BUILD_STATUS_IN_PROGRESS_FNAME}";
if [ -e "${DEFAULT_BUILD_LOG_FNAME}" ]; then
@@ -126,6 +126,8 @@ buildp_init_getopts() {
while [ "${#}" -gt 0 ]; do
case "${1}" in
--as-needed) ARG_AS_NEEDED=1; _shiftfl=1; ;;
+ --dump-on-abort)
+ ARG_DUMP_ON_ABORT=1; _shiftfl=1; ;;
--debug-minipx) ARG_DEBUG_MINIPIX=1; _shiftfl=1; ;;
-v*) _opt="${1#-}"; while [ -n "${_opt}" ]; do
: $((ARG_VERBOSE+=1)); _opt="${_opt#?}";
diff --git a/subr/ex_pkg_exec.subr b/subr/ex_pkg_exec.subr
index 9e4629ba..f21bc3d8 100644
--- a/subr/ex_pkg_exec.subr
+++ b/subr/ex_pkg_exec.subr
@@ -2,6 +2,21 @@
# set +o errexit -o noglob 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
@@ -102,6 +117,11 @@ ex_pkg_exec() {
|| [ "${_restart_at}" = "ALL" ]; then
ex_pkg_state_set "${_pkg_name}" finish;
fi;
+ elif [ "${_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;
fi;
return "${_rc}";
diff --git a/subr/pkgtool_init.subr b/subr/pkgtool_init.subr
new file mode 100644
index 00000000..da6a6640
--- /dev/null
+++ b/subr/pkgtool_init.subr
@@ -0,0 +1,133 @@
+#
+# set +o errexit -o noglob is assumed.
+#
+
+pkgtoolp_init_defaults() {
+ : ${ARCH:="nt64"}; : ${BUILD:="debug"}; : ${PKG_NAME:=""};
+ : ${BUILD_WORKDIR:=""}; : ${PREFIX=""};
+ ARG_RESTART_AT=""; ARG_UPDATE_DIFF=0;
+};
+
+pkgtoolp_init_env() {
+ local _fname="" _rc=0; _status="";
+ if ! umask 022; then
+ printf "Error: failed to setup environment.\n"; exit 1;
+ else for _fname in $(find subr -name *.subr); do
+ if ! . "${_fname}"; then
+ printf "Error: failed to source \`%s'.\n" "${_fname}"; exit 1;
+ fi;
+ done; fi;
+ return "${_rc}";
+};
+
+pkgtoolp_init_getopts() {
+ local _opt="" _shiftfl=0 _rc=0 OPTIND=0; _status="";
+ 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:C:D:Fhp:Pr:R _opt; then
+ case "${_opt}" in
+ a) ARCH="${OPTARG}"; ;;
+ b) BUILD="${OPTARG}"; ;;
+ h) pkgtoolp_usage; exit 0; ;;
+ *) pkgtoolp_usage; exit 1; ;;
+ esac; shift $((${OPTIND}-1)); OPTIND=1;
+ else
+ break;
+ fi;
+ done;
+ if [ "${_rc}" -eq 0 ]; then
+ while [ "${#}" -gt 0 ]; do
+ case "${1}" in
+ *=*) rtl_set_var_unsafe "${1%%=*}" "${1#*=}"; ;;
+ *) if [ "${#}" -ne 1 ]; then
+ _rc=1; _status="Error: invalid argument \`${1}'.";
+ fi; break; ;;
+ esac; shift; done;
+ if [ "${_rc:-0}" -eq 0 ]; then
+ if [ "${#}" -ne 1 ]\
+ && [ -z "${PKG_NAME}" ]; then
+ _rc=1; _status="Error: missing package name.";
+ elif [ "${#}" -eq 1 ]; then
+ PKG_NAME="${1}";
+ fi;
+ fi;
+ fi;
+ return "${_rc}";
+};
+
+pkgtoolp_init_prereqs() {
+ local _cmd="" _cmds_missing="" _rc=0; _status="";
+ for _cmd in \
+ awk bunzip2 cat chmod cmake cp date find flock g++ \
+ gcc git grep gunzip gzip hostname install kill \
+ ln lzip make mkdir mkfifo mv paste patch perl \
+ pgrep pkill printf readlink rm sed seq sha256sum \
+ sort stat tail tar test touch tr wget xz zip; do
+ if ! which "${_cmd}" >/dev/null 2>&1; then
+ _cmds_missing="${_cmds_missing:+${_cmds_missing} }${_cmd}";
+ fi;
+ done;
+ if [ -n "${_cmds_missing}" ]; then
+ _rc=1; _status="Error: missing prerequisite package(s): ${_cmds_missing}";
+ elif ! awk -V 2>/dev/null | grep -q "^GNU Awk "; then
+ _rc=1; _status="Error: awk(1) in \$PATH must be GNU Awk.";
+ elif ! sed --version 2>/dev/null | grep -q "^GNU sed "; then
+ _rc=1; _status="Error: sed(1) in \$PATH must be GNU sed.";
+ fi;
+ return "${_rc}";
+};
+
+pkgtoolp_init_vars() {
+ local _rc=0; _status="";
+ if ! rtl_lmatch "${ARCH}" "nt32 nt64"; then
+ _rc=1; _status="Error: invalid architecture \`${ARCH}'.";
+ elif ! rtl_lmatch "${BUILD}" "debug release"; then
+ _rc=1; _status="Error: unknown build type \`${BUILD}'.";
+ else case "${ARCH}" in
+ nt32) DEFAULT_TARGET="i686-nt32-midipix"; ;;
+ nt64) DEFAULT_TARGET="x86_64-nt64-midipix"; ;;
+ esac;
+ rtl_fileop source_opt \
+ "${HOME}/midipix_build.vars" "${HOME}/.midipix_build.vars" \
+ ../midipix_build.vars ./midipix.env;
+ if [ -z "${PREFIX}" ]; then
+ _rc=1; _status="Error: \${PREFIX} empty or unset.";
+ fi; fi;
+ return "${_rc}";
+};
+
+pkgtoolp_usage() {
+ echo "usage: ./pkgtool.sh [-a nt32|nt64] [-b debug|release] name" >&2;
+};
+
+pkgtool_init() {
+ local _fname="" _rc=0 _status="";
+ if ! pkgtoolp_init_env \
+ || ! pkgtoolp_init_defaults \
+ || ! pkgtoolp_init_getopts "${@}" \
+ || ! pkgtoolp_init_prereqs \
+ || ! pkgtoolp_init_vars; then
+ _rc="${?}"; rtl_log_msg fail "${_status}"; exit "${_rc}";
+ elif [ -n "${_status}" ]; then
+ rtl_log_msg info "${_status}"; exit 0;
+ else
+ return "${_rc}";
+ fi;
+};
+
+# vim:filetype=sh
diff --git a/subr/rtl_complex.subr b/subr/rtl_complex.subr
index e727e3cd..41f0b2b4 100644
--- a/subr/rtl_complex.subr
+++ b/subr/rtl_complex.subr
@@ -52,6 +52,41 @@ rtl_export_vars() {
done;
};
+rtl_filter_vars() {
+ local _fn="${1}" _fnfl=0 _qchar="" _var_spec="" _vars="" _vname="" IFS="
+"; 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="$(rtl_lconcat "${_vars}" "${_var_spec}" "\n")"; _fnfl=1;
+ else
+ _fnfl=0;
+ fi;
+ done;
+ echo "${_vars}";
+};
+
rtl_get_var_unsafe() {
local _vname="";
if [ "x${1}" = "x-u" ]; then
diff --git a/subr/rtl_string.subr b/subr/rtl_string.subr
index 0e549d3c..2d529786 100644
--- a/subr/rtl_string.subr
+++ b/subr/rtl_string.subr
@@ -12,6 +12,17 @@ rtl_isnumber() {
return "${_rc}";
};
+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=""; ;;
+ esac; done;
+ echo "${_s_new}";
+};
+
rtl_tolower() {
local _s="${1}" _s_new="";
while [ -n "${_s}" ]; do