android-ndk.scm 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2016 Danny Milosavljevic <dannym@scratchpost.org>
  3. ;;;
  4. ;;; This file is part of GNU Guix.
  5. ;;;
  6. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  7. ;;; under the terms of the GNU General Public License as published by
  8. ;;; the Free Software Foundation; either version 3 of the License, or (at
  9. ;;; your option) any later version.
  10. ;;;
  11. ;;; GNU Guix is distributed in the hope that it will be useful, but
  12. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. ;;; GNU General Public License for more details.
  15. ;;;
  16. ;;; You should have received a copy of the GNU General Public License
  17. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  18. (define-module (guix build-system android-ndk)
  19. #:use-module (guix search-paths)
  20. #:use-module (guix store)
  21. #:use-module (guix utils)
  22. #:use-module (guix derivations)
  23. #:use-module (guix packages)
  24. #:use-module (guix build-system)
  25. #:use-module (guix build-system gnu)
  26. #:use-module (ice-9 match)
  27. #:use-module (srfi srfi-26)
  28. #:export (android-ndk-build-system))
  29. (define %android-ndk-build-system-modules
  30. ;; Build-side modules imported by default.
  31. `((guix build android-ndk-build-system)
  32. (guix build syscalls)
  33. ,@%gnu-build-system-modules))
  34. (define* (android-ndk-build store name inputs
  35. #:key
  36. (tests? #t)
  37. (test-target #f)
  38. (phases '(@ (guix build android-ndk-build-system)
  39. %standard-phases))
  40. (outputs '("out"))
  41. (make-flags ''())
  42. (search-paths '())
  43. (system (%current-system))
  44. (guile #f)
  45. (imported-modules %android-ndk-build-system-modules)
  46. (modules '((guix build android-ndk-build-system)
  47. (guix build utils))))
  48. "Build SOURCE using Android NDK, and with INPUTS."
  49. (define builder
  50. `(begin
  51. (use-modules ,@modules)
  52. (android-ndk-build #:name ,name
  53. #:source ,(match (assoc-ref inputs "source")
  54. (((? derivation? source))
  55. (derivation->output-path source))
  56. ((source)
  57. source)
  58. (source
  59. source))
  60. #:system ,system
  61. #:test-target ,test-target
  62. #:tests? ,tests?
  63. #:phases ,phases
  64. #:make-flags (cons* "-f"
  65. ,(string-append
  66. (derivation->output-path
  67. (car (assoc-ref inputs "android-build")))
  68. "/share/android/build/core/main.mk")
  69. ,make-flags)
  70. #:outputs %outputs
  71. #:search-paths ',(map search-path-specification->sexp
  72. search-paths)
  73. #:inputs %build-inputs)))
  74. (define guile-for-build
  75. (match guile
  76. ((? package?)
  77. (package-derivation store guile system #:graft? #f))
  78. (#f ; the default
  79. (let* ((distro (resolve-interface '(gnu packages commencement)))
  80. (guile (module-ref distro 'guile-final)))
  81. (package-derivation store guile system #:graft? #f)))))
  82. (build-expression->derivation store name builder
  83. #:inputs inputs
  84. #:system system
  85. #:modules imported-modules
  86. #:outputs outputs
  87. #:guile-for-build guile-for-build))
  88. (define* (lower name
  89. #:key source inputs native-inputs outputs system target
  90. #:allow-other-keys
  91. #:rest arguments)
  92. "Return a bag for NAME."
  93. (define private-keywords
  94. '(#:source #:target #:inputs #:native-inputs #:outputs))
  95. (and (not target) ;; TODO: support cross-compilation
  96. (bag
  97. (name name)
  98. (system system)
  99. (target target)
  100. (host-inputs `(,@(if source
  101. `(("source" ,source))
  102. '())
  103. ,@inputs
  104. ;; Keep the standard inputs of 'gnu-build-system'
  105. ,@(standard-packages)))
  106. (build-inputs `(("android-build" ,(module-ref (resolve-interface '(gnu packages android)) 'android-make-stub))
  107. ("android-googletest" ,(module-ref (resolve-interface '(gnu packages android)) 'android-googletest))
  108. ,@native-inputs))
  109. (outputs outputs)
  110. (build android-ndk-build)
  111. (arguments (strip-keyword-arguments private-keywords arguments)))))
  112. (define android-ndk-build-system
  113. (build-system
  114. (name 'android-ndk)
  115. (description
  116. "Android NDK build system, to build Android NDK packages")
  117. (lower lower)))