1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2017 Peter Mikkelsen <petermikkelsen10@gmail.com>
3 ;;; Copyright © 2018 Marius Bakke <mbakke@fastmail.com>
5 ;;; This file is part of GNU Guix.
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.
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.
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/>.
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
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'.
41 (define %meson-build-system-modules
42 ;; Build-side modules imported by default.
43 `((guix build meson-build-system)
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))
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)))
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)))
61 #:key source inputs native-inputs outputs system target
62 (meson (default-meson))
63 (ninja (default-ninja))
67 "Return a bag for NAME."
68 (define private-keywords
69 `(#:source #:meson #:ninja #:inputs #:native-inputs #:outputs #:target))
71 (and (not target) ;; TODO: add support for cross-compilation.
75 (build-inputs `(("meson" ,meson)
78 (host-inputs `(,@(if source
82 ;; Keep the standard inputs of 'gnu-build-system'.
83 ,@(standard-packages)))
86 (arguments (strip-keyword-arguments private-keywords arguments)))))
88 (define* (meson-build store name inputs
91 (configure-flags ''())
99 (validate-runpath? #t)
102 (strip-flags ''("--strip-debug"))
103 (strip-directories ''("lib" "lib64" "libexec"
105 (elf-directories ''("lib" "lib64" "libexec"
107 (phases '(@ (guix build meson-build-system)
109 (system (%current-system))
110 (imported-modules %meson-build-system-modules)
111 (modules '((guix build meson-build-system)
112 (guix build utils))))
113 "Build SOURCE using MESON, and with INPUTS, assuming that SOURCE
114 has a 'meson.build' file."
116 `(let ((build-phases (if ,glib-or-gtk?
118 (modify-phases ,phases
119 (delete 'glib-or-gtk-compile-schemas)
120 (delete 'glib-or-gtk-wrap)))))
121 (use-modules ,@modules)
122 (meson-build #:source ,(match (assoc-ref inputs "source")
123 (((? derivation? source))
124 (derivation->output-path source))
131 #:inputs %build-inputs
132 #:search-paths ',(map search-path-specification->sexp
134 #:phases build-phases
135 #:configure-flags ,configure-flags
136 #:build-type ,build-type
138 #:test-target ,test-target
139 #:parallel-build? ,parallel-build?
140 #:parallel-tests? ,parallel-tests?
141 #:validate-runpath? ,validate-runpath?
142 #:patch-shebangs? ,patch-shebangs?
143 #:strip-binaries? ,strip-binaries?
144 #:strip-flags ,strip-flags
145 #:strip-directories ,strip-directories
146 #:elf-directories ,elf-directories)))
148 (define guile-for-build
151 (package-derivation store guile system #:graft? #f))
153 (let* ((distro (resolve-interface '(gnu packages commencement)))
154 (guile (module-ref distro 'guile-final)))
155 (package-derivation store guile system #:graft? #f)))))
157 (build-expression->derivation store name builder
160 #:modules imported-modules
162 #:guile-for-build guile-for-build))
164 (define meson-build-system
167 (description "The standard Meson build system")
170 ;;; meson.scm ends here