#!/bin/sh QUIET="${OK_QUIET:-false}" NORUN="${OK_NORUN:-false}" FORCE="${OK_FORCE:-false}" NODIE="${OK_NODIE:-false}" OKFILE="${OK_OKFILE:-./ok}" FRFILE="${OK_FRFILE:-./.fr}" DOARGS=true usage() { cat >&2 <&2 "* $@" if ! $NORUN then "$@"; ec="$?" if ! test $ec -eq 0 then echo >&2 "* not ok : $@" $NODIE || exit $((100 + $?)) fi fi } fr() ( exec > "$FRFILE" while read -r target job deps do printf '%s\tok %s\t%s\n' "$target" "$job" "$deps" done ) dep() { if ! DOARGS=false go "$@" then echo >&2 dep not ok exit $((200 + $?)) fi } all() { while read -r target job deps do if split "$line" | buildp "$target" then TARGET="$target" eval "$job" "$deps" fi done < "$FRFILE" } ### Backend buildp() { $FORCE && return 0 target="$1"; shift test -e "$target" || return 0 while read -r dep do if test "$dep" -nt "$target" then echo >&2 "$dep newer than $target" return 0 fi done return 1 } ### Entry point args() { $DOARGS || return 1 while getopts hqnBkxf:C: OPT do case "$OPT" in (h) usage; exit ;; (q) QUIET=true ;; (n) NORUN=true ;; (B) FORCE=true ;; (k) NODIE=true ;; (x) set -x ;; (f) if test -f "$OPTARG" then OKFILE="$OPTARG" else echo >&2 No okfile given. exit 2 fi ;; (C) if ! cd "$OPTARG" then echo >&2 Directory does not exist. exit 2 fi ;; (*) usage; exit 1 ;; esac done } go() { args "$@" && shift $((OPTIND - 1)) case "$OKFILE" in (*/*) ;; (*) OKFILE="./$OKFILE" ;; esac if ! test -f "$OKFILE" then echo >&2 Cannot find okfile "$OKFILE" exit 3 fi DEFAULT="$(sed -n 's/\([a-z][a-z]*\)().*/\1/p' "$OKFILE"|sed q)" test -z "$DEFAULT" && DEFAULT=all if ! . "$OKFILE" then echo >&2 Cannot source okfile "$OKFILE" exit 3 fi if test $# -eq 0 then "$DEFAULT" else for tgt do if grep -q "$tgt" "$FRFILE" then if split "$(grep "$tgt" "$FRFILE"|cut -f3-)"| \ buildp "$tgt" then TARGET="$tgt" eval \ "$(grep "$tgt" "$FRFILE"|cut -f2-)" fi else "$tgt" fi done fi } ### Utilities split() { eval set -- "$*" printf '%s\n' "$@" } ### Do it go "$@" && echo ok