about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorCase Duckworth2024-01-02 22:00:57 -0600
committerCase Duckworth2024-01-02 22:00:57 -0600
commit9c162a8d9afba45b869bba371f11db383bf2ec9e (patch)
tree1b2b5788a4570b3902a5f2daba2893891d23aea7
parentinitial commit (diff)
downloadok-9c162a8d9afba45b869bba371f11db383bf2ec9e.tar.gz
ok-9c162a8d9afba45b869bba371f11db383bf2ec9e.zip
Removed first version
-rwxr-xr-xok199
1 files changed, 0 insertions, 99 deletions
diff --git a/ok1 b/ok1 deleted file mode 100755 index 9d7971c..0000000 --- a/ok1 +++ /dev/null
@@ -1,99 +0,0 @@
1#!/bin/sh
2## ok: a minimal command runner and build tool
3# by Case Duckworth <acdw@acdw.net> -- released to the public domain
4
5QUIET=false
6NORUN=false
7FBUILD=false
8OKFILE=./ok
9FRFILE=.fr
10
11_usage() {
12 exec >&2
13 cat<<EOF
14Usage: ok [OPTIONS] [TARGET...]
15Options:
16 -h Show this help and exit
17 -q Don't output diagnostic messages
18 -x Run with set -x
19 -B Treat all targets as 'new' (force running)
20 -n Don't run commands
21 -f FILE Use FILE as \$OKFILE (default: 'ok')
22 -C DIRECTORY Change to DIRECTORY before doing anything
23Targets defined in $OKFILE:
24$(sed -n \
25 -e 's/^alias *\(.*\)/*\1/p' \
26 -e 's/^\([a-z][a-z]*\)().*##* *\(.*\)/ \1 # \2/p' \
27 -e 's/^\([a-z][a-z]*\)().*/ \1/p' \
28 "$OKFILE")
29EOF
30 exit $1
31}
32
33buildp() { # buildp target dependency...
34 $FBUILD && return
35 target="$1"; shift
36 test -e "$target" || return
37 for f
38 do
39 test x-- = "x$f" && continue
40 test "$f" -nt "$target" && return
41 done
42 return 1
43}
44
45ok() { # ok command...
46 $QUIET || printf >&2 '* %s\n' "$*"
47 $NORUN || "$@" || exit $((100 + $?))
48}
49
50quietly() { "$@" >/dev/null 2>&1; }
51
52frun() {
53 cut -f2- <"$FRFILE" |
54 while read -r line
55 do eval "$line"
56 done
57}
58
59fr() { # fr < GOAL JOB DEPS...
60 # recommended: use a heredoc
61 :>"$FRFILE"
62 while read -r goal job deps
63 do
64 eval set -- "$deps"
65 if buildp "$goal" "$@"
66 then
67 printf '%s\t%s %s\n' \
68 "$goal" \
69 "$job" "$(echo "$deps"|sed 's/--.*//')" \
70 >>"$FRFILE"
71 fi
72 done
73}
74
75while getopts hqnxBf:C: OPT
76do
77 case "$OPT" in
78 (h) _usage ;;
79 (q) QUIET=true ;;
80 (x) set -x ;;
81 (n) NORUN=true ;;
82 (B) FBUILD=true ;;
83 (f) OKFILE="$OPTARG" ;;
84 (C) cd "$OPTARG" || exit 2 ;;
85 (*) _usage 1 ;;
86 esac
87done
88shift $((OPTIND - 1))
89
90. "$OKFILE" || exit 3
91
92test -z "$1" && default
93for target
94do
95 if grep -q "$target" "$FRFILE"
96 then eval "$(grep "$target" "$FRFILE" | cut -f2-)"
97 else "$target"
98 fi
99done