gnu-bootstrap.scm 5.0 KB

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