openalsoft.gradle 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. // OpenAL Soft r1.16
  2. String openALSoftUrl = 'http://repo.or.cz/w/openal-soft.git/snapshot/e5016f814a265ed592a88acea95cf912c4bfdf12.zip'
  3. String openALSoftZipFile = 'OpenALSoft.zip'
  4. // OpenAL Soft directory the download is extracted into
  5. // Typically, the downloaded OpenAL Soft zip file will extract to a directory
  6. // called "openal-soft"
  7. String openALSoftFolder = 'openal-soft-e5016f8'
  8. //Working directories for the ndk build.
  9. String openalsoftBuildDir = "${buildDir}" + File.separator + 'openalsoft'
  10. String openalsoftClassesBuildDir = "${buildDir}" + File.separator + 'openalsoft_classes'
  11. String openalsoftBuildJniDir = openalsoftBuildDir + File.separator + 'jni'
  12. String openalsoftBuildLibsDir = openalsoftBuildDir + File.separator + 'libs'
  13. //Pre-compiled libs directory
  14. String openalsoftPreCompiledLibsDir = 'libs' + File.separator + 'openalsoft'
  15. // jME Android Native source files path
  16. String openalsoftJmeAndroidPath = 'src/native/jme_openalsoft'
  17. // Download external source files if not available
  18. task downloadOpenALSoft(type: MyDownload) {
  19. sourceUrl = openALSoftUrl
  20. target = file(openalsoftBuildDir + File.separator + openALSoftZipFile)
  21. }
  22. // Unzip external source files
  23. task unzipOpenALSoft(type: Copy) {
  24. def zipFile = file(openalsoftBuildDir + File.separator + openALSoftZipFile)
  25. def outputDir = file(openalsoftBuildDir)
  26. from zipTree(zipFile)
  27. into outputDir
  28. }
  29. unzipOpenALSoft.dependsOn {
  30. def zipFilePath = openalsoftBuildDir + File.separator + openALSoftZipFile
  31. def zipFile = new File(zipFilePath)
  32. // println "zipFile path: " + zipFile.absolutePath
  33. // println "zipFile exists: " + zipFile.exists()
  34. if (!zipFile.exists()) {
  35. downloadOpenALSoft
  36. }
  37. }
  38. // Copy external source files to jni directory
  39. task copyOpenALSoft(type: Copy) {
  40. def sourceDir = file(openalsoftBuildDir + File.separator + openALSoftFolder)
  41. def outputDir = file(openalsoftBuildJniDir)
  42. // println "copyOpenALSoft sourceDir: " + sourceDir
  43. // println "copyOpenALSoft outputDir: " + outputDir
  44. from sourceDir
  45. into outputDir
  46. }
  47. copyOpenALSoft.dependsOn {
  48. def openALSoftUnzipDir = new File(project.projectDir.absolutePath + File.separator + openALSoftFolder)
  49. // println "openALSoftUnzipDir path: " + openALSoftUnzipDir.absolutePath
  50. // println "openALSoftUnzipDir exists: " + openALSoftUnzipDir.isDirectory()
  51. if (!openALSoftUnzipDir.isDirectory()) {
  52. unzipOpenALSoft
  53. }
  54. }
  55. // Copy jME Android native files to jni directory
  56. task copyJmeOpenALSoft(type: Copy, dependsOn:copyOpenALSoft) {
  57. def sourceDir = file(openalsoftJmeAndroidPath)
  58. def outputDir = file(openalsoftBuildJniDir)
  59. // println "copyJmeOpenALSoft sourceDir: " + sourceDir
  60. // println "copyJmeOpenALSoft outputDir: " + outputDir
  61. from sourceDir
  62. into outputDir
  63. }
  64. task generateOpenAlSoftHeaders(type:Exec, dependsOn: copyJmeOpenALSoft) {
  65. def files0 = fileTree("src/main/java/").filter { it.isFile() && it.getName().endsWith(".java") }.files
  66. def files1 = fileTree("src/common/java/").filter { it.isFile() && it.getName().endsWith(".java") }.files
  67. def files2 = fileTree("../jme3-core/src/main/java/").filter { it.isFile() && it.getName().endsWith(".java") }.files
  68. def files3 = fileTree("../jme3-core/src/plugins/java/").filter { it.isFile() && it.getName().endsWith(".java") }.files
  69. def files4 = fileTree("../jme3-core/src/tools/java/").filter { it.isFile() && it.getName().endsWith(".java") }.files
  70. def files5 = fileTree("../jme3-terrain/src/main/java/").filter { it.isFile() && it.getName().endsWith(".java") }.files
  71. def filesList = "\"" + files0.join("\"\n\"") + "\"\n\"" + files1.join("\"\n\"") + "\"\n\"" + files2.join("\"\n\"") + "\"\n\"" + files3.join("\"\n\"") + "\"\n\"" + files4.join("\"\n\"") + "\"\n\"" + files5.join("\"\n\"") + "\""
  72. new File("$projectDir/java_classes.jtxt").text = filesList.replaceAll(java.util.regex.Pattern.quote("\\"), java.util.regex.Matcher.quoteReplacement("/"))
  73. executable org.gradle.internal.jvm.Jvm.current().getExecutable('javac')
  74. args '-h', openalsoftJmeAndroidPath
  75. args "@$projectDir/java_classes.jtxt"
  76. args '-d', openalsoftClassesBuildDir
  77. }
  78. task buildOpenAlSoftNativeLib(type: Exec, dependsOn: generateOpenAlSoftHeaders) {
  79. // println "openalsoft build dir: " + openalsoftBuildDir
  80. // println "ndkCommandPath: " + project.ndkCommandPath
  81. workingDir openalsoftBuildDir
  82. executable rootProject.ndkCommandPath
  83. args "-j" + Runtime.runtime.availableProcessors()
  84. }
  85. task updatePreCompiledOpenAlSoftLibs(type: Copy, dependsOn: buildOpenAlSoftNativeLib) {
  86. def sourceDir = new File(openalsoftBuildLibsDir)
  87. def outputDir = new File(openalsoftPreCompiledLibsDir)
  88. // println "updatePreCompiledOpenAlSoftLibs sourceDir: " + sourceDir
  89. // println "updatePreCompiledOpenAlSoftLibs outputDir: " + outputDir
  90. from sourceDir
  91. into outputDir
  92. }
  93. // Copy pre-compiled libs to build directory (when not building new libs)
  94. task copyPreCompiledOpenAlSoftLibs(type: Copy) {
  95. def sourceDir = file(openalsoftPreCompiledLibsDir)
  96. def outputDir = file(openalsoftBuildLibsDir)
  97. // println "copyStbiJmeFiles sourceDir: " + sourceDir
  98. // println "copyStbiJmeFiles outputDir: " + outputDir
  99. from sourceDir
  100. into outputDir
  101. }
  102. // ndkExists is a boolean from the build.gradle in the root project
  103. // buildNativeProjects is a string set to "true"
  104. if (ndkExists && buildNativeProjects == "true") {
  105. // build native libs and update stored pre-compiled libs to commit
  106. compileJava.dependsOn { updatePreCompiledOpenAlSoftLibs }
  107. } else {
  108. // use pre-compiled native libs (not building new ones)
  109. compileJava.dependsOn { copyPreCompiledOpenAlSoftLibs }
  110. }
  111. jar.into("lib") { from openalsoftBuildLibsDir }
  112. // Helper class to wrap ant dowload task
  113. class MyDownload extends DefaultTask {
  114. @Input
  115. String sourceUrl
  116. @OutputFile
  117. File target
  118. @TaskAction
  119. void download() {
  120. ant.get(src: sourceUrl, dest: target)
  121. }
  122. }