apenwarr-redo/minimal/do
Avery Pennarun 4243f31e1b Add minimal/do, a stripped-down redo implementation in 977 bytes of sh.
This could be good for distributing with your packages, so that people who
don't have redo installed can at least build it.  Also, we could use it for
building redo itself.

Will surely need to get slightly bigger as I inevitably discover I've
forgotten a critical feature.
2010-11-16 00:27:52 -08:00

54 lines
977 B
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="$1.do"
if [ ! -e "$TARGET" ]; then
printf '\033[32mdo \033[1m%s\033[m\n' "$PWD/$TARGET" >&2
echo "$PWD/$TARGET" >>"$DO_BUILT"
set "$TARGET" FIXME "$TARGET.tmp"
( . "$PWD/$DOFILE" >"$TARGET.tmp" ) &&
mv "$TARGET.tmp" "$TARGET"
else
echo "$1 exists." >&2
fi
}
redo()
{
for i in "$@"; do
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