summaryrefslogtreecommitdiff
path: root/distro
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2012-11-06 22:55:44 +0100
committerLudovic Courtès <ludo@gnu.org>2012-11-06 22:55:44 +0100
commit8ba60d7b65f16e9ca1ecf4535300fbfd08abbab2 (patch)
treebe906c9ca7a49843659be0037a7ee178867c5868 /distro
parentce1ef15b2577b439f433edfbea419afda047f421 (diff)
distro: Move bootstrap tarball packages to (distro packages make-bootstrap).
* distro/packages/base.scm (binutils-final): Make public. (static-package, %bash-static, %static-inputs, %static-binaries, %binutils-static, %binutils-static-stripped, %glibc-stripped, %gcc-static, %gcc-stripped, %guile-static, %guile-static-stripped, tarball-package, %bootstrap-binaries-tarball, %binutils-bootstrap-tarball, %glibc-bootstrap-tarball, %guile-bootstrap-tarball): Move to... * distro/packages/make-bootstrap.scm: ... here. New file. * Makefile.am (MODULES): Add it.
Diffstat (limited to 'distro')
-rw-r--r--distro/packages/base.scm476
-rw-r--r--distro/packages/make-bootstrap.scm511
2 files changed, 512 insertions, 475 deletions
diff --git a/distro/packages/base.scm b/distro/packages/base.scm
index 4128ef58de5..707e8db2f2d 100644
--- a/distro/packages/base.scm
+++ b/distro/packages/base.scm
@@ -847,7 +847,7 @@ exec ~a/bin/~a-gcc -B~a/lib -Wl,-dynamic-linker -Wl,~a/~a \"$@\"~%"
847 ("gcc" ,gcc-boot0-wrapped) 847 ("gcc" ,gcc-boot0-wrapped)
848 ,@(fold alist-delete %boot1-inputs '("libc" "gcc")))) 848 ,@(fold alist-delete %boot1-inputs '("libc" "gcc"))))
849 849
850(define binutils-final 850(define-public binutils-final
851 (package-with-bootstrap-guile 851 (package-with-bootstrap-guile
852 (package (inherit binutils) 852 (package (inherit binutils)
853 (arguments 853 (arguments
@@ -995,478 +995,4 @@ store.")
995 ("gcc" ,gcc-final) 995 ("gcc" ,gcc-final)
996 ("libc" ,glibc-final)))) 996 ("libc" ,glibc-final))))
997 997
998
999;;;
1000;;; Bootstrap binaries.
1001;;;
1002;;; These are the binaries that are taken for granted and used as the
1003;;; root of the whole bootstrap procedure.
1004;;;
1005
1006(define* (static-package p #:optional (loc (current-source-location)))
1007 "Return a statically-linked version of package P."
1008 ;; TODO: Move to (guix build-system gnu).
1009 (let ((args (package-arguments p)))
1010 (package (inherit p)
1011 (location (source-properties->location loc))
1012 (arguments
1013 (let ((augment (lambda (args)
1014 (let ((a (default-keyword-arguments args
1015 '(#:configure-flags '()
1016 #:strip-flags #f))))
1017 (substitute-keyword-arguments a
1018 ((#:configure-flags flags)
1019 `(cons* "--disable-shared"
1020 "LDFLAGS=-static"
1021 ,flags))
1022 ((#:strip-flags _)
1023 ''("--strip-all")))))))
1024 (if (procedure? args)
1025 (lambda x
1026 (augment (apply args x)))
1027 (augment args)))))))
1028
1029(define %bash-static
1030 (let ((bash-light (package (inherit bash-final)
1031 (inputs '()) ; no readline, no curses
1032 (arguments
1033 (let ((args `(#:modules ((guix build gnu-build-system)
1034 (guix build utils)
1035 (srfi srfi-1)
1036 (srfi srfi-26))
1037 ,@(package-arguments bash))))
1038 (substitute-keyword-arguments args
1039 ((#:configure-flags flags)
1040 `(list "--without-bash-malloc"
1041 "--disable-readline"
1042 "--disable-history"
1043 "--disable-help-builtin"
1044 "--disable-progcomp"
1045 "--disable-net-redirections"
1046 "--disable-nls"))))))))
1047 (static-package bash-light)))
1048
1049(define %static-inputs
1050 ;; Packages that are to be used as %BOOTSTRAP-INPUTS.
1051 (let ((coreutils (package (inherit coreutils)
1052 (arguments
1053 `(#:configure-flags
1054 '("--disable-nls"
1055 "--disable-silent-rules"
1056 "--enable-no-install-program=stdbuf,libstdbuf.so"
1057 "LDFLAGS=-static -pthread")
1058 ,@(package-arguments coreutils)))))
1059 (bzip2 (package (inherit bzip2)
1060 (arguments
1061 (substitute-keyword-arguments (package-arguments bzip2)
1062 ((#:phases phases)
1063 `(alist-cons-before
1064 'build 'dash-static
1065 (lambda _
1066 (substitute* "Makefile"
1067 (("^LDFLAGS[[:blank:]]*=.*$")
1068 "LDFLAGS = -static")))
1069 ,phases))))))
1070 (xz (package (inherit xz)
1071 (arguments
1072 `(#:strip-flags '("--strip-all")
1073 #:phases (alist-cons-before
1074 'configure 'static-executable
1075 (lambda _
1076 ;; Ask Libtool for a static executable.
1077 (substitute* "src/xz/Makefile.in"
1078 (("^xz_LDADD =")
1079 "xz_LDADD = -all-static")))
1080 %standard-phases)))))
1081 (gawk (package (inherit gawk)
1082 (arguments
1083 (lambda (system)
1084 `(#:phases (alist-cons-before
1085 'build 'no-export-dynamic
1086 (lambda* (#:key outputs #:allow-other-keys)
1087 ;; Since we use `-static', remove
1088 ;; `-export-dynamic'.
1089 (substitute* "configure"
1090 (("-export-dynamic") "")))
1091 %standard-phases)
1092 ,@((package-arguments gawk) system)))))))
1093 `(,@(map (match-lambda
1094 ((name package)
1095 (list name (static-package package (current-source-location)))))
1096 `(("tar" ,tar)
1097 ("gzip" ,gzip)
1098 ("bzip2" ,bzip2)
1099 ("xz" ,xz)
1100 ("patch" ,patch)
1101 ("coreutils" ,coreutils)
1102 ("sed" ,sed)
1103 ("grep" ,grep)
1104 ("gawk" ,gawk)))
1105 ("bash" ,%bash-static)
1106 ;; ("ld-wrapper" ,ld-wrapper)
1107 ;; ("binutils" ,binutils-final)
1108 ;; ("gcc" ,gcc-final)
1109 ;; ("libc" ,glibc-final)
1110 )))
1111
1112(define %static-binaries
1113 (package
1114 (name "static-binaries")
1115 (version "0")
1116 (build-system trivial-build-system)
1117 (source #f)
1118 (inputs %static-inputs)
1119 (arguments
1120 `(#:modules ((guix build utils))
1121 #:builder
1122 (begin
1123 (use-modules (ice-9 ftw)
1124 (ice-9 match)
1125 (srfi srfi-1)
1126 (srfi srfi-26)
1127 (guix build utils))
1128
1129 (let ()
1130 (define (directory-contents dir)
1131 (map (cut string-append dir "/" <>)
1132 (scandir dir (negate (cut member <> '("." ".."))))))
1133
1134 (define (copy-directory source destination)
1135 (for-each (lambda (file)
1136 (format #t "copying ~s...~%" file)
1137 (copy-file file
1138 (string-append destination "/"
1139 (basename file))))
1140 (directory-contents source)))
1141
1142 (let* ((out (assoc-ref %outputs "out"))
1143 (bin (string-append out "/bin")))
1144 (mkdir-p bin)
1145
1146 ;; Copy Coreutils binaries.
1147 (let* ((coreutils (assoc-ref %build-inputs "coreutils"))
1148 (source (string-append coreutils "/bin")))
1149 (copy-directory source bin))
1150
1151 ;; For the other inputs, copy just one binary, which has the
1152 ;; same name as the input.
1153 (for-each (match-lambda
1154 ((name . dir)
1155 (let ((source (string-append dir "/bin/" name)))
1156 (format #t "copying ~s...~%" source)
1157 (copy-file source
1158 (string-append bin "/" name)))))
1159 (alist-delete "coreutils" %build-inputs))
1160
1161 ;; But of course, there are exceptions to this rule.
1162 (let ((grep (assoc-ref %build-inputs "grep")))
1163 (copy-file (string-append grep "/bin/fgrep")
1164 (string-append bin "/fgrep"))
1165 (copy-file (string-append grep "/bin/egrep")
1166 (string-append bin "/egrep")))
1167
1168 ;; Clear references to the store path.
1169 (for-each remove-store-references
1170 (directory-contents bin))
1171
1172 (with-directory-excursion bin
1173 ;; Programs such as Perl's build system want these aliases.
1174 (symlink "bash" "sh")
1175 (symlink "gawk" "awk"))
1176
1177 #t)))))
1178 (synopsis "Statically-linked bootstrap binaries")
1179 (description
1180 "Binaries used to bootstrap the distribution.")
1181 (license #f)
1182 (home-page #f)))
1183
1184(define %binutils-static
1185 ;; Statically-linked Binutils.
1186 (package (inherit binutils)
1187 (name "binutils-static")
1188 (arguments
1189 `(#:configure-flags '("--disable-gold")
1190 #:strip-flags '("--strip-all")
1191 #:phases (alist-cons-before
1192 'configure 'all-static
1193 (lambda _
1194 ;; The `-all-static' libtool flag can only be passed
1195 ;; after `configure', since configure tests don't use
1196 ;; libtool, and only for executables built with libtool.
1197 (substitute* '("binutils/Makefile.in"
1198 "gas/Makefile.in"
1199 "ld/Makefile.in")
1200 (("^LDFLAGS =(.*)$" line)
1201 (string-append line
1202 "\nAM_LDFLAGS = -static -all-static\n"))))
1203 %standard-phases)))))
1204
1205(define %binutils-static-stripped
1206 ;; The subset of Binutils that we need.
1207 (package (inherit %binutils-static)
1208 (build-system trivial-build-system)
1209 (arguments
1210 `(#:modules ((guix build utils))
1211 #:builder
1212 (begin
1213 (use-modules (guix build utils))
1214
1215 (setvbuf (current-output-port) _IOLBF)
1216 (let* ((in (assoc-ref %build-inputs "binutils"))
1217 (out (assoc-ref %outputs "out"))
1218 (bin (string-append out "/bin")))
1219 (mkdir-p bin)
1220 (for-each (lambda (file)
1221 (let ((target (string-append bin "/" file)))
1222 (format #t "copying `~a'...~%" file)
1223 (copy-file (string-append in "/bin/" file)
1224 target)
1225 (remove-store-references target)))
1226 '("ar" "as" "ld" "nm" "objcopy" "objdump"
1227 "ranlib" "readelf" "size" "strings" "strip"))
1228 #t))))
1229 (inputs `(("binutils" ,%binutils-static)))))
1230
1231(define %glibc-stripped
1232 ;; GNU libc's essential shared libraries, dynamic linker, and headers,
1233 ;; with all references to store directories stripped. As a result,
1234 ;; libc.so is unusable and need to be patched for proper relocation.
1235 (package (inherit glibc-final)
1236 (name "glibc-stripped")
1237 (build-system trivial-build-system)
1238 (arguments
1239 `(#:modules ((guix build utils))
1240 #:builder
1241 (begin
1242 (use-modules (guix build utils))
1243
1244 (setvbuf (current-output-port) _IOLBF)
1245 (let* ((out (assoc-ref %outputs "out"))
1246 (libdir (string-append out "/lib"))
1247 (incdir (string-append out "/include"))
1248 (libc (assoc-ref %build-inputs "libc"))
1249 (linux (assoc-ref %build-inputs "linux-headers")))
1250 (mkdir-p libdir)
1251 (for-each (lambda (file)
1252 (let ((target (string-append libdir "/"
1253 (basename file))))
1254 (copy-file file target)
1255 (remove-store-references target)))
1256 (find-files (string-append libc "/lib")
1257 "^(crt.*|ld.*|lib(c|m|dl|rt|pthread|nsl|util).*\\.so(\\..*)?|libc_nonshared\\.a)$"))
1258
1259 (copy-recursively (string-append libc "/include") incdir)
1260
1261 ;; Copy some of the Linux-Libre headers that glibc headers
1262 ;; refer to.
1263 (mkdir (string-append incdir "/linux"))
1264 (for-each (lambda (file)
1265 (copy-file (string-append linux "/include/linux/" file)
1266 (string-append incdir "/linux/"
1267 (basename file))))
1268 '("limits.h" "errno.h" "socket.h" "kernel.h"
1269 "sysctl.h" "param.h" "ioctl.h" "types.h"
1270 "posix_types.h" "stddef.h"))
1271
1272 (copy-recursively (string-append linux "/include/asm")
1273 (string-append incdir "/asm"))
1274 (copy-recursively (string-append linux "/include/asm-generic")
1275 (string-append incdir "/asm-generic"))
1276 #t))))
1277 (inputs `(("libc" ,glibc-final)
1278 ("linux-headers" ,linux-libre-headers)))))
1279
1280(define %gcc-static
1281 ;; A statically-linked GCC, with stripped-down functionality.
1282 (package (inherit gcc-final)
1283 (name "gcc-static")
1284 (arguments
1285 (lambda (system)
1286 `(#:modules ((guix build utils)
1287 (guix build gnu-build-system)
1288 (srfi srfi-1)
1289 (srfi srfi-26)
1290 (ice-9 regex))
1291 ,@(substitute-keyword-arguments ((package-arguments gcc-final) system)
1292 ((#:guile _) #f)
1293 ((#:implicit-inputs? _) #t)
1294 ((#:configure-flags flags)
1295 `(append (list
1296 "--disable-shared"
1297 "--disable-plugin"
1298 "--enable-languages=c"
1299 "--disable-libmudflap"
1300 "--disable-libgomp"
1301 "--disable-libssp"
1302 "--disable-libquadmath"
1303 "--disable-decimal-float")
1304 (remove (cut string-match "--(.*plugin|enable-languages)" <>)
1305 ,flags)))
1306 ((#:make-flags flags)
1307 `(cons "BOOT_LDFLAGS=-static" ,flags))))))
1308 (inputs `(("gmp-source" ,(package-source gmp))
1309 ("mpfr-source" ,(package-source mpfr))
1310 ("mpc-source" ,(package-source mpc))
1311 ("binutils" ,binutils-final)
1312 ,@(package-inputs gcc-4.7)))))
1313
1314(define %gcc-stripped
1315 ;; The subset of GCC files needed for bootstrap.
1316 (package (inherit gcc-4.7)
1317 (name "gcc-stripped")
1318 (build-system trivial-build-system)
1319 (source #f)
1320 (arguments
1321 `(#:modules ((guix build utils))
1322 #:builder
1323 (begin
1324 (use-modules (srfi srfi-1)
1325 (srfi srfi-26)
1326 (guix build utils))
1327
1328 (setvbuf (current-output-port) _IOLBF)
1329 (let* ((out (assoc-ref %outputs "out"))
1330 (bindir (string-append out "/bin"))
1331 (libdir (string-append out "/lib"))
1332 (libexecdir (string-append out "/libexec"))
1333 (gcc (assoc-ref %build-inputs "gcc")))
1334 (copy-recursively (string-append gcc "/bin") bindir)
1335 (for-each remove-store-references
1336 (find-files bindir ".*"))
1337
1338 (copy-recursively (string-append gcc "/lib") libdir)
1339 (for-each remove-store-references
1340 (remove (cut string-suffix? ".h" <>)
1341 (find-files libdir ".*")))
1342
1343 (copy-recursively (string-append gcc "/libexec")
1344 libexecdir)
1345 (for-each remove-store-references
1346 (find-files libexecdir ".*"))
1347 #t))))
1348 (inputs `(("gcc" ,%gcc-static)))))
1349
1350(define %guile-static
1351 ;; A statically-linked Guile that is relocatable--i.e., it can search
1352 ;; .scm and .go files relative to its installation directory, rather
1353 ;; than in hard-coded configure-time paths.
1354 (let ((guile (package (inherit guile-2.0)
1355 (inputs
1356 `(("patch/relocatable"
1357 ,(search-patch "guile-relocatable.patch"))
1358 ("patch/utf8"
1359 ,(search-patch "guile-default-utf8.patch"))
1360 ,@(package-inputs guile-2.0)))
1361 (arguments
1362 `(;; When `configure' checks for ltdl availability, it
1363 ;; doesn't try to link using libtool, and thus fails
1364 ;; because of a missing -ldl. Work around that.
1365 #:configure-flags '("LDFLAGS=-ldl")
1366
1367 #:phases (alist-cons-before
1368 'configure 'static-guile
1369 (lambda _
1370 (substitute* "libguile/Makefile.in"
1371 ;; Create a statically-linked `guile'
1372 ;; executable.
1373 (("^guile_LDFLAGS =")
1374 "guile_LDFLAGS = -all-static")
1375
1376 ;; Add `-ldl' *after* libguile-2.0.la.
1377 (("^guile_LDADD =(.*)$" _ ldadd)
1378 (string-append "guile_LDADD = "
1379 (string-trim-right ldadd)
1380 " -ldl\n"))))
1381 %standard-phases)
1382
1383 ;; Allow Guile to be relocated, as is needed during
1384 ;; bootstrap.
1385 #:patches
1386 (list (assoc-ref %build-inputs "patch/relocatable")
1387 (assoc-ref %build-inputs "patch/utf8"))
1388
1389 ;; There are uses of `dynamic-link' in
1390 ;; {foreign,coverage}.test that don't fly here.
1391 #:tests? #f)))))
1392 (static-package guile (current-source-location))))
1393
1394(define %guile-static-stripped
1395 ;; A stripped static Guile binary, for use during bootstrap.
1396 (package (inherit %guile-static)
1397 (name "guile-static-stripped")
1398 (build-system trivial-build-system)
1399 (arguments
1400 `(#:modules ((guix build utils))
1401 #:builder
1402 (let ()
1403 (use-modules (guix build utils))
1404
1405 (let ((in (assoc-ref %build-inputs "guile"))
1406 (out (assoc-ref %outputs "out")))
1407 (mkdir-p (string-append out "/share/guile/2.0"))
1408 (copy-recursively (string-append in "/share/guile/2.0")
1409 (string-append out "/share/guile/2.0"))
1410
1411 (mkdir-p (string-append out "/lib/guile/2.0/ccache"))
1412 (copy-recursively (string-append in "/lib/guile/2.0/ccache")
1413 (string-append out "/lib/guile/2.0/ccache"))
1414
1415 (mkdir (string-append out "/bin"))
1416 (copy-file (string-append in "/bin/guile")
1417 (string-append out "/bin/guile"))
1418 (remove-store-references (string-append out "/bin/guile"))
1419 #t))))
1420 (inputs `(("guile" ,%guile-static)))))
1421
1422(define (tarball-package pkg)
1423 "Return a package containing a tarball of PKG."
1424 (package (inherit pkg)
1425 (location (source-properties->location (current-source-location)))
1426 (name (string-append (package-name pkg) "-tarball"))
1427 (build-system trivial-build-system)
1428 (inputs `(("tar" ,tar)
1429 ("xz" ,xz)
1430 ("input" ,pkg)))
1431 (arguments
1432 (lambda (system)
1433 (let ((name (package-name pkg))
1434 (version (package-version pkg)))
1435 `(#:modules ((guix build utils))
1436 #:builder
1437 (begin
1438 (use-modules (guix build utils))
1439 (let ((out (assoc-ref %outputs "out"))
1440 (input (assoc-ref %build-inputs "input"))
1441 (tar (assoc-ref %build-inputs "tar"))
1442 (xz (assoc-ref %build-inputs "xz")))
1443 (mkdir out)
1444 (set-path-environment-variable "PATH" '("bin") (list tar xz))
1445 (with-directory-excursion input
1446 (zero? (system* "tar" "cJvf"
1447 (string-append out "/"
1448 ,name "-" ,version
1449 "-" ,system ".tar.xz")
1450 ".")))))))))))
1451
1452(define %bootstrap-binaries-tarball
1453 ;; A tarball with the statically-linked bootstrap binaries.
1454 (tarball-package %static-binaries))
1455
1456(define %binutils-bootstrap-tarball
1457 ;; A tarball with the statically-linked Binutils programs.
1458 (tarball-package %binutils-static-stripped))
1459
1460(define %glibc-bootstrap-tarball
1461 ;; A tarball with GNU libc's shared libraries, dynamic linker, and headers.
1462 (tarball-package %glibc-stripped))
1463
1464(define %gcc-bootstrap-tarball
1465 ;; A tarball with a dynamic-linked GCC and its headers.
1466 (tarball-package %gcc-stripped))
1467
1468(define %guile-bootstrap-tarball
1469 ;; A tarball with the statically-linked, relocatable Guile.
1470 (tarball-package %guile-static-stripped))
1471
1472;;; base.scm ends here 998;;; base.scm ends here
diff --git a/distro/packages/make-bootstrap.scm b/distro/packages/make-bootstrap.scm
new file mode 100644
index 00000000000..3bc6e6b542e
--- /dev/null
+++ b/distro/packages/make-bootstrap.scm
@@ -0,0 +1,511 @@
1;;; Guix --- Nix package management from Guile. -*- coding: utf-8 -*-
2;;; Copyright (C) 2012 Ludovic Courtès <ludo@gnu.org>
3;;;
4;;; This file is part of Guix.
5;;;
6;;; 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;;; 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 Guix. If not, see <http://www.gnu.org/licenses/>.
18
19(define-module (distro packages make-bootstrap)
20 #:use-module (guix utils)
21 #:use-module (guix packages)
22 #:use-module (guix build-system trivial)
23 #:use-module ((distro) #:select (search-patch))
24 #:use-module (distro packages base)
25 #:use-module (distro packages bash)
26 #:use-module (distro packages compression)
27 #:use-module (distro packages gawk)
28 #:use-module (distro packages guile)
29 #:use-module (distro packages multiprecision)
30 #:use-module (ice-9 match)
31 #:export (%bootstrap-binaries-tarball
32 %binutils-bootstrap-tarball
33 %glibc-bootstrap-tarball
34 %gcc-bootstrap-tarball
35 %guile-bootstrap-tarball))
36
37;;; Commentary:
38;;;
39;;; This modules provides tools to build tarballs of the "bootstrap binaries"
40;;; used in (distro packages bootstrap). These statically-linked binaries are
41;;; taken for granted and used as the root of the whole bootstrap procedure.
42;;;
43;;; Code:
44
45(define* (static-package p #:optional (loc (current-source-location)))
46 "Return a statically-linked version of package P."
47 ;; TODO: Move to (guix build-system gnu).
48 (let ((args (package-arguments p)))
49 (package (inherit p)
50 (location (source-properties->location loc))
51 (arguments
52 (let ((augment (lambda (args)
53 (let ((a (default-keyword-arguments args
54 '(#:configure-flags '()
55 #:strip-flags #f))))
56 (substitute-keyword-arguments a
57 ((#:configure-flags flags)
58 `(cons* "--disable-shared"
59 "LDFLAGS=-static"
60 ,flags))
61 ((#:strip-flags _)
62 ''("--strip-all")))))))
63 (if (procedure? args)
64 (lambda x
65 (augment (apply args x)))
66 (augment args)))))))
67
68(define %bash-static
69 (let ((bash-light (package (inherit bash-final)
70 (inputs '()) ; no readline, no curses
71 (arguments
72 (let ((args `(#:modules ((guix build gnu-build-system)
73 (guix build utils)
74 (srfi srfi-1)
75 (srfi srfi-26))
76 ,@(package-arguments bash))))
77 (substitute-keyword-arguments args
78 ((#:configure-flags flags)
79 `(list "--without-bash-malloc"
80 "--disable-readline"
81 "--disable-history"
82 "--disable-help-builtin"
83 "--disable-progcomp"
84 "--disable-net-redirections"
85 "--disable-nls"))))))))
86 (static-package bash-light)))
87
88(define %static-inputs
89 ;; Packages that are to be used as %BOOTSTRAP-INPUTS.
90 (let ((coreutils (package (inherit coreutils)
91 (arguments
92 `(#:configure-flags
93 '("--disable-nls"
94 "--disable-silent-rules"
95 "--enable-no-install-program=stdbuf,libstdbuf.so"
96 "LDFLAGS=-static -pthread")
97 ,@(package-arguments coreutils)))))
98 (bzip2 (package (inherit bzip2)
99 (arguments
100 (substitute-keyword-arguments (package-arguments bzip2)
101 ((#:phases phases)
102 `(alist-cons-before
103 'build 'dash-static
104 (lambda _
105 (substitute* "Makefile"
106 (("^LDFLAGS[[:blank:]]*=.*$")
107 "LDFLAGS = -static")))
108 ,phases))))))
109 (xz (package (inherit xz)
110 (arguments
111 `(#:strip-flags '("--strip-all")
112 #:phases (alist-cons-before
113 'configure 'static-executable
114 (lambda _
115 ;; Ask Libtool for a static executable.
116 (substitute* "src/xz/Makefile.in"
117 (("^xz_LDADD =")
118 "xz_LDADD = -all-static")))
119 %standard-phases)))))
120 (gawk (package (inherit gawk)
121 (arguments
122 (lambda (system)
123 `(#:phases (alist-cons-before
124 'build 'no-export-dynamic
125 (lambda* (#:key outputs #:allow-other-keys)
126 ;; Since we use `-static', remove
127 ;; `-export-dynamic'.
128 (substitute* "configure"
129 (("-export-dynamic") "")))
130 %standard-phases)
131 ,@((package-arguments gawk) system)))))))
132 `(,@(map (match-lambda
133 ((name package)
134 (list name (static-package package (current-source-location)))))
135 `(("tar" ,tar)
136 ("gzip" ,gzip)
137 ("bzip2" ,bzip2)
138 ("xz" ,xz)
139 ("patch" ,patch)
140 ("coreutils" ,coreutils)
141 ("sed" ,sed)
142 ("grep" ,grep)
143 ("gawk" ,gawk)))
144 ("bash" ,%bash-static)
145 ;; ("ld-wrapper" ,ld-wrapper)
146 ;; ("binutils" ,binutils-final)
147 ;; ("gcc" ,gcc-final)
148 ;; ("libc" ,glibc-final)
149 )))
150
151(define %static-binaries
152 (package
153 (name "static-binaries")
154 (version "0")
155 (build-system trivial-build-system)
156 (source #f)
157 (inputs %static-inputs)
158 (arguments
159 `(#:modules ((guix build utils))
160 #:builder
161 (begin
162 (use-modules (ice-9 ftw)
163 (ice-9 match)
164 (srfi srfi-1)
165 (srfi srfi-26)
166 (guix build utils))
167
168 (let ()
169 (define (directory-contents dir)
170 (map (cut string-append dir "/" <>)
171 (scandir dir (negate (cut member <> '("." ".."))))))
172
173 (define (copy-directory source destination)
174 (for-each (lambda (file)
175 (format #t "copying ~s...~%" file)
176 (copy-file file
177 (string-append destination "/"
178 (basename file))))
179 (directory-contents source)))
180
181 (let* ((out (assoc-ref %outputs "out"))
182 (bin (string-append out "/bin")))
183 (mkdir-p bin)
184
185 ;; Copy Coreutils binaries.
186 (let* ((coreutils (assoc-ref %build-inputs "coreutils"))
187 (source (string-append coreutils "/bin")))
188 (copy-directory source bin))
189
190 ;; For the other inputs, copy just one binary, which has the
191 ;; same name as the input.
192 (for-each (match-lambda
193 ((name . dir)
194 (let ((source (string-append dir "/bin/" name)))
195 (format #t "copying ~s...~%" source)
196 (copy-file source
197 (string-append bin "/" name)))))
198 (alist-delete "coreutils" %build-inputs))
199
200 ;; But of course, there are exceptions to this rule.
201 (let ((grep (assoc-ref %build-inputs "grep")))
202 (copy-file (string-append grep "/bin/fgrep")
203 (string-append bin "/fgrep"))
204 (copy-file (string-append grep "/bin/egrep")
205 (string-append bin "/egrep")))
206
207 ;; Clear references to the store path.
208 (for-each remove-store-references
209 (directory-contents bin))
210
211 (with-directory-excursion bin
212 ;; Programs such as Perl's build system want these aliases.
213 (symlink "bash" "sh")
214 (symlink "gawk" "awk"))
215
216 #t)))))
217 (synopsis "Statically-linked bootstrap binaries")
218 (description
219 "Binaries used to bootstrap the distribution.")
220 (license #f)
221 (home-page #f)))
222
223(define %binutils-static
224 ;; Statically-linked Binutils.
225 (package (inherit binutils)
226 (name "binutils-static")
227 (arguments
228 `(#:configure-flags '("--disable-gold")
229 #:strip-flags '("--strip-all")
230 #:phases (alist-cons-before
231 'configure 'all-static
232 (lambda _
233 ;; The `-all-static' libtool flag can only be passed
234 ;; after `configure', since configure tests don't use
235 ;; libtool, and only for executables built with libtool.
236 (substitute* '("binutils/Makefile.in"
237 "gas/Makefile.in"
238 "ld/Makefile.in")
239 (("^LDFLAGS =(.*)$" line)
240 (string-append line
241 "\nAM_LDFLAGS = -static -all-static\n"))))
242 %standard-phases)))))
243
244(define %binutils-static-stripped
245 ;; The subset of Binutils that we need.
246 (package (inherit %binutils-static)
247 (build-system trivial-build-system)
248 (arguments
249 `(#:modules ((guix build utils))
250 #:builder
251 (begin
252 (use-modules (guix build utils))
253
254 (setvbuf (current-output-port) _IOLBF)
255 (let* ((in (assoc-ref %build-inputs "binutils"))
256 (out (assoc-ref %outputs "out"))
257 (bin (string-append out "/bin")))
258 (mkdir-p bin)
259 (for-each (lambda (file)
260 (let ((target (string-append bin "/" file)))
261 (format #t "copying `~a'...~%" file)
262 (copy-file (string-append in "/bin/" file)
263 target)
264 (remove-store-references target)))
265 '("ar" "as" "ld" "nm" "objcopy" "objdump"
266 "ranlib" "readelf" "size" "strings" "strip"))
267 #t))))
268 (inputs `(("binutils" ,%binutils-static)))))
269
270(define %glibc-stripped
271 ;; GNU libc's essential shared libraries, dynamic linker, and headers,
272 ;; with all references to store directories stripped. As a result,
273 ;; libc.so is unusable and need to be patched for proper relocation.
274 (package (inherit glibc-final)
275 (name "glibc-stripped")
276 (build-system trivial-build-system)
277 (arguments
278 `(#:modules ((guix build utils))
279 #:builder
280 (begin
281 (use-modules (guix build utils))
282
283 (setvbuf (current-output-port) _IOLBF)
284 (let* ((out (assoc-ref %outputs "out"))
285 (libdir (string-append out "/lib"))
286 (incdir (string-append out "/include"))
287 (libc (assoc-ref %build-inputs "libc"))
288 (linux (assoc-ref %build-inputs "linux-headers")))
289 (mkdir-p libdir)
290 (for-each (lambda (file)
291 (let ((target (string-append libdir "/"
292 (basename file))))
293 (copy-file file target)
294 (remove-store-references target)))
295 (find-files (string-append libc "/lib")
296 "^(crt.*|ld.*|lib(c|m|dl|rt|pthread|nsl|util).*\\.so(\\..*)?|libc_nonshared\\.a)$"))
297
298 (copy-recursively (string-append libc "/include") incdir)
299
300 ;; Copy some of the Linux-Libre headers that glibc headers
301 ;; refer to.
302 (mkdir (string-append incdir "/linux"))
303 (for-each (lambda (file)
304 (copy-file (string-append linux "/include/linux/" file)
305 (string-append incdir "/linux/"
306 (basename file))))
307 '("limits.h" "errno.h" "socket.h" "kernel.h"
308 "sysctl.h" "param.h" "ioctl.h" "types.h"
309 "posix_types.h" "stddef.h"))
310
311 (copy-recursively (string-append linux "/include/asm")
312 (string-append incdir "/asm"))
313 (copy-recursively (string-append linux "/include/asm-generic")
314 (string-append incdir "/asm-generic"))
315 #t))))
316 (inputs `(("libc" ,glibc-final)
317 ("linux-headers" ,linux-libre-headers)))))
318
319(define %gcc-static
320 ;; A statically-linked GCC, with stripped-down functionality.
321 (package (inherit gcc-final)
322 (name "gcc-static")
323 (arguments
324 (lambda (system)
325 `(#:modules ((guix build utils)
326 (guix build gnu-build-system)
327 (srfi srfi-1)
328 (srfi srfi-26)
329 (ice-9 regex))
330 ,@(substitute-keyword-arguments ((package-arguments gcc-final) system)
331 ((#:guile _) #f)
332 ((#:implicit-inputs? _) #t)
333 ((#:configure-flags flags)
334 `(append (list
335 "--disable-shared"
336 "--disable-plugin"
337 "--enable-languages=c"
338 "--disable-libmudflap"
339 "--disable-libgomp"
340 "--disable-libssp"
341 "--disable-libquadmath"
342 "--disable-decimal-float")
343 (remove (cut string-match "--(.*plugin|enable-languages)" <>)
344 ,flags)))
345 ((#:make-flags flags)
346 `(cons "BOOT_LDFLAGS=-static" ,flags))))))
347 (inputs `(("gmp-source" ,(package-source gmp))
348 ("mpfr-source" ,(package-source mpfr))
349 ("mpc-source" ,(package-source mpc))
350 ("binutils" ,binutils-final)
351 ,@(package-inputs gcc-4.7)))))
352
353(define %gcc-stripped
354 ;; The subset of GCC files needed for bootstrap.
355 (package (inherit gcc-4.7)
356 (name "gcc-stripped")
357 (build-system trivial-build-system)
358 (source #f)
359 (arguments
360 `(#:modules ((guix build utils))
361 #:builder
362 (begin
363 (use-modules (srfi srfi-1)
364 (srfi srfi-26)
365 (guix build utils))
366
367 (setvbuf (current-output-port) _IOLBF)
368 (let* ((out (assoc-ref %outputs "out"))
369 (bindir (string-append out "/bin"))
370 (libdir (string-append out "/lib"))
371 (libexecdir (string-append out "/libexec"))
372 (gcc (assoc-ref %build-inputs "gcc")))
373 (copy-recursively (string-append gcc "/bin") bindir)
374 (for-each remove-store-references
375 (find-files bindir ".*"))
376
377 (copy-recursively (string-append gcc "/lib") libdir)
378 (for-each remove-store-references
379 (remove (cut string-suffix? ".h" <>)
380 (find-files libdir ".*")))
381
382 (copy-recursively (string-append gcc "/libexec")
383 libexecdir)
384 (for-each remove-store-references
385 (find-files libexecdir ".*"))
386 #t))))
387 (inputs `(("gcc" ,%gcc-static)))))
388
389(define %guile-static
390 ;; A statically-linked Guile that is relocatable--i.e., it can search
391 ;; .scm and .go files relative to its installation directory, rather
392 ;; than in hard-coded configure-time paths.
393 (let ((guile (package (inherit guile-2.0)
394 (inputs
395 `(("patch/relocatable"
396 ,(search-patch "guile-relocatable.patch"))
397 ("patch/utf8"
398 ,(search-patch "guile-default-utf8.patch"))
399 ,@(package-inputs guile-2.0)))
400 (arguments
401 `(;; When `configure' checks for ltdl availability, it
402 ;; doesn't try to link using libtool, and thus fails
403 ;; because of a missing -ldl. Work around that.
404 #:configure-flags '("LDFLAGS=-ldl")
405
406 #:phases (alist-cons-before
407 'configure 'static-guile
408 (lambda _
409 (substitute* "libguile/Makefile.in"
410 ;; Create a statically-linked `guile'
411 ;; executable.
412 (("^guile_LDFLAGS =")
413 "guile_LDFLAGS = -all-static")
414
415 ;; Add `-ldl' *after* libguile-2.0.la.
416 (("^guile_LDADD =(.*)$" _ ldadd)
417 (string-append "guile_LDADD = "
418 (string-trim-right ldadd)
419 " -ldl\n"))))
420 %standard-phases)
421
422 ;; Allow Guile to be relocated, as is needed during
423 ;; bootstrap.
424 #:patches
425 (list (assoc-ref %build-inputs "patch/relocatable")
426 (assoc-ref %build-inputs "patch/utf8"))
427
428 ;; There are uses of `dynamic-link' in
429 ;; {foreign,coverage}.test that don't fly here.
430 #:tests? #f)))))
431 (static-package guile (current-source-location))))
432
433(define %guile-static-stripped
434 ;; A stripped static Guile binary, for use during bootstrap.
435 (package (inherit %guile-static)
436 (name "guile-static-stripped")
437 (build-system trivial-build-system)
438 (arguments
439 `(#:modules ((guix build utils))
440 #:builder
441 (let ()
442 (use-modules (guix build utils))
443
444 (let ((in (assoc-ref %build-inputs "guile"))
445 (out (assoc-ref %outputs "out")))
446 (mkdir-p (string-append out "/share/guile/2.0"))
447 (copy-recursively (string-append in "/share/guile/2.0")
448 (string-append out "/share/guile/2.0"))
449
450 (mkdir-p (string-append out "/lib/guile/2.0/ccache"))
451 (copy-recursively (string-append in "/lib/guile/2.0/ccache")
452 (string-append out "/lib/guile/2.0/ccache"))
453
454 (mkdir (string-append out "/bin"))
455 (copy-file (string-append in "/bin/guile")
456 (string-append out "/bin/guile"))
457 (remove-store-references (string-append out "/bin/guile"))
458 #t))))
459 (inputs `(("guile" ,%guile-static)))))
460
461(define (tarball-package pkg)
462 "Return a package containing a tarball of PKG."
463 (package (inherit pkg)
464 (location (source-properties->location (current-source-location)))
465 (name (string-append (package-name pkg) "-tarball"))
466 (build-system trivial-build-system)
467 (inputs `(("tar" ,tar)
468 ("xz" ,xz)
469 ("input" ,pkg)))
470 (arguments
471 (lambda (system)
472 (let ((name (package-name pkg))
473 (version (package-version pkg)))
474 `(#:modules ((guix build utils))
475 #:builder
476 (begin
477 (use-modules (guix build utils))
478 (let ((out (assoc-ref %outputs "out"))
479 (input (assoc-ref %build-inputs "input"))
480 (tar (assoc-ref %build-inputs "tar"))
481 (xz (assoc-ref %build-inputs "xz")))
482 (mkdir out)
483 (set-path-environment-variable "PATH" '("bin") (list tar xz))
484 (with-directory-excursion input
485 (zero? (system* "tar" "cJvf"
486 (string-append out "/"
487 ,name "-" ,version
488 "-" ,system ".tar.xz")
489 ".")))))))))))
490
491(define %bootstrap-binaries-tarball
492 ;; A tarball with the statically-linked bootstrap binaries.
493 (tarball-package %static-binaries))
494
495(define %binutils-bootstrap-tarball
496 ;; A tarball with the statically-linked Binutils programs.
497 (tarball-package %binutils-static-stripped))
498
499(define %glibc-bootstrap-tarball
500 ;; A tarball with GNU libc's shared libraries, dynamic linker, and headers.
501 (tarball-package %glibc-stripped))
502
503(define %gcc-bootstrap-tarball
504 ;; A tarball with a dynamic-linked GCC and its headers.
505 (tarball-package %gcc-stripped))
506
507(define %guile-bootstrap-tarball
508 ;; A tarball with the statically-linked, relocatable Guile.
509 (tarball-package %guile-static-stripped))
510
511;;; make-bootstrap.scm ends here