Skip to content

Instantly share code, notes, and snippets.

@bbarker bbarker/makefileWrap-build.gradle Secret
Last active Aug 29, 2015

Embed
What would you like to do?
A build.gradle script that will wrap a generic makefile.
//
// Author: Brandon Barker, January 2015
//
// Copy this Makefile wrapper in to a project directory.
// Name it 'build.gradle'
// You should then be able to use Java IDEs with Gradle
// support to build makefile related projects. You may
// want to adjust your .gitignore to include the following:
//
// *.iml
// .gradle
// .idea
// gradle
// gradlew
// gradlew.bat
// atlassian-ide-plugin.xml
apply plugin: 'java'
sourceCompatibility = 1.5
version = '1.0'
repositories {
mavenCentral()
}
apply plugin: 'idea' // '' for creating an IntelliJ project
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.11'
}
ext {
taskLen = project.gradle.startParameter.taskNames.size()
}
task baseNull {
println "Gradle finished."
}
def myNextTask(Integer i) {
if (i > 0) {
return "${project.gradle.startParameter.taskNames[i - 1]}"
} else {
return "baseNull"
}
}
taskLen.times { i ->
task "${project.gradle.startParameter.taskNames[i]}" (
type: MyExternTask,
dependsOn: myNextTask(i)) {
mycmdln = "make ${project.gradle.startParameter.taskNames[i]}"
}
}
// Need to include this somehow, so as to avoid copying it each time
// (like atsmake-pre, etc.)
/* ****** ****** */
class \
MyExternTask
extends DefaultTask
{
//
def mycmdln
//
def OSName
def CYGHOME = System.getenv('CYGHOME')
def SHELL = ''
//
@TaskAction
def myrun()
{
OSName = System.getProperty("os.name")
//
if (OSName.startsWith("Windows")) {
if (CYGHOME != null) {
if (!File(CYGHOME).isDirectory()) {
CYGHOME = "C:\\cygwin64"
}
} else {
CYGHOME = "C:\\cygwin64"
}
// For now need to use Cygwin
// Probably should use `cygpath` in the future for lower chance of breaking.
SHELL = "${CYGHOME}\\bin\\bash"
mycmdln = "${SHELL} -l -c 'cd \"${project.projectDir}\"; ${mycmdln}'"
}
project.exec
{
commandLine = mycmdln.split().toList()
}
}
//
} // end of [MyExternTask]
/* ****** ****** */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.