Prototype: makerule(target, sources)

Return type: string

Description: Evaluates whether a target file needs to be built or rebuilt from one or more sources files.

This function can accept many types of data parameters.

The function is provided to emulate the semantics of the Unix make program.

In a traditional Makefile, rules take the form

target: source1 source2 ..
(tab) commands

The top line evaluates to a predicate for executing a number of commands, which is true if the target file does not exist, or if any of the sources dependencies in the list has been changed since the target was last built.

The makerule function emulates the same semantics and sets a class if the target needs to be built or rebuit, i.e. if the top line of an equivalent makefile is true.


  • target: string - Target filename - in the range: "?(/.*)
  • sources: string - Source filename or CFEngine variable identifier or inline JSON - in the range: .*

The sources argument may be either a scalar (indicating a single source) or a list reference or a data container. If the sources argument specifies a list, then the entire list of sources is used to determine whether the target needs rebuilding.



 "build_me" expression => makerule("/tmp/target", "/tmp/source.c");
 "build_me_ab" expression => makerule("/tmp/target", '["/tmp/source.a","/tmp/source.b"]' );



      "/usr/bin/gcc -o /tmp/target /tmp/source.c";

History: The collecting function behavior was added in 3.9.

See also: About collecting functions.