Creating Libraries

MakeMe creates libraries by specifying the sources to compile in a library target. For example:

targets {
    libdemo: {
        type: 'lib',
        sources: '*.c',
    },
}

The sources property is set to the list of files to compile. See Compiling Sources for how to use the sources property.

Building this target will then compile the specified source files and build the named library with the relevant compiled objects.

me libdemo

When building, MakeMe transparently creates targets for each of the compiled source files and for any include files referenced by the sources. If the source file or its include files are updated, the relevant source file or files will be recompiled and library rebuilt.

Dependencies

On some platforms, linking a library will require that all unresolved references in other libraries be resolved before the link can successfully complete. Such library dependencies are specified via the depends property. The depends property takes a list of other targets that must be built before the current target can complete. Furthermore, the compiler, defines includes, libraries, libpaths and linker properties from the other target are imported into the current target. For example, given::

libsqlite3: {
    type: 'lib',
    defines: [ 'FTS4' ],
    includes : [ /usr/include/sqlite ],
    sources: [ '*.c' ],
},

Then the following library target will depend on libsqlite3. It will automatically link with libsqlite3, and when the source for libappweb is compiled, it will use the exported defines and includes from libsqlite3.

libappweb: {
    type: 'lib',
    sources: [ '*.c' ],
    headers: [ '*.h' ],
    depends: [ 'libsqlite3' ],
},

Note: the names in the depends property these are the target names (target.name property) and not the library name. To specify external libraries that are not built with MakeMe, use the libraries property collection.

Configurable Components

Products are sometimes configured with components that provide libraries to augment the product. For example: the PHP component adds the libphp5 library. To conditionally build a target only if an specific component is available, use the ifdef property. For example:

librocket: {
    type: 'lib',
    sources: [ '*.c' ],
    headers: [ '*.h' ],
    ifdef: [ 'fuel' ],

The ifdef property indicates that this target should only be built if the fuel component is enabled. Note this will not import any defined libraries, library paths, include paths or compiler definitions to this target. To do that, you need to use the depends property or the uses property for optional components.

Static Libraries

By default, MakeMe will build a shared library for a library target. To build a static library, set the static property to true.

libname: {
    type: 'lib',
    sources: '*.c',
    static: true,
},

A complete static build is also possible via the --static configure option. This will cause all targets of type 'lib' to be static libraries instead of shared libraries.

configure --static

To learn more, read about Creating Executables.

© Embedthis Software. All rights reserved.