android-ndk.scm 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2016 Danny Milosavljevic <dannym@scratchpost.org>
  3. ;;; Copyright © 2021 Ludovic Courtès <ludo@gnu.org>
  4. ;;;
  5. ;;; This file is part of GNU Guix.
  6. ;;;
  7. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  8. ;;; under the terms of the GNU General Public License as published by
  9. ;;; the Free Software Foundation; either version 3 of the License, or (at
  10. ;;; your option) any later version.
  11. ;;;
  12. ;;; GNU Guix is distributed in the hope that it will be useful, but
  13. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  14. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. ;;; GNU General Public License for more details.
  16. ;;;
  17. ;;; You should have received a copy of the GNU General Public License
  18. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  19. (define-module (guix build-system android-ndk)
  20. #:use-module (guix search-paths)
  21. #:use-module (guix store)
  22. #:use-module (guix utils)
  23. #:use-module (guix gexp)
  24. #:use-module (guix monads)
  25. #:use-module (guix packages)
  26. #:use-module (guix build-system)
  27. #:use-module (guix build-system gnu)
  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 name inputs
  35. #:key
  36. source
  37. (tests? #t)
  38. (test-target #f)
  39. (phases '%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. (with-imported-modules imported-modules
  51. #~(begin
  52. (use-modules #$@(sexp->gexp modules))
  53. (android-ndk-build #:name #$name
  54. #:source #+source
  55. #:system #$system
  56. #:test-target #$test-target
  57. #:tests? #$tests?
  58. #:phases #$phases
  59. #:bootstrap-scripts '() ;no autotools machinery
  60. #:make-flags
  61. (cons* "-f"
  62. #$(file-append (gexp-input-thing
  63. (car (assoc-ref inputs
  64. "android-build")))
  65. "/share/android/build/core/main.mk")
  66. #$make-flags)
  67. #:outputs #$(outputs->gexp outputs)
  68. #:search-paths '#$(sexp->gexp
  69. (map search-path-specification->sexp
  70. search-paths))
  71. #:inputs #$(input-tuples->gexp inputs)))))
  72. (mlet %store-monad ((guile (package->derivation (or guile (default-guile))
  73. system #:graft? #f)))
  74. (gexp->derivation name builder
  75. #:system system
  76. #:guile-for-build guile)))
  77. (define* (lower name
  78. #:key source inputs native-inputs outputs system target
  79. #:allow-other-keys
  80. #:rest arguments)
  81. "Return a bag for NAME."
  82. (define private-keywords
  83. '(#:target #:inputs #:native-inputs #:outputs))
  84. (and (not target) ;; TODO: support cross-compilation
  85. (bag
  86. (name name)
  87. (system system)
  88. (target target)
  89. (host-inputs `(,@(if source
  90. `(("source" ,source))
  91. '())
  92. ,@inputs
  93. ;; Keep the standard inputs of 'gnu-build-system'
  94. ,@(standard-packages)))
  95. (build-inputs `(("android-build" ,(module-ref (resolve-interface '(gnu packages android)) 'android-make-stub))
  96. ("android-googletest" ,(module-ref (resolve-interface '(gnu packages android)) 'android-googletest))
  97. ,@native-inputs))
  98. (outputs outputs)
  99. (build android-ndk-build)
  100. (arguments (strip-keyword-arguments private-keywords arguments)))))
  101. (define android-ndk-build-system
  102. (build-system
  103. (name 'android-ndk)
  104. (description
  105. "Android NDK build system, to build Android NDK packages")
  106. (lower lower)))