Search code examples
ctestingautotoolsstubs

autotools: don't include library when doing “make check”


So I'm writing tests for my code, and I want to stub out the calls to library functions (make sure that it's calling the right library calls at the right time, and that it handles errors appropriately).

I think I'm SOL with the C standard library functions, but those aren't the only libraries I'm using.

When building my final executable (not my test executable), I want to use -lfuse, so I included this line in my configure.ac

AC_CHECK_LIB([fuse], [fuse_main])

However, this also tosses in -lfuse when it tries to build my check_PROGRAMS.

Is there some way I can tell autotools that I don't want the -lfuse library when building my test executable (make check)? Then I should be able to stub out the library calls as I wish, since there won't be anything else linked with the same name.


Solution

  • I see that libfuse supplies a fuse.pc file in its source distribution, so the proper way to check for it is to use pkg-config. You can do

    PKG_CHECK_MODULES([APPNAME], [fuse ...and any other libraries to check for...])
    

    in your configure.ac, and then

    appname_CFLAGS += @APPNAME_CFLAGS@
    appname_LIBS += @APPNAME_LIBS@
    

    in src/Makefile.am. Then just don't add those variables to your test programs.