ocaml-build-system.scm 5.0 KB

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