gnu: r-igraph: Move to (gnu packages cran).
[jackhill/guix/guix.git] / guix / build / make-bootstrap.scm
CommitLineData
f13f60cb 1;;; GNU Guix --- Functional package management for GNU
484437bd 2;;; Copyright © 2015, 2017 Manolis Fragkiskos Ragkousis <manolis837@gmail.com>
76832d34 3;;; Copyright © 2015, 2019 Ludovic Courtès <ludo@gnu.org>
4f3811f6 4;;; Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
f13f60cb
MR
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)
4f3811f6
JN
27 #:export (copy-linux-headers
28 make-stripped-libc))
f13f60cb
MR
29
30;; Commentary:
31;;
32;; This module provides facilities to build the bootstrap binaries.
33;;
34;; Code:
35
4f3811f6
JN
36(define (copy-linux-headers output kernel-headers)
37 "Copy to OUTPUT the subset of KERNEL-HEADERS that is needed when producing a
38bootstrap 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 '(
4f3811f6
JN
50 "atalk.h" ; for 2.2.5
51 "errno.h"
52 "falloc.h"
53 "if_addr.h" ; for 2.16.0
54 "if_ether.h" ; for 2.2.5
55 "if_link.h" ; for 2.16.0
56 "ioctl.h"
57 "kernel.h"
58 "limits.h"
59 "neighbour.h" ; for 2.16.0
60 "netlink.h" ; for 2.16.0
61 "param.h"
62 "prctl.h" ; for 2.16.0
63 "posix_types.h"
64 "rtnetlink.h" ; for 2.16.0
65 "socket.h"
66 "stddef.h"
67 "swab.h" ; for 2.2.5
68 "sysctl.h"
69 "sysinfo.h" ; for 2.2.5
70 "types.h"
71 "version.h" ; for 2.2.5
72 ))
73
74 (copy-recursively (string-append kernel-headers "/include/asm")
75 (string-append incdir "/asm"))
76 (copy-recursively (string-append kernel-headers "/include/asm-generic")
77 (string-append incdir "/asm-generic"))
78 (copy-recursively (string-append kernel-headers "/include/linux/byteorder")
79 (string-append incdir "/linux/byteorder"))
80 #t))
81
f13f60cb
MR
82(define (make-stripped-libc output libc kernel-headers)
83 "Copy to OUTPUT the subset of LIBC and KERNEL-HEADERS that is needed
84when producing a bootstrap libc."
85
86 (define (copy-mach-headers output kernel-headers)
87 (let* ((incdir (string-append output "/include")))
88 (copy-recursively (string-append libc "/include") incdir)
89
90 (copy-recursively (string-append kernel-headers "/include/mach")
91 (string-append incdir "/mach"))
92 #t))
93
4f3811f6 94 (define (copy-libc+linux-headers output kernel-headers)
f13f60cb
MR
95 (let* ((incdir (string-append output "/include")))
96 (copy-recursively (string-append libc "/include") incdir)
4f3811f6 97 (copy-linux-headers output kernel-headers)))
f13f60cb
MR
98
99 (define %libc-object-files-rx "^(crt.*|ld.*|lib(c|m|dl|rt|pthread|nsl|\
484437bd
MR
100util).*\\.so(\\..*)?|lib(machuser|hurduser).so.*|(libc(rt|)|libpthread)\
101_nonshared\\.a)$")
f13f60cb 102
76832d34 103 (setvbuf (current-output-port) 'line)
f13f60cb
MR
104 (let* ((libdir (string-append output "/lib")))
105 (mkdir-p libdir)
106 (for-each (lambda (file)
107 (let ((target (string-append libdir "/"
108 (basename file))))
109 (copy-file file target)
110 (remove-store-references target)))
111 (find-files (string-append libc "/lib") %libc-object-files-rx))
112 #t)
113
114 (if (directory-exists? (string-append kernel-headers "/include/mach"))
115 (copy-mach-headers output kernel-headers)
4f3811f6 116 (copy-libc+linux-headers output kernel-headers)))
f13f60cb
MR
117
118