Fixes for porting to FreeBSD

A few commits to allow compiling on FreeBSD, verified on FreeBSD 9 with adding some values in config.mk