apenwarr-redo/minimal/do
2010-11-16 03:11:28 -08:00

57 lines
1 KiB
Bash
Executable file

#!/bin/sh
#
# A minimal alternative to djb redo that doesn't support incremental builds.
# For the full version, visit http://github.com/apenwarr/redo
#
export REDO="$(dirname "$0")/$(basename "$0")"
IFS="
"
if [ -z "$DO_BUILT" ]; then
export DO_BUILT="$PWD/.do_built"
if [ -e "$DO_BUILT" ]; then
echo "Removing previously built files..." >&2
sort "$DO_BUILT" | uniq | tee "$DO_BUILT.new" | xargs rm -f
mv "$DO_BUILT.new" "$DO_BUILT"
fi
fi
_do()
{
TARGET="$1"
DOFILE="$TARGET.do"
if [ ! -e "$TARGET" ]; then
printf '\033[32mdo \033[1m%s\033[m\n' "$PWD/$TARGET" >&2
echo "$PWD/$TARGET" >>"$DO_BUILT"
set "$TARGET" "" "$TARGET.tmp"
( . "$PWD/$DOFILE" >"$TARGET.tmp" ) &&
mv "$TARGET.tmp" "$TARGET"
else
echo "$TARGET exists." >&2
fi
}
redo()
{
for i in "$@"; do
if [ -e "$i/." ]; then
i="$i/all"
fi
D="$(dirname "$i")"
B="$(basename "$i")"
( cd "$D" && _do "$B" )
done
}
alias redo-ifchange="redo"
alias redo-ifcreate=":"
set -e
if [ -n "$*" ]; then
redo "$@"
else
redo all
fi