Merge branch 'master' into core-updates
[jackhill/guix/guix.git] / guix / build-system / waf.scm
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2015 Ricardo Wurmus <rekado@elephly.net>
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 waf)
20 #:use-module (guix store)
21 #:use-module (guix utils)
22 #:use-module (guix packages)
23 #:use-module (guix derivations)
24 #:use-module (guix build-system)
25 #:use-module (guix build-system gnu)
26 #:use-module ((guix build-system python)
27 #:select (default-python default-python2))
28 #:use-module (ice-9 match)
29 #:use-module (srfi srfi-26)
30 #:export (%waf-build-system-modules
31 waf-build
32 waf-build-system))
33
34 ;; Commentary:
35 ;;
36 ;; Standard build procedure for applications using 'waf'. This is very
37 ;; similar to the 'python-build-system' and is implemented as an extension of
38 ;; 'gnu-build-system'.
39 ;;
40 ;; Code:
41
42 (define %waf-build-system-modules
43 ;; Build-side modules imported by default.
44 `((guix build waf-build-system)
45 ,@%gnu-build-system-modules))
46
47 (define* (lower name
48 #:key source inputs native-inputs outputs system target
49 (python (default-python))
50 #:allow-other-keys
51 #:rest arguments)
52 "Return a bag for NAME."
53 (define private-keywords
54 '(#:source #:target #:python #:inputs #:native-inputs))
55
56 (and (not target) ;XXX: no cross-compilation
57 (bag
58 (name name)
59 (system system)
60 (host-inputs `(,@(if source
61 `(("source" ,source))
62 '())
63 ,@inputs
64
65 ;; Keep the standard inputs of 'gnu-build-system'.
66 ,@(standard-packages)))
67 (build-inputs `(("python" ,python)
68 ,@native-inputs))
69 (outputs outputs)
70 (build waf-build) ; only change compared to 'lower' in python.scm
71 (arguments (strip-keyword-arguments private-keywords arguments)))))
72
73 (define* (waf-build store name inputs
74 #:key
75 (tests? #t)
76 (test-target "check")
77 (configure-flags ''())
78 (phases '(@ (guix build waf-build-system)
79 %standard-phases))
80 (outputs '("out"))
81 (search-paths '())
82 (system (%current-system))
83 (guile #f)
84 (imported-modules %waf-build-system-modules)
85 (modules '((guix build waf-build-system)
86 (guix build utils))))
87 "Build SOURCE with INPUTS. This assumes that SOURCE provides a 'waf' file
88 as its build system."
89 (define builder
90 `(begin
91 (use-modules ,@modules)
92 (waf-build #:name ,name
93 #:source ,(match (assoc-ref inputs "source")
94 (((? derivation? source))
95 (derivation->output-path source))
96 ((source)
97 source)
98 (source
99 source))
100 #:configure-flags ,configure-flags
101 #:system ,system
102 #:test-target ,test-target
103 #:tests? ,tests?
104 #:phases ,phases
105 #:outputs %outputs
106 #:search-paths ',(map search-path-specification->sexp
107 search-paths)
108 #:inputs %build-inputs)))
109
110 (define guile-for-build
111 (match guile
112 ((? package?)
113 (package-derivation store guile system #:graft? #f))
114 (#f ; the default
115 (let* ((distro (resolve-interface '(gnu packages commencement)))
116 (guile (module-ref distro 'guile-final)))
117 (package-derivation store guile system #:graft? #f)))))
118
119 (build-expression->derivation store name builder
120 #:inputs inputs
121 #:system system
122 #:modules imported-modules
123 #:outputs outputs
124 #:guile-for-build guile-for-build))
125
126 (define waf-build-system
127 (build-system
128 (name 'waf)
129 (description "The standard waf build system")
130 (lower lower)))
131
132 ;;; waf.scm ends here