3
votes

I was hoping to get some help regarding the good practice automake based, toolkit build (compile) procedure. I am writing a toolkit which consists of several external and couple of internal libraries together with demo tools. Until now I was doing my own makefile scripts to compile it but now I would like to switch to autotools, that is I would like to move from my wanky scripts to something more standardized. So what I am looking for is some help, a minimum example which I could study. This minimum example should be in accord to "good practice" principles and preserve the following tree structure:

toolkit/src/libint/ 
    libinternal.cpp libinternal.hpp 
toolkit/src/libext/ 
    externallib/ 
toolkit/bin/ 
    my binaries 
toolkit/demo/tool1/ 
    tool1.cpp tool1.hpp 
toolkit/demo/tool2/ 
    tool2.cpp tool2.hpp 
toolkit/lib/ 
    libinternal.a libexternal.a 
toolkit/include/libint/ 
    libinternal.hpp 
toolkit/include/libext/ 
    libexternal.hpp 

Usually I have my demo tools in demo folder under separate subfolders which are compiled using headers and libraries from include and lib folders. This means that in my makefile I usually first compile libraries into include and lib folder and then demo tools while building the toolkit.

Could anyone provide a minimal example for required configure.ac and Makefile.am files for the above tree source structure (any suggestions regarding the source tree are more then welcomed)

thank you

1
What's libext/externallib/? And if it's external, why is a copy needed in lib/? The autotools use a build directory, with the goal of installing libraries, headers, programs in directories specified by: ./configure --help - Brett Hale
I'm just trying to get a better idea of external dependencies vs. what you want installed. i.e., you might not want the demos installed - just used for testing, etc. Unfortunately, the autotools learning curve is pretty steep; in the mean time, this is probably the best tutorial I've seen. - Brett Hale
external dependencies are libraries that are not part of the system and some are not instalable (old libraries) which need to be compiled all over if moved to different OS. that is why I have externallib/ directory. but if this complicates things and since i am looking for a learning example this can be ignored. Maybe instead an example with boost can be provided. Thank you - user8060

1 Answers

2
votes

The first desition will be whether your libraries will be installed independently or will be linked to the binary -- a convenience library --.

In both of the cases, you will need to use autoconf, automake and libtool. I will ignore the configure.ac file and focus in the Makefile.am. The directory should look like:

  ./
    lib/
       Makefile.am 
       ...
    bin/
    ...
    Makefile.am 

In the top Makefile.am you should have this:

 $ cat Makefile.am 
 SUBDIRS = . lib  # note the "." which means that the current directory is executed first 

In the lib Makefile.am

 $ cat lib/Makefile.am
 noinst_LTLIBRARIES        = libexternal.a
 libexternal_a_SOURCES     = source.c source.h
 libexternal_a_LIBADD      = -lm

In case that you want the library to be installed independently just replace noinst with lib

So the lib Makefile.am will look like:

 $ cat lib/Makefile.am
 lib_LTLIBRARIES           = libexternal.a
 libexternal_a_SOURCES     = source.c source.h
 libexternal_a_LIBADD      = -lm