Ninja plugin

Description

The ninja plugin is used for executing Makefiles.

Mandatory settings

There are no mandatory settings for this plugin.

Optional settings

The configuration of the ninja plugin may contain the following settings:

patterns

A list of patterns to apply on the command line. See Patterns (5).

enviroment

A list of environment variables that should be set before the commands are executed. See Environment (5).

command-line

Additional command line parameters to pass as a list of separate arguments. By default no additional arguments are added.

working-dir

The working directory of the command. Can be an absolute path are a relative one w.r.t. the path to the considered configuration file. Commands that should be executed relative to the current working dir can use the {EH_WORKING_DIR} pattern.

build-dir

The path to the build directory. This is either an absolute path are a path relative to the location of this file. Default: . (the current working directory).

Example

Configuration

commands:                       # Define the commands that can be run
    example: Run the ninja example
    clean: Clean the build
    run: Run the files that were built

patterns:                       # Define the patterns that can be used
    TARGET:                     # Define the EXAMPLE_PATTERN.
        default-values:         # Only define the default value
            - hello
            - world

example:
    - clean
    - ninja                      # Use the ninja plugin when running the 'example' command
    - run

clean:                          # Use the ninja plugin when running the 'clean' command
    - ninja

run:
    - command-line-command

ninja:
    environment:                # Define additional environment variables
        WORLD: "world!"
    build-dir: .                # Set the build dir
    example:                    # Specific settings for the 'example' command
        patterns:               # The patterns that are used by the ninja plugins
            - TARGET
        command-line:           # Define additional command line arguments
            - -k                # An example argument passed to ninja
            - 2
            - "{TARGET}"   # Define the ninja target to execute
    clean:
        command-line:
            - clean

command-line-command:
    patterns:
        - TARGET
    command-line:
        - build/ninja/{TARGET}

Additional files

In order for the above example to work, the following file hierarchy needs to be created in the directory:

ninja.build:

CXX = g++
CXXFLAGS = -Wall
LDFLAGS = 
BUILD_DIR = build/ninja

rule cc
    command = $CXX $CXXFLAGS $LDFLAGS -o $out $in

rule rmdir
    command = rm -rf $dir

build $BUILD_DIR/hello: cc src/hello.cpp
build hello: phony $BUILD_DIR/hello

build $BUILD_DIR/world: cc src/world.cpp
build world: phony $BUILD_DIR/world

build clean: rmdir
    dir = $BUILD_DIR

build all: phony hello world

default all

hello.cpp:

#include <cstdlib>
#include <iostream>

auto main() -> int {
    std::cout << "Hello" << std::endl;
    return EXIT_SUCCESS;
}

world.cpp:

#include <cstdlib>
#include <iostream>

auto main() -> int {
    std::cout << "World!" << std::endl;
    return EXIT_SUCCESS;
}

Usage

Save the example to an exec-helper configuration file and execute in the same directory:

eh example

See also

See exec-helper (1) for information about the usage of exec-helper.

See Custom plugins (5) for the available plugins and their configuration options.

See Configuration (5) for information about the configuration file format.