From b08b92248b7f9ee61b7039ac4abd2acf68c6b4de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C5=8Dshin?= Date: Sun, 17 Dec 2023 01:49:49 -0500 Subject: [PATCH] mmake: -j$(nproc), passthrough o// Now `mmake o/ape/ape.elf` works. --- tool/zsh/mmake | 9 ++++++--- tool/zsh/nproc | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 tool/zsh/nproc diff --git a/tool/zsh/mmake b/tool/zsh/mmake index 78418f1d5..e11aa9d29 100644 --- a/tool/zsh/mmake +++ b/tool/zsh/mmake @@ -23,14 +23,17 @@ esac } local -a targs local -a flags +local j=-j$(autoload -Uz nproc >/dev/null 2>&1 ; nproc) while (( $# > 0 )); do case $1 in - -*|*=*) flags+=($1); shift ;; - *) targs+=($1); shift ;; + -j*) j=$1; shift ;; + -*|*=*) flags+=($1); shift ;; + o/*) flags+=($1); shift ;; # cheat; passthru + *) targs+=($1); shift ;; esac done local make [[ -x /opt/cosmocc/bin/make ]] && make=/opt/cosmocc/bin/make [[ -z $make ]] && make=build/bootstrap/make.com ( set -x - exec $make $flags MODE=$mode ${(@)targs/#/o/$mode/} ) + exec $make $j $flags MODE=$mode ${(@)targs/#/o/$mode/} ) diff --git a/tool/zsh/nproc b/tool/zsh/nproc new file mode 100644 index 000000000..e1151857f --- /dev/null +++ b/tool/zsh/nproc @@ -0,0 +1,18 @@ +[[ -x $(whence -p nproc) ]] && { + command nproc && { + unfunction nproc + return + } +} +[[ -x $(which sysctl) ]] && { + nproc() { + sysctl -n hw.ncpu + } + nproc && return +} +# TODO other platforms +echo nproc: no implementation found >&2 +nproc() { + echo 2 +} +nproc