Improved build script for use on FreeBSD; added sanity checks