summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordavidovski <david@davidovski.xyz>2024-03-21 11:32:02 +0000
committerdavidovski <david@davidovski.xyz>2024-03-21 11:33:45 +0000
commit14b7eb50d3c2f41fec9d03580a5f531cc91f6dad (patch)
tree4a87afba4a719aa2e5dfec30d7d62a847d60ee1d
parentf8b8b0a7cad96c648c896fa6eb660fdb988dfdb2 (diff)
do not rebuild files that haven't changed
-rwxr-xr-xsrc/shblg.sh29
1 files changed, 21 insertions, 8 deletions
diff --git a/src/shblg.sh b/src/shblg.sh
index 61ef7db..e5b10f5 100755
--- a/src/shblg.sh
+++ b/src/shblg.sh
@@ -8,6 +8,12 @@ usage () {
exit 1
}
+# check if a file has changed since last generating
+#
+newer () {
+ [ ! -e "$2" ] || [ "$1" -nt "$2" ]
+}
+
while getopts ":o:i:h" opt; do
case "$opt" in
o)
@@ -29,22 +35,29 @@ process () {
dirpath="${1%"${1##*/}"}"
out_file="${OUTPUT_DIR}${path}"
- printf "%s ...\n" "$path"
[ -d "$1" ] && {
+
mkdir -p "$out_file"
for f in "$1"/*; do
process "$f"
done
+
return 0
- } || [ -x "$1" ] && (
- # execute the file
- cd "$dirpath"
- "$1" > "${out_file}"
+ } || [ -x "$1" ] && {
+ newer "$1" "$out_file" && (
+ # execute the file
+ cd $dirpath
+ printf "#!%s\n" "$path"
+ "$1" > "$out_file"
+ )
return 0
- ) || {
- # just copy the file as is
- cp "$1" "$out_file"
+ } || {
+ newer "$1" "$out_file" && (
+ # just copy the file as is
+ printf "%s\n" "$path"
+ cp "$1" "$out_file"
+ )
return 0
}
}