# $Id: Makefile 1216 2017-07-07 00:59:13Z wollman $

# Parameters...

# Set VERBOSE to "-v" if you want to see the output of dot(1)'s optimizer.
# The best I've seen so far has been 468 crossings (with MCLIMIT set to
# 16384.0), but it's possible a further increase, or changing the parameters
# to unflatten will result in fewer crossings.  Setting UNFLATTEN to 1 will
# effectively disable unflatten (may be useful to generate a wider, but
# shallower graph with all same-ranked nodes on the same horizontal line).
VERBOSE?=
MCLIMIT?=16384.0
UNFLATTEN?=5
SVGFONT?="Bitstream Vera Serif"

all: csail.pdf csail.svg

# Currently we generate the PDF by generating PostScript, editing the
# output to fix up a few bugs in the output, and then converting to
# PDF with GhostScript.  GraphViz's internal PDF implementation (which
# uses Cairo) is getting better and at some point will be superior,
# but can't parse the CSAIL logo (which is an EPSF, not a bitmap).

csail.pdf: csail.ps
	ps2pdf csail.ps

# Explanation of this pipeline...
#
# The main connected component of this graph is very wide.  unflatten adjusts
# the edge weights to allow some edges of nodes with multiple children to be
# longer, which allows the children to be stacked vertically rather than
# lining up vertically along the same baseline.
#
# ccomps -x extracts the connected components of the main graph into subgraphs,
# which are used later on to float the smaller components into otherwise
# unoccupied whitespace on the page.
#
# dot does the actual graph layout.  See comments above about VERBOSE and
# MCLIMIT.  The page size that dot and subsequent utilities assume is
# referenced in three places, two inside csail.dot and one (using different
# units) in fixup.sed, which must be synchronized.
#
# gvpack floats the smaller connected components into gaps in the large one.
#
# neato -s -n2 just generates the output without changing any of the layout.
#
# fixup.sed edits the PostScript output of neato to (a) use the correct
# width of the string "CSAIL Academic Genealogy", and (b) to set the correct
# PostScript output device page dimensions so that it can be printed on
# a plotter or converted to a PDF at the intended size.
# 
csail.ps: csail.dot csail-logo.eps fixup.sed url-qrcode.png
	unflatten -l $(UNFLATTEN) -f csail.dot | ccomps -x | dot $(VERBOSE) -Gmclimit=$(MCLIMIT) | gvpack | neato -s -n2 -Tps | sed -f fixup.sed > csail.ps

# This should be the same pipeline as is used above but without the sed
# since it generates SVG rather than PostScript.  The SVG driver can't do
# anything with the CSAIL logo (which is Encapsulated PostScript) so it's
# not a dependency for this format.
csail.svg: csail.dot url-qrcode.png
	unflatten -l $(UNFLATTEN) -f csail.dot | ccomps -x | dot $(VERBOSE) -Gmclimit=$(MCLIMIT) -Nfontname=$(SVGFONT) | gvpack | neato -s -n2 -Tsvg > csail.svg

# Only clean intermediate files (the output files are stored in the
# Subversion repo and should not be deleted).
clean:
	rm -f csail.ps
