Auto-generated class hierarchy diagrams

Unfortunately still working on that coursework, I've just added support in the API documentation makefile to automatically generate a class hierarchy diagram using the GObject hierarchy file created by gtk-doc and marshalling it to GraphViz. It basically analyses the depth of each line in the hierarchy file and creates relationships in the dot file as appropriate. It doesn't sound complex, but it took a heck of a lot of fiddling to get automake happy with my syntax.

	echo "digraph class_hierarchy" > $(DOC_MODULE).dot
	echo "{" >> $(DOC_MODULE).dot
	(IFS=$$'\n'; \
	for current_line in `cat $(DOC_MODULE).hierarchy`; do \
		depth_colours=( red green blue yellow ); \
		depth=`echo $$current_line | grep -o "  " | wc -l | sed s/\ //g`; \
		echo "$$current_line [shape=box, color=$${depth_colours[$$depth]}]" >> $(DOC_MODULE).dot; \
		last_line[$$depth]=$$current_line; \
		if [ $$depth -gt 0 ]; then \
			echo "$${last_line[`expr $$depth - 1`]} -> $$current_line" >> $(DOC_MODULE).dot; \
		fi; \
	echo "}" >> $(DOC_MODULE).dot
	dot -Tpng $(DOC_MODULE).dot > $(DOC_MODULE).png
	touch graph-build.stamp

4 thoughts on “Auto-generated class hierarchy diagrams

  1. Zack

    Why not put most of that in an external shell script? I find this is a much better choice for anything that needs to be longer than two lines in a makefile.

  2. Stefan Kost

    As a gtk-doc maintainer I wonder how many people would be interested in more graphs. personally I am quite happy with the text based hierarchy trees. If you are interested propose it on the gtk-doc mailing-list or post a feature request.

    1. Philip Withnall Post author

      I'm actually quite happy with how well gtk-doc does things at the moment (excellent job!); I just added this so I could use the image in my writeup, and partly because I was bored during lessons. 🙂

Comments are closed.