Tweak build on FreeBSD

* add configuration for bsd (FreeBSD)
* libdl is not required on FreeBSD
* it's better to detect lua with pkgconfig (probably also true for linux)
* linking with threads is correctly done with -pthread