guix: Add the 'qt' build system.
[jackhill/guix/guix.git] / guix / build / qt-build-system.scm
CommitLineData
b6d852ce
HG
1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2014 Federico Beffa <beffa@fbengineering.ch>
3;;; Copyright © 2014, 2015 Ludovic Courtès <ludo@gnu.org>
4;;; Copyright © 2018 Mark H Weaver <mhw@netris.org>
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 qt-build-system)
23 #:use-module ((guix build cmake-build-system) #:prefix cmake:)
24 #:use-module (guix build utils)
25 #:use-module (ice-9 match)
26 #:use-module (ice-9 regex)
27 #:use-module (ice-9 ftw)
28 #:use-module (srfi srfi-1)
29 #:use-module (srfi srfi-26)
30 #:export (%standard-phases
31 qt-build))
32
33;; Commentary:
34;;
35;; Builder-side code of the standard Qt build procedure.
36;;
37;; Code:
38
39(define (variables-for-wrapping base-directories)
40
41 (define (collect-sub-dirs base-directories subdirectory)
42 (filter-map
43 (lambda (dir)
44 (let ((directory (string-append dir subdirectory)))
45 (if (directory-exists? directory) directory #f)))
46 base-directories))
47
48 (filter
49 (lambda (var-to-wrap) (not (null? (last var-to-wrap))))
50 (map
51 (lambda (var-spec)
52 `(,(first var-spec) = ,(collect-sub-dirs base-directories (last var-spec))))
53 (list
54 ;; these shall match the search-path-specification for Qt and KDE
55 ;; libraries
56 '("XDG_DATA_DIRS" "/share")
57 '("XDG_CONFIG_DIRS" "/etc/xdg")
58 '("QT_PLUGIN_PATH" "/lib/qt5/plugins")
59 '("QML2_IMPORT_PATH" "/lib/qt5/qml")))))
60
61(define* (wrap-all-programs #:key inputs outputs
62 (qt-wrap-excluded-outputs '())
63 #:allow-other-keys)
64 "Implement phase \"qt-wrap\": look for GSettings schemas and
65gtk+-v.0 libraries and create wrappers with suitably set environment variables
66if found.
67
68Wrapping is not applied to outputs whose name is listed in
69QT-WRAP-EXCLUDED-OUTPUTS. This is useful when an output is known not
70to contain any Qt binaries, and where wrapping would gratuitously
71add a dependency of that output on Qt."
72 (define (find-files-to-wrap directory)
73 (append-map
74 (lambda (dir)
75 (if (directory-exists? dir) (find-files dir ".*") (list)))
76 (list (string-append directory "/bin")
77 (string-append directory "/sbin")
78 (string-append directory "/libexec")
79 (string-append directory "/lib/libexec"))))
80
81 (define input-directories
82 ;; FIXME: Filter out unwanted inputs, e.g. cmake
83 (match inputs
84 (((_ . dir) ...)
85 dir)))
86
87 (define handle-output
88 (match-lambda
89 ((output . directory)
90 (unless (member output qt-wrap-excluded-outputs)
91 (let ((bin-list (find-files-to-wrap directory))
92 (vars-to-wrap (variables-for-wrapping
93 (append (list output)
94 input-directories))))
95 (when (not (null? vars-to-wrap))
96 (for-each (cut apply wrap-program <> vars-to-wrap)
97 bin-list)))))))
98
99 (for-each handle-output outputs)
100 #t)
101
102(define %standard-phases
103 (modify-phases cmake:%standard-phases
104 (add-after 'install 'qt-wrap wrap-all-programs)))
105
106(define* (qt-build #:key inputs (phases %standard-phases)
107 #:allow-other-keys #:rest args)
108 "Build the given package, applying all of PHASES in order."
109 (apply cmake:cmake-build #:inputs inputs #:phases phases args))