aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Deutschmann <whissi@gentoo.org>2019-08-30 18:08:38 +0200
committerThomas Deutschmann <whissi@gentoo.org>2019-08-30 18:08:38 +0200
commit381b319cdee541dccf0180774acb3952ee60b281 (patch)
tree2fcb42042abfa2c939e0e3bd947642f09c9cb3ba /gen_funcs.sh
parentgen_funcs.sh: Import gcc-* functions from toolchain eclass (diff)
downloadgenkernel-381b319cdee541dccf0180774acb3952ee60b281.tar.gz
genkernel-381b319cdee541dccf0180774acb3952ee60b281.tar.bz2
genkernel-381b319cdee541dccf0180774acb3952ee60b281.zip
gen_funcs.sh: Import makeopts_jobs function from multiprocessing eclass
Signed-off-by: Thomas Deutschmann <whissi@gentoo.org>
Diffstat (limited to 'gen_funcs.sh')
-rwxr-xr-xgen_funcs.sh20
1 files changed, 20 insertions, 0 deletions
diff --git a/gen_funcs.sh b/gen_funcs.sh
index 381c6459..c3bcee62 100755
--- a/gen_funcs.sh
+++ b/gen_funcs.sh
@@ -1853,5 +1853,25 @@ make_bootdir_writable() {
fi
}
+# @FUNCTION: makeopts_jobs
+# @USAGE: [${MAKEOPTS}] [${inf:-999}]
+# @DESCRIPTION:
+# Searches the arguments (defaults to ${MAKEOPTS}) and extracts the jobs number
+# specified therein. Useful for running non-make tools in parallel too.
+# i.e. if the user has MAKEOPTS=-j9, this will echo "9" -- we can't return the
+# number as bash normalizes it to [0, 255]. If the flags haven't specified a
+# -j flag, then "1" is shown as that is the default `make` uses. Since there's
+# no way to represent infinity, we return ${inf} (defaults to 999) if the user
+# has -j without a number.
+makeopts_jobs() {
+ [[ $# -eq 0 ]] && set -- "${MAKEOPTS}"
+ # This assumes the first .* will be more greedy than the second .*
+ # since POSIX doesn't specify a non-greedy match (i.e. ".*?").
+ local jobs=$(echo " $* " | sed -r -n \
+ -e 's:.*[[:space:]](-[a-z]*j|--jobs[=[:space:]])[[:space:]]*([0-9]+).*:\2:p' \
+ -e "s:.*[[:space:]](-[a-z]*j|--jobs)[[:space:]].*:${2:-999}:p")
+ echo ${jobs:-1}
+}
+
unset GK_DEFAULT_IFS
declare -r GK_DEFAULT_IFS="${IFS}"