chiark / gitweb /
find-plag
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 3 Mar 2019 11:22:20 +0000 (11:22 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 3 Mar 2019 11:22:20 +0000 (11:22 +0000)
Makefile
find-plag [new file with mode: 0755]

index bc72f22c02abbcc2ef3d76a0e72d67be734b0146..ee8052ab7e58e454d59349bff316473a232c379d 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -4,7 +4,14 @@ o= >$@.tmp && $i
 
 export PERL_HASH_SEED=1
 
-PLANAR_GRAPH=planar-graph
+# PLAG_DEBUG   ?= $(PLAG)     # effectively
+# PLAG_RELEASE ?= $(PLAG)     # ie caller may set these
+PLAG_DIR     ?= ../planar-graph
+
+USE_PLAG_DEBUG   := $(shell ./find-plag \
+ debug:release "$(PLAG_DIR)" "$(PLAG_DEBUG)" "$(PLAG_RELEASE)" "$(PLAG)")
+USE_PLAG_RELEASE := $(shell ./find-plag \
+ release:debug "$(PLAG_DIR)" "$(PLAG_RELEASE)" "$(PLAG_DEBUG)" "$(PLAG)")
 
 # with planar-graph 74bbc2b1da372d3456c00bcb07f3358c739e5721
 
@@ -18,7 +25,7 @@ map.plag: generate-plag input-graph Parse.pm
        ./$< input-graph $o
 
 # create opt.plag.reuse to shortcut this
-opt.plag: maybe-rerun-optim map.plag $(PLANAR_GRAPH) Makefile
+opt.plag: maybe-rerun-optim map.plag $(USE_PLAG_RELEASE) Makefile
        ./$(filter-out Makefile, $^) $@ .opt.plag.sums \
                R                                       \
                DUAL                                    \
@@ -28,8 +35,8 @@ opt.plag: maybe-rerun-optim map.plag $(PLANAR_GRAPH) Makefile
                D 0 NLOPT                               \
                W $@.tmp
 
-faces.plag: opt.plag $(PLANAR_GRAPH) Makefile
-       $(PLANAR_GRAPH) RF $< W-FACES $@.tmp && $i
+faces.plag: opt.plag $(USE_PLAG_DEBUG) Makefile
+       $(USE_PLAG_DEBUG) RF $< W-FACES $@.tmp && $i
 
 whole.ps: generate-board faces.plag input-graph misc-data.pl Parse.pm
        ./generate-board -XS faces.plag input-graph $o
diff --git a/find-plag b/find-plag
new file mode 100755 (executable)
index 0000000..45b9773
--- /dev/null
+++ b/find-plag
@@ -0,0 +1,35 @@
+#!/bin/bash
+set -e
+
+cmd=planar-graph
+
+want="$1"; shift
+dir="$1"; shift
+
+printf >&2 "selecting %s (%s)..." "$cmd" "${want%%:*}"
+
+for val in "$@"; do
+       if [ "$val" ]; then
+               printf >&2 ' %s\n' "$val"
+               printf '%s\n' "$def"
+               exit 0
+       fi
+done
+
+if type -p $cmd 2>/dev/null; then
+       printf >&2 ' PATH\n'
+       exit 0
+fi
+
+for which in ${want//\:/ }; do
+       r="$dir/target/$which/$cmd"
+       if test -e "$r"; then
+               printf >&2 ' %s\n' "$r"
+               printf '%s\n' "$r"
+               exit 0
+       fi
+done
+
+printf >&2 ' no!\n'
+echo missing-planar-graph-utility
+exit 16