build-system: Introduce "bags" as an intermediate representation.
[jackhill/guix/guix.git] / guix / build-system / perl.scm
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2013, 2014 Ludovic Courtès <ludo@gnu.org>
3 ;;;
4 ;;; This file is part of GNU Guix.
5 ;;;
6 ;;; GNU Guix is free software; you can redistribute it and/or modify it
7 ;;; under the terms of the GNU General Public License as published by
8 ;;; the Free Software Foundation; either version 3 of the License, or (at
9 ;;; your option) any later version.
10 ;;;
11 ;;; GNU Guix is distributed in the hope that it will be useful, but
12 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ;;; GNU General Public License for more details.
15 ;;;
16 ;;; You should have received a copy of the GNU General Public License
17 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
18
19 (define-module (guix build-system perl)
20 #:use-module (guix store)
21 #:use-module (guix utils)
22 #:use-module (guix derivations)
23 #:use-module (guix build-system)
24 #:use-module (guix build-system gnu)
25 #:use-module (guix packages)
26 #:use-module (ice-9 match)
27 #:export (perl-build
28 perl-build-system))
29
30 ;; Commentary:
31 ;;
32 ;; Standard build procedure for Perl packages using the "makefile
33 ;; maker"---i.e., "perl Makefile.PL". This is implemented as an extension of
34 ;; `gnu-build-system'.
35 ;;
36 ;; Code:
37
38 (define (default-perl)
39 "Return the default Perl package."
40
41 ;; Do not use `@' to avoid introducing circular dependencies.
42 (let ((module (resolve-interface '(gnu packages perl))))
43 (module-ref module 'perl)))
44
45 (define* (lower name
46 #:key source inputs native-inputs outputs target
47 (perl (default-perl))
48 #:allow-other-keys
49 #:rest arguments)
50 "Return a bag for NAME."
51 (define private-keywords
52 '(#:source #:target #:perl #:inputs #:native-inputs))
53
54 (and (not target) ;XXX: no cross-compilation
55 (bag
56 (name name)
57 (host-inputs `(,@(if source
58 `(("source" ,source))
59 '())
60 ,@inputs
61
62 ;; Keep the standard inputs of 'gnu-build-system'.
63 ,@(standard-packages)))
64 (build-inputs `(("perl" ,perl)
65 ,@native-inputs))
66 (outputs outputs)
67 (build perl-build)
68 (arguments (strip-keyword-arguments private-keywords arguments)))))
69
70 (define* (perl-build store name inputs
71 #:key
72 (search-paths '())
73 (tests? #t)
74 (parallel-build? #t)
75 (parallel-tests? #t)
76 (make-maker-flags ''())
77 (phases '(@ (guix build perl-build-system)
78 %standard-phases))
79 (outputs '("out"))
80 (system (%current-system))
81 (guile #f)
82 (imported-modules '((guix build perl-build-system)
83 (guix build gnu-build-system)
84 (guix build utils)))
85 (modules '((guix build perl-build-system)
86 (guix build utils))))
87 "Build SOURCE using PERL, and with INPUTS. This assumes that SOURCE
88 provides a `Makefile.PL' file as its build system."
89 (define builder
90 `(begin
91 (use-modules ,@modules)
92 (perl-build #:name ,name
93 #:source ,(match (assoc-ref inputs "source")
94 (((? derivation? source))
95 (derivation->output-path source))
96 ((source)
97 source)
98 (source
99 source))
100 #:search-paths ',(map search-path-specification->sexp
101 search-paths)
102 #:make-maker-flags ,make-maker-flags
103 #:phases ,phases
104 #:system ,system
105 #:test-target "test"
106 #:tests? ,tests?
107 #:parallel-build? ,parallel-build?
108 #:parallel-tests? ,parallel-tests?
109 #:outputs %outputs
110 #:inputs %build-inputs)))
111
112 (define guile-for-build
113 (match guile
114 ((? package?)
115 (package-derivation store guile system))
116 (#f ; the default
117 (let* ((distro (resolve-interface '(gnu packages commencement)))
118 (guile (module-ref distro 'guile-final)))
119 (package-derivation store guile system)))))
120
121 (build-expression->derivation store name builder
122 #:system system
123 #:inputs inputs
124 #:modules imported-modules
125 #:outputs outputs
126 #:guile-for-build guile-for-build))
127
128 (define perl-build-system
129 (build-system
130 (name 'perl)
131 (description "The standard Perl build system")
132 (lower lower)))
133
134 ;;; perl.scm ends here