home · contact · privacy
Server: Remove unneeded library includes.
[plomrogue] / build / redo_scripts / redo-ifchange
index d345a39694f007e3516e7945045ef138f4cd4c77..4de341785b5e74fcc1c13a033349cbfac1373ea7 100755 (executable)
@@ -53,6 +53,12 @@ _add_target() {
   fi
 }
 
+_add_target_buildtime() {
+  [ -z "$1" ] && exit 1
+  # Portable timestamps for systems supporting GNU date format '%N'.
+  date +%s%N | tr -d '%N' > "$REDO_DIR$1".buildtime
+}
+
 _dependencies_uptodate() {
   target="$1"
   target_relpath=${target##$REDO_BASE/}
@@ -112,8 +118,16 @@ _dependencies_uptodate() {
     # target would not be built. If a dependency build timestamp is
     # greater than or equal to a targets build timestamp, assume the
     # dependency has been rebuilt and the target should be rebuilt.
-    target_ts="$(cat "$REDO_DIR/$target_abspath.buildtime" 2>/dev/null || echo 0)"
-    dependency_ts="$(cat "$REDO_DIR/$dependency.buildtime" 2>/dev/null || echo 0)"
+    if [ -e "$REDO_DIR/$target_abspath.buildtime" ]; then \
+      read target_ts < "$REDO_DIR/$target_abspath.buildtime";
+    else
+      target_ts=0
+    fi
+    if [ -e "$REDO_DIR/$dependency.buildtime" ]; then
+      read dependency_ts < "$REDO_DIR/$dependency.buildtime"
+    else
+       dependency_ts=0
+    fi
     if [ "$dependency_ts" -ge "$target_ts" ]; then
       _echo_debug_message \
         "$REDO_DEPTH$dir$target_relpath dependency $dependency_relpath uptodate, but built later than $target_relpath."
@@ -155,13 +169,12 @@ _do() {
     [ -e "$target.do" ] || _find_dofile "$target"
     # Add non existing .do file to non-existence dependencies so target is built when
     # .do file in question is created.
-    _add_dependency_ne "$(readlink -f "$target")" "$PWD/$target.do"
+    _add_dependency_ne "$target_abspath" "$PWD/$target.do"
     if [ ! -e "$dofile" ]; then
       # If .do file does not exist and target exists, it is a source file.
       if [ -e "$target" ]; then
-        _add_target "$(readlink -f $target)"
-        # Portable timestamps for systems supporting GNU date format '%N'.
-        date +%s%N | tr -d '%N' > "$REDO_DIR/$target_abspath".buildtime
+        _add_target "$target_abspath"
+        _add_target_buildtime "$target_abspath"
         return 0
       # If .do file does not exist and target does not exist, stop.
       else
@@ -170,7 +183,7 @@ _do() {
       fi
     # Add .do file to dependencies so target is built when .do file changes.
     else
-      _add_dependency "$(readlink -f "$target")" "$PWD/$dofile"
+      _add_dependency "$target_abspath" "$PWD/$dofile"
       _add_target "$PWD/$dofile"
     fi
     printf '%sredo %s%s%s%s%s\n' \
@@ -190,12 +203,14 @@ _do() {
     ! test -s "$tmp.tmp2" ||
     mv "$tmp.tmp2" "$target" 2>/dev/null
     rm -f "$tmp.tmp2"
-    # Portable timestamps for systems supporting GNU date format '%N'.
-    date +%s%N | tr -d '%N' > "$REDO_DIR/$target_abspath".buildtime
+    _add_target_buildtime "$target_abspath"
   else
     _echo_debug_message "$REDO_DEPTH$dir$target is up to date."
   fi
-  _add_target "$(readlink -f $target)"
+  # Some do files (like all.do) do not usually generate output.
+  if [ -e "$target" ]; then
+    _add_target "$target_abspath"
+  fi
 }
 
 _echo_debug_message() {
@@ -240,7 +255,7 @@ _is_uptodate() {
     if [ ! -e "$REDO_DIR/$target".ctime ]; then
       _echo_debug_message "$REDO_DEPTH$dir$target_relpath.ctime does not exist."
       # Add source file to dependencies so target is built when source file changes.
-      _add_target "$(readlink -f $target)"
+      _add_target "$target_abspath"
       return 0
     else
       _echo_debug_message "$REDO_DEPTH$dir$target_relpath.ctime exists."
@@ -258,8 +273,7 @@ _is_uptodate() {
       fi
       # If a file exists and has an entry in the dependency database and ctime
       # is the same as in the entry in the ctime database, it is up to date.
-      if [ "$(cat "$REDO_DIR/$target".ctime 2>/dev/null || :)" = \
-        "$(stat -c%Y "$target")" ]; then
+      if (export LC_ALL=C; stat -c%Y "$target" | grep -Fqx -f "$REDO_DIR/$target".ctime); then
         _echo_debug_message "$REDO_DEPTH$dir$target_relpath.ctime match."
         return 0
       else
@@ -267,8 +281,7 @@ _is_uptodate() {
         # If a file exists and has an entry in the dependency database and
         # ctime is different from the entry in the ctime database, but md5sum
         # is the same as md5sum in the md5sum database, it is up to date.
-        if [ "$(cat "$REDO_DIR/$target".md5sum 2>/dev/null || :)" = \
-          "$(md5sum < "$target")" ]; then
+        if (md5sum < "$target" | grep -Fqx -f "$REDO_DIR/$target".md5sum); then
           _echo_debug_message "$REDO_DEPTH$dir$target_relpath.md5sum match."
           return 0
         else
@@ -301,7 +314,9 @@ _run_dofile() {
 
 set +e
 if [ -n "$1" ]; then
-  for target; do
+  targets="$@"
+  [ "$REDO_SHUFFLE" = "1" ] && targets=$(shuf -e "$@")
+  for target in $targets; do
     _dirsplit "$target"
     _dir_shovel "$dir" "$base"
     dir="$xdir" base="$xbase" basetmp="$xbasetmp"