This repository has been archived on 2021-08-25. You can view files and clone it, but cannot push or open issues or pull requests.
shellbuild/sb

74 lines
1.6 KiB
Text
Raw Permalink Normal View History

2021-08-25 19:43:37 +03:00
#!/bin/sh
die() {
echo "$0: error: $1"
exit 2
}
sbcache="$PWD/.sbcache"
[ ! -d $sbcache ] && mkdir "$sbcache"
# [utilities]
match_files() {
find . -maxdepth 1 -type f -name "$1"
}
match_files_recurse() {
find . -type f -name "$1"
}
ext() {
match_files "*.$1"
}
ext_all() {
match_files_recurse "*.$1"
}
depends() {
modified=""
continue_anyway="false"
for i in "$@"; do
# if any of the files are new or modifed, we will let the caller continue execution
case "$i" in
_*)
"$i" >/dev/null
if [ $? -ne 3 ]; then
continue_anyway="true"
fi
;;
*)
cachepath="$sbcache/.$(basename $i).sbmod"
if [ ! -f "$cachepath" ] || [ $(cat "$cachepath") != $(stat -c '%Y' "$i") ]; then
echo $(stat -c '%Y' "$i") > "$cachepath"
modified="${modified} ${i}"
fi
;;
esac
done
if [ "$modified" = "" ] && [ "$continue_anyway" == "false" ]; then
echo "return 3"
return
fi
echo 'modified="$modified"'
}
# load the file, making its functions and variables available here and vice-versa
sbfile="$PWD/sbrc"
[ ! -f "$sbfile" ] && die "no such sbrc in current directory"
. "$sbfile"
# run functions from the file as requested by the user
case "$1" in
"")
__default
if [ $? -eq 3 ]; then
exit 0
fi
;;
*)
"_$1" || die "failed to run script $1"
;;
esac