Gentoo patches

Includes changes from Gentoo to make this work on more systems and fix other bugs.  Also has warning removal from my compilation attempts from Debian.