+####################
+# googlemap stuff
+# Uses:
+# GMAP_SERVER, the hostname that runs an ndnmap instance
+# GMAP_PROBES, a list of tuples of the form
+# <linkid>=<nodeid>=<internal_linkid>=<frequency>
+# e.g.
+# SENDER-MUX=SENDER=3=0.5
+# which would mean, the link 'SENDER-MUX' should be monitored at the 'SENDER' node and is coded
+# in links.json with id=3, every half second
+# sliver-ovs gmap-probe is designed to run in background,
+# and so that a new run will kill any previously running instance
+gprobes: $(foreach probe,$(GMAP_PROBES),gprobe-$(probe))
+
+gprobe-%: FORCE
+ $(SSH) -n $(call solve,$(word 2,$(subst @, ,$(*F)))) $(SUDO) \
+ sliver-ovs gmap-probe L$(word 1,$(subst @, ,$(*F))) $(GMAP_SERVER) $(word 3,$(subst @, ,$(*F))) $(word 4,$(subst @, ,$(*F)))
+
+jsons: routers.json links.json geocode.json
+.PHONE: jsons
+
+routers.json: $(CONF)
+ @{ echo "["; \
+ sep=" "; \
+ for n in $(CONF_NODE_IDS); do \
+ echo " $$sep\"$$n\""; \
+ sep=", "; \
+ done; \
+ echo "]"; \
+ } > $@
+
+links.json: $(foreach l,$(LINKS),cache/json.$(l))
+ @{ echo "["; \
+ cat $^ | sed '2,$$s/^/, /'; \
+ echo "]"; \
+ } > $@
+
+cache/json.%: $(CONF)
+ @echo "{\"id\": $($*_linkid), \"start\": \"$(call get,$*@1)\", \"end\": \"$(call get,$*@2)\"}" > $@
+
+geocode.json: $(foreach n,$(CONF_NODE_IDS),cache/geocode.$(n))
+ @{ echo "{"; \
+ sep=" "; \
+ for f in $^; do \
+ echo -n "$$sep"; \
+ cat $$f; \
+ sep=", "; \
+ done; \
+ echo "}"; \
+ } > $@
+
+cache/geocode.%: cache/loc.% $(CONF)
+ @{ echo "\"$*\": {"; \
+ echo " \"name\": \"$(HOST_$*)\","; \
+ echo " \"shortname\": \"$*\","; \
+ echo " \"site\": \"\","; \
+ echo " \"backbone\": false,"; \
+ echo " \"position\": [ $(shell cat cache/loc.$*) ]"; \
+ echo " }"; \
+ } > $@
+
+cache/loc.%: $(CONF)
+ @wget -O - 'http://freegeoip.net/csv/$(HOST_$*)' | \
+ awk -F, '{ printf "%s, %s\n", $$8, $$9 }' > $@
+
+####################
+# 'virtual' targets in that there's no real file attached
+define node_shortcuts
+sshcheck.$(1): sshcheck-$(1) FORCE
+db.$(1): cache/db.$(1) FORCE
+switch.$(1): cache/switch.$(1) FORCE
+start.$(1): cache/start.$(1) FORCE
+stop.$(1): cache/stop.$(1) FORCE
+status.$(1): cache/status.$(1) FORCE
+bridge.$(1): cache/bridge.$(1) FORCE
+host.$(1): cache/host.$(1) FORCE
+controller.$(1): cache/controller.$(1) FORCE
+# switch already depends on db, but well
+cache/start.$(1): cache/db.$(1) cache/switch.$(1) FORCE
+endef
+
+$(foreach id,$(ALL_NODE_IDS), $(eval $(call node_shortcuts,$(id))))
+
+define link_shortcuts
+iface.%: cache/iface.%
+endpoint.%: cache/endpoint.%
+endef
+
+$(foreach id,$(ALL_LINK_IDS), $(eval $(call link_shortcuts,$(id))))
+
+help:
+ @cat Makefile.help