Fix generating links to docs

This makes correct links to docs when run from setup.
See bug #3886 and gh issue #279.