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 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 perl-build-system)
20 #:use-module ((guix build gnu-build-system) #:prefix gnu:)
21 #:use-module (guix build utils)
22 #:use-module (ice-9 match)
23 #:export (%standard-phases
24 perl-build))
25
26 ;; Commentary:
27 ;;
28 ;; Builder-side code of the standard Perl package build procedure.
29 ;;
30 ;; Code:
31
32 (define* (configure #:key outputs make-maker?
33 (make-maker-flags '()) (module-build-flags '())
34 #:allow-other-keys)
35 "Configure the given Perl package."
36 (let* ((out (assoc-ref outputs "out"))
37 (args (cond
38 ;; Prefer to use Module::Build unless otherwise told
39 ((and (file-exists? "Build.PL")
40 (not make-maker?))
41 `("Build.PL" ,(string-append "--prefix=" out)
42 "--installdirs=site" ,@module-build-flags))
43 ((file-exists? "Makefile.PL")
44 `("Makefile.PL" ,(string-append "PREFIX=" out)
45 ;; Prevent installation of 'perllocal.pod' files for
46 ;; determinism. These are typically used to build a
47 ;; catalogue of installed packages, but does not provide
48 ;; any useful information when installed with a module.
49 "INSTALLDIRS=site" "NO_PERLLOCAL=1" ,@make-maker-flags))
50 (else (error "no Build.PL or Makefile.PL found")))))
51 (format #t "running `perl' with arguments ~s~%" args)
52 (zero? (apply system* "perl" args))))
53
54 (define-syntax-rule (define-w/gnu-fallback* (name args ...) body ...)
55 (define* (name args ... #:rest rest)
56 (if (access? "Build" X_OK)
57 (begin body ...)
58 (apply (assoc-ref gnu:%standard-phases 'name) rest))))
59
60 (define-w/gnu-fallback* (build)
61 (zero? (system* "./Build")))
62
63 (define-w/gnu-fallback* (check #:key target
64 (tests? (not target)) (test-flags '())
65 #:allow-other-keys)
66 (if tests?
67 (zero? (apply system* "./Build" "test" test-flags))
68 (begin
69 (format #t "test suite not run~%")
70 #t)))
71
72 (define-w/gnu-fallback* (install)
73 (zero? (system* "./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 (replace 'install install)
80 (replace 'check check)
81 (replace 'build build)
82 (replace 'configure configure)))
83
84 (define* (perl-build #:key inputs (phases %standard-phases)
85 #:allow-other-keys #:rest args)
86 "Build the given Perl package, applying all of PHASES in order."
87 (apply gnu:gnu-build
88 #:inputs inputs #:phases phases
89 args))
90
91 ;;; perl-build-system.scm ends here