make-bootstrap.scm 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2015, 2017 Manolis Fragkiskos Ragkousis <manolis837@gmail.com>
  3. ;;; Copyright © 2015, 2019 Ludovic Courtès <ludo@gnu.org>
  4. ;;; Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
  5. ;;;
  6. ;;; This file is part of GNU Guix.
  7. ;;;
  8. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  9. ;;; under the terms of the GNU General Public License as published by
  10. ;;; the Free Software Foundation; either version 3 of the License, or (at
  11. ;;; your option) any later version.
  12. ;;;
  13. ;;; GNU Guix is distributed in the hope that it will be useful, but
  14. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. ;;; GNU General Public License for more details.
  17. ;;;
  18. ;;; You should have received a copy of the GNU General Public License
  19. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  20. (define-module (guix build make-bootstrap)
  21. #:use-module (srfi srfi-1)
  22. #:use-module (srfi srfi-11)
  23. #:use-module (srfi srfi-19)
  24. #:use-module (srfi srfi-26)
  25. #:use-module (guix build utils)
  26. #:export (copy-linux-headers
  27. make-stripped-libc))
  28. ;; Commentary:
  29. ;;
  30. ;; This module provides facilities to build the bootstrap binaries.
  31. ;;
  32. ;; Code:
  33. (define (copy-linux-headers output kernel-headers)
  34. "Copy to OUTPUT the subset of KERNEL-HEADERS that is needed when producing a
  35. bootstrap libc."
  36. (let* ((incdir (string-append output "/include")))
  37. (mkdir-p incdir)
  38. ;; Copy some of the Linux-Libre headers that glibc headers
  39. ;; refer to.
  40. (mkdir (string-append incdir "/linux"))
  41. (for-each (lambda (file)
  42. (install-file (pk 'src (string-append kernel-headers "/include/linux/" file))
  43. (pk 'dest (string-append incdir "/linux"))))
  44. '(
  45. "atalk.h" ; for 2.2.5
  46. "errno.h"
  47. "falloc.h"
  48. "if_addr.h" ; for 2.16.0
  49. "if_ether.h" ; for 2.2.5
  50. "if_link.h" ; for 2.16.0
  51. "ioctl.h"
  52. "kernel.h"
  53. "limits.h"
  54. "neighbour.h" ; for 2.16.0
  55. "netlink.h" ; for 2.16.0
  56. "param.h"
  57. "prctl.h" ; for 2.16.0
  58. "posix_types.h"
  59. "rtnetlink.h" ; for 2.16.0
  60. "socket.h"
  61. "stddef.h"
  62. "swab.h" ; for 2.2.5
  63. "sysctl.h"
  64. "sysinfo.h" ; for 2.2.5
  65. "types.h"
  66. "version.h" ; for 2.2.5
  67. ))
  68. (copy-recursively (string-append kernel-headers "/include/asm")
  69. (string-append incdir "/asm"))
  70. (copy-recursively (string-append kernel-headers "/include/asm-generic")
  71. (string-append incdir "/asm-generic"))
  72. (copy-recursively (string-append kernel-headers "/include/linux/byteorder")
  73. (string-append incdir "/linux/byteorder"))
  74. #t))
  75. (define (make-stripped-libc output libc kernel-headers)
  76. "Copy to OUTPUT the subset of LIBC and KERNEL-HEADERS that is needed
  77. when producing a bootstrap libc."
  78. (define (copy-mach-headers output kernel-headers)
  79. (let* ((incdir (string-append output "/include")))
  80. (copy-recursively (string-append libc "/include") incdir)
  81. (copy-recursively (string-append kernel-headers "/include/mach")
  82. (string-append incdir "/mach"))
  83. #t))
  84. (define (copy-libc+linux-headers output kernel-headers)
  85. (let* ((incdir (string-append output "/include")))
  86. (copy-recursively (string-append libc "/include") incdir)
  87. (copy-linux-headers output kernel-headers)))
  88. (define %libc-object-files-rx "^(crt.*|ld.*|lib(c|m|dl|rt|pthread|nsl|\
  89. util).*\\.so(\\..*)?|lib(machuser|hurduser).so.*|(libc(rt|)|libpthread)\
  90. _nonshared\\.a)$")
  91. (setvbuf (current-output-port) 'line)
  92. (let* ((libdir (string-append output "/lib")))
  93. (mkdir-p libdir)
  94. (for-each (lambda (file)
  95. (let ((target (string-append libdir "/"
  96. (basename file))))
  97. (copy-file file target)
  98. (remove-store-references target)))
  99. (find-files (string-append libc "/lib") %libc-object-files-rx))
  100. #t)
  101. (if (directory-exists? (string-append kernel-headers "/include/mach"))
  102. (copy-mach-headers output kernel-headers)
  103. (copy-libc+linux-headers output kernel-headers)))