Commit | Line | Data |
---|---|---|
b6d852ce HG |
1 | ;;; GNU Guix --- Functional package management for GNU |
2 | ;;; Copyright © 2013, 2014, 2015 Ludovic Courtès <ludo@gnu.org> | |
3 | ;;; Copyright © 2013 Cyril Roelandt <tipecaml@gmail.com> | |
4 | ;;; Copyright © 2017 Ricardo Wurmus <rekado@elephly.net> | |
5 | ;;; Copyright © 2019 Hartmut Goebel <h.goebel@crazy-compilers.com> | |
6 | ;;; | |
7 | ;;; This file is part of GNU Guix. | |
8 | ;;; | |
9 | ;;; GNU Guix is free software; you can redistribute it and/or modify it | |
10 | ;;; under the terms of the GNU General Public License as published by | |
11 | ;;; the Free Software Foundation; either version 3 of the License, or (at | |
12 | ;;; your option) any later version. | |
13 | ;;; | |
14 | ;;; GNU Guix is distributed in the hope that it will be useful, but | |
15 | ;;; WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | ;;; GNU General Public License for more details. | |
18 | ;;; | |
19 | ;;; You should have received a copy of the GNU General Public License | |
20 | ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>. | |
21 | ||
22 | (define-module (guix build-system qt) | |
23 | #:use-module (guix store) | |
24 | #:use-module (guix utils) | |
25 | #:use-module (guix derivations) | |
26 | #:use-module (guix search-paths) | |
27 | #:use-module (guix build-system) | |
28 | #:use-module (guix build-system cmake) | |
29 | #:use-module (guix build-system gnu) | |
30 | #:use-module (guix packages) | |
31 | #:use-module (ice-9 match) | |
32 | #:export (%qt-build-system-modules | |
33 | qt-build | |
34 | qt-build-system)) | |
35 | ||
36 | ;; Commentary: | |
37 | ;; | |
38 | ;; This build system is an extension of the 'cmake-build-system'. It | |
39 | ;; accommodates the needs of Qt and KDE applications by adding a phase run | |
40 | ;; after the 'install' phase: | |
41 | ;; | |
42 | ;; 'qt-wrap' phase: | |
43 | ;; | |
44 | ;; This phase looks for Qt5 plugin paths, QML paths and some XDG paths as well | |
45 | ;; as the corresponding environment variables. If any of these is found in | |
46 | ;; the output or if respective environment variables are set, then all | |
47 | ;; programs in the output's "bin", "sbin", "libexec and "lib/libexec" | |
48 | ;; directories are wrapped in scripts defining the necessary environment | |
49 | ;; variables. | |
50 | ;; | |
51 | ;; Code: | |
52 | ||
53 | (define %qt-build-system-modules | |
54 | ;; Build-side modules imported and used by default. | |
55 | `((guix build qt-build-system) | |
56 | ,@%cmake-build-system-modules)) | |
57 | ||
58 | (define (default-cmake) | |
59 | "Return the default CMake package." | |
60 | ||
61 | ;; Do not use `@' to avoid introducing circular dependencies. | |
62 | (let ((module (resolve-interface '(gnu packages cmake)))) | |
63 | (module-ref module 'cmake-minimal))) | |
64 | ||
65 | ;; This barely is a copy from (guix build-system cmake), only adjusted to use | |
66 | ;; the variables defined here. | |
67 | (define* (lower name | |
68 | #:key source inputs native-inputs outputs system target | |
69 | (cmake (default-cmake)) | |
70 | #:allow-other-keys | |
71 | #:rest arguments) | |
72 | "Return a bag for NAME." | |
73 | (define private-keywords | |
74 | `(#:source #:cmake #:inputs #:native-inputs #:outputs | |
75 | ,@(if target '() '(#:target)))) | |
76 | ||
77 | (bag | |
78 | (name name) | |
79 | (system system) | |
80 | (target target) | |
81 | (build-inputs `(,@(if source | |
82 | `(("source" ,source)) | |
83 | '()) | |
84 | ,@`(("cmake" ,cmake)) | |
85 | ,@native-inputs | |
86 | ,@(if target | |
87 | ;; Use the standard cross inputs of | |
88 | ;; 'gnu-build-system'. | |
89 | (standard-cross-packages target 'host) | |
90 | '()) | |
91 | ;; Keep the standard inputs of 'gnu-build-system'. | |
92 | ,@(standard-packages))) | |
93 | (host-inputs inputs) | |
94 | ||
95 | ;; The cross-libc is really a target package, but for bootstrapping | |
96 | ;; reasons, we can't put it in 'host-inputs'. Namely, 'cross-gcc' is a | |
97 | ;; native package, so it would end up using a "native" variant of | |
98 | ;; 'cross-libc' (built with 'gnu-build'), whereas all the other packages | |
99 | ;; would use a target variant (built with 'gnu-cross-build'.) | |
100 | (target-inputs (if target | |
101 | (standard-cross-packages target 'target) | |
102 | '())) | |
103 | (outputs outputs) | |
104 | (build (if target qt-cross-build qt-build)) | |
105 | (arguments (strip-keyword-arguments private-keywords arguments)))) | |
106 | ||
107 | ||
108 | (define* (qt-build store name inputs | |
c19260ea HG |
109 | #:key (guile #f) |
110 | (outputs '("out")) (configure-flags ''()) | |
111 | (search-paths '()) | |
112 | (make-flags ''()) | |
113 | (out-of-source? #t) | |
114 | (build-type "RelWithDebInfo") | |
115 | (tests? #t) | |
116 | (test-target "test") | |
117 | (parallel-build? #t) (parallel-tests? #f) | |
118 | (validate-runpath? #t) | |
119 | (patch-shebangs? #t) | |
120 | (strip-binaries? #t) | |
121 | (strip-flags ''("--strip-debug")) | |
122 | (strip-directories ''("lib" "lib64" "libexec" | |
123 | "bin" "sbin")) | |
124 | (phases '(@ (guix build qt-build-system) | |
125 | %standard-phases)) | |
126 | (qt-wrap-excluded-outputs ''()) | |
127 | (system (%current-system)) | |
128 | (imported-modules %qt-build-system-modules) | |
129 | (modules '((guix build qt-build-system) | |
130 | (guix build utils)))) | |
b6d852ce HG |
131 | "Build SOURCE using CMAKE, and with INPUTS. This assumes that SOURCE |
132 | provides a 'CMakeLists.txt' file as its build system." | |
133 | (define builder | |
134 | `(begin | |
135 | (use-modules ,@modules) | |
fce8ec9e | 136 | (qt-build #:source ,(match (assoc-ref inputs "source") |
c19260ea HG |
137 | (((? derivation? source)) |
138 | (derivation->output-path source)) | |
139 | ((source) | |
140 | source) | |
141 | (source | |
142 | source)) | |
143 | #:system ,system | |
144 | #:outputs %outputs | |
145 | #:inputs %build-inputs | |
146 | #:search-paths ',(map search-path-specification->sexp | |
147 | search-paths) | |
148 | #:phases ,phases | |
149 | #:qt-wrap-excluded-outputs ,qt-wrap-excluded-outputs | |
150 | #:configure-flags ,configure-flags | |
151 | #:make-flags ,make-flags | |
152 | #:out-of-source? ,out-of-source? | |
153 | #:build-type ,build-type | |
154 | #:tests? ,tests? | |
155 | #:test-target ,test-target | |
156 | #:parallel-build? ,parallel-build? | |
157 | #:parallel-tests? ,parallel-tests? | |
158 | #:validate-runpath? ,validate-runpath? | |
159 | #:patch-shebangs? ,patch-shebangs? | |
160 | #:strip-binaries? ,strip-binaries? | |
161 | #:strip-flags ,strip-flags | |
162 | #:strip-directories ,strip-directories))) | |
b6d852ce HG |
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 | |
178 | #:guile-for-build guile-for-build)) | |
179 | ||
180 | \f | |
181 | ;;; | |
182 | ;;; Cross-compilation. | |
183 | ;;; | |
184 | ||
185 | (define* (qt-cross-build store name | |
c19260ea HG |
186 | #:key |
187 | target native-drvs target-drvs | |
188 | (guile #f) | |
189 | (outputs '("out")) | |
190 | (configure-flags ''()) | |
191 | (search-paths '()) | |
192 | (native-search-paths '()) | |
193 | (make-flags ''()) | |
194 | (out-of-source? #t) | |
195 | (build-type "RelWithDebInfo") | |
196 | (tests? #f) ; nothing can be done | |
197 | (test-target "test") | |
198 | (parallel-build? #t) (parallel-tests? #f) | |
199 | (validate-runpath? #t) | |
200 | (patch-shebangs? #t) | |
201 | (strip-binaries? #t) | |
202 | (strip-flags ''("--strip-debug" | |
203 | "--enable-deterministic-archives")) | |
204 | (strip-directories ''("lib" "lib64" "libexec" | |
205 | "bin" "sbin")) | |
206 | (phases '(@ (guix build qt-build-system) | |
b6d852ce | 207 | %standard-phases)) |
c19260ea HG |
208 | (system (%current-system)) |
209 | (build (nix-system->gnu-triplet system)) | |
210 | (imported-modules %qt-build-system-modules) | |
211 | (modules '((guix build qt-build-system) | |
212 | (guix build utils)))) | |
b6d852ce HG |
213 | "Cross-build NAME using CMAKE for TARGET, where TARGET is a GNU triplet and |
214 | with INPUTS. This assumes that SOURCE provides a 'CMakeLists.txt' file as its | |
215 | build system." | |
216 | (define builder | |
217 | `(begin | |
218 | (use-modules ,@modules) | |
219 | (let () | |
220 | (define %build-host-inputs | |
221 | ',(map (match-lambda | |
222 | ((name (? derivation? drv) sub ...) | |
223 | `(,name . ,(apply derivation->output-path drv sub))) | |
224 | ((name path) | |
225 | `(,name . ,path))) | |
226 | native-drvs)) | |
227 | ||
228 | (define %build-target-inputs | |
229 | ',(map (match-lambda | |
230 | ((name (? derivation? drv) sub ...) | |
231 | `(,name . ,(apply derivation->output-path drv sub))) | |
232 | ((name (? package? pkg) sub ...) | |
233 | (let ((drv (package-cross-derivation store pkg | |
234 | target system))) | |
235 | `(,name . ,(apply derivation->output-path drv sub)))) | |
236 | ((name path) | |
237 | `(,name . ,path))) | |
238 | target-drvs)) | |
239 | ||
fce8ec9e | 240 | (qt-build #:source ,(match (assoc-ref native-drvs "source") |
c19260ea HG |
241 | (((? derivation? source)) |
242 | (derivation->output-path source)) | |
243 | ((source) | |
244 | source) | |
245 | (source | |
246 | source)) | |
247 | #:system ,system | |
248 | #:build ,build | |
249 | #:target ,target | |
250 | #:outputs %outputs | |
251 | #:inputs %build-target-inputs | |
252 | #:native-inputs %build-host-inputs | |
253 | #:search-paths ',(map search-path-specification->sexp | |
254 | search-paths) | |
255 | #:native-search-paths ',(map | |
256 | search-path-specification->sexp | |
257 | native-search-paths) | |
258 | #:phases ,phases | |
259 | #:configure-flags ,configure-flags | |
260 | #:make-flags ,make-flags | |
261 | #:out-of-source? ,out-of-source? | |
262 | #:build-type ,build-type | |
263 | #:tests? ,tests? | |
264 | #:test-target ,test-target | |
265 | #:parallel-build? ,parallel-build? | |
266 | #:parallel-tests? ,parallel-tests? | |
267 | #:validate-runpath? ,validate-runpath? | |
268 | #:patch-shebangs? ,patch-shebangs? | |
269 | #:strip-binaries? ,strip-binaries? | |
270 | #:strip-flags ,strip-flags | |
271 | #:strip-directories ,strip-directories)))) | |
b6d852ce HG |
272 | |
273 | (define guile-for-build | |
274 | (match guile | |
275 | ((? package?) | |
276 | (package-derivation store guile system #:graft? #f)) | |
277 | (#f ; the default | |
278 | (let* ((distro (resolve-interface '(gnu packages commencement))) | |
279 | (guile (module-ref distro 'guile-final))) | |
280 | (package-derivation store guile system #:graft? #f))))) | |
281 | ||
282 | (build-expression->derivation store name builder | |
283 | #:system system | |
284 | #:inputs (append native-drvs target-drvs) | |
285 | #:outputs outputs | |
286 | #:modules imported-modules | |
287 | #:guile-for-build guile-for-build)) | |
288 | ||
289 | (define qt-build-system | |
290 | (build-system | |
291 | (name 'qt) | |
292 | (description | |
293 | "The CMake build system augmented with definition of suitable environment | |
294 | variables for Qt and KDE in program wrappers.") | |
295 | (lower lower))) |