2010-11-15 20:39:34 -08:00
|
|
|
#!/bin/sh
|
|
|
|
|
#
|
|
|
|
|
# A minimal alternative to djb redo that doesn't support incremental builds.
|
|
|
|
|
# For the full version, visit http://github.com/apenwarr/redo
|
|
|
|
|
#
|
2010-12-11 21:47:55 -08:00
|
|
|
export REDO="$(cd "$(dirname "$0")" && echo "$PWD/$(basename "$0")")"
|
2010-11-15 20:39:34 -08:00
|
|
|
|
|
|
|
|
if [ -z "$DO_BUILT" ]; then
|
|
|
|
|
export DO_BUILT="$PWD/.do_built"
|
|
|
|
|
if [ -e "$DO_BUILT" ]; then
|
|
|
|
|
echo "Removing previously built files..." >&2
|
2010-12-11 20:54:46 -08:00
|
|
|
sort -u "$DO_BUILT" | tee "$DO_BUILT.new" |
|
2010-11-17 18:24:40 -08:00
|
|
|
while read f; do rm -f "$f"; done
|
2010-11-15 20:39:34 -08:00
|
|
|
mv "$DO_BUILT.new" "$DO_BUILT"
|
|
|
|
|
fi
|
2010-12-11 21:47:55 -08:00
|
|
|
DO_PATH="$DO_BUILT.dir"
|
|
|
|
|
export PATH="$DO_PATH:$PATH"
|
|
|
|
|
rm -rf "$DO_PATH"
|
|
|
|
|
mkdir "$DO_PATH"
|
|
|
|
|
for d in redo redo-ifchange; do
|
|
|
|
|
ln -s "$REDO" "$DO_PATH/$d";
|
|
|
|
|
done
|
|
|
|
|
for d in redo-ifcreate redo-stamp redo-always; do
|
|
|
|
|
ln -s /bin/true "$DO_PATH/$d";
|
|
|
|
|
done
|
2010-11-15 20:39:34 -08:00
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
2010-11-21 00:16:37 -08:00
|
|
|
_dirsplit()
|
|
|
|
|
{
|
|
|
|
|
OLDIFS="$IFS"
|
|
|
|
|
IFS=/
|
|
|
|
|
set -- $1
|
|
|
|
|
IFS="$OLDIFS"
|
|
|
|
|
dir=""
|
|
|
|
|
while [ $# -gt 1 ]; do
|
|
|
|
|
dir="$dir$1/"
|
|
|
|
|
shift
|
|
|
|
|
done
|
|
|
|
|
base="$1"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2010-11-15 20:39:34 -08:00
|
|
|
_do()
|
|
|
|
|
{
|
2010-11-16 03:28:44 -08:00
|
|
|
DIR="$1"
|
|
|
|
|
TARGET="$2"
|
2010-11-15 20:39:34 -08:00
|
|
|
if [ ! -e "$TARGET" ]; then
|
2010-11-16 03:28:44 -08:00
|
|
|
printf '\033[32mdo %s\033[1m%s\033[m\n' \
|
|
|
|
|
"$DO_DEPTH" "$DIR$TARGET" >&2
|
2010-11-15 20:39:34 -08:00
|
|
|
echo "$PWD/$TARGET" >>"$DO_BUILT"
|
2010-11-16 03:20:52 -08:00
|
|
|
dof=".$TARGET"
|
|
|
|
|
DOFILE="$TARGET.do"
|
2010-11-17 18:24:40 -08:00
|
|
|
BASE="$TARGET"
|
|
|
|
|
EXT=""
|
2010-11-16 03:20:52 -08:00
|
|
|
while [ ! -e "$DOFILE" ]; do
|
|
|
|
|
dof2=$(echo "$dof" | sed 's/\.[^\.]*//')
|
|
|
|
|
[ "$dof" = "$dof2" ] && break
|
|
|
|
|
dof="$dof2"
|
|
|
|
|
DOFILE="default$dof.do"
|
2010-11-17 18:24:40 -08:00
|
|
|
BASE="$(basename "$TARGET" "$dof")"
|
|
|
|
|
EXT="$dof"
|
2010-11-16 03:20:52 -08:00
|
|
|
done
|
2010-11-17 18:24:40 -08:00
|
|
|
set "$BASE" "$EXT" "$TARGET.tmp"
|
|
|
|
|
RV=
|
2010-11-16 03:28:44 -08:00
|
|
|
(
|
|
|
|
|
export DO_DEPTH="$DO_DEPTH "
|
2010-12-11 20:54:46 -08:00
|
|
|
export REDO_TARGET="$PWD/$TARGET"
|
2010-11-17 18:24:40 -08:00
|
|
|
set -e
|
2010-11-16 03:28:44 -08:00
|
|
|
. "$PWD/$DOFILE" >"$TARGET.tmp"
|
2010-11-17 18:24:40 -08:00
|
|
|
) || RV="$?"
|
|
|
|
|
[ -z "$RV" ] && mv "$TARGET.tmp" "$TARGET" 2>/dev/null
|
|
|
|
|
: >>"$TARGET"
|
|
|
|
|
if [ -n "$RV" ]; then
|
2010-12-11 20:36:42 -08:00
|
|
|
printf "do: %s%s\n" "$DO_DEPTH" \
|
|
|
|
|
"$DIR$TARGET: got exit code $RV" >&2
|
|
|
|
|
return $RV
|
2010-11-17 18:24:40 -08:00
|
|
|
fi
|
2010-11-15 20:39:34 -08:00
|
|
|
else
|
2010-11-16 03:28:44 -08:00
|
|
|
echo "do $DO_DEPTH$TARGET exists." >&2
|
2010-11-15 20:39:34 -08:00
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
redo()
|
|
|
|
|
{
|
|
|
|
|
for i in "$@"; do
|
2010-11-21 00:16:37 -08:00
|
|
|
_dirsplit "$i"
|
2010-12-11 20:36:42 -08:00
|
|
|
( cd "$dir" && _do "$dir" "$base" ) || return 1
|
2010-11-15 20:39:34 -08:00
|
|
|
done
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
if [ -n "$*" ]; then
|
|
|
|
|
redo "$@"
|
|
|
|
|
else
|
|
|
|
|
redo all
|
|
|
|
|
fi
|