gnu: jsoncpp: Update to 1.9.0.
[guix.git] / guix / build / ocaml-build-system.scm
blob99111ad300df287cfc2b5bce6672a77f7eb9c72f
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2016, 2017 Julien Lepiller <julien@lepiller.eu>
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/>.
19 (define-module (guix build ocaml-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             ocaml-build))
26 ;; Commentary:
28 ;; Builder-side code of the standard ocaml build procedure.
30 ;; Code:
32 (define* (ocaml-findlib-environment #:key outputs #:allow-other-keys)
33   (let* ((out (assoc-ref outputs "out")))
34     (setenv "OCAMLFIND_DESTDIR" (string-append out "/lib/ocaml/site-lib"))
35     (setenv "OCAMLFIND_LDCONF" "ignore"))
36   #t)
38 (define* (configure #:key outputs (configure-flags '())
39                     (test-flags '("--enable-tests")) tests?
40                     #:allow-other-keys)
41   "Configure the given package."
42   (let* ((out        (assoc-ref outputs "out")))
43     (format #t "build directory: ~s~%" (getcwd))
44     (if (file-exists? "setup.ml")
45       (let ((args `("-configure"
46                     "--prefix" ,out
47                     ,@(if tests?
48                           test-flags
49                           '())
50                     ,@configure-flags)))
51         (format #t "running 'setup.ml' with arguments ~s~%" args)
52         (apply invoke "ocaml" "setup.ml" args))
53        (let ((args `("-prefix" ,out ,@configure-flags)))
54         (format #t "running 'configure' with arguments ~s~%" args)
55         (apply invoke "./configure" args))))
56     #t)
58 (define* (build #:key inputs outputs (build-flags '()) (make-flags '())
59                 (use-make? #f) #:allow-other-keys)
60   "Build the given package."
61   (if (and (file-exists? "setup.ml") (not use-make?))
62     (apply invoke "ocaml" "setup.ml" "-build" build-flags)
63     (if (file-exists? "Makefile")
64       (apply invoke "make" make-flags)
65       (let ((file (if (file-exists? "pkg/pkg.ml") "pkg/pkg.ml" "pkg/build.ml")))
66         (apply invoke "ocaml" "-I"
67                       (string-append (assoc-ref inputs "findlib")
68                                      "/lib/ocaml/site-lib")
69                       file build-flags))))
70   #t)
72 (define* (check #:key inputs outputs (make-flags '()) (test-target "test") tests?
73                   (use-make? #f) #:allow-other-keys)
74   "Install the given package."
75   (when tests?
76     (if (and (file-exists? "setup.ml") (not use-make?))
77       (invoke "ocaml" "setup.ml" (string-append "-" test-target))
78       (if (file-exists? "Makefile")
79         (apply invoke "make" test-target make-flags)
80         (let ((file (if (file-exists? "pkg/pkg.ml") "pkg/pkg.ml" "pkg/build.ml")))
81           (invoke "ocaml" "-I"
82                   (string-append (assoc-ref inputs "findlib")
83                                  "/lib/ocaml/site-lib")
84                   file test-target)))))
85   #t)
87 (define* (install #:key outputs (build-flags '()) (make-flags '()) (use-make? #f)
88                   (install-target "install")
89                   #:allow-other-keys)
90   "Install the given package."
91   (let ((out (assoc-ref outputs "out")))
92     (if (and (file-exists? "setup.ml") (not use-make?))
93       (apply invoke "ocaml" "setup.ml"
94              (string-append "-" install-target) build-flags)
95       (if (file-exists? "Makefile")
96         (apply invoke "make" install-target make-flags)
97         (invoke "opam-installer" "-i" (string-append "--prefix=" out)
98                 (string-append "--libdir=" out "/lib/ocaml/site-lib")))))
99   #t)
101 (define* (prepare-install #:key outputs #:allow-other-keys)
102   "Prepare for building the given package."
103   (mkdir-p (string-append (assoc-ref outputs "out") "/lib/ocaml/site-lib"))
104   (mkdir-p (string-append (assoc-ref outputs "out") "/bin"))
105   #t)
107 (define %standard-phases
108   ;; Everything is as with the GNU Build System except for the `configure'
109   ;; , `build', `check' and `install' phases.
110   (modify-phases gnu:%standard-phases
111     (delete 'bootstrap)
112     (add-before 'configure 'ocaml-findlib-environment
113                 ocaml-findlib-environment)
114     (add-before 'install 'prepare-install prepare-install)
115     (replace 'configure configure)
116     (replace 'build build)
117     (replace 'check check)
118     (replace 'install install)))
120 (define* (ocaml-build #:key inputs (phases %standard-phases)
121                       #:allow-other-keys #:rest args)
122   "Build the given package, applying all of PHASES in order."
123   (apply gnu:gnu-build #:inputs inputs #:phases phases args))
125 ;;; ocaml-build-system.scm ends here