Autotools backport

Backport of Bitcoin's Autotools, fixes OS X build issues.