Autotools backport

Backport of Bitcon's Autotools, gets OS X working.