gnu: emacs-org: Update to 9.4.
[jackhill/guix/guix.git] / guix / build-system / meson.scm
CommitLineData
07c101e2
PM
1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2017 Peter Mikkelsen <petermikkelsen10@gmail.com>
ad4910ee 3;;; Copyright © 2018, 2019 Marius Bakke <mbakke@fastmail.com>
07c101e2
PM
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
20(define-module (guix build-system meson)
21 #:use-module (guix store)
22 #:use-module (guix utils)
23 #:use-module (guix derivations)
24 #:use-module (guix search-paths)
25 #:use-module (guix build-system)
26 #:use-module (guix build-system gnu)
27 #:use-module (guix build-system glib-or-gtk)
28 #:use-module (guix packages)
29 #:use-module (ice-9 match)
30 #:export (%meson-build-system-modules
31 meson-build-system))
32
33;; Commentary:
34;;
35;; Standard build procedure for packages using Meson. This is implemented as an
36;; extension of `gnu-build-system', with the option to turn on the glib/gtk
37;; phases from `glib-or-gtk-build-system'.
38;;
39;; Code:
40
41(define %meson-build-system-modules
42 ;; Build-side modules imported by default.
43 `((guix build meson-build-system)
07c101e2
PM
44 ;; The modules from glib-or-gtk contains the modules from gnu-build-system,
45 ;; so there is no need to import that too.
46 ,@%glib-or-gtk-build-system-modules))
47
48(define (default-ninja)
49 "Return the default ninja package."
50 ;; Lazily resolve the binding to avoid a circular dependency.
51 (let ((module (resolve-interface '(gnu packages ninja))))
52 (module-ref module 'ninja)))
53
54(define (default-meson)
55 "Return the default meson package."
56 ;; Lazily resolve the binding to avoid a circular dependency.
57 (let ((module (resolve-interface '(gnu packages build-tools))))
58 (module-ref module 'meson-for-build)))
59
07c101e2
PM
60(define* (lower name
61 #:key source inputs native-inputs outputs system target
62 (meson (default-meson))
63 (ninja (default-ninja))
ea1cd554 64 (glib-or-gtk? #f)
07c101e2
PM
65 #:allow-other-keys
66 #:rest arguments)
67 "Return a bag for NAME."
68 (define private-keywords
69 `(#:source #:meson #:ninja #:inputs #:native-inputs #:outputs #:target))
70
71 (and (not target) ;; TODO: add support for cross-compilation.
72 (bag
73 (name name)
74 (system system)
75 (build-inputs `(("meson" ,meson)
76 ("ninja" ,ninja)
2073b55e
LC
77 ,@native-inputs
78 ,@inputs
79 ;; Keep the standard inputs of 'gnu-build-system'.
80 ,@(standard-packages)))
81 (host-inputs (if source
82 `(("source" ,source))
83 '()))
07c101e2
PM
84 (outputs outputs)
85 (build meson-build)
86 (arguments (strip-keyword-arguments private-keywords arguments)))))
87
88(define* (meson-build store name inputs
89 #:key (guile #f)
90 (outputs '("out"))
91 (configure-flags ''())
92 (search-paths '())
c43b0903 93 (build-type "debugoptimized")
07c101e2
PM
94 (tests? #t)
95 (test-target "test")
96 (glib-or-gtk? #f)
97 (parallel-build? #t)
98 (parallel-tests? #f)
99 (validate-runpath? #t)
100 (patch-shebangs? #t)
101 (strip-binaries? #t)
102 (strip-flags ''("--strip-debug"))
103 (strip-directories ''("lib" "lib64" "libexec"
104 "bin" "sbin"))
105 (elf-directories ''("lib" "lib64" "libexec"
106 "bin" "sbin"))
107 (phases '(@ (guix build meson-build-system)
108 %standard-phases))
109 (system (%current-system))
110 (imported-modules %meson-build-system-modules)
111 (modules '((guix build meson-build-system)
ad4910ee
MB
112 (guix build utils)))
113 allowed-references
114 disallowed-references)
07c101e2
PM
115 "Build SOURCE using MESON, and with INPUTS, assuming that SOURCE
116has a 'meson.build' file."
ad4910ee
MB
117
118 ;; TODO: Copied from build-system/gnu, factorize this!
119 (define canonicalize-reference
120 (match-lambda
121 ((? package? p)
122 (derivation->output-path (package-derivation store p system
123 #:graft? #f)))
124 (((? package? p) output)
125 (derivation->output-path (package-derivation store p system
126 #:graft? #f)
127 output))
128 ((? string? output)
129 output)))
130
07c101e2
PM
131 (define builder
132 `(let ((build-phases (if ,glib-or-gtk?
133 ,phases
134 (modify-phases ,phases
135 (delete 'glib-or-gtk-compile-schemas)
136 (delete 'glib-or-gtk-wrap)))))
137 (use-modules ,@modules)
138 (meson-build #:source ,(match (assoc-ref inputs "source")
139 (((? derivation? source))
140 (derivation->output-path source))
141 ((source)
142 source)
143 (source
144 source))
145 #:system ,system
146 #:outputs %outputs
147 #:inputs %build-inputs
148 #:search-paths ',(map search-path-specification->sexp
149 search-paths)
94eb59fb 150 #:phases build-phases
07c101e2
PM
151 #:configure-flags ,configure-flags
152 #:build-type ,build-type
153 #:tests? ,tests?
154 #:test-target ,test-target
155 #:parallel-build? ,parallel-build?
156 #:parallel-tests? ,parallel-tests?
157 #:validate-runpath? ,validate-runpath?
158 #:patch-shebangs? ,patch-shebangs?
159 #:strip-binaries? ,strip-binaries?
160 #:strip-flags ,strip-flags
161 #:strip-directories ,strip-directories
162 #:elf-directories ,elf-directories)))
163
164 (define guile-for-build
165 (match guile
166 ((? package?)
167 (package-derivation store guile system #:graft? #f))
168 (#f ; the default
169 (let* ((distro (resolve-interface '(gnu packages commencement)))
170 (guile (module-ref distro 'guile-final)))
171 (package-derivation store guile system #:graft? #f)))))
172
173 (build-expression->derivation store name builder
174 #:system system
175 #:inputs inputs
176 #:modules imported-modules
177 #:outputs outputs
ad4910ee
MB
178 #:guile-for-build guile-for-build
179 #:allowed-references
180 (and allowed-references
181 (map canonicalize-reference
182 allowed-references))
183 #:disallowed-references
184 (and disallowed-references
185 (map canonicalize-reference
186 disallowed-references))))
07c101e2
PM
187
188(define meson-build-system
189 (build-system
190 (name 'meson)
191 (description "The standard Meson build system")
192 (lower lower)))
193
194;;; meson.scm ends here