X-Git-Url: https://plomlompom.com/repos/berlin_corona.txt?a=blobdiff_plain;f=build%2Fredo_scripts%2Fredo-ifchange;h=532587a0c4d81b18fea609a9e3801dd2df76fe84;hb=7d0f78a38b268446ad5d62b1e388487d3e3e121f;hp=bdec2d4dae215b11ab69c6d3451f0317762fed95;hpb=68dc4d386509aeebbbc5ce20dddbe9c0bf4f6eb9;p=plomrogue diff --git a/build/redo_scripts/redo-ifchange b/build/redo_scripts/redo-ifchange index bdec2d4..532587a 100755 --- a/build/redo_scripts/redo-ifchange +++ b/build/redo_scripts/redo-ifchange @@ -12,11 +12,24 @@ # Overflow oder eine Format String Vulnerability zwischen die anderen # Codezeilen und schreibe das auch nicht dran. +# GNU vs BSD. +test=`command -v md5sum | wc -l` +if [ 1 -gt $test ] +then + alias md5sum='md5 -r' +fi +alias stat_cY='stat -c%Y' +test=`stat --version 2>&1 | grep GNU | wc -l` +if [ 1 -gt $test ] +then + alias stat_cY='stat -f%Y' +fi + _add_ctime_md5sum() { target=$1 local base; _dirsplit "$target" [ -d "$REDO_DIR/$dir" ] || LANG=C mkdir -p "$REDO_DIR/$dir" - LANG=C stat -c%Y "$target" >"$REDO_DIR/$target".ctime + LANG=C stat_cY "$target" >"$REDO_DIR/$target".ctime LANG=C md5sum <"$target" >"$REDO_DIR/$target".md5sum } @@ -27,7 +40,7 @@ _add_dependency() { [ "$parent" = "$dependency" ] && exit 1 local base; _dirsplit "$parent" [ -d "$REDO_DIR/$dir" ] || LANG=C mkdir -p "$REDO_DIR/$dir" - ctime="$(LANG=C stat -c%Y "$dependency")" + ctime="$(LANG=C stat_cY "$dependency")" md5sum="$(LANG=C md5sum < "$dependency")" printf '%s\t%s\t%s\n' "$dependency" "$ctime" "$md5sum" >> \ "$REDO_DIR"/"$parent".dependencies.tmp @@ -70,6 +83,10 @@ _dependencies_ne_uptodate() { _target_uptodate() { target=$1 + # If a target is a top-level target, it is not up to date. + if [ -z "$REDO_TARGET" ]; then + return 1 + fi # If a target does not exist, it is not up to date. if [ ! -e "$target" ]; then _echo_debug_message "$target does not exist." @@ -87,7 +104,7 @@ _target_uptodate() { fi if [ -e "$REDO_DIR/$target".ctime ]; then read ctime_stored <"$REDO_DIR/$target".ctime - ctime_actual="$(LANG=C stat -c%Y "$target")" + ctime_actual="$(LANG=C stat_cY "$target")" _echo_debug_message "$target stored ctime $ctime_stored" _echo_debug_message "$target actual ctime $ctime_actual" if [ "$ctime_stored" = "$ctime_actual" ]; then @@ -101,7 +118,7 @@ _target_uptodate() { if [ "$md5sum_stored" = "$md5sum_actual" ]; then # If stored md5sum of target matches actual md5sum, but stored # ctime does not, redo needs to update stored ctime of target. - LANG=C stat -c%Y "$target" >"$REDO_DIR/$target".md5sum + LANG=C stat_cY "$target" >"$REDO_DIR/$target".md5sum return 0 fi _echo_debug_message "$target out of date." @@ -123,9 +140,9 @@ _dependencies_uptodate() { fi _echo_debug_message "$target dependency check:" # If any dependency does not exist, the target is out of date. - LANG=C stat -c%Y $(LANG=C cut -f1 "$REDO_DIR/$target".dependencies) > \ - "$REDO_DIR/".dependencies.ctimes 2>&- || return 1 - exec 3< "$REDO_DIR/".dependencies.ctimes + LANG=C stat_cY $(LANG=C cut -f1 "$REDO_DIR/$target".dependencies) > \ + "$REDO_DIR/$target".dependencies.ctimes 2>&- || return 1 + exec 3< "$REDO_DIR/$target".dependencies.ctimes exec 4< "$REDO_DIR/$target".dependencies while read ctime_actual <&3 && read dependency ctime_stored md5sum_stored <&4; do # If a .always file exists, the dependency is out of date. @@ -192,7 +209,9 @@ _do() { [ -e "$target.do" ] || _find_dofile "$target" if [ ! -e "$dofile" ]; then # If .do file does not exist and target exists, it is a source file. - if [ -e "$target" ]; then + if [ -e "$target_abspath" ]; then + _add_dependency "$REDO_TARGET" "$target_abspath" + _add_ctime_md5sum "$target_abspath" return 0 # If .do file does not exist and target does not exist, stop. else @@ -202,7 +221,7 @@ _do() { fi printf '%sredo %s%s%s%s%s\n' \ "$green" "$REDO_DEPTH" "$bold" "$target_relpath" "$plain" >&2 - ( _run_dofile "$target" "$base" "$tmp.tmp" ) + ( _run_dofile "$target" "${base##*/}" "$tmp.tmp" ) rv="$?" # Add non existing .do file to non-existence dependencies so # target is built when .do file in question is created. @@ -231,7 +250,7 @@ _do() { "$REDO_DIR/$target_abspath".dependencies_ne >&2 fi # Some do files (like all.do) do not usually generate output. - if [ -e "$target" ]; then + if [ -e "$target_abspath" ]; then # Record dependency on parent target. _add_dependency "$REDO_TARGET" "$target_abspath" _add_ctime_md5sum "$target_abspath"