Build: configure: improve header detection
Previously, a long list of headers were detected but not required, even though
the code used them unconditionally. Now, distinguish optional headers from
required headers, and error if any required header is not detected.
Also, take better advantage of the autoconf header-checking macros.