diff options
Diffstat (limited to 'gnu/packages/haskell.scm')
-rw-r--r-- | gnu/packages/haskell.scm | 278 |
1 files changed, 276 insertions, 2 deletions
diff --git a/gnu/packages/haskell.scm b/gnu/packages/haskell.scm index 699b45e45a..effc6eeb1b 100644 --- a/gnu/packages/haskell.scm +++ b/gnu/packages/haskell.scm @@ -5,8 +5,8 @@ ;;; Copyright © 2015, 2019 Eric Bavier <bavier@member.fsf.org> ;;; Copyright © 2016, 2018, 2019, 2021 Ludovic Courtès <ludo@gnu.org> ;;; Copyright © 2016, 2017 Nikita <nikita@n0.is> -;;; Copyright © 2016 Efraim Flashner <efraim@flashner.co.il> -;;; Copyright © 2015, 2016, 2017, 2018, 2019, 2020 Ricardo Wurmus <rekado@elephly.net> +;;; Copyright © 2016, 2022 Efraim Flashner <efraim@flashner.co.il> +;;; Copyright © 2015, 2016, 2017, 2018, 2019, 2020, 2022 Ricardo Wurmus <rekado@elephly.net> ;;; Copyright © 2016, 2017 David Craven <david@craven.ch> ;;; Copyright © 2017 Danny Milosavljevic <dannym@scratchpost.org> ;;; Copyright © 2017 Peter Mikkelsen <petermikkelsen10@gmail.com> @@ -41,10 +41,19 @@ (define-module (gnu packages haskell) #:use-module (gnu packages) + #:use-module (gnu packages autotools) + #:use-module (gnu packages base) + #:use-module (gnu packages bash) + #:use-module (gnu packages bison) #:use-module (gnu packages bootstrap) + #:use-module (gnu packages compression) #:use-module (gnu packages elf) + #:use-module (gnu packages file) + #:use-module (gnu packages gawk) + #:use-module (gnu packages gcc) #:use-module (gnu packages ghostscript) #:use-module (gnu packages libffi) + #:use-module (gnu packages linux) #:use-module (gnu packages lisp) #:use-module (gnu packages multiprecision) #:use-module (gnu packages ncurses) @@ -54,6 +63,7 @@ #:use-module (guix build-system gnu) #:use-module (guix download) #:use-module (guix git-download) + #:use-module (guix gexp) #:use-module ((guix licenses) #:prefix license:) #:use-module (guix packages) #:use-module (guix utils) @@ -99,6 +109,270 @@ top of CLISP.") (license license:bsd-4)))) +;; This package contains lots of generated .hc files containing C code to +;; bootstrap the compiler without a Haskell compiler. The included .hc files +;; cover not just the compiler sources but also all Haskell libraries. +(define-public nhc98 + (package + (name "nhc98") + (version "1.22") + (source + (origin + (method url-fetch) + (uri (string-append "https://www.haskell.org/nhc98/nhc98src-" + version ".tar.gz")) + (sha256 + (base32 + "0fkgxgsd2iqxvwcgnad1702kradwlbcal6rxdrgb22vd6dnc3i8l")) + (patches (search-patches "nhc98-c-update.patch")))) + (build-system gnu-build-system) + (supported-systems '("i686-linux" "x86_64-linux")) + (arguments + (list + #:tests? #false ;there is no test target + #:system "i686-linux" + #:parallel-build? #false ;not supported + #:strip-binaries? #false ;doesn't work + #:make-flags '(list "all-gcc") + #:phases + #~(modify-phases %standard-phases + (replace 'configure + (lambda _ + (setenv "SHELL" (which "sh")) + (setenv "CPATH" (string-append + (getcwd) "/src/runtime/Kernel:" + (or (getenv "C_INCLUDE_PATH") ""))) + (substitute* "configure" + (("echo '#!/bin/sh'") + (string-append "echo '#!" (which "sh") "'"))) + (with-fluids ((%default-port-encoding #f)) + (substitute* '("script/greencard.inst" + "script/harch.inst" + "script/hi.inst" + "script/hmake-config.inst" + ;; TODO: can't fix this with substitute* + ;"script/hmake.inst" + "script/hood.inst" + "script/hsc2hs.inst" + "script/nhc98-pkg.inst" + "script/nhc98.inst") + (("^MACHINE=.*") "MACHINE=ix86-Linux\n"))) + (invoke "sh" "configure" + (string-append "--prefix=" #$output) + ;; Remove -m32 from compiler/linker invocation + "--ccoption=" + "--ldoption="))) + (replace 'install + (lambda _ + (invoke "sh" "configure" + (string-append "--prefix=" #$output) + ;; Remove -m32 from compiler/linker invocation + "--ccoption=" + "--ldoption=" + "--install")))))) + (home-page "https://www.haskell.org/nhc98") + (synopsis "Nearly a Haskell Compiler") + (description + "nhc98 is a small, standards-compliant compiler for Haskell 98, the lazy +functional programming language. It aims to produce small executables that +run in small amounts of memory. It produces medium-fast code, and compilation +is itself quite fast.") + (license + (license:non-copyleft + "https://www.haskell.org/nhc98/copyright.html")))) + +(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")) + (patches (search-patches "ghc-4.patch")))) + (build-system gnu-build-system) + (supported-systems '("i686-linux" "x86_64-linux")) + (arguments + `(#:system "i686-linux" + #: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 (search-input-file inputs + "/bin/config.sub") + ".") + + ;; Avoid dependency on "happy" + (substitute* "configure.in" + (("FPTOOLS_HAPPY") "echo sure\n")) + + ;; Set options suggested in ghc/interpreter/README.BUILDING.HUGS. + (with-output-to-file "mk/build.mk" + (lambda () + (display " +WithGhcHc=ghc-4.06 +GhcLibWays=u +#HsLibsFor=hugs +# Setting this leads to building the interpreter. +GhcHcOpts=-DDEBUG +GhcRtsHcOpts=-optc-DDEBUG -optc-D__HUGS__ -unreg -optc-g -optc-D_GNU_SOURCE=1 +GhcRtsCcOpts=-optc-DDEBUG -optc-g -optc-D__HUGS__ -optc-D_GNU_SOURCE=1 +SplitObjs=NO +"))) + + (substitute* "ghc/interpreter/interface.c" + ;; interface.c:2702: `stackOverflow' redeclared as different kind of symbol + ;; ../includes/Stg.h:188: previous declaration of `stackOverflow' + ((".*Sym\\(stackOverflow\\).*") "") + ;; interface.c:2713: `stg_error_entry' undeclared here (not in a function) + ;; interface.c:2713: initializer element is not constant + ;; interface.c:2713: (near initialization for `rtsTab[11].ad') + ((".*SymX\\(stg_error_entry\\).*") "") + ;; interface.c:2713: `Upd_frame_info' undeclared here (not in a function) + ;; interface.c:2713: initializer element is not constant + ;; interface.c:2713: (near initialization for `rtsTab[32].ad') + ((".*SymX\\(Upd_frame_info\\).*") "")) + + ;; We need to use the absolute file names here or else the linker + ;; will complain about missing symbols. Perhaps this could be + ;; avoided by modifying the library search path in a way that + ;; this old linker understands. + (substitute* "ghc/interpreter/Makefile" + (("-lbfd -liberty") + (string-append (search-input-file inputs "/lib/libbfd.a") " " + (search-input-file inputs "/lib/libiberty.a")))) + + (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))) + + (setenv "CONFIG_SHELL" bash) + (setenv "SHELL" bash)) + + ;; The 'hscpp' script invokes GCC 2.95's 'cpp' (RAWCPP), which + ;; segfaults unless passed '-x c'. + (substitute* "mk/config.mk.in" + (("-traditional") + "-traditional -x c")) + + (setenv "CPP" (which "cpp")) + (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"))) + (invoke bash "./configure"))))) + (replace 'configure + (lambda* (#:key build inputs outputs #:allow-other-keys) + (let ((bash (which "bash")) + (out (assoc-ref outputs "out"))) + (call-with-output-file "config.cache" + (lambda (port) + ;; GCC 2.95 fails to deal with anonymous unions in glibc's + ;; 'struct_rusage.h', so skip that. + (display "ac_cv_func_getrusage=no\n" port))) + + (invoke bash "./configure" + "--enable-hc-boot" + (string-append "--prefix=" out) + (string-append "--build=" build) + (string-append "--host=" build))))) + (add-before 'build 'make-boot + (lambda _ + ;; CLK_TCK has been removed from recent libc. + (substitute* "ghc/interpreter/nHandle.c" + (("CLK_TCK") "sysconf (_SC_CLK_TCK)")) + + ;; Only when building with more recent GCC + (when #false + ;; GCC 2.95 is fine with these comments, but GCC 4.6 is not. + (substitute* "ghc/rts/universal_call_c.S" + (("^# .*") ""))) + + ;; Only when using more recent Perl + (when #false + (substitute* "ghc/driver/ghc-asm.prl" + (("local\\(\\$\\*\\) = 1;") "") + (("endef\\$/") "endef$/s"))) + + (setenv "CPATH" + (string-append (getcwd) "/ghc/includes:" + (getcwd) "/mk:" + (or (getenv "CPATH") ""))) + (invoke "make" "boot"))) + (replace 'build + (lambda _ + ;; TODO: since we don't have a Haskell compiler we cannot build + ;; the standard library. And without the standard library we + ;; cannot build a Haskell compiler. + ;; 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. + (invoke "make" "all"))) + (add-after 'build 'build-hugs + (lambda _ + (invoke "make" "-C" "ghc/interpreter") + (invoke "make" "-C" "ghc/interpreter" "install"))) + (add-after 'install 'install-sources + (lambda* (#:key outputs #:allow-other-keys) + (let ((lib (string-append (assoc-ref outputs "out") "/lib"))) + (copy-recursively "hslibs" + (string-append lib "/hslibs")) + (copy-recursively "ghc/lib" + (string-append lib "/ghc/lib")) + (copy-recursively "ghc/compiler" + (string-append lib "/ghc/compiler")) + (copy-recursively "ghc/interpreter/lib" lib) + (install-file "ghc/interpreter/nHandle.so" lib))))))) + (native-inputs + (list autoconf-2.13 + bison ;for parser.y + config + + ;; Needed to support lvalue casts. + gcc-2.95 + + ;; Use an older assembler to work around this error in GMP: + ;; Error: `%edx' not allowed with `testb' + binutils-2.33 + + ;; 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-5.14)) + (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. The value of +this package lies in the modified build of Hugs that is linked with GHC's STG +runtime system, the RTS. \"STG\" stands for \"spineless, tagless, +G-machine\"; it is the abstract machine designed to support nonstrict +higher-order functional languages. Neither the compiler nor the Haskell +libraries are included in this package.") + (license license:bsd-3))) + (define ghc-bootstrap-x86_64-7.8.4 (origin (method url-fetch) |