1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2013, 2014, 2015, 2019, 2020 Ludovic Courtès <ludo@gnu.org>
3 ;;; Copyright © 2013 Cyril Roelandt <tipecaml@gmail.com>
4 ;;; Copyright © 2014 Federico Beffa <beffa@fbengineering.ch>
6 ;;; This file is part of GNU Guix.
8 ;;; GNU Guix is free software; you can redistribute it and/or modify it
9 ;;; under the terms of the GNU General Public License as published by
10 ;;; the Free Software Foundation; either version 3 of the License, or (at
11 ;;; your option) any later version.
13 ;;; GNU Guix is distributed in the hope that it will be useful, but
14 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;;; GNU General Public License for more details.
18 ;;; You should have received a copy of the GNU General Public License
19 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
21 (define-module (guix build-system glib-or-gtk)
22 #:use-module (guix store)
23 #:use-module (guix utils)
24 #:use-module (guix derivations)
25 #:use-module (guix search-paths)
26 #:use-module (guix build-system)
27 #:use-module (guix build-system gnu)
28 #:use-module (guix packages)
29 #:use-module (ice-9 match)
30 #:export (%glib-or-gtk-build-system-modules
32 glib-or-gtk-build-system))
36 ;; This build system is an extension of the 'gnu-build-system'. It
37 ;; accomodates the needs of applications making use of glib or gtk+ (with "or"
38 ;; to be interpreted in the mathematical sense). This is achieved by adding
39 ;; two phases run after the 'install' phase:
41 ;; 'glib-or-gtk-wrap' phase:
43 ;; a) This phase looks for GSettings schemas, GIO modules and theming data.
44 ;; If any of these is found in any input package, then all programs in
45 ;; "out/bin" are wrapped in scripts defining the nedessary environment
48 ;; b) Looks for the existence of "libdir/gtk-3.0" directories in all input
49 ;; packages. If any is found, then the environment variable "GTK_PATH" is
50 ;; suitably set and added to the wrappers. The variable "GTK_PATH" has been
51 ;; preferred over "GTK_EXE_PREFIX" because the latter can only point to a
52 ;; single directory, while we may need to point to several ones.
54 ;; 'glib-or-gtk-compile-schemas' phase:
56 ;; Looks for the presence of "out/share/glib-2.0/schemas". If that directory
57 ;; exists and does not include a file named "gschemas.compiled", then
58 ;; "glib-compile-schemas" is run in that directory.
62 (define %default-modules
63 ;; Build-side modules made available in the build environment.
64 '((guix build glib-or-gtk-build-system)
67 (define %glib-or-gtk-build-system-modules
68 ;; Build-side modules imported and used by default.
69 `((guix build glib-or-gtk-build-system)
70 ,@%gnu-build-system-modules))
72 (define (default-glib)
73 "Return the default glib package from which we use
74 \"glib-compile-schemas\"."
75 ;; Do not use `@' to avoid introducing circular dependencies.
76 (let ((module (resolve-interface '(gnu packages glib))))
77 (module-ref module 'glib)))
80 #:key source inputs native-inputs outputs system target
86 "Return a bag for NAME."
87 (define private-keywords
88 '(#:source #:target #:glib #:inputs #:native-inputs
89 #:outputs #:implicit-inputs?))
91 (and (not target) ;XXX: no cross-compilation
95 (host-inputs (if source
98 (build-inputs `(,@native-inputs
100 ("glib:bin" ,glib "bin") ; to compile schemas
101 ,@(if implicit-inputs?
105 (build glib-or-gtk-build)
106 (arguments (strip-keyword-arguments private-keywords arguments)))))
108 (define* (glib-or-gtk-build store name inputs
112 (configure-flags ''())
113 ;; Disable icon theme cache generation.
114 (make-flags ''("gtk_update_icon_cache=true"))
117 (test-target "check")
120 (validate-runpath? #t)
123 (strip-flags ''("--strip-debug"))
124 (strip-directories ''("lib" "lib64" "libexec"
126 (phases '(@ (guix build glib-or-gtk-build-system)
128 (glib-or-gtk-wrap-excluded-outputs ''())
129 (system (%current-system))
130 (imported-modules %glib-or-gtk-build-system-modules)
131 (modules %default-modules)
133 disallowed-references)
134 "Build SOURCE with INPUTS. See GNU-BUILD for more details."
135 (define canonicalize-reference
138 (derivation->output-path (package-derivation store p system)))
139 (((? package? p) output)
140 (derivation->output-path (package-derivation store p system)
147 (use-modules ,@modules)
148 (glib-or-gtk-build #:source ,(match (assoc-ref inputs "source")
149 (((? derivation? source))
150 (derivation->output-path source))
157 #:inputs %build-inputs
158 #:search-paths ',(map search-path-specification->sexp
161 #:glib-or-gtk-wrap-excluded-outputs
162 ,glib-or-gtk-wrap-excluded-outputs
163 #:configure-flags ,configure-flags
164 #:make-flags ,make-flags
165 #:out-of-source? ,out-of-source?
167 #:test-target ,test-target
168 #:parallel-build? ,parallel-build?
169 #:parallel-tests? ,parallel-tests?
170 #:validate-runpath? ,validate-runpath?
171 #:patch-shebangs? ,patch-shebangs?
172 #:strip-binaries? ,strip-binaries?
173 #:strip-flags ,strip-flags
174 #:strip-directories ,strip-directories)))
176 (define guile-for-build
179 (package-derivation store guile system #:graft? #f))
181 (let* ((distro (resolve-interface '(gnu packages commencement)))
182 (guile (module-ref distro 'guile-final)))
183 (package-derivation store guile system #:graft? #f)))))
185 (build-expression->derivation store name builder
188 #:modules imported-modules
191 (and allowed-references
192 (map canonicalize-reference
194 #:disallowed-references
195 (and disallowed-references
196 (map canonicalize-reference
197 disallowed-references))
198 #:guile-for-build guile-for-build))
200 (define glib-or-gtk-build-system
204 "The GNU Build System—i.e., ./configure && make && make install,
205 augmented with definition of suitable environment variables for glib and gtk+
206 in program wrappers.")