Description: Modify the build scipts for being built in Debian
Author: Kai-Chung Yan ()
Last-Update: 2016-10-27
Forwarded: not-needed
--- a/build.gradle
+++ b/build.gradle
@@ -32,9 +32,6 @@
         repositories {
             mavenDeployer {
                 if (project.hasProperty('release')) {
-                    repository(url: uri("https://gradle.artifactoryonline.com/gradle/libs-releases-local")) {
-                        authentication(userName: artifactoryUserName, password: artifactoryPassword)
-                    }
                 } else if (project.hasProperty('snapshot')) {
                     repository(url: uri("https://gradle.artifactoryonline.com/gradle/libs-snapshots-local")) {
                         authentication(userName: artifactoryUserName, password: artifactoryPassword)
@@ -91,47 +88,21 @@
 
 model {
     platforms {
-        osx_i386 {
-            architecture "i386"
-            operatingSystem "osx"
-        }
-        osx_amd64 {
-            architecture "amd64"
-            operatingSystem "osx"
-        }
-        linux_i386 {
-            architecture "i386"
-            operatingSystem "linux"
-        }
-        linux_amd64 {
-            architecture "amd64"
-            operatingSystem "linux"
-        }
-        windows_i386 {
-            architecture "i386"
-            operatingSystem "windows"
-        }
-        windows_amd64 {
-            architecture "amd64"
-            operatingSystem "windows"
-        }
-        freebsd_i386 {
-            architecture "i386"
-            operatingSystem "freebsd"
-        }
-        freebsd_amd64 {
-            architecture "amd64"
-            operatingSystem "freebsd"
+        debian {
+            architecture "${"dpkg-architecture --query DEB_HOST_ARCH".execute().text}"
+            operatingSystem "${"dpkg-architecture --query DEB_HOST_ARCH_OS".execute().text}"
+        }
+    }
+    toolChains {
+        cxx(Gcc) {
+            //path '/usr/bin/c++'
+            target 'debian'
         }
     }
-
     components {
         nativePlatform(NativeLibrarySpec) {
             baseName 'native-platform'
-            // TODO - this should be the default. Figure out why this is not working
-            $.platforms.each { p ->
-                targetPlatform p.name
-            }
+            targetPlatform 'debian'
             sources {
                 cpp {
                     source.srcDirs = ['src/shared/cpp', 'src/main/cpp']
@@ -142,11 +113,7 @@
 
         nativePlatformCurses(NativeLibrarySpec) {
             baseName 'native-platform-curses'
-            $.platforms.each { p ->
-                if (!p.operatingSystem.windows) {
-                    targetPlatform p.name
-                }
-            }
+            targetPlatform 'debian'
             sources {
                 cpp {
                     source.srcDirs = ['src/shared/cpp', 'src/curses/cpp']
@@ -165,7 +132,7 @@
                     cppCompiler.args '-I', "${org.gradle.internal.jvm.Jvm.current().javaHome}/include/darwin"
                     cppCompiler.args '-mmacosx-version-min=10.4'
                     linker.args '-mmacosx-version-min=10.4'
-                } else if (targetPlatform.operatingSystem.linux) {
+                } else if (targetPlatform.operatingSystem.linux || targetPlatform.operatingSystem.name.contains('hurd')) {
                     cppCompiler.args '-I', "${org.gradle.internal.jvm.Jvm.current().javaHome}/include"
                     cppCompiler.args '-I', "${org.gradle.internal.jvm.Jvm.current().javaHome}/include/linux"
                     cppCompiler.args '-D_FILE_OFFSET_BITS=64'
@@ -173,14 +140,23 @@
                     cppCompiler.args "-I${org.gradle.internal.jvm.Jvm.current().javaHome}/include"
                     cppCompiler.args "-I${org.gradle.internal.jvm.Jvm.current().javaHome}/include/win32"
                     linker.args "Shlwapi.lib", "Advapi32.lib"
-                } else if (targetPlatform.operatingSystem.freeBSD) {
+                } else if (targetPlatform.operatingSystem.freeBSD || targetPlatform.operatingSystem.name.contains('bsd')) {
                     cppCompiler.args '-I', "${org.gradle.internal.jvm.Jvm.current().javaHome}/include"
-                    cppCompiler.args '-I', "${org.gradle.internal.jvm.Jvm.current().javaHome}/include/freebsd"
+                    cppCompiler.args '-I', "${org.gradle.internal.jvm.Jvm.current().javaHome}/include/bsd"
                 }
                 cppCompiler.args "-I${nativeHeadersDir}"
                 tasks.withType(CppCompile) { task ->
                     task.dependsOn project.tasks.nativeHeaders
                 }
+                "${"dpkg-buildflags --get CXXFLAGS".execute().text}".split().each {
+                    cppCompiler.args it
+                }
+                "${"dpkg-buildflags --get CPPFLAGS".execute().text}".split().each {
+                    cppCompiler.args it
+                }
+                "${"dpkg-buildflags --get LDFLAGS".execute().text}".split().each {
+                    linker.args it
+                }
             }
 
             // Using internal class here to make this simple
@@ -190,40 +166,6 @@
                 if (!buildable) {
                     return
                 }
-
-                if (targetPlatform.operatingSystem.name in ['linux', 'freebsd'] && targetPlatform.architecture != arch) {
-                    // Native plugins don't detect whether multilib support is available or not. Assume not for now
-                    return
-                }
-
-                def variantName = targetPlatform.name.replace('_', '-')
-                def taskName = "jar-${variantName}"
-                def nativeJar = project.tasks.findByName(taskName)
-                if (nativeJar == null) {
-                    nativeJar = project.tasks.create(taskName, Jar) {
-                        baseName = "native-platform-$variantName"
-                    }
-                    artifacts {
-                        jni nativeJar
-                        runtime nativeJar
-                    }
-                    def jniPom = deployer.addFilter(variantName) { artifact, file ->
-                        return file == nativeJar.archivePath
-                    }
-                    jniPom.groupId = project.group
-                    jniPom.artifactId = nativeJar.baseName
-                    jniPom.version = project.version
-                    jniPom.scopeMappings.mappings.clear()
-                }
-
-                binary.tasks.withType(LinkSharedLibrary) { builderTask ->
-                    nativeJar.into("net/rubygrapefruit/platform/$variantName") { from builderTask.outputFile }
-                    nativeJar.dependsOn builderTask
-                }
-                project.tasks.test {
-                    dependsOn nativeJar
-                    classpath.from nativeJar
-                }
             }
         }
     }
