openalsoft.gradle 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. String jmeHeaders = 'src/native/headers'
  18. // Download external source files if not available
  19. task downloadOpenALSoft(type: MyDownload) {
  20. sourceUrl = openALSoftUrl
  21. target = file(openalsoftBuildDir + File.separator + openALSoftZipFile)
  22. }
  23. // Unzip external source files
  24. task unzipOpenALSoft(type: Copy) {
  25. def zipFile = file(openalsoftBuildDir + File.separator + openALSoftZipFile)
  26. def outputDir = file(openalsoftBuildDir)
  27. from zipTree(zipFile)
  28. into outputDir
  29. }
  30. unzipOpenALSoft.dependsOn {
  31. def zipFilePath = openalsoftBuildDir + File.separator + openALSoftZipFile
  32. def zipFile = new File(zipFilePath)
  33. // println "zipFile path: " + zipFile.absolutePath
  34. // println "zipFile exists: " + zipFile.exists()
  35. if (!zipFile.exists()) {
  36. downloadOpenALSoft
  37. }
  38. }
  39. // Copy external source files to jni directory
  40. task copyOpenALSoft(type: Copy) {
  41. def sourceDir = file(openalsoftBuildDir + File.separator + openALSoftFolder)
  42. def outputDir = file(openalsoftBuildJniDir)
  43. // println "copyOpenALSoft sourceDir: " + sourceDir
  44. // println "copyOpenALSoft outputDir: " + outputDir
  45. from sourceDir
  46. into outputDir
  47. }
  48. copyOpenALSoft.dependsOn {
  49. def openALSoftUnzipDir = new File(project.projectDir.absolutePath + File.separator + openALSoftFolder)
  50. // println "openALSoftUnzipDir path: " + openALSoftUnzipDir.absolutePath
  51. // println "openALSoftUnzipDir exists: " + openALSoftUnzipDir.isDirectory()
  52. if (!openALSoftUnzipDir.isDirectory()) {
  53. unzipOpenALSoft
  54. }
  55. }
  56. // Copy JME Headers to jni directory
  57. task copyJmeHeadersOpenAL(type: Copy) {
  58. from file(jmeHeaders)
  59. into file(openalsoftBuildJniDir + File.separator + "headers")
  60. }
  61. // Copy jME Android native files to jni directory
  62. task copyJmeOpenALSoft(type: Copy, dependsOn: [copyOpenALSoft, copyJmeHeadersOpenAL]) {
  63. def sourceDir = file(openalsoftJmeAndroidPath)
  64. def outputDir = file(openalsoftBuildJniDir)
  65. // println "copyJmeOpenALSoft sourceDir: " + sourceDir
  66. // println "copyJmeOpenALSoft outputDir: " + outputDir
  67. from sourceDir
  68. into outputDir
  69. }
  70. task buildOpenAlSoftNativeLib(type: Exec, dependsOn: copyJmeOpenALSoft) {
  71. // println "openalsoft build dir: " + openalsoftBuildDir
  72. // println "ndkCommandPath: " + project.ndkCommandPath
  73. workingDir openalsoftBuildDir
  74. executable rootProject.ndkCommandPath
  75. args "-j" + Runtime.runtime.availableProcessors()
  76. }
  77. task updatePreCompiledOpenAlSoftLibs(type: Copy, dependsOn: buildOpenAlSoftNativeLib) {
  78. def sourceDir = new File(openalsoftBuildLibsDir)
  79. def outputDir = new File(openalsoftPreCompiledLibsDir)
  80. // println "updatePreCompiledOpenAlSoftLibs sourceDir: " + sourceDir
  81. // println "updatePreCompiledOpenAlSoftLibs outputDir: " + outputDir
  82. from sourceDir
  83. into outputDir
  84. }
  85. // Copy pre-compiled libs to build directory (when not building new libs)
  86. task copyPreCompiledOpenAlSoftLibs(type: Copy) {
  87. def sourceDir = file(openalsoftPreCompiledLibsDir)
  88. def outputDir = file(openalsoftBuildLibsDir)
  89. // println "copyStbiJmeFiles sourceDir: " + sourceDir
  90. // println "copyStbiJmeFiles outputDir: " + outputDir
  91. from sourceDir
  92. into outputDir
  93. }
  94. // ndkExists is a boolean from the build.gradle in the root project
  95. // buildNativeProjects is a string set to "true"
  96. if (ndkExists && buildNativeProjects == "true") {
  97. // build native libs and update stored pre-compiled libs to commit
  98. compileJava.dependsOn { updatePreCompiledOpenAlSoftLibs }
  99. } else {
  100. // use pre-compiled native libs (not building new ones)
  101. compileJava.dependsOn { copyPreCompiledOpenAlSoftLibs }
  102. }
  103. jar.into("lib") { from openalsoftBuildLibsDir }
  104. // Helper class to wrap ant dowload task
  105. class MyDownload extends DefaultTask {
  106. @Input
  107. String sourceUrl
  108. @OutputFile
  109. File target
  110. @TaskAction
  111. void download() {
  112. ant.get(src: sourceUrl, dest: target)
  113. }
  114. }