makefile: Generate Makefile from given list of rules ('job').

View source: R/makefile.R

makefileR Documentation

Generate Makefile from given list of rules (job).

Description

In the (GNU) make jargon, rule is a sequence of commands to build a result. In this package, rule should be understood similarly: It is a command or a sequence of command that optionally produces some files and depends on some other files (such as data files, scripts) or other rules. Moreover, a rule contain a command for cleanup, i.e. for removal of generated files.

Usage

makefile(
  job = list(),
  fileName = NULL,
  makeScript = "Makefile.R",
  vars = NULL,
  all = TRUE,
  tasks = TRUE,
  clean = TRUE,
  makefile = TRUE,
  depends = NULL
)

Arguments

job

A list of rules (i.e. of instances of the S3 class rmake.rule - see rule())

fileName

A file to write to. If NULL, the result is returned as a character vector instead of writing to a file.

makeScript

A name of the file that calls this function (in order to generate the makefile rule)

vars

A named character vector of shell variables that will be declared in the resulting Makefile (additionally to [defaultVars])

all

TRUE if the all rule should be automatically created and added: created all rule has dependencies to all the other rules, which causes that everything is built if make all is executed in shell's command line.

tasks

TRUE if "task" rules should be automatically created and added – see rule() for more details.

clean

TRUE if the clean rule should be automatically created and added

makefile

TRUE if the Makefile rule should be automatically created and added: this rule causes that any change in the R script - that generates the Makefile (i.e. that calls makefile()) - issues the re-generation of the Makefile in the beginning of any build.

depends

a character vector of file names that the makefile generating script depends on

Details

The makefile() function takes a list of rules (see rule()) and generates a Makefile from them. Additionally, all and clean rules are optionally generated too, which can be executed from shell by issuing make all or make clean command, respectively, in order to build everything or erase all generated files.

If there is a need to group some rules into a group, it can be done either via dependencies or by using the task mechanism. Each rule may get assigned one or more tasks (see task in rule()). Each task is then created as a standalone rule depending on assigned rules. That way, executing make task_name will build all rules with assigned task task_name. By default, all rules are assigned to task all, which allows make all to build everything.

Value

If fileName is NULL, the function returns a character vector with the contents of the Makefile. Instead, the content is written to the given fileName.

Author(s)

Michal Burda

See Also

rule(), rmakeSkeleton()

Examples

# create some jobs
job <- list(
    rRule('dataset.rds', 'preprocess.R', 'dataset.csv'),
    markdownRule('report.pdf', 'report.Rmd', 'dataset.rds'),
    markdownRule('details.pdf', 'details.Rmd', 'dataset.rds'))

# generate Makefile (output as a character vector)
makefile(job)

# generate to file
tmp <- tempdir()
makefile(job, file.path(tmp, "Makefile"))

beerda/rmake documentation built on July 2, 2022, 6:24 p.m.