Usage
Configuration
Since the release of 1.0 there is a project extension gnumake
, which allows defaults to be set for all GnuMakeBuild
tasks
gnumake {
executable '/path/to/make' (1)
makefile 'Makefile' (2)
execArgs '--server', 'server.com', '/opt/pi/make' (3)
defaultFlags BUILD_NUMBER : System.getenv('BUILD_NUMBER') (4)
}
1 | Set the path to the make executable. By default is is 'make' for all platforms, except Solaris and FreeBSD where it is 'gmake |
2 | The makefile to look for. By default it is unset, which means make will look for GNUmakefile, makefile, and Makefile in that order. |
3 | Arguments that will be added to make invocations. These arguments added to the front of the GnuMakeBuild tasks arguments i.e. directly following the executable when run. This is the recommended approach when running some kind of environment preparation i.e running another tool which will invoke make |
4 | Make flags that will be added to all GnuMakeBuild tasks, (unless a task sets defaultFlags = false) |
The make task
As from 1.0 a default task by names of make
has been added.
Additional tasks can still be added by doing
import org.ysb33r.gradle.gnumake.GnuMakeBuild
task runMake (type:GnuMakeBuild) {
targets 'build','install'
flags DESTDIR : '/copy/files/here', BUILD_NUMBER : '12345'
}
Task configuration
A large number of configuration attributes are available. Some are pure prooperties which can only be set by assignment.
tasks.named('make', GnuMakeBuild) {
alwaysMake = false (1)
environmentOverrides = false (2)
ignoreErrors = false (3)
keepGoing = false (4)
jobs = 1 (5)
noDefaultFlags = false (6)
noExecArgs = false (7)
}
1 | Equivalent of -B |
2 | Equivalent of -e |
3 | Equivalent of -i |
4 | Equivalent of -k |
5 | Equivalent of -j |
6 | Determine inheritance of gnumake.defaultFlags . |
7 | Determine inheritance of gnumake.execArgs |
Others can be set by a more declaritive style, but can be reset if necessary if need be. It is recommended to use the declaritive style as it makes for easy appending of entities and will also lead to a more readable style.
tasks.named('make', GnuMakeBuild) {
makefile 'Makefile' (1)
executable '/path/to/make' (2)
chDir '/change/to/here' (3)
workingDir '/change/here/before/running/make' (4)
includeDirs 'dir1', 'dir2' (5)
flags DESTDIR : '/copy/files/here', BUILD_NUMBER : '12345' (6)
switches '--foo', '--bar' (7)
targets 'clean', 'install' (8)
}
1 | Makefile to use.
Equivalent of '-f'.
If not set will try to read a default from
gnumake.makefile .
Will be converted to a String at point of task execution. |
2 | Override whatever is defined in gnumake.executable . |
3 | Change to this directory before processing starts.
Equivalent of -C .
Will be evaluated with project.file at point of task execution. |
4 | Directory to change to before the make command is run.
Do not confuse it with
chDir .
This is a seldom used option, but should you need it, you’ll be glad it is there.
The default is to start form project.projectDir . |
5 | Search path for make include files.
Equivalent of -I .
Can be called more than once to add more search paths.
Will be evaluated with project.files at point of task execution. |
6 | Makes flags.
Equivalant of passing X=Y on the command-line.
Can be called more than once to add more build flags. |
7 | Pass arbitrary switches to the make executable.
This allows for the flexibility in the extreme case where none of the current attributes addresses the context in which a make build might be called. it is recommended that this option only be used if a switch is needed which is not otherwise available. switches can be called more than once to append more switches. |
8 | Targets in the makefile that needs to be executed. This can be null which means the default target as deifned in the makefile will be executed. Can be called more than once to add more targets. |
As there is no trivial way for Gradle to query Make regarding input sources and output artifacts, the best source of knowledge is the build script author.
This person can configure a set of input files or directories to monitor in order to determine whether the GnuMakeBuild
task is up to date.
In a similar fashion output directories and files can be added.
Simply use the existing TaskInputs
and TaskOutputs
that is available in Gradle.
tasks.named('make', GnuMakeBuild) {
inputs.dir 'dir1'
inputs.file 'single.file.to.check'
inputs.files 'file1','file2'
outputs.dir 'dir1'
outputs.file 'single.file.to.check'
outputs.files 'file1','file2'
}
Rules
With the release of 1.0 the ability to run a make invocation for a specified target has also been added.
Internally the properties for the task will be taken from the defined task in the build script with the exception of makeInputs
, makeOutputs
and targets
.
Thus the task makeClean
will track the properties of the make
task, but when executed will only attempt to run the clean
target.
This is best explained by an example. Consider the following configuration:
tasks.named('make', GnuMakeBuild) {
makefile 'MyMakefile'
chDir 'legacyBuild'
targets 'build', 'install'
}
If this is run, then the effective executed command-line is
make -C legacyBuild -f MyMakefile build install
However, by means of a rule it is possible to execute a task called makeClean
for which the effective executed command-line is
make -C legacyBuild -f MyMakefile clean
It is as simple as that. No addditional configuration is required. It is also possible to create dependencies on these tasks i.e.e
clean.dependsOn 'makeClean'
If another GnuMakeBuild
task were created i.e. runMake
then the task for the above would simply be runMakeClean
.
In v1.0 tasks created via rules do not have up to date checks in the same way that a GnuMakeBuild
tasks have as described earlier.
If this is needed they will need to be manually added via inputs
and outputs
.
It is possible that support will be added in a future release if the community requests it.