gnu-bootstrap.scm 5.2 KB

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