Builds the doc tree properly.