diff options
author | Julien Lepiller <julien@lepiller.eu> | 2021-02-27 00:07:30 +0100 |
---|---|---|
committer | Julien Lepiller <julien@lepiller.eu> | 2021-03-03 17:04:16 +0100 |
commit | 0bd58ae7ff0d5c3935b0d660819aca4a0493ef8a (patch) | |
tree | 25a1ddaac71282a7f82a7a045e76e56e3cecfe0d /gnu/packages/ocaml.scm | |
parent | 63df962225a92a4a51dbc31b6e41bc15fe0962b9 (diff) | |
download | guix-0bd58ae7ff0d5c3935b0d660819aca4a0493ef8a.tar.gz |
gnu: ocaml-4.07: Bootstrap.
* gnu/packages/ocaml.scm (ocaml-4.07): Implement bootstrap via camlboot.
Diffstat (limited to 'gnu/packages/ocaml.scm')
-rw-r--r-- | gnu/packages/ocaml.scm | 153 |
1 files changed, 150 insertions, 3 deletions
diff --git a/gnu/packages/ocaml.scm b/gnu/packages/ocaml.scm index 604812261d..3eb14c77f6 100644 --- a/gnu/packages/ocaml.scm +++ b/gnu/packages/ocaml.scm @@ -254,7 +254,11 @@ functional, imperative and object-oriented styles of programming.") (base32 "1v3z5ar326f3hzvpfljg4xj8b9lmbrl53fn57yih1bkbx3gr3yzj")))))) -(define-public ocaml-4.07 +;; This package is a bootstrap package for ocaml-4.07. It builds from camlboot, +;; using the upstream sources for ocaml 4.07. It installs a bytecode ocamllex +;; and ocamlc, the bytecode interpreter ocamlrun, and generated .depend files +;; that we otherwise remove for bootstrap purposes. +(define ocaml-4.07-boot (package (inherit ocaml-4.09) (version "4.07.1") @@ -266,11 +270,150 @@ functional, imperative and object-oriented styles of programming.") "/ocaml-" version ".tar.xz")) (sha256 (base32 - "1f07hgj5k45cylj1q3k5mk8yi02cwzx849b1fwnwia8xlcfqpr6z")))) + "1f07hgj5k45cylj1q3k5mk8yi02cwzx849b1fwnwia8xlcfqpr6z")) + (modules '((guix build utils))) + (snippet + `(begin + ;; Remove bootstrap binaries and pre-generated source files, + ;; to ensure we actually bootstrap properly. + (for-each delete-file (find-files "." "^.depend$")) + (delete-file "boot/ocamlc") + (delete-file "boot/ocamllex"))))) + (arguments + `(#:tests? #f + #:phases + (modify-phases %standard-phases + (add-before 'configure 'copy-bootstrap + (lambda* (#:key inputs #:allow-other-keys) + (let ((camlboot (assoc-ref inputs "camlboot"))) + (copy-file (string-append camlboot "/bin/ocamllex") "boot/ocamllex") + (copy-file (string-append camlboot "/bin/ocamlc") "boot/ocamlc") + (chmod "boot/ocamllex" #o755) + (chmod "boot/ocamlc" #o755)))) + (replace 'configure + (lambda* (#:key outputs #:allow-other-keys) + (let* ((out (assoc-ref outputs "out")) + (mandir (string-append out "/share/man"))) + (invoke "./configure" + "--prefix" out + "--mandir" mandir)))) + (replace 'build + (lambda* (#:key parallel-build? #:allow-other-keys) + (define* (make . args) + (apply invoke "make" + (append (if parallel-build? + `("-j" ,(number->string (parallel-job-count))) + '()) + args))) + ;; create empty .depend files because they are included by various + ;; Makefiles, and they have no rule to generate them. + (invoke "touch" ".depend" "stdlib/.depend" "byterun/.depend" + "tools/.depend" "lex/.depend" "asmrun/.depend" + "debugger/.depend" "ocamltest/.depend" "ocamldoc/.depend" + "ocamldoc/stdlib_non_prefixed/.depend" + "otherlibs/bigarray/.depend" "otherlibs/graph/.depend" + "otherlibs/raw_spacetime_lib/.depend" "otherlibs/str/.depend" + "otherlibs/systhreads/.depend" "otherlibs/threads/.depend" + "otherlibs/unix/.depend" "otherlibs/win32unix/.depend") + ;; We cannot build ocamldep until we have created all the .depend + ;; files, so replace it with ocamlc -depend. + (substitute* "tools/Makefile" + (("\\$\\(CAMLRUN\\) ./ocamldep") "../boot/ocamlc -depend")) + (substitute* '("otherlibs/graph/Makefile" + "otherlibs/systhreads/Makefile" + "otherlibs/threads/Makefile" + "otherlibs/unix/Makefile") + (("\\$\\(CAMLRUN\\) ../../tools/ocamldep") + "../../boot/ocamlc -depend")) + (substitute* '("otherlibs/bigarray/Makefile" + "otherlibs/raw_spacetime_lib/Makefile" + "otherlibs/str/Makefile" + "otherlibs/win32unix/Makefile") + (("\\$\\(CAMLRUN\\) \\$\\(ROOTDIR\\)/tools/ocamldep") + "../../boot/ocamlc -depend")) + ;; Ensure we copy needed file, so we can generate a proper .depend + (substitute* "ocamldoc/Makefile" + (("include Makefile.unprefix") + "include Makefile.unprefix +depend: $(STDLIB_MLIS) $(STDLIB_DEPS)")) + ;; Generate required tools for `alldepend' + (make "-C" "byterun" "depend") + (make "-C" "byterun" "all") + (copy-file "byterun/ocamlrun" "boot/ocamlrun") + (make "ocamlyacc") + (copy-file "yacc/ocamlyacc" "boot/ocamlyacc") + (make "-C" "stdlib" "sys.ml") + (make "-C" "stdlib" "CAMLDEP=../boot/ocamlc -depend" "depend") + ;; Build and copy files later used by `tools' + (make "-C" "stdlib" "COMPILER=" + "CAMLC=../boot/ocamlc -use-prims ../byterun/primitives" + "all") + (for-each + (lambda (file) + (copy-file file (string-append "boot/" (basename file)))) + (cons* "stdlib/stdlib.cma" "stdlib/std_exit.cmo" "stdlib/camlheader" + (find-files "stdlib" ".*.cmi$"))) + (symlink "../byterun/libcamlrun.a" "boot/libcamlrun.a") + ;; required for ocamldoc/stdlib_non_prefixed + (make "parsing/parser.mli") + ;; required for dependencies + (make "-C" "tools" + "CAMLC=../boot/ocamlc -nostdlib -I ../boot -use-prims ../byterun/primitives -I .." + "make_opcodes" "cvt_emit") + ;; generate all remaining .depend files + (make "alldepend" + (string-append "ocamllex=" (getcwd) "/boot/ocamlrun " + (getcwd) "/boot/ocamllex") + (string-append "CAMLDEP=" (getcwd) "/boot/ocamlc -depend") + (string-append "OCAMLDEP=" (getcwd) "/boot/ocamlc -depend") + (string-append "ocamldep=" (getcwd) "/boot/ocamlc -depend")) + ;; Build ocamllex + (make "CAMLC=boot/ocamlc -nostdlib -I boot -use-prims byterun/primitives" + "ocamlc") + ;; Build ocamlc + (make "-C" "lex" + "CAMLC=../boot/ocamlc -strict-sequence -nostdlib -I ../boot -use-prims ../byterun/primitives" + "all"))) + (replace 'install + (lambda* (#:key outputs #:allow-other-keys) + (let* ((out (assoc-ref outputs "out")) + (bin (string-append out "/bin")) + (depends (string-append out "/share/depends"))) + (mkdir-p bin) + (mkdir-p depends) + (install-file "ocamlc" bin) + (install-file "lex/ocamllex" bin) + (for-each + (lambda (file) + (let ((dir (string-append depends "/" (dirname file)))) + (mkdir-p dir) + (install-file file dir))) + (find-files "." "^\\.depend$")))))))) + (native-inputs + `(("camlboot" ,camlboot) + ("perl" ,perl) + ("pkg-config" ,pkg-config))))) + +(define-public ocaml-4.07 + (package + (inherit ocaml-4.07-boot) (arguments (substitute-keyword-arguments (package-arguments ocaml-4.09) ((#:phases phases) `(modify-phases ,phases + (add-before 'configure 'copy-bootstrap + (lambda* (#:key inputs #:allow-other-keys) + (let ((ocaml (assoc-ref inputs "ocaml"))) + (copy-file (string-append ocaml "/bin/ocamllex") "boot/ocamllex") + (copy-file (string-append ocaml "/bin/ocamlc") "boot/ocamlc") + (chmod "boot/ocamllex" #o755) + (chmod "boot/ocamlc" #o755) + (let ((rootdir (getcwd))) + (with-directory-excursion (string-append ocaml "/share/depends") + (for-each + (lambda (file) + (copy-file file (string-append rootdir "/" file))) + (find-files "." "."))))))) (replace 'configure (lambda* (#:key outputs #:allow-other-keys) (let* ((out (assoc-ref outputs "out")) @@ -279,7 +422,11 @@ functional, imperative and object-oriented styles of programming.") ;; --prefix=<PREFIX> syntax (with equals sign). (invoke "./configure" "--prefix" out - "--mandir" mandir)))))))))) + "--mandir" mandir)))))))) + (native-inputs + `(("ocaml" ,ocaml-4.07-boot) + ("perl" ,perl) + ("pkg-config" ,pkg-config))))) (define-public ocaml ocaml-4.11) |