Merge branch 'master' into core-updates
[jackhill/guix/guix.git] / guix / build / perl-build-system.scm
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2013, 2015, 2018 Ludovic Courtès <ludo@gnu.org>
3 ;;; Copyright © 2018 Mark H Weaver <mhw@netris.org>
4 ;;;
5 ;;; This file is part of GNU Guix.
6 ;;;
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.
11 ;;;
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.
16 ;;;
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/>.
19
20 (define-module (guix build perl-build-system)
21 #:use-module ((guix build gnu-build-system) #:prefix gnu:)
22 #:use-module (guix build utils)
23 #:use-module (ice-9 match)
24 #:export (%standard-phases
25 perl-build))
26
27 ;; Commentary:
28 ;;
29 ;; Builder-side code of the standard Perl package build procedure.
30 ;;
31 ;; Code:
32
33 (define* (configure #:key outputs make-maker?
34 (make-maker-flags '()) (module-build-flags '())
35 #:allow-other-keys)
36 "Configure the given Perl package."
37 (let* ((out (assoc-ref outputs "out"))
38 (args (cond
39 ;; Prefer to use Module::Build unless otherwise told
40 ((and (file-exists? "Build.PL")
41 (not make-maker?))
42 `("Build.PL" ,(string-append "--prefix=" out)
43 "--installdirs=site" ,@module-build-flags))
44 ((file-exists? "Makefile.PL")
45 `("Makefile.PL" ,(string-append "PREFIX=" out)
46 ;; Prevent installation of 'perllocal.pod' files for
47 ;; determinism. These are typically used to build a
48 ;; catalogue of installed packages, but does not provide
49 ;; any useful information when installed with a module.
50 "INSTALLDIRS=site" "NO_PERLLOCAL=1" ,@make-maker-flags))
51 (else (error "no Build.PL or Makefile.PL found")))))
52 (format #t "running `perl' with arguments ~s~%" args)
53 (apply invoke "perl" args)))
54
55 (define-syntax-rule (define-w/gnu-fallback* (name args ...) body ...)
56 (define* (name args ... #:rest rest)
57 (if (access? "Build" X_OK)
58 (begin body ...)
59 (apply (assoc-ref gnu:%standard-phases 'name) rest))))
60
61 (define-w/gnu-fallback* (build)
62 (invoke "./Build"))
63
64 (define-w/gnu-fallback* (check #:key target
65 (tests? (not target)) (test-flags '())
66 #:allow-other-keys)
67 (if tests?
68 (apply invoke "./Build" "test" test-flags)
69 (format #t "test suite not run~%"))
70 #t)
71
72 (define-w/gnu-fallback* (install)
73 (invoke "./Build" "install"))
74
75 (define %standard-phases
76 ;; Everything is as with the GNU Build System except for the `configure',
77 ;; `build', `check', and `install' phases.
78 (modify-phases gnu:%standard-phases
79 (delete 'bootstrap)
80 (replace 'install install)
81 (replace 'check check)
82 (replace 'build build)
83 (replace 'configure configure)))
84
85 (define* (perl-build #:key inputs (phases %standard-phases)
86 #:allow-other-keys #:rest args)
87 "Build the given Perl package, applying all of PHASES in order."
88 (apply gnu:gnu-build
89 #:inputs inputs #:phases phases
90 args))
91
92 ;;; perl-build-system.scm ends here