Various fixes.

Fix build for FreeBSD.

Fixed missing libraries for tools.