summaryrefslogtreecommitdiffhomepage
path: root/subr
diff options
context:
space:
mode:
Diffstat (limited to 'subr')
-rw-r--r--subr/build_init.subr46
-rw-r--r--subr/ex_pkg_dispatch.subr10
-rw-r--r--subr/ex_pkg_env.subr14
-rw-r--r--subr/pkg_install_files.subr6
-rw-r--r--subr/rtl_complex.subr24
-rw-r--r--subr/rtl_string.subr9
6 files changed, 73 insertions, 36 deletions
diff --git a/subr/build_init.subr b/subr/build_init.subr
index c5f91174..eeeaf60b 100644
--- a/subr/build_init.subr
+++ b/subr/build_init.subr
@@ -87,7 +87,7 @@ buildp_init_env() {
};
buildp_init_files() {
- local _log_last_fname="" _log_last_ts="" _rc=0; _status=""
+ 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
@@ -98,12 +98,12 @@ buildp_init_files() {
_rc=1; _status="Error: failed to clean environment.";
elif ! rtl_check_path_vars "${DEFAULT_CHECK_PATH_VARS}"; then
_rc=1; _status="${_status}";
- else
- touch "${DEFAULT_BUILD_STATUS_IN_PROGRESS_FNAME}";
+ else touch "${DEFAULT_BUILD_STATUS_IN_PROGRESS_FNAME}";
if [ -e "${DEFAULT_BUILD_LOG_FNAME}" ]; then
- _log_last_ts="$(stat -c %Y "${DEFAULT_BUILD_LOG_FNAME}")";
- _log_last_ts="$(awk 'BEGIN {printf(strftime("%Y-%m-%d-%H-%M-%S", '"${_log_last_ts}"'))}')";
- _log_last_fname="${DEFAULT_BUILD_LOG_FNAME}.${_log_last_ts}";
+ 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;
@@ -224,21 +224,20 @@ buildp_init_groups() {
buildp_init_prereqs() {
local _cmd="" _cmds_missing="" _rc=0; _status="";
for _cmd in \
- awk bunzip2 cat chmod cmake cp date find flock g++ \
- gcc git grep gunzip gzip hostname install kill \
- ln lzip make mkdir mkfifo mv paste patch perl \
- pgrep pkill printf readlink rm sed seq sha256sum \
- sort stat tail tar test touch tr wget xz zip; do
+ awk bunzip2 bzip2 cat chmod cmake cp date find flock \
+ g++ gcc git grep gunzip gzip hostname install kill \
+ ln lzip make mkdir mkfifo mktemp mv paste patch perl \
+ pgrep pkill printf readlink rm sed sha256sum sort \
+ tail tar test touch tr uniq 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.";
+ elif ! (FNAME="$(mktemp)" && { trap "rm -f \"\${FNAME}\"" EXIT; \
+ sed -i'' -e '' "${FNAME}" >/dev/null 2>&1; }); then
+ _rc=1; _status="Error: sed(1) in \${PATH} does not support the \`-i' option.";
fi;
return "${_rc}";
};
@@ -256,20 +255,19 @@ buildp_init_vars() {
nt32) DEFAULT_TARGET="i686-nt32-midipix"; ;;
nt64) DEFAULT_TARGET="x86_64-nt64-midipix"; ;;
esac;
- if [ -e "/proc/cpuinfo" ]; then
- DEFAULT_BUILD_CPUS="$(awk '/^processor/{cpus++} END{print cpus}' /proc/cpuinfo)";
+ if DEFAULT_BUILD_CPUS="$(rtl_get_cpu_count)"; then
if [ "${ARG_PARALLEL}" = "auto" ]\
&& [ "${DEFAULT_BUILD_CPUS}" -gt 1 ]; then
ARG_PARALLEL=$((${DEFAULT_BUILD_CPUS}/2));
fi;
+ 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;
- 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}";
+ fi; return "${_rc}";
};
build_init() {
diff --git a/subr/ex_pkg_dispatch.subr b/subr/ex_pkg_dispatch.subr
index f0c0a2b6..5274d3f3 100644
--- a/subr/ex_pkg_dispatch.subr
+++ b/subr/ex_pkg_dispatch.subr
@@ -129,8 +129,9 @@ exp_pkg_dispatch_packages() {
local _build_steps_default="${1}" _build_vars_default="${2}" _dispatch_fn="${3}" \
_group_name="${4}" _njobs_max="${5}" _pipe_path="${6}" _pkg_complete="${7}" \
_restart_at="${8}" _restart_recursive="${9}" _workdir="${10}" \
- _njob=0 _pkg_depends="" _pkg_name="";
- for _njob in $(seq 1 $((${_njobs_max}-${EXP_PKG_DISPATCH_NJOBS}))); do
+ _foundfl=0 _njob=0 _pkg_depends="" _pkg_name="";
+ while [ "${EXP_PKG_DISPATCH_NJOBS:-0}" -lt "${_njobs_max}" ]; do
+ _foundfl=0;
for _pkg_name in ${EXP_PKG_NAMES}; do
if ! rtl_lmatch "${_pkg_complete}" "${_pkg_name}"\
&& ! rtl_lmatch "${EX_PKG_DISPATCH_WAIT}" "${_pkg_name}"\
@@ -138,9 +139,12 @@ exp_pkg_dispatch_packages() {
exp_pkg_dispatch_package "${_build_steps_default}" \
"${_build_vars_default}" "${_dispatch_fn}" \
"${_group_name}" "${_pkg_name}" "${_restart_at}" \
- "${_workdir}"; break;
+ "${_workdir}"; _foundfl=1; break;
fi;
done;
+ if [ "${_foundfl:-0}" -eq 0 ]; then
+ break;
+ fi;
done;
};
diff --git a/subr/ex_pkg_env.subr b/subr/ex_pkg_env.subr
index 7b1483b7..b4e1810f 100644
--- a/subr/ex_pkg_env.subr
+++ b/subr/ex_pkg_env.subr
@@ -56,18 +56,20 @@ exp_pkg_env_set() {
_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_name}")")"
+ rtl_set_vars _vars_set "${_vname}" \
+ "$(rtl_lconcat "${_var_prefixes}" \
+ "$(rtl_toupper "PKG_${PKG_INHERIT_FROM} PKG_${_pkg_name}")")"
else
- rtl_set_vars _vars_set "${_vname}" \
- "$(rtl_lconcat "${_var_prefixes}" "$(rtl_toupper "PKG_${_pkg_name}")")";
+ rtl_set_vars _vars_set "${_vname}" \
+ "$(rtl_lconcat "${_var_prefixes}" \
+ "$(rtl_toupper "PKG_${_pkg_name}")")";
fi;
done;
rtl_push_IFS :; for _vname in ${PKG_ENV_VARS_EXTRA}; do
export "${_vname}";
done; rtl_pop_IFS;
- rtl_unset_vars $(rtl_lfilter \
- "$(set | awk -F= '/^PKG_/{print $1}' | sort)" \
+ rtl_unset_vars $(rtl_lfilter \
+ "$(set | sed -ne '/^PKG_[^=]*=/s/=.*$//p')" \
"${_vars_set}");
};
diff --git a/subr/pkg_install_files.subr b/subr/pkg_install_files.subr
index 362f4926..c555499b 100644
--- a/subr/pkg_install_files.subr
+++ b/subr/pkg_install_files.subr
@@ -13,9 +13,9 @@ pkgp_install_files() {
pkgp_install_files_pkgconfig() {
local _pc_path="";
for _pc_path in $(find "${PKG_DESTDIR}" -name \*.pc); do
- if grep -Eq '^libdir=[^$]+$' "${_pc_path}"\
- && ! sed -i"" -e '/^libdir=[^$]\+$/s/^libdir=\(.\+\)$/libdir=${exec_prefix}\1/' \
- -e '/^exec_prefix=$/s/^.*$/exec_prefix=${prefix}/' \
+ 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;
diff --git a/subr/rtl_complex.subr b/subr/rtl_complex.subr
index 41f0b2b4..01e373ea 100644
--- a/subr/rtl_complex.subr
+++ b/subr/rtl_complex.subr
@@ -87,6 +87,21 @@ rtl_filter_vars() {
echo "${_vars}";
};
+rtl_get_cpu_count() {
+ local _line="" _ncpus=0 _rc=0 _sname="$(uname -s 2>/dev/null)"; _status="";
+ case "${_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));
+ fi;
+ done < /proc/cpuinfo; echo "${_ncpus}";
+ fi; ;;
+ *) _rc=1; _status="Error: unknown platform \`${_sname}'."; ;;
+ esac; return "${_rc}";
+};
+
rtl_get_var_unsafe() {
local _vname="";
if [ "x${1}" = "x-u" ]; then
@@ -109,6 +124,15 @@ rtl_head() {
echo "${_s}";
};
+rtl_is_newer() {
+ local _new_fname="${1}" _old_fname="${2}";
+ if [ -n "$(find -name "${_new_fname}" -newer "${_old_fname}" 2>/dev/null)" ]; then
+ return 0;
+ else
+ return 1;
+ fi;
+};
+
rtl_kill_tree() {
local _pid="${1}" _signal="${2:-TERM}" _pid_child="" _pids="";
if _pids="$(pgrep -P "${_pid}")"\
diff --git a/subr/rtl_string.subr b/subr/rtl_string.subr
index 2d529786..c30cfe8c 100644
--- a/subr/rtl_string.subr
+++ b/subr/rtl_string.subr
@@ -12,6 +12,15 @@ rtl_isnumber() {
return "${_rc}";
};
+rtl_match() {
+ local _s="${1}" _find="${2}";
+ if [ "${_s#${_find}}" != "${_s}" ]; then
+ return 0;
+ else
+ return 1;
+ fi;
+};
+
rtl_subst() {
local _s="${1}" _find="${2}" _replace="${3}" _prefix="" _s_new="";
while [ -n "${_s}" ]; do