A rule is an atomic element of the build process. It defines a set of target file names
to be built with a given build command from a given set of depends files
that the targets depend on, and which can be removed by a given clean command.
Usage
rule(
target,
depends = NULL,
build = NULL,
clean = NULL,
task = "all",
phony = FALSE,
type = ""
)Arguments
- target
A character vector of target file names that are created by the given build command
- depends
A character vector of file names the build command depends on
- build
A shell command that runs the build of the given target
- clean
A shell command that erases all files produced by the build command
- task
A character vector of parent task names. The mechanism of tasks allows grouping rules. Anything different from
'all'will cause the creation of a new task depending on the given rule. Executingmake tasknamewill then force building this rule.- phony
Whether the rule has a
PHONY(i.e., non-file) target. A rule should be marked withphonyif the target is not a file name that would be generated by thebuildcommands. E.g.,allorcleanare phony targets. Also, all targets representing tasks (seetaskabove) are phony.- type
A string representing a type of rule used e.g. when printing a rule in an easily readable format. For instance,
rRule()usesR,markdownRule()usesmarkdown, etc.
Details
If there is a need to group some rules together, one can assign them the same task identifier in
the task argument. Each rule may be assigned one or more tasks. Tasks may then be built
by executing make task_name on the command line, which forces rebuilding of all rules assigned to
task 'task_name'. By default, all rules are assigned to task all,
which causes the make all command to build everything.
Examples
r <- rule(target='something.abc',
depends=c('file.a', 'file.b', 'file.c'),
build='myCompiler file.a file.b file.c -o something.abc',
clean='$(RM) something.abc')
# generate the content of a makefile (as character vector)
makefile(list(r))
#> [1] "# This file is generated by rmake - do not edit by hand"
#> [2] "ifeq ($(origin .FEATURES),undefined)"
#> [3] "$(error This Makefile requires GNU Make. Please install it and use 'gmake' or 'make' depending on your system)"
#> [4] "endif"
#> [5] "REQUIRED_VERSION := 3.82"
#> [6] "ifeq ($(filter $(REQUIRED_VERSION),$(firstword $(sort $(MAKE_VERSION) $(REQUIRED_VERSION)))),)"
#> [7] "$(error GNU Make $(REQUIRED_VERSION) or higher is required. You are using $(MAKE_VERSION))"
#> [8] "endif"
#> [9] "SHELL=/bin/sh"
#> [10] "R=\"$(R_HOME)/bin$(R_ARCH)/Rscript\""
#> [11] "RM=rm"
#> [12] "CP=cp"
#> [13] ".ONESHELL:"
#> [14] ""
#> [15] ".PHONY: all"
#> [16] "all: Makefile something.abc"
#> [17] "\t"
#> [18] "something.abc: file.a file.b file.c"
#> [19] "\tmyCompiler file.a file.b file.c -o something.abc"
#> [20] ".PHONY: clean"
#> [21] "clean: "
#> [22] "\t$(RM) something.abc"
#> [23] "Makefile: Makefile.R"
#> [24] "\t$(R) - <<'EOFrmake'"
#> [25] "\t{"
#> [26] "\t params <- list(.target = \"Makefile\", .script = \"Makefile.R\", .depends = NULL, .task = \"all\")"
#> [27] "\t source(\"Makefile.R\")"
#> [28] "\t}"
#> [29] "\tEOFrmake"
# generate to file
tmp <- tempdir()
makefile(list(r), file.path(tmp, "Makefile"))