tweak build checks

- avoids linking against libzmq when checking for sys/un.h
 when zmq is unspecified and unavailable.
- avoids creating temp files outside build dir with `has_function` checks.