Code Monkey home page Code Monkey logo

gnumake-gradle-plugin's Introduction

GNU Make Gradle Plugin

Provides a wrapper for calling GNU Make from Gradle. This is especially useful for projects migrating to Gradle or when constructing complex build systems of which some components utilise GNU make as it build tool. Most common command-line switches are supported, but for full flexibility it is possible to add any additional switch via the switches property.

NOTE: There is an issue with the 1.1 release under Windows which prevents flags form being passed correctly to Make. If you use that feature you should hold back from upgrading.

Known compatibility

  • 1.1.1 - Gradle 2.0 - 2.14

  • 1.1 - Gradle 2.0 - 2.14 (Not recommended for Windows platforms)

  • 1.0 - Gradle 2.0

  • 0.3 - Gradle 2.0

  • 0.2 - Gradle 2.0

  • 0.1 - Gradle 1.12

  • 0.0.9 - Gradle 1.9

  • 0.0.3 - Gradle 1.6

  • 0.0.2 - Gradle 1.6

Adding the plugin

buildscript {
  repositories {
      maven {
          url "https://plugins.gradle.org/m2/"
      }
  }
  dependencies {
    classpath 'org.ysb33r.gradle:gnumake:{revnumber}'
  }
}

apply plugin : 'org.ysb33r.gnumake'

or if you use Gradle 2.1+

plugins {
  id 'org.ysb33r.gnumake' version '{revnumber}'
}

Global configuration

Sinc 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.

make {

  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.

make {

  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)

}
  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.

Two more options exist which helps to determine up to date status. 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.

make {
  makeInputs { // (1)
    dir 'dir1'
    file 'single.file.to.check'
    files 'file1','file2'
  }
  makeOutputs { // (2)
    dir 'dir1'
    file 'single.file.to.check'
    files 'file1','file2'
  }
}
  1. makeInputs has three methods, each of which can be called multiple times. The methods are evaluated as per Gradle TaskInputs.

  2. makeOutputs has three methods, each of which can be called multiple times. The methods are evaluated as per Gradle TaskOutputs.

Deprecated Properties

A number of properties from earlier releases have been deprecated.

dir

Use chDir instead

tasks

Use targets instead

buildFile

Use makefile instead

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:

make {
  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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.