From a233e84067051cf9bdcb8dc66c2383490ca5ff03 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Tue, 2 Jan 2024 21:59:39 -0600 Subject: initial commit --- ok | 109 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ok1 | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 208 insertions(+) create mode 100755 ok create mode 100755 ok1 diff --git a/ok b/ok new file mode 100755 index 0000000..058c98d --- /dev/null +++ b/ok @@ -0,0 +1,109 @@ +#!/bin/sh + +QUIET=false +NORUN=false +FNEW=false +_ARGS=true + +OKFILE=./ok +FRFILE=.fr + +usage(){ + exec >&2 + cat<&2 '* %s\n' "$*" + $NORUN || "$@" || exit $((100 + $?)) +} + +quietly(){ "$@" >/dev/null 2>&1; } + +allfiles(){ + cut -f2- <"$FRFILE" | + while read -r line + do eval "$line" + done +} + +fr(){ # fr < TARGET JOB DEPS... + # recommended: use a heredoc + :>"$FRFILE" + while read -r target job deps + do + eval set -- "$deps" + printf '%s\tok %s\t%s\n' \ + "$target" \ + "$job" \ + "$(printf '%s\n' "$deps"|sed 's/--.*//')" \ + >>"$FRFILE" + done +} + +go "$@" diff --git a/ok1 b/ok1 new file mode 100755 index 0000000..9d7971c --- /dev/null +++ b/ok1 @@ -0,0 +1,99 @@ +#!/bin/sh +## ok: a minimal command runner and build tool +# by Case Duckworth -- released to the public domain + +QUIET=false +NORUN=false +FBUILD=false +OKFILE=./ok +FRFILE=.fr + +_usage() { + exec >&2 + cat<&2 '* %s\n' "$*" + $NORUN || "$@" || exit $((100 + $?)) +} + +quietly() { "$@" >/dev/null 2>&1; } + +frun() { + cut -f2- <"$FRFILE" | + while read -r line + do eval "$line" + done +} + +fr() { # fr < GOAL JOB DEPS... + # recommended: use a heredoc + :>"$FRFILE" + while read -r goal job deps + do + eval set -- "$deps" + if buildp "$goal" "$@" + then + printf '%s\t%s %s\n' \ + "$goal" \ + "$job" "$(echo "$deps"|sed 's/--.*//')" \ + >>"$FRFILE" + fi + done +} + +while getopts hqnxBf:C: OPT +do + case "$OPT" in + (h) _usage ;; + (q) QUIET=true ;; + (x) set -x ;; + (n) NORUN=true ;; + (B) FBUILD=true ;; + (f) OKFILE="$OPTARG" ;; + (C) cd "$OPTARG" || exit 2 ;; + (*) _usage 1 ;; + esac +done +shift $((OPTIND - 1)) + +. "$OKFILE" || exit 3 + +test -z "$1" && default +for target +do + if grep -q "$target" "$FRFILE" + then eval "$(grep "$target" "$FRFILE" | cut -f2-)" + else "$target" + fi +done -- cgit 1.4.1-21-gabe81