build: support multiple headers in check_statement

This feature will be used in the next commit.
build: fix shm detection on OpenBSD

Fixes #427