+#!/bin/sh
+# script args: source_file target_file
+
+use_clusters='no'
+if [ ! -z "$USE_CLUSTERS" ]; then
+ use_clusters=$USE_CLUSTERS
+fi
+
+# args: file snippet
+# file will be modified in place
+include_dot_snippet ()
+{
+ echo "Adding to $1 graphviz snipet $2 ..."
+ sed -i "/digraph/r $2" $1
+}
+
+# args: file patch
+apply_patch ()
+{
+ if [ -f "$2" ]; then
+ echo "Applying to $1 patch $2 ..."
+ patch $1 $2
+ fi
+}
+
+cp $1 $2
+apply_patch $2 deps.patch
+include_dot_snippet $2 daemons.dot
+if [ "$use_clusters" = "yes" ]; then
+ include_dot_snippet $2 clusters.dot
+fi
+