2
0

openalsoft.gradle 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. // OpenAL Soft r1.21.1
  2. // TODO: update URL to jMonkeyEngine fork once it's updated with latest kcat's changes
  3. String openALSoftUrl = 'https://github.com/kcat/openal-soft/archive/1.21.1.zip'
  4. String openALSoftZipFile = 'OpenALSoft.zip'
  5. // OpenAL Soft directory the download is extracted into
  6. // Typically, the downloaded OpenAL Soft zip file will extract to a directory
  7. // called "openal-soft"
  8. String openALSoftFolder = 'openal-soft-1.21.1'
  9. //Working directories for the ndk build.
  10. String openalsoftBuildDir = "${buildDir}" + File.separator + 'openalsoft'
  11. String openalsoftClassesBuildDir = "${buildDir}" + File.separator + 'openalsoft_classes'
  12. String openalsoftBuildJniDir = openalsoftBuildDir + File.separator + 'jni'
  13. String openalsoftBuildLibsDir = openalsoftBuildDir + File.separator + 'libs'
  14. //Pre-compiled libs directory
  15. def rootPath = rootProject.projectDir.absolutePath
  16. String openalsoftPreCompiledLibsDir = rootPath + File.separator + 'build' + File.separator + 'native' + File.separator + 'android' + File.separator + 'openalsoft'
  17. // jME Android Native source files path
  18. String openalsoftJmeAndroidPath = 'src/native/jme_openalsoft'
  19. String jmeHeaders = 'src/native/headers'
  20. // Download external source files if not available
  21. task downloadOpenALSoft(type: MyDownload) {
  22. sourceUrl = openALSoftUrl
  23. target = file(openalsoftBuildDir + File.separator + openALSoftZipFile)
  24. }
  25. // Unzip external source files
  26. task unzipOpenALSoft(type: Copy) {
  27. def zipFile = file(openalsoftBuildDir + File.separator + openALSoftZipFile)
  28. def outputDir = file(openalsoftBuildDir)
  29. from zipTree(zipFile)
  30. into outputDir
  31. }
  32. unzipOpenALSoft.dependsOn {
  33. def zipFilePath = openalsoftBuildDir + File.separator + openALSoftZipFile
  34. def zipFile = new File(zipFilePath)
  35. // println "zipFile path: " + zipFile.absolutePath
  36. // println "zipFile exists: " + zipFile.exists()
  37. if (!zipFile.exists()) {
  38. downloadOpenALSoft
  39. }
  40. }
  41. // Copy external source files to jni directory
  42. task copyOpenALSoft(type: Copy) {
  43. def sourceDir = file(openalsoftBuildDir + File.separator + openALSoftFolder)
  44. def outputDir = file(openalsoftBuildJniDir)
  45. // println "copyOpenALSoft sourceDir: " + sourceDir
  46. // println "copyOpenALSoft outputDir: " + outputDir
  47. from sourceDir
  48. into outputDir
  49. }
  50. copyOpenALSoft.dependsOn {
  51. def openALSoftUnzipDir = new File(openalsoftBuildDir + File.separator + openALSoftFolder)
  52. // println "openALSoftUnzipDir path: " + openALSoftUnzipDir.absolutePath
  53. // println "openALSoftUnzipDir exists: " + openALSoftUnzipDir.isDirectory()
  54. if (!openALSoftUnzipDir.isDirectory()) {
  55. unzipOpenALSoft
  56. }
  57. }
  58. // Copy JME Headers to jni directory
  59. task copyJmeHeadersOpenAL(type: Copy) {
  60. from file(jmeHeaders)
  61. into file(openalsoftBuildJniDir + File.separator + "headers")
  62. }
  63. // Copy jME Android native files to jni directory
  64. task copyJmeOpenALSoft(type: Copy, dependsOn: [copyOpenALSoft, copyJmeHeadersOpenAL]) {
  65. def sourceDir = file(openalsoftJmeAndroidPath)
  66. def outputDir = file(openalsoftBuildJniDir)
  67. // println "copyJmeOpenALSoft sourceDir: " + sourceDir
  68. // println "copyJmeOpenALSoft outputDir: " + outputDir
  69. from sourceDir
  70. into outputDir
  71. }
  72. task buildOpenAlSoftNativeLib(type: Exec, dependsOn: copyJmeOpenALSoft) {
  73. // println "openalsoft build dir: " + openalsoftBuildDir
  74. // println "ndkCommandPath: " + project.ndkCommandPath
  75. workingDir openalsoftBuildDir
  76. executable rootProject.ndkCommandPath
  77. args "-j" + Runtime.runtime.availableProcessors()
  78. }
  79. task updatePreCompiledOpenAlSoftLibs(type: Copy, dependsOn: buildOpenAlSoftNativeLib) {
  80. def sourceDir = new File(openalsoftBuildLibsDir)
  81. def outputDir = new File(openalsoftPreCompiledLibsDir)
  82. // println "updatePreCompiledOpenAlSoftLibs sourceDir: " + sourceDir
  83. // println "updatePreCompiledOpenAlSoftLibs outputDir: " + outputDir
  84. from sourceDir
  85. into outputDir
  86. }
  87. // Copy pre-compiled libs to build directory (when not building new libs)
  88. task copyPreCompiledOpenAlSoftLibs(type: Copy) {
  89. def sourceDir = file(openalsoftPreCompiledLibsDir)
  90. def outputDir = file(openalsoftBuildLibsDir)
  91. // println "copyStbiJmeFiles sourceDir: " + sourceDir
  92. // println "copyStbiJmeFiles outputDir: " + outputDir
  93. from sourceDir
  94. into outputDir
  95. }
  96. // ndkExists is a boolean from the build.gradle in the root project
  97. // buildNativeProjects is a string set to "true"
  98. if (ndkExists && buildNativeProjects == "true") {
  99. // build native libs and update stored pre-compiled libs to commit
  100. compileJava.dependsOn { updatePreCompiledOpenAlSoftLibs }
  101. } else {
  102. // use pre-compiled native libs (not building new ones)
  103. compileJava.dependsOn { copyPreCompiledOpenAlSoftLibs }
  104. }
  105. jar.into("lib") { from openalsoftBuildLibsDir }
  106. // Helper class to wrap ant download task
  107. class MyDownload extends DefaultTask {
  108. @Input
  109. String sourceUrl
  110. @OutputFile
  111. File target
  112. @TaskAction
  113. void download() {
  114. ant.get(src: sourceUrl, dest: target)
  115. }
  116. }