Targets

A MakeMe project may specify any number of targets to be built via the MakeMe DOM. A target represents a discrete item to build in the project.

A target is defined as a collection of properties under the targets property.

targets {
    rocket: {
        type: 'exe'
        sources: '*.c',
    },
},

Target Dependencies

MakeMe targets can depend on other targets that must be built first. Dependencies are expressed as an ordered list of targets in the depends property. For example:

targets {
    fuel: {
        type: 'lib'
        sources: 'fuel/*.c',
    },
    rocket: {
        type: 'exe'
        sources: '*.c',
        depends: ['libfuel'],
    },
}

The defines, includes, libraries, library paths and linker options defined by the depended upon target are inherited by the target.

When MakeMe is invoked, it may nominate specific actions or targets to build on the command line. These are called goals. If no goals are provided, a default build is run using the special goal called 'all'.

$ me libfuel  # builds only libfuel
$ me rocket   # builds libfuel then rocket
$ me          # builds all targets

Goals

When 'me' is invoked, the command line goals are used to select the targets to build. Each target has as target.goals propery which is an array of goals for which the target should be built. For example:

rocket: {
    type: 'exe'
    sources: '*.c',
    goals: ['all', 'rocket'],
},

With the goals specified above, the rocket target will be built if invoked as:

me         # to build all targets
me rocket  # to build just the rocket

Target goals are automatically defined if not explicitly specified. In fact, most targets do not explicitly define their goals. If unspecified, a default goals property will be defined for each target that minimally contains the name of the target. Executable, library and file targets will also have the special goal 'all' so that they are created for default builds.

Target Build Order

Before building, MakeMe parses the entire MakeMe file configuration and creates a build tree based on which targets depend on what. MakeMe then builds the targets by doing a depth-first traversal of the build tree. It successfully detects and handles dependency loops.

Target Default Properties

Often targets need very similar configuration. MakeMe provides a defaults collection of properties that are inherited by all exe, lib and obj targets. For example:

defaults: {
    '+defines': [ 'TUNE=SPEED ],
    '+libraries': [ 'math' ],
}

This will use the TUNE=SPEED compiler definition when compiling all source files, and the math library when linking executables (and libraries on some systems).

MakeMe also provides an internal collection of properties that are inherited by only the targets in the same MakeMe file.

internal: {
    '+defines': [ 'TUNE=SIZE ],
}

Enabling and Disabling Targets

Targets can be selectively enabled or disabled based on the value of the enable property. The property may be set to a string containing an arbitrary script expression that is evaluated and if true the target is enabled. For example:

appwebMonitor: {
    enable: "me.platform.like == 'windows'",
    type: 'exe',
    sources: [ 'windows/appwebMonitor.c' ],
},

This will enable this target only if building for windows. Note that if you forget to wrap the enable expression as a string, it will be evaluated when the MakeMe file is loaded, not when the target is evaluated. In some cases, this will work if that portion of the DOM referenced in your expression has been defined. Best to always wrap your enable expression in quotes.

Enable Samples

SSL has a special setting that can be tested for targets that require SSL before building

transact: {
    /* Enable if SSL is enabled */
    enable: "me.settings.ssl",
    type: 'exe',
    sources: [ '*.c' ],
},

This example tests if the CGI configurable component is enabled.

cgiProgram: {
    /* Enable if SSL is enabled */
    enable: "me.targets.cgi.enable",
    type: 'exe',
    sources: [ '*.c' ],
},

This target is only enabled if building for the local platform and not cross-building.

'tests': {
    enable: "!me.platform.cross",
    action: "run-tests()",
},

© Embedthis Software. All rights reserved.