| 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 | |
| 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 derivations) |
| 24 | #:use-module (guix packages) |
| 25 | #:use-module (guix build-system) |
| 26 | #:use-module (guix build-system gnu) |
| 27 | #:use-module (ice-9 match) |
| 28 | #:use-module (srfi srfi-26) |
| 29 | #:export (android-ndk-build-system)) |
| 30 | |
| 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 | |
| 37 | (define* (android-ndk-build store name inputs |
| 38 | #:key |
| 39 | (tests? #t) |
| 40 | (test-target #f) |
| 41 | (phases '(@ (guix build android-ndk-build-system) |
| 42 | %standard-phases)) |
| 43 | (outputs '("out")) |
| 44 | (make-flags ''()) |
| 45 | (search-paths '()) |
| 46 | (system (%current-system)) |
| 47 | (guile #f) |
| 48 | (imported-modules %android-ndk-build-system-modules) |
| 49 | (modules '((guix build android-ndk-build-system) |
| 50 | (guix build utils)))) |
| 51 | "Build SOURCE using Android NDK, and with INPUTS." |
| 52 | (define builder |
| 53 | `(begin |
| 54 | (use-modules ,@modules) |
| 55 | (android-ndk-build #:name ,name |
| 56 | #:source ,(match (assoc-ref inputs "source") |
| 57 | (((? derivation? source)) |
| 58 | (derivation->output-path source)) |
| 59 | ((source) |
| 60 | source) |
| 61 | (source |
| 62 | source)) |
| 63 | #:system ,system |
| 64 | #:test-target ,test-target |
| 65 | #:tests? ,tests? |
| 66 | #:phases ,phases |
| 67 | #:make-flags (cons* "-f" |
| 68 | ,(string-append |
| 69 | (derivation->output-path |
| 70 | (car (assoc-ref inputs "android-build"))) |
| 71 | "/share/android/build/core/main.mk") |
| 72 | ,make-flags) |
| 73 | #:outputs %outputs |
| 74 | #:search-paths ',(map search-path-specification->sexp |
| 75 | search-paths) |
| 76 | #:inputs %build-inputs))) |
| 77 | |
| 78 | (define guile-for-build |
| 79 | (match guile |
| 80 | ((? package?) |
| 81 | (package-derivation store guile system #:graft? #f)) |
| 82 | (#f ; the default |
| 83 | (let* ((distro (resolve-interface '(gnu packages commencement))) |
| 84 | (guile (module-ref distro 'guile-final))) |
| 85 | (package-derivation store guile system #:graft? #f))))) |
| 86 | |
| 87 | (build-expression->derivation store name builder |
| 88 | #:inputs inputs |
| 89 | #:system system |
| 90 | #:modules imported-modules |
| 91 | #:outputs outputs |
| 92 | #:guile-for-build guile-for-build)) |
| 93 | |
| 94 | (define* (lower name |
| 95 | #:key source inputs native-inputs outputs system target |
| 96 | #:allow-other-keys |
| 97 | #:rest arguments) |
| 98 | "Return a bag for NAME." |
| 99 | |
| 100 | (define private-keywords |
| 101 | '(#:source #:target #:inputs #:native-inputs #:outputs)) |
| 102 | |
| 103 | (and (not target) ;; TODO: support cross-compilation |
| 104 | (bag |
| 105 | (name name) |
| 106 | (system system) |
| 107 | (target target) |
| 108 | (host-inputs `(,@(if source |
| 109 | `(("source" ,source)) |
| 110 | '()) |
| 111 | ,@inputs |
| 112 | |
| 113 | ;; Keep the standard inputs of 'gnu-build-system' |
| 114 | ,@(standard-packages))) |
| 115 | (build-inputs `(("android-build" ,(module-ref (resolve-interface '(gnu packages android)) 'android-make-stub)) |
| 116 | ("android-googletest" ,(module-ref (resolve-interface '(gnu packages android)) 'android-googletest)) |
| 117 | ,@native-inputs)) |
| 118 | (outputs outputs) |
| 119 | (build android-ndk-build) |
| 120 | (arguments (strip-keyword-arguments private-keywords arguments))))) |
| 121 | |
| 122 | (define android-ndk-build-system |
| 123 | (build-system |
| 124 | (name 'android-ndk) |
| 125 | (description |
| 126 | "Android NDK build system, to build Android NDK packages") |
| 127 | (lower lower))) |