Search code examples
autotoolsautomake

How do I execute but not install a binary with autotools?


I am writing a small library and want to make it accessible using autotools with automake 1.11. The only interesting outcome is the library libfoo.so.

I wrote a unit test for the library which I want be executed during the make process or when running make check. I don not want the unit test to appear in $PREFIX/foo/bin/.

How do I achieve these goals?


Solution

  • As the automake manual describes, you use the "check_" prefix. Let's say the library is built under the directory src/, and the unit tests are under tests/ - then in the tests/Makefile.am file:

    check_PROGRAMS = unit_test
    
    unit_test_SOURCES = unit_test.c
    unit_test_LDADD = $(top_builddir)/src/libfoo.la
    

    I assume you're using libtool of course. This takes care of linking, dynamic paths, etc., if you're building a shared library.

    You should also have a look at the use of the TESTS variable in automake.