Commit | Line | Data |
---|---|---|
9c9407f7 TS |
1 | ;;; GNU Guix --- Functional package management for GNU |
2 | ;;; Copyright © 2020 Timothy Sample <samplet@ngyro.com> | |
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 | ||
19 | ;; Commentary: | |
20 | ;; | |
21 | ;; These procedures can be used to adapt the GNU Build System to build | |
22 | ;; pure Scheme packages targeting the bootstrap Guile. | |
23 | ;; | |
24 | ;; Code: | |
25 | ||
26 | (define-module (guix build gnu-bootstrap) | |
27 | #:use-module (guix build utils) | |
28 | #:use-module (system base compile) | |
29 | #:export (bootstrap-configure | |
30 | bootstrap-build | |
31 | bootstrap-install)) | |
32 | ||
33 | (define (bootstrap-configure version modules scripts) | |
34 | "Create a procedure that configures an early bootstrap package. The | |
35 | procedure will search the MODULES directory and configure all of the | |
36 | '.in' files with VERSION. It will then search the SCRIPTS directory and | |
37 | configure all of the '.in' files with the bootstrap Guile and its module | |
38 | and object directories." | |
39 | (lambda* (#:key inputs outputs #:allow-other-keys) | |
40 | (let* ((out (assoc-ref outputs "out")) | |
41 | (guile-dir (assoc-ref inputs "guile")) | |
42 | (guile (string-append guile-dir "/bin/guile")) | |
43 | (moddir (string-append out "/share/guile/site/" | |
44 | (effective-version))) | |
45 | (godir (string-append out "/lib/guile/" | |
46 | (effective-version) | |
47 | "/site-ccache"))) | |
48 | (for-each (lambda (template) | |
49 | (format #t "Configuring ~a~%" template) | |
50 | (let ((target (string-drop-right template 3))) | |
51 | (copy-file template target) | |
52 | (substitute* target | |
53 | (("@VERSION@") version)))) | |
54 | (find-files modules | |
55 | (lambda (fn st) | |
56 | (string-suffix? ".in" fn)))) | |
57 | (for-each (lambda (template) | |
58 | (format #t "Configuring ~a~%" template) | |
59 | (let ((target (string-drop-right template 3))) | |
60 | (copy-file template target) | |
61 | (substitute* target | |
62 | (("@GUILE@") guile) | |
63 | (("@MODDIR@") moddir) | |
64 | (("@GODIR@") godir)) | |
65 | (chmod target #o755))) | |
66 | (find-files scripts | |
67 | (lambda (fn st) | |
68 | (string-suffix? ".in" fn)))) | |
69 | #t))) | |
70 | ||
71 | (define (bootstrap-build modules) | |
72 | "Create a procedure that builds an early bootstrap package. The | |
73 | procedure will search the MODULES directory and compile all of the | |
74 | '.scm' files." | |
75 | (lambda _ | |
76 | (add-to-load-path (getcwd)) | |
77 | (for-each (lambda (scm) | |
78 | (let* ((base (string-drop-right scm 4)) | |
79 | (go (string-append base ".go")) | |
80 | (dir (dirname scm))) | |
81 | (format #t "Compiling ~a~%" scm) | |
82 | (compile-file scm #:output-file go))) | |
83 | (find-files modules "\\.scm$")) | |
84 | #t)) | |
85 | ||
86 | (define (bootstrap-install modules scripts) | |
87 | "Create a procedure that installs an early bootstrap package. The | |
88 | procedure will install all of the '.scm' and '.go' files in the MODULES | |
89 | directory, and all the executable files in the SCRIPTS directory." | |
90 | (lambda* (#:key inputs outputs #:allow-other-keys) | |
91 | (let* ((out (assoc-ref outputs "out")) | |
92 | (guile-dir (assoc-ref inputs "guile")) | |
93 | (guile (string-append guile-dir "/bin/guile")) | |
94 | (moddir (string-append out "/share/guile/site/" | |
95 | (effective-version))) | |
96 | (godir (string-append out "/lib/guile/" | |
97 | (effective-version) | |
98 | "/site-ccache"))) | |
99 | (for-each (lambda (scm) | |
100 | (let* ((base (string-drop-right scm 4)) | |
101 | (go (string-append base ".go")) | |
102 | (dir (dirname scm))) | |
103 | (format #t "Installing ~a~%" scm) | |
104 | (install-file scm (string-append moddir "/" dir)) | |
105 | (format #t "Installing ~a~%" go) | |
106 | (install-file go (string-append godir "/" dir)))) | |
107 | (find-files modules "\\.scm$")) | |
108 | (for-each (lambda (script) | |
109 | (format #t "Installing ~a~%" script) | |
110 | (install-file script (string-append out "/bin"))) | |
111 | (find-files scripts | |
112 | (lambda (fn st) | |
113 | (executable-file? fn)))) | |
114 | #t))) |