Search code examples
cautotoolsautomake

Autotools specifying install path of static library


How can I install a library to $(top_srcdir)/lib/foo.a?

If I try to use:

noinst_LIBRARIES=$(top_srcdir)/lib/foo.a foo_a_SOURCES= foo.c foo.h bar.c, bar.h

I get library has foo_a as canonical name (possible typo)

I have foo.* and bar.* in $(top_srcdir)/foobar/.

Any Ideas ?


Solution

  • As the action you are trying to achieve is not standard, GNU/Autotools does not support that feature. Nevertheless, GNU/Autotools let the programmers to tweak their system by using local rules which extend the functionability of its Makefile rules.

    For instance, to copy your library to an specific location you can write:

    # Standard way
    noinst_LDLIBRARIES = foo.a
    
    # Here is where you tweak, all-local will be performed
    # after compilation.
    all-local:
      -cp $(builddir)/foo.* $(buildir)/libs
    

    Note that $(srcdir) and $(builddir) are identical when you call configure in the same directory the configure script is place. When you call configure from a different directory buildir and srcdir will differ.

    Links