FreeBSD compatibility fixes

Add __FreeBSD__ to __APPLE__ shims or add own where necessary.
Fixes build on FreeBSD.
Get exepath on FreeBSD via sysctl(3) instead of using /proc

The proc filesystem is not mounted on FreeBSD by default and the
executable path information is better to be obtained via sysctl(3).