diff mbox series

[bug#53609,2/2] gnu: Add ghc-4.

Message ID 20220128174852.10637-2-rekado@elephly.net
State Accepted
Headers show
Series [bug#53609,1/2] gnu: Add perl-5.14. | expand

Checks

Context Check Description
cbaines/comparison success View comparision
cbaines/git branch success View Git branch
cbaines/applying patch success View Laminar job
cbaines/issue success View issue

Commit Message

Ricardo Wurmus Jan. 28, 2022, 5:48 p.m. UTC
* gnu/packages/commencement.scm (ghc-4): New variable.
---
 gnu/packages/commencement.scm | 131 ++++++++++++++++++++++++++++++++++
 1 file changed, 131 insertions(+)

Comments

Ricardo Wurmus Jan. 29, 2022, 6:56 p.m. UTC | #1
There had to be a catch, and sure enough: there is one.  This ghc-4
package doesn’t include everything it should.  The good news is that the
RTS of GHC is included.  The bad news is that the standard library
doesn’t exist.

This old build system is a bit too optimistic and will ignore any build
failure.  There are two failures:

--8<---------------cut here---------------start------------->8---
make[3]: *** No rule to make target 'Array.o', needed by 'libHSstd.a'. Stop.
[…]
make[2]: *** No rule to make target 'utils/Argv.o', needed by 'hsc'.  Stop.
--8<---------------cut here---------------end--------------->8---

“Stop.” here is not to be taken literally, it seems.  The build
continues but libHSstd.a doesn’t make it to the finish line.  Array.o
would presumably be built from Haskell code.

This means that the vision I had during a fever dream is still worth
following: combine the GHC RTS with the Hugs interpreter to interpret
the Haskell code of GHC 4 to use it to compile the Haskell code of GHC 4.
diff mbox series

Patch

diff --git a/gnu/packages/commencement.scm b/gnu/packages/commencement.scm
index 96d914344d..03f1ea276c 100644
--- a/gnu/packages/commencement.scm
+++ b/gnu/packages/commencement.scm
@@ -30,6 +30,7 @@ 
 
 (define-module (gnu packages commencement)
   #:use-module (gnu packages)
+  #:use-module (gnu packages autotools)
   #:use-module (gnu packages bootstrap)
   #:use-module (gnu packages base)
   #:use-module (gnu packages bash)
@@ -3902,5 +3903,135 @@  (define-public gfortran-toolchain
 gfortran, as well as libc (headers and binaries, plus debugging symbols
 in the @code{debug} output), and binutils.")))
 
+(define-public ghc-4
+  (package
+    (name "ghc")
+    (version "4.08.2")
+    (source
+     (origin
+       (method url-fetch)
+       (uri (string-append "https://www.haskell.org/ghc/dist/"
+                           version "/" name "-" version "-src.tar.bz2"))
+       (sha256
+        (base32
+         "0ar4nxy4cr5vwvfj71gmc174vx0n3lg9ka05sa1k60c8z0g3xp1q"))))
+    (build-system gnu-build-system)
+    (supported-systems '("i686-linux" "x86_64-linux"))
+    (arguments
+     `(#:system "i686-linux"
+       #:implicit-inputs? #f
+       #:strip-binaries? #f
+       #:phases
+       (modify-phases %standard-phases
+         (replace 'bootstrap
+           (lambda* (#:key inputs #:allow-other-keys)
+             (delete-file "configure")
+             (delete-file "config.sub")
+             (install-file (string-append (assoc-ref inputs "automake")
+                                          "/share/automake-1.16/config.sub")
+                           ".")
+             (let ((bash (which "bash")))
+               (substitute* '("configure.in"
+                              "ghc/configure.in"
+                              "ghc/rts/gmp/mpn/configure.in"
+                              "ghc/rts/gmp/mpz/configure.in"
+                              "ghc/rts/gmp/configure.in"
+                              "distrib/configure-bin.in")
+                 (("`/bin/sh") (string-append "`" bash))
+                 (("SHELL=/bin/sh") (string-append "SHELL=" bash))
+                 (("^#! /bin/sh") (string-append "#! " bash)))
+
+               (substitute* '("mk/config.mk.in"
+                              "ghc/rts/gmp/mpz/Makefile.in"
+                              "ghc/rts/gmp/Makefile.in")
+                 (("^SHELL.*=.*/bin/sh") (string-append "SHELL = " bash)))
+               (substitute* "aclocal.m4"
+                 (("SHELL=/bin/sh") (string-append "SHELL=" bash))))
+
+             (invoke "autoreconf" "--verbose" "--force")))
+         (add-before 'configure 'configure-gmp
+           (lambda* (#:key build inputs outputs #:allow-other-keys)
+             (with-directory-excursion "ghc/rts/gmp"
+               (let ((bash (which "bash"))
+                     (out  (assoc-ref outputs "out")))
+                 (setenv "CONFIG_SHELL" bash)
+                 (setenv "SHELL" bash)
+                 (invoke bash "./configure")))))
+         (replace 'configure
+           (lambda* (#:key build inputs outputs #:allow-other-keys)
+             (let ((bash (which "bash"))
+                   (out  (assoc-ref outputs "out")))
+               (setenv "CONFIG_SHELL" bash)
+               (setenv "SHELL" bash)
+               (invoke bash "./configure"
+                       "--enable-hc-boot"
+                       (string-append "--prefix=" out)
+                       (string-append "--build=" build)
+                       (string-append "--host=" build)))))
+         (replace 'build
+           (lambda _
+             ;; mkdirhier doesn't get built, so just use mkdir -p.
+             (substitute* "mk/paths.mk"
+               (("^INSTALL_DIR.*")
+                "INSTALL_DIR = mkdir -p"))
+
+             #;
+             (substitute* "ghc/driver/ghc-asm.prl"
+               (("local\\(\\$\\*\\) = 1;") "")
+               (("endef\\$/") "endef$/s"))
+
+             (invoke "make" "boot")
+             (invoke "make"))))))
+    (native-inputs
+     `(("gcc" ,gcc-mesboot0)
+       ("libc" ,glibc-mesboot0)
+       ("binutils" ,binutils-mesboot0)
+
+       ("autoconf" ,autoconf-2.13)
+       ("automake" ,automake)
+
+       ("make" ,gnu-make-final)
+       ("sed" ,sed-final)
+       ("grep" ,grep-final)
+       ("coreutils" ,coreutils-final)
+       ("bash" ,bash-final)
+       ("ld-wrapper" ,ld-wrapper)
+       ("kernel-headers" ,%bootstrap-linux-libre-headers)
+       ("tar" ,tar)
+       ("bzip2" ,bzip2)
+       ("diffutils" ,diffutils)
+       ("file" ,file)
+       ("findutils" ,findutils)
+       ("gawk" ,gawk)
+
+       ;; TODO: Perl used to allow setting $* to enable multi-line
+       ;; matching.  If we want to use a more recent Perl we need to
+       ;; patch all expressions that require multi-line matching.  Hard
+       ;; to tell.
+       ("perl" ,perl-5.14)))
+    (native-search-paths (list (search-path-specification
+                                (variable "GHC_PACKAGE_PATH")
+                                (files (list
+                                        (string-append "lib/ghc-" version)))
+                                (file-pattern ".*\\.conf\\.d$")
+                                (file-type 'directory))))
+    (home-page "https://www.haskell.org/ghc")
+    (synopsis "The Glasgow Haskell Compiler")
+    (description
+     "The Glasgow Haskell Compiler (GHC) is a state-of-the-art compiler and
+interactive environment for the functional language Haskell.")
+    (license license:bsd-3)))
+    (native-search-paths (list (search-path-specification
+                                (variable "GHC_PACKAGE_PATH")
+                                (files (list
+                                        (string-append "lib/ghc-" version)))
+                                (file-pattern ".*\\.conf\\.d$")
+                                (file-type 'directory))))
+    (home-page "https://www.haskell.org/ghc")
+    (synopsis "The Glasgow Haskell Compiler")
+    (description
+     "The Glasgow Haskell Compiler (GHC) is a state-of-the-art compiler and
+interactive environment for the functional language Haskell.")
+    (license license:bsd-3)))
 
 ;;; commencement.scm ends here