android-ndk-build-system.scm 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2018 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 android-ndk-build-system)
  19. #:use-module ((guix build gnu-build-system) #:prefix gnu:)
  20. #:use-module (guix build utils)
  21. #:use-module (ice-9 format)
  22. #:use-module (ice-9 match)
  23. #:use-module (srfi srfi-1)
  24. #:use-module (srfi srfi-26)
  25. #:export (%standard-phases
  26. android-ndk-build))
  27. ;; Commentary:
  28. ;;
  29. ;; Builder-side code of the Android NDK build system.
  30. ;;
  31. ;; Code:
  32. (define* (configure #:key inputs outputs #:allow-other-keys)
  33. (let ((library-directories (filter-map (match-lambda
  34. ((name . path)
  35. (if (eq? 'directory (stat:type (stat path)))
  36. path
  37. #f)))
  38. inputs)))
  39. (setenv "CC" "gcc")
  40. (setenv "CXX" "g++")
  41. (setenv "CPPFLAGS"
  42. (string-join
  43. (map (cut string-append "-I " <> "/include") library-directories)
  44. " "))
  45. (setenv "LDFLAGS"
  46. (string-append "-L . "
  47. (string-join
  48. (map (lambda (x)
  49. (string-append "-L " x "/lib" " -Wl,-rpath=" x "/lib"))
  50. library-directories)
  51. " ")))
  52. #t))
  53. (define* (install #:key inputs outputs (make-flags '()) #:allow-other-keys)
  54. (let ((out (assoc-ref outputs "out")))
  55. (apply invoke "make" "install"
  56. (string-append "prefix=" out)
  57. make-flags)
  58. #t))
  59. (define* (check #:key target inputs outputs (tests? (not target)) (make-flags '()) #:allow-other-keys)
  60. (if tests?
  61. (begin
  62. (apply invoke "make" "check" make-flags)
  63. (when (and (file-exists? "tests") tests?)
  64. (with-directory-excursion "tests"
  65. (apply invoke "make" "check" make-flags))))
  66. (format #t "test suite not run~%"))
  67. #t)
  68. (define %standard-phases
  69. (modify-phases gnu:%standard-phases
  70. (replace 'configure configure)
  71. (replace 'install install)
  72. (replace 'check check)))
  73. (define* (android-ndk-build #:key inputs (phases %standard-phases)
  74. #:allow-other-keys #:rest args)
  75. "Build the given Android NDK package, applying all of PHASES in order."
  76. (apply gnu:gnu-build #:inputs inputs #:phases phases args))