Autotools fixes

This supersedes issue #1685.