kobrien
kobrien

Reputation: 3149

Autotools conditional include

I have a C file that includes a header. This header is in different locations depending on the distribution of Linux the build machine is running.

What is the cleanest way to detect the header in the differing locations using autotools?

Upvotes: 1

Views: 223

Answers (2)

William Pursell
William Pursell

Reputation: 212148

It is not the responsibility of the maintainer to worry about such things. Any reasonably constructed distribution will be set up so that the preprocessor can find the header file wherever it is located if it is installed on the system (as opposed to a user's $HOME or some other non-standard location). Setting up the tool chain to find the header if it is installed in a non-standard location is a platform specific task, most easily accomplished in Linux by setting CPPFLAGS. For example, the user might run

./configure CPPFLAGS=-I/p/a/t/h

(configure scripts generated with older versions of autoconf may require the call to be CPPFLAGS=-I/p/a/t/h ./configure) or she may add /p/a/t/h to CPATH, or use any other method available to inform the preprocessor where to look for include files. As the maintainer, all you need to do is ensure that the configure script checks that the user has set up the tool chain correctly, and you do that by including an invocation of AC_CHECK_HEADERS in configure.ac:

AC_CHECK_HEADERS([foo.h])

Upvotes: 1

Some programmer dude
Some programmer dude

Reputation: 409136

Use the standard AC_CHECK_HEADERS macro.

It will create correct preprocessor defines for the headers.

For example:

AC_CHECK_HEADERS([somepath/foo.h someotherpath/foo.h])

Will create the preprocessor defines HAVE_SOMEPATH_FOO_H or HAVE_SOMEOTHERPATH_FOO_H depending on which of the headers are found. Or both if both headers are found. Use these macros to decide which header to include.

Upvotes: 4

Related Questions