android-ndk.scm 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. #:use-module (ice-9 match)
  29. #:use-module (srfi srfi-26)
  30. #:export (android-ndk-build-system))
  31. (define %android-ndk-build-system-modules
  32. ;; Build-side modules imported by default.
  33. `((guix build android-ndk-build-system)
  34. (guix build syscalls)
  35. ,@%gnu-build-system-modules))
  36. (define* (android-ndk-build name inputs
  37. #:key
  38. source
  39. (tests? #t)
  40. (test-target #f)
  41. (phases '%standard-phases)
  42. (outputs '("out"))
  43. (make-flags #~'())
  44. (search-paths '())
  45. (system (%current-system))
  46. (guile #f)
  47. (imported-modules %android-ndk-build-system-modules)
  48. (modules '((guix build android-ndk-build-system)
  49. (guix build utils))))
  50. "Build SOURCE using Android NDK, and with INPUTS."
  51. (define builder
  52. (with-imported-modules imported-modules
  53. #~(begin
  54. (use-modules #$@(sexp->gexp modules))
  55. (android-ndk-build #:name #$name
  56. #:source #+source
  57. #:system #$system
  58. #:test-target #$test-target
  59. #:tests? #$tests?
  60. #:phases #$phases
  61. #:bootstrap-scripts '() ;no autotools machinery
  62. #:make-flags
  63. (cons* "-f"
  64. #$(file-append (gexp-input-thing
  65. (car (assoc-ref inputs
  66. "android-build")))
  67. "/share/android/build/core/main.mk")
  68. #$make-flags)
  69. #:outputs #$(outputs->gexp outputs)
  70. #:search-paths '#$(sexp->gexp
  71. (map search-path-specification->sexp
  72. search-paths))
  73. #:inputs #$(input-tuples->gexp inputs)))))
  74. (mlet %store-monad ((guile (package->derivation (or guile (default-guile))
  75. system #:graft? #f)))
  76. (gexp->derivation name builder
  77. #:system system
  78. #:guile-for-build guile)))
  79. (define* (lower name
  80. #:key source inputs native-inputs outputs system target
  81. #:allow-other-keys
  82. #:rest arguments)
  83. "Return a bag for NAME."
  84. (define private-keywords
  85. '(#:target #:inputs #:native-inputs #:outputs))
  86. (and (not target) ;; TODO: support cross-compilation
  87. (bag
  88. (name name)
  89. (system system)
  90. (target target)
  91. (host-inputs `(,@(if source
  92. `(("source" ,source))
  93. '())
  94. ,@inputs
  95. ;; Keep the standard inputs of 'gnu-build-system'
  96. ,@(standard-packages)))
  97. (build-inputs `(("android-build" ,(module-ref (resolve-interface '(gnu packages android)) 'android-make-stub))
  98. ("android-googletest" ,(module-ref (resolve-interface '(gnu packages android)) 'android-googletest))
  99. ,@native-inputs))
  100. (outputs outputs)
  101. (build android-ndk-build)
  102. (arguments (strip-keyword-arguments private-keywords arguments)))))
  103. (define android-ndk-build-system
  104. (build-system
  105. (name 'android-ndk)
  106. (description
  107. "Android NDK build system, to build Android NDK packages")
  108. (lower lower)))