android-ndk-build-system.scm 3.2 KB

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