1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2020 Brett Gilio <brettg@gnu.org>
4 ;;; This file is part of GNU Guix.
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.
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.
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 (gnu packages mercury)
20 #:use-module (guix download)
21 #:use-module (guix git-download)
22 #:use-module (guix packages)
23 #:use-module (guix utils)
24 #:use-module ((guix licenses) #:prefix license:)
25 #:use-module (guix build-system gnu)
26 #:use-module (gnu packages autotools)
27 #:use-module (gnu packages bdw-gc)
28 #:use-module (gnu packages readline)
29 #:use-module (gnu packages texinfo)
30 #:use-module (gnu packages flex)
31 #:use-module (gnu packages shells)
32 #:use-module (gnu packages bison)
33 #:use-module (gnu packages pkg-config)
34 #:use-module (ice-9 match)) ; match-lambda
36 ;; NOTE: Mercury uses a tightly coupled fork of BDWGC and
37 ;; libatomic-ops. When updating the package, please check the GitHub
38 ;; repository to ensure that the submodule commit matches what is
40 (define (gc-fork package-name package-url
41 package-commit package-hash)
42 (let ((commit package-commit))
43 (package (inherit package-name)
50 (sha256 (base32 package-hash)))))))
52 ;; NOTE: Mercury /MUST/ bootstrap from a tarball release.
53 ;; Once the bootstrapping compiler is established, this
54 ;; minimal build can be used for further compiling Mercury
55 ;; from a git checkout with additional grades enabled.
56 (define-public mercury-minimal
58 (name "mercury-minimal")
63 "https://dl.mercurylang.org/release/mercury-srcdist-"
67 "1gkr9w8lsdzqykqwd3f1a1phsqv090648i14ilhv8jdg85frdimr"))))
68 (build-system gnu-build-system)
70 `(#:modules ((guix build gnu-build-system)
73 #:tests? #f ; Tests are run on the stage-2 compiler.
74 ;; TODO: Find a way to bypass all static linkages.
75 #:configure-flags (list "--enable-minimal-install")
77 (modify-phases %standard-phases
78 (add-after 'unpack 'replace-boehm-gc
79 (lambda* (#:key inputs outputs #:allow-other-keys)
80 (let ((out (assoc-ref outputs "out"))
81 (libgc (assoc-ref inputs "libgc"))
82 (libatomic-ops (assoc-ref inputs "libatomic-ops"))
83 (unpack (assoc-ref %standard-phases 'unpack))
84 (patch-source-shebangs
85 (assoc-ref %standard-phases 'patch-source-shebangs)))
87 ((src orig-name new-name)
88 (with-directory-excursion "."
89 (apply unpack (list #:source src)))
90 (delete-file-recursively new-name)
91 (invoke "mv" orig-name new-name)
92 (with-directory-excursion new-name
93 (apply patch-source-shebangs (list #:source src)))))
94 `((,libgc "source" "boehm_gc")))
96 ((src orig-name new-name)
97 (with-directory-excursion "."
98 (apply unpack (list #:source src)))
99 (delete-file-recursively new-name)
100 (invoke "mv" orig-name new-name)
101 (with-directory-excursion new-name
102 (apply patch-source-shebangs (list #:source src)))))
103 `((,libatomic-ops "source" "boehm_gc/libatomic_ops")))
105 (add-after 'replace-boehm-gc 'patch-paths
110 "scripts/mercury_update_interface.in"
111 "scripts/mercury_config.in"
113 "scripts/Mmake.vars.in"
115 "scripts/rs6000_hack"
118 "scripts/canonical_grade"
122 "scripts/canonical_grade.in"
125 "scripts/mkfifo_using_mknod.in"
126 "scripts/prepare_install_dir.in"
127 "scripts/mprof_merge_runs"
131 "bindist/bindist.Makefile"
132 "boehm_gc/configure.ac"
133 "boehm_gc/Makefile.direct")
134 (("/bin/sh") (which "sh"))
135 (("/bin/pwd") (which "pwd"))
136 (("/bin/rm") (which "rm")))
139 `(("texinfo" ,texinfo)
143 ("readline" ,readline)
144 ("libatomic-ops" ,(package-source
147 "https://github.com/Mercury-Language/libatomic_ops.git"
148 "49b70d57f6922fd8be55a7dcb77955c8abfc9ae9"
149 "1flvwscsa6b2b8a38vhhcgl10bbkb5nnihw7s7iia60cinf7wcqm")))
150 ("libgc" ,(package-source
153 "https://github.com/Mercury-Language/bdwgc.git"
154 "43ac2ea45261ba0a715534e9da41b2504904c46a"
155 "0bmzmbs7id0ndyhy9xli6fhfad1shrim6vmy2k8m1nqr5wb31q76")))
156 ("pkg-config" ,pkg-config)))
157 (synopsis "Pure logic programming language (used only for
158 bootstrapping dependent Mercury)")
159 (description "Mercury is a logic/functional programming language which
160 combines the clarity and expressiveness of declarative programming with advanced
161 static analysis and error detection features. Its highly optimized execution
162 algorithm delivers efficiency far in excess of existing logic programming
163 systems, and close to conventional programming systems. Mercury addresses
164 the problems of large-scale program development, allowing modularity,
165 separate compilation, and numerous optimization/time trade-offs.")
166 (home-page "https://mercurylang.org")
167 (license license:gpl2)))
169 ;; NOTE: This package is quite large and will take an extensive
170 ;; amount of time to compile, especially with bootcheck functionality
171 ;; enabled. To ensure that we do not monopolize the CI & build servers,
172 ;; please make sure that your changes are justified.
173 (define-public mercury
174 (package (inherit mercury-minimal)
181 (url "https://github.com/Mercury-Language/mercury")
182 (commit (string-append
184 (string-join (string-split version #\.) "_")))))
185 (file-name (git-file-name name version))
188 "1pc51r7vlqmi689rkwdkk1ka2dyk36q11dqvl339cizng6mp72h6"))))
190 (substitute-keyword-arguments
191 (package-arguments mercury-minimal)
192 ;; TODO: Find a way to bypass all static linkages.
193 ((#:configure-flags flags ''())
195 ((#:tests? _) #f) ; FIXME: Many test-cases failing.
197 `(modify-phases ,phases
198 (replace 'patch-paths
204 "scripts/mercury_update_interface.in"
205 "scripts/mercury_config.in"
207 "scripts/Mmake.vars.in"
209 "scripts/rs6000_hack"
215 "scripts/canonical_grade.in"
218 "scripts/mkfifo_using_mknod.in"
219 "scripts/prepare_install_dir.in"
220 "scripts/mprof_merge_runs"
225 "boehm_gc/configure.ac"
226 "boehm_gc/Makefile.direct")
227 (("/bin/sh") (which "sh"))
228 (("/bin/pwd") (which "pwd"))
229 (("/bin/rm") (which "rm"))
230 (("boehm_gc/.git") "boehm_gc"))
234 (invoke "./prepare.sh")
236 ;; TODO: Uncomment phase when tests are enabled.
239 ;; (invoke "./tools/bootcheck")
242 ;; TODO: The mercury configuration system determines
243 ;; grade support by looking for available toolchains.
244 ;; Eventually we need to add inputs for Java, Erlang,
245 ;; C#, etc. in order to enable these extra grades.
247 `(("mercury-minimal" ,mercury-minimal)
248 ("autoconf" ,autoconf)
249 ("automake" ,automake)
250 ,@(package-native-inputs mercury-minimal)))
251 (synopsis "Pure logic programming language")))