cosmopolitan/tool/zsh/mmake
Jōshin dd57c685aa
mmake gets smarter
`o/$mode/*` is passed through as-is. `o/*` other than `$mode` has
`$mode` inserted. `*` has `o/$mode/` prepended.

Really leveraging zsh default tab completion here; if you have built
things with `MODE=` you can leverage that for perfect tab completion
in other modes.
2023-12-17 15:42:27 -05:00

44 lines
1.1 KiB
Text

# Cosmopolitan zsh make helper.
# Setup (in ~/.zshrc, for instance):
# fpath+=($COSMO/tool/zsh)
# autoload -Uz mmake
# e.g.:
# mmake tiny ape/ape.elf
local mode
case $1 in
(m|MODE)=*)
mode=${1#*=}; shift ;;
aarch64|x86_64|aarch64-(zero|tiny)|x86_64-tiny) ;&
zero|fastbuild|opt|optlinux|rel|asan|dbg|sysv) ;&
tiny(|linux(|bsd)|sysv|nowin)|nox87|llvm|ansi)
mode=$1; shift ;;
*)
mode=${MODE:-${m}} ;;
esac
[[ -z $mode ]] && {
local arch=$(uname -m)
case $arch in
arm64|aarch64) mode=aarch64 ;;
esac
}
local -a targs
local -a flags
local j
while (( $# > 0 )); do
case $1 in
-j*) j=$1; shift ;;
-*|*=*) flags+=($1); shift ;;
o/$mode/*) targs+=($1); shift ;;
o/*) targs+=(o/$mode/${1#*/}); shift ;;
*) targs+=(o/$mode/$1); shift ;;
esac
done
[[ -z $j ]] && {
whence nproc >/dev/null 2>&1 || autoload -Uz nproc
j=-j$(nproc)
}
local make
[[ -x /opt/cosmocc/bin/make ]] && make=/opt/cosmocc/bin/make
[[ -z $make ]] && make=build/bootstrap/make.com
( set -x
exec $make $j $flags MODE=$mode $targs )