chiark / gitweb /
maybe-rerun-optim
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 28 Feb 2019 01:25:54 +0000 (01:25 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 28 Feb 2019 01:25:54 +0000 (01:25 +0000)
Makefile
maybe-rerun-optim [new file with mode: 0755]

index 5ce5779f77f0b23837247fbef2e8d6671410b5d5..d15de38419dee23a3f28e32024153cf30e061279 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -9,18 +9,16 @@ PLANAR_GRAPH=planar-graph
 map.plag: generate-plag input-graph Parse.pm 
        ./$< input-graph $o
 
-opt.plag: map.plag $(PLANAR_GRAPH)
-       sha256sum $^ >.opt.plag.sums.tmp
-       cmp .opt.plag.sums.tmp .opt.plag.sums || (      \
-       $(PLANAR_GRAPH) RF $<                           \
+# create opt.plag.reuse to shortcut this
+opt.plag: maybe-rerun-optim map.plag $(PLANAR_GRAPH)
+       ./$^ $@ .opt.plag.sums \
+               R                                       \
                DUAL                                    \
                OUTER-F2V OUTER-SPLIT                   \
                B T OUTER-F2V OUTER-F12VA               \
                PCO CP RAE                              \
-               D 0 NLOPT                               \
+               D 0 NLOPT                               \
                W $@.tmp                                \
-               && $i                                   \
-               && mv -vf .opt.plag.sums.tmp .opt.plag.sums )
 
 #map.ps: map.dot
 #      neato -Tps $^ $o
diff --git a/maybe-rerun-optim b/maybe-rerun-optim
new file mode 100755 (executable)
index 0000000..23331e9
--- /dev/null
@@ -0,0 +1,26 @@
+#!/bin/bash
+set -e
+set -o posix
+set -o pipefail
+
+input=$1       ; shift
+planar_graph=$1        ; shift
+dest=$1                ; shift
+sums=$1                ; shift
+
+inst () { mv -vf $dest.tmp $dest; }
+
+if test -f $dest.reuse; then
+       cp -v $@.reuse $@.tmp
+       inst
+       exit 0
+fi
+
+sha256sum "$input" "$planar_graph" >$sums.tmp
+for arg in "$@"; do printf >>$sums.tmp "%s\n" "$arg"; done
+
+if cmp $sums.tmp $sums; then
+       exit 0
+fi
+
+"$planar_graph" <$input "$@"