Aage Torleif
Aage Torleif

Reputation: 2013

How to force autoconf to not define a macro?

I regularly run into this problem while building C projects that use autoconf so I'm looking for a repeatable way to do this. I often have a library where I'd like to undef a macro that is generated by autoheader in a config.h file. For example - right now I want to make sure that #define CLOCK_GETTIME 1 is generated as #undef CLOCK_GETTIME.

Assume in this example the clock_gettime is checked like so.

AC_CHECK_FUNCS([clock_gettime])

In the past I manually edit the file to remove defines. But I can't believe there isn't something I cant just pass to ./configure to override the default behavior of AC_CHECK_FUNCS.

How do I change what autoconf decides to define in my config.h?

Upvotes: 2

Views: 533

Answers (1)

MemReflect
MemReflect

Reputation: 551

./configure 'ac_cv_func_clock_gettime=no' should work. For example:

mkdir foo
cd foo
printf '%s\n' \
    'AC_INIT([foo], [0.1])' \
    'AC_CONFIG_HEADERS([config.h])' \
    'AC_CHECK_FUNCS([clock_gettime])' \
    'AC_OUTPUT' \
    > configure.ac
autoheader
autoconf
./configure >/dev/null 2>&1 \
    && grep CLOCK_GETTIME config.h
./configure 'ac_cv_func_clock_gettime=no' >/dev/null 2>&1 \
    && grep CLOCK_GETTIME config.h

Output on my system:

#define HAVE_CLOCK_GETTIME 1
/* #undef HAVE_CLOCK_GETTIME */

All cache variables created by AC_CHECK_FUNC, AC_CHECK_FUNCS, and AC_CHECK_FUNCS_ONCE have a general form described in the official documentation:

This macro caches its result in the ac_cv_func_function variable.

Here are some more examples:

ac_cv_func_strcasecmp        # AC_CHECK_FUNC([strcasecmp])
ac_cv_func_mempcpy           # AC_CHECK_FUNC([mempcpy])
ac_cv_func_pthread_create    # AC_CHECK_FUNC([pthread_create])

Upvotes: 2

Related Questions