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 Ludovic Courtès <ludo@gnu.org>
4 ;;;
5 ;;; This file is part of GNU Guix.
6 ;;;
7 ;;; GNU Guix is free software; you can redistribute it and/or modify it
8 ;;; under the terms of the GNU General Public License as published by
9 ;;; the Free Software Foundation; either version 3 of the License, or (at
10 ;;; your option) any later version.
11 ;;;
12 ;;; GNU Guix is distributed in the hope that it will be useful, but
13 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;;; GNU General Public License for more details.
16 ;;;
17 ;;; You should have received a copy of the GNU General Public License
18 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
19
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 (make-stripped-libc))
27
28 ;; Commentary:
29 ;;
30 ;; This module provides facilities to build the bootstrap binaries.
31 ;;
32 ;; Code:
33
34 (define (make-stripped-libc output libc kernel-headers)
35 "Copy to OUTPUT the subset of LIBC and KERNEL-HEADERS that is needed
36 when producing a bootstrap libc."
37
38 (define (copy-mach-headers output kernel-headers)
39 (let* ((incdir (string-append output "/include")))
40 (copy-recursively (string-append libc "/include") incdir)
41
42 (copy-recursively (string-append kernel-headers "/include/mach")
43 (string-append incdir "/mach"))
44 #t))
45
46 (define (copy-linux-headers output kernel-headers)
47 (let* ((incdir (string-append output "/include")))
48 (copy-recursively (string-append libc "/include") incdir)
49
50 ;; Copy some of the Linux-Libre headers that glibc headers
51 ;; refer to.
52 (mkdir (string-append incdir "/linux"))
53 (for-each (lambda (file)
54 (install-file (string-append kernel-headers "/include/linux/" file)
55 (string-append incdir "/linux")))
56 '("limits.h" "errno.h" "socket.h" "kernel.h"
57 "sysctl.h" "param.h" "ioctl.h" "types.h"
58 "posix_types.h" "stddef.h" "falloc.h"))
59
60 (copy-recursively (string-append kernel-headers "/include/asm")
61 (string-append incdir "/asm"))
62 (copy-recursively (string-append kernel-headers "/include/asm-generic")
63 (string-append incdir "/asm-generic"))
64 #t))
65
66 (define %libc-object-files-rx "^(crt.*|ld.*|lib(c|m|dl|rt|pthread|nsl|\
67 util).*\\.so(\\..*)?|lib(machuser|hurduser).so.*|(libc(rt|)|libpthread)\
68 _nonshared\\.a)$")
69
70 (setvbuf (current-output-port) _IOLBF)
71 (let* ((libdir (string-append output "/lib")))
72 (mkdir-p libdir)
73 (for-each (lambda (file)
74 (let ((target (string-append libdir "/"
75 (basename file))))
76 (copy-file file target)
77 (remove-store-references target)))
78 (find-files (string-append libc "/lib") %libc-object-files-rx))
79 #t)
80
81 (if (directory-exists? (string-append kernel-headers "/include/mach"))
82 (copy-mach-headers output kernel-headers)
83 (copy-linux-headers output kernel-headers)))
84
85