Merge branch 'master' into core-updates
[jackhill/guix/guix.git] / guix / build / make-bootstrap.scm
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
21 (define-module (guix build make-bootstrap)
22 #:use-module (srfi srfi-1)
23 #:use-module (srfi srfi-11)
24 #:use-module (srfi srfi-19)
25 #:use-module (srfi srfi-26)
26 #:use-module (guix build utils)
27 #:export (copy-linux-headers
28 make-stripped-libc))
29
30 ;; Commentary:
31 ;;
32 ;; This module provides facilities to build the bootstrap binaries.
33 ;;
34 ;; Code:
35
36 (define (copy-linux-headers output kernel-headers)
37 "Copy to OUTPUT the subset of KERNEL-HEADERS that is needed when producing a
38 bootstrap libc."
39
40 (let* ((incdir (string-append output "/include")))
41 (mkdir-p incdir)
42
43 ;; Copy some of the Linux-Libre headers that glibc headers
44 ;; refer to.
45 (mkdir (string-append incdir "/linux"))
46 (for-each (lambda (file)
47 (install-file (pk 'src (string-append kernel-headers "/include/linux/" file))
48 (pk 'dest (string-append incdir "/linux"))))
49 '(
50 "a.out.h" ; for 2.2.5
51 "atalk.h" ; for 2.2.5
52 "errno.h"
53 "falloc.h"
54 "if_addr.h" ; for 2.16.0
55 "if_ether.h" ; for 2.2.5
56 "if_link.h" ; for 2.16.0
57 "ioctl.h"
58 "kernel.h"
59 "limits.h"
60 "neighbour.h" ; for 2.16.0
61 "netlink.h" ; for 2.16.0
62 "param.h"
63 "prctl.h" ; for 2.16.0
64 "posix_types.h"
65 "rtnetlink.h" ; for 2.16.0
66 "socket.h"
67 "stddef.h"
68 "swab.h" ; for 2.2.5
69 "sysctl.h"
70 "sysinfo.h" ; for 2.2.5
71 "types.h"
72 "version.h" ; for 2.2.5
73 ))
74
75 (copy-recursively (string-append kernel-headers "/include/asm")
76 (string-append incdir "/asm"))
77 (copy-recursively (string-append kernel-headers "/include/asm-generic")
78 (string-append incdir "/asm-generic"))
79 (copy-recursively (string-append kernel-headers "/include/linux/byteorder")
80 (string-append incdir "/linux/byteorder"))
81 #t))
82
83 (define (make-stripped-libc output libc kernel-headers)
84 "Copy to OUTPUT the subset of LIBC and KERNEL-HEADERS that is needed
85 when producing a bootstrap libc."
86
87 (define (copy-mach-headers output kernel-headers)
88 (let* ((incdir (string-append output "/include")))
89 (copy-recursively (string-append libc "/include") incdir)
90
91 (copy-recursively (string-append kernel-headers "/include/mach")
92 (string-append incdir "/mach"))
93 #t))
94
95 (define (copy-libc+linux-headers output kernel-headers)
96 (let* ((incdir (string-append output "/include")))
97 (copy-recursively (string-append libc "/include") incdir)
98 (copy-linux-headers output kernel-headers)))
99
100 (define %libc-object-files-rx "^(crt.*|ld.*|lib(c|m|dl|rt|pthread|nsl|\
101 util).*\\.so(\\..*)?|lib(machuser|hurduser).so.*|(libc(rt|)|libpthread)\
102 _nonshared\\.a)$")
103
104 (setvbuf (current-output-port) 'line)
105 (let* ((libdir (string-append output "/lib")))
106 (mkdir-p libdir)
107 (for-each (lambda (file)
108 (let ((target (string-append libdir "/"
109 (basename file))))
110 (copy-file file target)
111 (remove-store-references target)))
112 (find-files (string-append libc "/lib") %libc-object-files-rx))
113 #t)
114
115 (if (directory-exists? (string-append kernel-headers "/include/mach"))
116 (copy-mach-headers output kernel-headers)
117 (copy-libc+linux-headers output kernel-headers)))
118
119