Version 1 (modified by andreasw, 14 years ago) (diff)

started first draft Files in Source Directories

The source code directories are usually the src directories in a project's subdirectory, or subdirectories under src.

The Makefiles in those directories take care of the fun stuff. They define, what is to be built (libraries, executables), how it is built, and where (and if) the product is to be installed.

Beginning of the File

# Copyright (C) 2006 International Business Machines and others.
# All Rights Reserved.
# This file is distributed under the Common Public License.

## $Id: 789 2006-06-01 20:11:12Z andreasw $

# Author:  Andreas Waechter           IBM    2006-04-13

  • As usual, we start with a copyright note, author information, and the svn:keywords "$Id$". I'm not sure if the AUTOMAKE_OPTIONS variable has to be set here...

Building a Library

Name of the Library

# Name of the library compiled in this directory.  We want it to be installed
# in the 'lib' directory
  • First we tell Automake the name of the library that we want to create. The extension ".la" is used, since we are using the Libtool utility to handle libraries, which allows us to build both static and shared libraries on almost all platforms. The final name of the library(ies) depends on the platform.
  • In the above example, we use the Automake prefix lib_ to tell Automake, that we want this library to be installed in the lib installation directory. As Automake primary we use LTLIBRARIES (as opposed to LIBRARIES) to tell Autoconf, that we want to use Libtool.
  • If we want to build a library that is not going to be installed, we use the noinst_ prefix. For example, we might have the source code for the final library distributed into different directories, but in the end we only want to install one library that containts everything. In this case, we need to create auxilliary libraries in each source code directory (except for one), that are later collected into a single one. The auxilliary libraries should not be installed.

The corresponding line in the file for an auxilliary library then looks like:

# Name of the library compiled in this directory.  We don't want it to be
# installed since it will be collected into the libCgl library

Source Files for the Library

# List all source files for this library, including headers
libClp_la_SOURCES = \
        ClpConfig.h \
        ClpCholeskyBase.cpp ClpCholeskyBase.hpp \
        ClpCholeskyDense.cpp ClpCholeskyDense.hpp \
        ClpCholeskyUfl.cpp ClpCholeskyUfl.hpp \
        Clp_C_Interface.cpp Clp_C_Interface.h \
        ClpParameters.hpp \
  • To tell Automake which source files should be compiled in order to build the library, we use the library name as prefix (with "." and "-" replaced by "_"), and the SOURCES primary. In this list, one also includes all corresponding header files, so that they would be installed in a tarball generated by make dist.

Based on the extension of the source files, automake will figure out how they are to be compiled. In COIN, we use ".c" for C code, ".cpp" for C++ code, and ".f" for Fortran code.

Additional Link Command for the Library

This subsection is likely to change

# This is for libtool

For now, just use the above line for your library, no matter if it is installed or not.

Building a Program

Name of the Program

# Name of the executable compiled in this directory.  We want it to be
# installed in the 'bin' directory
bin_PROGRAMS = clp
  • First we tell Automake the name of the executable that we want to create. Usually, we want those to be installed in the bin installation directory, as indicated by the bin_ prefix. However, the unit test program is usually not installed, in which case one uses the noinst_ prefix.

Source Files for the Executable

# List all source files for this executable, including headers
clp_SOURCES = \
        ClpMain.cpp \
        CbcOrClpParam.cpp CbcOrClpParam.hpp \
        MyEventHandler.cpp MyEventHandler.hpp \
        MyMessageHandler.cpp MyMessageHandler.hpp \
  • Just as for libraries, one lists all source files, includin headers, in a variable, which has the program name as prefix, and uses the SOURCES primary.

Specifying Linking Flags

This subsection is likely to change

# List all additionally required COIN libraries
clp_LDADD = \

# Here we add additional libraries
LIBS += $(ADDLIBS) `cat $(COINUTILSOBJDIR)/coinutils_addlibs.txt`

# Finally, the -rpath flag is used by libtool to make sure that the shared
# library is found (in the lib install directory) when we are using dynamic
# libraries.
clp_LDFLAGS = -rpath $(libdir)
  • For now, list all COIN library dependencies in _LDADD (using the libtool extension ".la"), additional library dependencies are added to LIBS, and the _LDFLAGS should just be set as shown (to ensure that the program is compiled to hardwire the library installation directory into the executable, if shared libraries are used).
  • Note:
    • The ADDLIBS Autoconf output variable is set to the list of additional library dependencies for third party packages.
    • For COIN projects, the AC_COIN_HAS_PROJECT Autoconf macro generates output variables PRJSRCDIR and PRJOBJDIR, which are set to the project's main source and object subdirectory (which are different for a VPATH compilation). Here, PRJ is the name of the project as provided to the macro in all capital letters.

Additional Flags