mirror of
http://git.davidovski.xyz/shblg.git
synced 2024-08-15 00:43:48 +00:00
do not rebuild files that haven't changed
This commit is contained in:
parent
f8b8b0a7ca
commit
14b7eb50d3
1 changed files with 21 additions and 8 deletions
29
src/shblg.sh
29
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
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue