diff options
-rwxr-xr-x | ok1 | 99 |
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 | |||
5 | QUIET=false | ||
6 | NORUN=false | ||
7 | FBUILD=false | ||
8 | OKFILE=./ok | ||
9 | FRFILE=.fr | ||
10 | |||
11 | _usage() { | ||
12 | exec >&2 | ||
13 | cat<<EOF | ||
14 | Usage: ok [OPTIONS] [TARGET...] | ||
15 | Options: | ||
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 | ||
23 | Targets 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") | ||
29 | EOF | ||
30 | exit $1 | ||
31 | } | ||
32 | |||
33 | buildp() { # 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 | |||
45 | ok() { # ok command... | ||
46 | $QUIET || printf >&2 '* %s\n' "$*" | ||
47 | $NORUN || "$@" || exit $((100 + $?)) | ||
48 | } | ||
49 | |||
50 | quietly() { "$@" >/dev/null 2>&1; } | ||
51 | |||
52 | frun() { | ||
53 | cut -f2- <"$FRFILE" | | ||
54 | while read -r line | ||
55 | do eval "$line" | ||
56 | done | ||
57 | } | ||
58 | |||
59 | fr() { # 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 | |||
75 | while getopts hqnxBf:C: OPT | ||
76 | do | ||
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 | ||
87 | done | ||
88 | shift $((OPTIND - 1)) | ||
89 | |||
90 | . "$OKFILE" || exit 3 | ||
91 | |||
92 | test -z "$1" && default | ||
93 | for target | ||
94 | do | ||
95 | if grep -q "$target" "$FRFILE" | ||
96 | then eval "$(grep "$target" "$FRFILE" | cut -f2-)" | ||
97 | else "$target" | ||
98 | fi | ||
99 | done | ||