Mirror of GNU Guix
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

819 lines
34 KiB

gnu: Fix common unquote typos. It's easy to mistype ‘("foo" foo)’ as ‘("foo", foo)’ (which also works). Fix such typos for the proper edification of our young. * gnu/packages/android.scm: Move unquotes to their operands. * gnu/packages/bootloaders.scm: Likewise. * gnu/packages/build-tools.scm: Likewise. * gnu/packages/chemistry.scm: Likewise. * gnu/packages/compression.scm: Likewise. * gnu/packages/connman.scm: Likewise. * gnu/packages/django.scm: Likewise. * gnu/packages/emulators.scm: Likewise. * gnu/packages/engineering.scm: Likewise. * gnu/packages/file-systems.scm: Likewise. * gnu/packages/freedesktop.scm: Likewise. * gnu/packages/games.scm: Likewise. * gnu/packages/gimp.scm: Likewise. * gnu/packages/gl.scm: Likewise. * gnu/packages/gnome.scm: Likewise. * gnu/packages/graphics.scm: Likewise. * gnu/packages/haskell.scm: Likewise. * gnu/packages/irc.scm: Likewise. * gnu/packages/julia.scm: Likewise. * gnu/packages/kde-frameworks.scm: Likewise. * gnu/packages/linux.scm: Likewise. * gnu/packages/lua.scm: Likewise. * gnu/packages/mail.scm: Likewise. * gnu/packages/make-bootstrap.scm: Likewise. * gnu/packages/messaging.scm: Likewise. * gnu/packages/music.scm: Likewise. * gnu/packages/networking.scm: Likewise. * gnu/packages/ocaml.scm: Likewise. * gnu/packages/perl.scm: Likewise. * gnu/packages/python.scm: Likewise. * gnu/packages/python-web.scm: Likewise. * gnu/packages/qt.scm: Likewise. * gnu/packages/ratpoison.scm: Likewise. * gnu/packages/sdl.scm: Likewise. * gnu/packages/sml.scm: Likewise. * gnu/packages/terminals.scm: Likewise. * gnu/packages/text-editors.scm: Likewise. * gnu/packages/video.scm: Likewise. * gnu/packages/virtualization.scm: Likewise. * gnu/packages/vulkan.scm: Likewise. * gnu/packages/wget.scm: Likewise. * gnu/packages/wine.scm: Likewise. * gnu/packages/wm.scm: Likewise. * gnu/packages/xdisorg.scm: Likewise. * gnu/packages/xml.scm: Likewise. * gnu/packages/xorg.scm: Likewise.
4 years ago
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2012, 2013, 2014, 2015, 2016, 2017, 2018 Ludovic Courtès <ludo@gnu.org>
  3. ;;; Copyright © 2017 Efraim Flashner <efraim@flashner.co.il>
  4. ;;; Copyright © 2018 Tobias Geerinckx-Rice <me@tobias.gr>
  5. ;;; Copyright © 2018 Mark H Weaver <mhw@netris.org>
  6. ;;; Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
  7. ;;;
  8. ;;; This file is part of GNU Guix.
  9. ;;;
  10. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  11. ;;; under the terms of the GNU General Public License as published by
  12. ;;; the Free Software Foundation; either version 3 of the License, or (at
  13. ;;; your option) any later version.
  14. ;;;
  15. ;;; GNU Guix is distributed in the hope that it will be useful, but
  16. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  17. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. ;;; GNU General Public License for more details.
  19. ;;;
  20. ;;; You should have received a copy of the GNU General Public License
  21. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  22. (define-module (gnu packages make-bootstrap)
  23. #:use-module (guix utils)
  24. #:use-module (guix packages)
  25. #:use-module ((guix licenses) #:select (gpl3+))
  26. #:use-module (guix build-system trivial)
  27. #:use-module (guix build-system gnu)
  28. #:use-module ((gnu packages) #:select (search-patch))
  29. #:use-module (gnu packages base)
  30. #:use-module (gnu packages cross-base)
  31. #:use-module (gnu packages bash)
  32. #:use-module (gnu packages compression)
  33. #:use-module (gnu packages gawk)
  34. #:use-module (gnu packages gcc)
  35. #:use-module (gnu packages guile)
  36. #:use-module (gnu packages bdw-gc)
  37. #:use-module (gnu packages libunistring)
  38. #:use-module (gnu packages linux)
  39. #:use-module (gnu packages hurd)
  40. #:use-module (gnu packages mes)
  41. #:use-module (gnu packages multiprecision)
  42. #:use-module (ice-9 match)
  43. #:use-module (srfi srfi-1)
  44. #:export (%bootstrap-binaries-tarball
  45. %linux-libre-headers-bootstrap-tarball
  46. %binutils-bootstrap-tarball
  47. %glibc-bootstrap-tarball
  48. %gcc-bootstrap-tarball
  49. %guile-bootstrap-tarball
  50. %mescc-tools-bootstrap-tarball
  51. %mes-bootstrap-tarball
  52. %bootstrap-tarballs
  53. %guile-static-stripped))
  54. ;;; Commentary:
  55. ;;;
  56. ;;; This module provides tools to build tarballs of the "bootstrap binaries"
  57. ;;; used in (gnu packages bootstrap). These statically-linked binaries are
  58. ;;; taken for granted and used as the root of the whole bootstrap procedure.
  59. ;;;
  60. ;;; Code:
  61. (define* (glibc-for-bootstrap #:optional (base glibc))
  62. "Return a libc deriving from BASE whose `system' and `popen' functions looks
  63. for `sh' in $PATH, and without nscd, and with static NSS modules."
  64. (package (inherit base)
  65. (source (origin (inherit (package-source base))
  66. (patches (cons (search-patch "glibc-bootstrap-system.patch")
  67. (origin-patches (package-source base))))))
  68. (arguments
  69. (substitute-keyword-arguments (package-arguments base)
  70. ((#:configure-flags flags)
  71. ;; Arrange so that getaddrinfo & co. do not contact the nscd,
  72. ;; and can use statically-linked NSS modules.
  73. `(cons* "--disable-nscd" "--disable-build-nscd"
  74. "--enable-static-nss"
  75. ,flags))))
  76. ;; Remove the 'debug' output to allow bit-reproducible builds (when the
  77. ;; 'debug' output is used, ELF files end up with a .gnu_debuglink, which
  78. ;; includes a CRC of the corresponding debugging symbols; those symbols
  79. ;; contain store file names, so the CRC changes at every rebuild.)
  80. (outputs (delete "debug" (package-outputs base)))))
  81. (define (package-with-relocatable-glibc p)
  82. "Return a variant of P that uses the libc as defined by
  83. `glibc-for-bootstrap'."
  84. (define (cross-bootstrap-libc)
  85. (let ((target (%current-target-system)))
  86. (glibc-for-bootstrap
  87. ;; `cross-libc' already returns a cross libc, so clear
  88. ;; %CURRENT-TARGET-SYSTEM.
  89. (parameterize ((%current-target-system #f))
  90. (cross-libc target)))))
  91. ;; Standard inputs with the above libc and corresponding GCC.
  92. (define (inputs)
  93. (if (%current-target-system) ; is this package cross built?
  94. `(("cross-libc" ,(cross-bootstrap-libc)))
  95. '()))
  96. (define (native-inputs)
  97. (if (%current-target-system)
  98. (let ((target (%current-target-system)))
  99. `(("cross-gcc" ,(cross-gcc target
  100. #:xbinutils (cross-binutils target)
  101. #:libc (cross-bootstrap-libc)))
  102. ("cross-binutils" ,(cross-binutils target))
  103. ,@(%final-inputs)))
  104. `(("libc" ,(glibc-for-bootstrap))
  105. ("libc:static" ,(glibc-for-bootstrap) "static")
  106. ("gcc" ,(package (inherit gcc)
  107. (outputs '("out")) ; all in one so libgcc_s is easily found
  108. (inputs
  109. `(("libc" ,(glibc-for-bootstrap))
  110. ("libc:static" ,(glibc-for-bootstrap) "static")
  111. ,@(package-inputs gcc)))))
  112. ,@(fold alist-delete (%final-inputs) '("libc" "gcc")))))
  113. (package-with-explicit-inputs p inputs
  114. (current-source-location)
  115. #:native-inputs native-inputs))
  116. (define %static-inputs
  117. ;; Packages that are to be used as %BOOTSTRAP-INPUTS.
  118. (let ((coreutils (package (inherit coreutils)
  119. (arguments
  120. `(#:configure-flags
  121. '("--disable-nls"
  122. "--disable-silent-rules"
  123. "--enable-no-install-program=stdbuf,libstdbuf.so"
  124. "CFLAGS=-Os -g0" ; smaller, please
  125. "LDFLAGS=-static -pthread")
  126. #:tests? #f ; signal-related Gnulib tests fail
  127. ,@(package-arguments coreutils)))
  128. ;; Remove optional dependencies such as GMP. Keep Perl
  129. ;; except if it's missing (which is the case when
  130. ;; cross-compiling).
  131. (inputs (match (assoc "perl" (package-inputs coreutils))
  132. (#f '())
  133. (x (list x))))
  134. ;; Remove the 'debug' output (see above for the reason.)
  135. (outputs '("out"))))
  136. (bzip2 (package (inherit bzip2)
  137. (arguments
  138. (substitute-keyword-arguments (package-arguments bzip2)
  139. ((#:phases phases)
  140. `(modify-phases ,phases
  141. (add-before 'build 'dash-static
  142. (lambda _
  143. (substitute* "Makefile"
  144. (("^LDFLAGS[[:blank:]]*=.*$")
  145. "LDFLAGS = -static"))
  146. #t))))))))
  147. (xz (package (inherit xz)
  148. (outputs '("out"))
  149. (arguments
  150. `(#:strip-flags '("--strip-all")
  151. #:phases (modify-phases %standard-phases
  152. (add-before 'configure 'static-executable
  153. (lambda _
  154. ;; Ask Libtool for a static executable.
  155. (substitute* "src/xz/Makefile.in"
  156. (("^xz_LDADD =")
  157. "xz_LDADD = -all-static"))
  158. #t)))))))
  159. (gawk (package (inherit gawk)
  160. (source (origin (inherit (package-source gawk))
  161. (patches (cons (search-patch "gawk-shell.patch")
  162. (origin-patches
  163. (package-source gawk))))))
  164. (arguments
  165. `(;; Starting from gawk 4.1.0, some of the tests for the
  166. ;; plug-in mechanism just fail on static builds:
  167. ;;
  168. ;; ./fts.awk:1: error: can't open shared library `filefuncs' for reading (No such file or directory)
  169. #:tests? #f
  170. ,@(substitute-keyword-arguments (package-arguments gawk)
  171. ((#:phases phases)
  172. `(modify-phases ,phases
  173. (add-before 'configure 'no-export-dynamic
  174. (lambda _
  175. ;; Since we use `-static', remove
  176. ;; `-export-dynamic'.
  177. (substitute* "configure"
  178. (("-Wl,-export-dynamic") ""))
  179. #t)))))))
  180. (inputs (if (%current-target-system)
  181. `(("bash" ,static-bash))
  182. '()))))
  183. (tar (package (inherit tar)
  184. (arguments
  185. (substitute-keyword-arguments (package-arguments tar)
  186. ((#:phases phases)
  187. `(modify-phases ,phases
  188. (replace 'set-shell-file-name
  189. (lambda _
  190. ;; Do not use "/bin/sh" to run programs; see
  191. ;; <http://lists.gnu.org/archive/html/guix-devel/2016-09/msg02272.html>.
  192. (substitute* "src/system.c"
  193. (("/bin/sh") "sh")
  194. (("execv ") "execvp "))
  195. #t))))))))
  196. ;; We don't want to retain a reference to /gnu/store in the bootstrap
  197. ;; versions of egrep/fgrep, so we remove the custom phase added since
  198. ;; grep@2.25. The effect is 'egrep' and 'fgrep' look for 'grep' in
  199. ;; $PATH.
  200. (grep (package
  201. (inherit grep)
  202. (inputs '()) ;remove PCRE, which is optional
  203. (arguments
  204. (substitute-keyword-arguments (package-arguments grep)
  205. ((#:phases phases)
  206. `(modify-phases ,phases
  207. (delete 'fix-egrep-and-fgrep)))))))
  208. (finalize (compose static-package
  209. package-with-relocatable-glibc)))
  210. `(,@(map (match-lambda
  211. ((name package)
  212. (list name (finalize package))))
  213. `(("tar" ,tar)
  214. ("gzip" ,gzip)
  215. ("bzip2" ,bzip2)
  216. ("xz" ,xz)
  217. ("patch" ,patch)
  218. ("coreutils" ,coreutils)
  219. ("sed" ,sed)
  220. ("grep" ,grep)
  221. ("gawk" ,gawk)))
  222. ("bash" ,static-bash))))
  223. (define %static-binaries
  224. (package
  225. (name "static-binaries")
  226. (version "0")
  227. (build-system trivial-build-system)
  228. (source #f)
  229. (inputs %static-inputs)
  230. (arguments
  231. `(#:modules ((guix build utils))
  232. #:builder
  233. (begin
  234. (use-modules (ice-9 ftw)
  235. (ice-9 match)
  236. (srfi srfi-1)
  237. (srfi srfi-26)
  238. (guix build utils))
  239. (let ()
  240. (define (directory-contents dir)
  241. (map (cut string-append dir "/" <>)
  242. (scandir dir (negate (cut member <> '("." ".."))))))
  243. (define (copy-directory source destination)
  244. (for-each (lambda (file)
  245. (format #t "copying ~s...~%" file)
  246. (copy-file file
  247. (string-append destination "/"
  248. (basename file))))
  249. (directory-contents source)))
  250. (let* ((out (assoc-ref %outputs "out"))
  251. (bin (string-append out "/bin")))
  252. (mkdir-p bin)
  253. ;; Copy Coreutils binaries.
  254. (let* ((coreutils (assoc-ref %build-inputs "coreutils"))
  255. (source (string-append coreutils "/bin")))
  256. (copy-directory source bin))
  257. ;; For the other inputs, copy just one binary, which has the
  258. ;; same name as the input.
  259. (for-each (match-lambda
  260. ((name . dir)
  261. (let ((source (string-append dir "/bin/" name)))
  262. (format #t "copying ~s...~%" source)
  263. (copy-file source
  264. (string-append bin "/" name)))))
  265. (alist-delete "coreutils" %build-inputs))
  266. ;; But of course, there are exceptions to this rule.
  267. (let ((grep (assoc-ref %build-inputs "grep")))
  268. (install-file (string-append grep "/bin/fgrep") bin)
  269. (install-file (string-append grep "/bin/egrep") bin))
  270. ;; Clear references to the store path.
  271. (for-each remove-store-references
  272. (directory-contents bin))
  273. (with-directory-excursion bin
  274. ;; Programs such as Perl's build system want these aliases.
  275. (symlink "bash" "sh")
  276. (symlink "gawk" "awk"))
  277. #t)))))
  278. (synopsis "Statically-linked bootstrap binaries")
  279. (description
  280. "Binaries used to bootstrap the distribution.")
  281. (license gpl3+)
  282. (home-page #f)))
  283. (define %linux-libre-headers-stripped
  284. ;; The subset of Linux-Libre-Headers that we need.
  285. (package (inherit linux-libre-headers)
  286. (name (string-append (package-name linux-libre-headers) "-stripped"))
  287. (build-system trivial-build-system)
  288. (outputs '("out"))
  289. (arguments
  290. `(#:modules ((guix build utils)
  291. (guix build make-bootstrap))
  292. #:builder
  293. (begin
  294. (use-modules (guix build utils)
  295. (guix build make-bootstrap))
  296. (let* ((in (assoc-ref %build-inputs "linux-libre-headers"))
  297. (out (assoc-ref %outputs "out")))
  298. (copy-linux-headers out in)
  299. #t))))
  300. (inputs `(("linux-libre-headers" ,linux-libre-headers)))))
  301. (define %binutils-static
  302. ;; Statically-linked Binutils.
  303. (package (inherit binutils)
  304. (name "binutils-static")
  305. (arguments
  306. `(#:configure-flags (cons "--disable-gold"
  307. ,(match (memq #:configure-flags
  308. (package-arguments binutils))
  309. ((#:configure-flags flags _ ...)
  310. flags)))
  311. #:strip-flags '("--strip-all")
  312. #:phases (modify-phases %standard-phases
  313. (add-before 'configure 'all-static
  314. (lambda _
  315. ;; The `-all-static' libtool flag can only be passed
  316. ;; after `configure', since configure tests don't use
  317. ;; libtool, and only for executables built with libtool.
  318. (substitute* '("binutils/Makefile.in"
  319. "gas/Makefile.in"
  320. "ld/Makefile.in")
  321. (("^LDFLAGS =(.*)$" line)
  322. (string-append line
  323. "\nAM_LDFLAGS = -static -all-static\n")))
  324. #t)))))))
  325. (define %binutils-static-stripped
  326. ;; The subset of Binutils that we need.
  327. (package (inherit %binutils-static)
  328. (name (string-append (package-name %binutils-static) "-stripped"))
  329. (build-system trivial-build-system)
  330. (outputs '("out"))
  331. (arguments
  332. `(#:modules ((guix build utils))
  333. #:builder
  334. (begin
  335. (use-modules (guix build utils))
  336. (setvbuf (current-output-port) _IOLBF)
  337. (let* ((in (assoc-ref %build-inputs "binutils"))
  338. (out (assoc-ref %outputs "out"))
  339. (bin (string-append out "/bin")))
  340. (mkdir-p bin)
  341. (for-each (lambda (file)
  342. (let ((target (string-append bin "/" file)))
  343. (format #t "copying `~a'...~%" file)
  344. (copy-file (string-append in "/bin/" file)
  345. target)
  346. (remove-store-references target)))
  347. '("ar" "as" "ld" "nm" "objcopy" "objdump"
  348. "ranlib" "readelf" "size" "strings" "strip"))
  349. #t))))
  350. (inputs `(("binutils" ,%binutils-static)))))
  351. (define (%glibc-stripped)
  352. ;; GNU libc's essential shared libraries, dynamic linker, and headers,
  353. ;; with all references to store directories stripped. As a result,
  354. ;; libc.so is unusable and need to be patched for proper relocation.
  355. (let ((glibc (glibc-for-bootstrap)))
  356. (package (inherit glibc)
  357. (name "glibc-stripped")
  358. (build-system trivial-build-system)
  359. (arguments
  360. `(#:modules ((guix build utils)
  361. (guix build make-bootstrap))
  362. #:builder
  363. (begin
  364. (use-modules (guix build make-bootstrap))
  365. (make-stripped-libc (assoc-ref %outputs "out")
  366. (assoc-ref %build-inputs "libc")
  367. (assoc-ref %build-inputs "kernel-headers")))))
  368. (inputs `(("kernel-headers"
  369. ,(if (or (and (%current-target-system)
  370. (hurd-triplet? (%current-target-system)))
  371. (string-suffix? "-hurd" (%current-system)))
  372. gnumach-headers
  373. linux-libre-headers))
  374. ("libc" ,(let ((target (%current-target-system)))
  375. (if target
  376. (glibc-for-bootstrap
  377. (parameterize ((%current-target-system #f))
  378. (cross-libc target)))
  379. glibc)))))
  380. ;; Only one output.
  381. (outputs '("out")))))
  382. (define %gcc-static
  383. ;; A statically-linked GCC, with stripped-down functionality.
  384. (package-with-relocatable-glibc
  385. (package (inherit gcc)
  386. (name "gcc-static")
  387. (outputs '("out")) ; all in one
  388. (arguments
  389. `(#:modules ((guix build utils)
  390. (guix build gnu-build-system)
  391. (srfi srfi-1)
  392. (srfi srfi-26)
  393. (ice-9 regex))
  394. ,@(substitute-keyword-arguments (package-arguments gcc)
  395. ((#:guile _) #f)
  396. ((#:implicit-inputs? _) #t)
  397. ((#:configure-flags flags)
  398. `(append (list
  399. ;; We don't need a full bootstrap here.
  400. "--disable-bootstrap"
  401. ;; Make sure '-static' is passed where it matters.
  402. "--with-stage1-ldflags=-static"
  403. ;; GCC 4.8+ requires a C++ compiler and library.
  404. "--enable-languages=c,c++"
  405. ;; Make sure gcc-nm doesn't require liblto_plugin.so.
  406. "--disable-lto"
  407. "--disable-shared"
  408. "--disable-plugin"
  409. "--disable-libmudflap"
  410. "--disable-libatomic"
  411. "--disable-libsanitizer"
  412. "--disable-libitm"
  413. "--disable-libgomp"
  414. "--disable-libcilkrts"
  415. "--disable-libvtv"
  416. "--disable-libssp"
  417. "--disable-libquadmath")
  418. (remove (cut string-match "--(.*plugin|enable-languages)" <>)
  419. ,flags)))
  420. ((#:phases phases)
  421. `(modify-phases ,phases
  422. (add-after 'pre-configure 'remove-lgcc_s
  423. (lambda _
  424. ;; Remove the '-lgcc_s' added to GNU_USER_TARGET_LIB_SPEC in
  425. ;; the 'pre-configure phase of our main gcc package, because
  426. ;; that shared library is not present in this static gcc. See
  427. ;; <https://lists.gnu.org/archive/html/guix-devel/2015-01/msg00008.html>.
  428. (substitute* (cons "gcc/config/rs6000/sysv4.h"
  429. (find-files "gcc/config"
  430. "^gnu-user.*\\.h$"))
  431. ((" -lgcc_s}}") "}}"))
  432. #t)))))))
  433. (inputs
  434. `(("zlib:static" ,zlib "static")
  435. ,@(package-inputs gcc)))
  436. (native-inputs
  437. (if (%current-target-system)
  438. `(;; When doing a Canadian cross, we need GMP/MPFR/MPC both
  439. ;; as target inputs and as native inputs; the latter is
  440. ;; needed when building build-time tools ('genconstants',
  441. ;; etc.) Failing to do that leads to misdetections of
  442. ;; declarations by 'gcc/configure', and eventually to
  443. ;; duplicate declarations as reported in
  444. ;; <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59217>.
  445. ("gmp-native" ,gmp)
  446. ("mpfr-native" ,mpfr)
  447. ("mpc-native" ,mpc)
  448. ,@(package-native-inputs gcc))
  449. (package-native-inputs gcc))))))
  450. (define %gcc-stripped
  451. ;; The subset of GCC files needed for bootstrap.
  452. (package (inherit gcc)
  453. (name "gcc-stripped")
  454. (build-system trivial-build-system)
  455. (source #f)
  456. (outputs '("out")) ;only one output
  457. (arguments
  458. `(#:modules ((guix build utils))
  459. #:builder
  460. (begin
  461. (use-modules (srfi srfi-1)
  462. (srfi srfi-26)
  463. (guix build utils))
  464. (setvbuf (current-output-port) _IOLBF)
  465. (let* ((out (assoc-ref %outputs "out"))
  466. (bindir (string-append out "/bin"))
  467. (libdir (string-append out "/lib"))
  468. (includedir (string-append out "/include"))
  469. (libexecdir (string-append out "/libexec"))
  470. (gcc (assoc-ref %build-inputs "gcc")))
  471. (copy-recursively (string-append gcc "/bin") bindir)
  472. (for-each remove-store-references
  473. (find-files bindir ".*"))
  474. (copy-recursively (string-append gcc "/lib") libdir)
  475. (for-each remove-store-references
  476. (remove (cut string-suffix? ".h" <>)
  477. (find-files libdir ".*")))
  478. (copy-recursively (string-append gcc "/libexec")
  479. libexecdir)
  480. (for-each remove-store-references
  481. (find-files libexecdir ".*"))
  482. ;; Starting from GCC 4.8, helper programs built natively
  483. ;; (‘genchecksum’, ‘gcc-nm’, etc.) rely on C++ headers.
  484. (copy-recursively (string-append gcc "/include/c++")
  485. (string-append includedir "/c++"))
  486. ;; For native builds, check whether the binaries actually work.
  487. ,@(if (%current-target-system)
  488. '()
  489. '((for-each (lambda (prog)
  490. (invoke (string-append gcc "/bin/" prog)
  491. "--version"))
  492. '("gcc" "g++" "cpp"))))
  493. #t))))
  494. (inputs `(("gcc" ,%gcc-static)))))
  495. (define %mescc-tools-static
  496. ;; A statically linked MesCC Tools for bootstrap.
  497. (package
  498. (inherit mescc-tools)
  499. (name "mescc-tools-static")
  500. (arguments
  501. `(#:system "i686-linux"
  502. ,@(substitute-keyword-arguments (package-arguments mescc-tools)
  503. ((#:make-flags flags)
  504. `(cons "CC=gcc -static" ,flags)))))))
  505. (define %mes-minimal
  506. ;; A minimal Mes without documentation dependencies, for bootstrap.
  507. (let ((triplet "i686-unknown-linux-gnu"))
  508. (package
  509. (inherit mes)
  510. (name "mes-minimal")
  511. (native-inputs
  512. `(("guile" ,guile-2.2)))
  513. (arguments
  514. `(#:system "i686-linux"
  515. #:strip-binaries? #f
  516. #:phases
  517. (modify-phases %standard-phases
  518. (add-before 'configure 'optional-dot
  519. (lambda _
  520. (substitute* "configure"
  521. (("#:version-option \"-V\"" all)
  522. (string-append all "#:optional? #t")))))))))))
  523. (define-public %mes-minimal-stripped
  524. ;; The subset of Mes files needed for bootstrap.
  525. (package
  526. (inherit %mes-minimal)
  527. (name "mes-minimal-stripped")
  528. (build-system trivial-build-system)
  529. (source #f)
  530. (arguments
  531. `(#:modules ((guix build utils))
  532. #:builder
  533. (begin
  534. (use-modules (srfi srfi-1)
  535. (srfi srfi-26)
  536. (guix build utils))
  537. (setvbuf (current-output-port) _IOLBF)
  538. (let* ((out (assoc-ref %outputs "out"))
  539. (bindir (string-append out "/bin"))
  540. (libdir (string-append out "/lib"))
  541. (mes (assoc-ref %build-inputs "mes")))
  542. (copy-recursively (string-append mes "/bin") bindir)
  543. (copy-recursively (string-append mes "/lib") libdir)
  544. (copy-recursively (string-append mes "/share/mes/lib") libdir)
  545. (for-each remove-store-references
  546. (remove (lambda (file) (or (string-suffix? ".h" file)
  547. (string-suffix? ".c" file)))
  548. (find-files out ".*")))
  549. #t))))
  550. (inputs `(("mes" ,%mes-minimal)))))
  551. (define %guile-static
  552. ;; A statically-linked Guile that is relocatable--i.e., it can search
  553. ;; .scm and .go files relative to its installation directory, rather
  554. ;; than in hard-coded configure-time paths.
  555. (let* ((patches (cons* (search-patch "guile-relocatable.patch")
  556. (search-patch "guile-2.2-default-utf8.patch")
  557. (search-patch "guile-linux-syscalls.patch")
  558. (origin-patches (package-source guile-2.2))))
  559. (source (origin (inherit (package-source guile-2.2))
  560. (patches patches)))
  561. (guile (package (inherit guile-2.2)
  562. (name (string-append (package-name guile-2.2) "-static"))
  563. (source source)
  564. (synopsis "Statically-linked and relocatable Guile")
  565. ;; Remove the 'debug' output (see above for the reason.)
  566. (outputs (delete "debug" (package-outputs guile-2.2)))
  567. (inputs
  568. `(("libunistring:static" ,libunistring "static")
  569. ,@(package-inputs guile-2.2)))
  570. (propagated-inputs
  571. `(("bdw-gc" ,libgc)
  572. ,@(alist-delete "bdw-gc"
  573. (package-propagated-inputs guile-2.2))))
  574. (arguments
  575. (substitute-keyword-arguments (package-arguments guile-2.2)
  576. ((#:configure-flags flags '())
  577. ;; When `configure' checks for ltdl availability, it
  578. ;; doesn't try to link using libtool, and thus fails
  579. ;; because of a missing -ldl. Work around that.
  580. ''("LDFLAGS=-ldl"))
  581. ((#:phases phases '%standard-phases)
  582. `(modify-phases ,phases
  583. ;; Do not record the absolute file name of 'sh' in
  584. ;; (ice-9 popen). This makes 'open-pipe' unusable in
  585. ;; a build chroot ('open-pipe*' is fine) but avoids
  586. ;; keeping a reference to Bash.
  587. (delete 'pre-configure)
  588. (add-before 'configure 'static-guile
  589. (lambda _
  590. (substitute* "libguile/Makefile.in"
  591. ;; Create a statically-linked `guile'
  592. ;; executable.
  593. (("^guile_LDFLAGS =")
  594. "guile_LDFLAGS = -all-static")
  595. ;; Add `-ldl' *after* libguile-2.2.la.
  596. (("^guile_LDADD =(.*)$" _ ldadd)
  597. (string-append "guile_LDADD = "
  598. (string-trim-right ldadd)
  599. " -ldl\n")))))))
  600. ((#:tests? _ #f)
  601. ;; There are uses of `dynamic-link' in
  602. ;; {foreign,coverage}.test that don't fly here.
  603. #f))))))
  604. (package-with-relocatable-glibc (static-package guile))))
  605. (define %guile-static-stripped
  606. ;; A stripped static Guile binary, for use during bootstrap.
  607. (package (inherit %guile-static)
  608. (name "guile-static-stripped")
  609. (build-system trivial-build-system)
  610. (arguments
  611. ;; The end result should depend on nothing but itself.
  612. `(#:allowed-references ("out")
  613. #:modules ((guix build utils))
  614. #:builder
  615. (let ()
  616. (use-modules (guix build utils))
  617. (let* ((in (assoc-ref %build-inputs "guile"))
  618. (out (assoc-ref %outputs "out"))
  619. (guile1 (string-append in "/bin/guile"))
  620. (guile2 (string-append out "/bin/guile")))
  621. (mkdir-p (string-append out "/share/guile/2.2"))
  622. (copy-recursively (string-append in "/share/guile/2.2")
  623. (string-append out "/share/guile/2.2"))
  624. (mkdir-p (string-append out "/lib/guile/2.2/ccache"))
  625. (copy-recursively (string-append in "/lib/guile/2.2/ccache")
  626. (string-append out "/lib/guile/2.2/ccache"))
  627. (mkdir (string-append out "/bin"))
  628. (copy-file guile1 guile2)
  629. ;; Verify that the relocated Guile works.
  630. ,@(if (%current-target-system)
  631. '()
  632. '((invoke guile2 "--version")))
  633. ;; Strip store references.
  634. (remove-store-references guile2)
  635. ;; Verify that the stripped Guile works. If it aborts, it could be
  636. ;; that it tries to open iconv descriptors and fails because libc's
  637. ;; iconv data isn't available (see `guile-default-utf8.patch'.)
  638. ,@(if (%current-target-system)
  639. '()
  640. '((invoke guile2 "--version")))
  641. #t))))
  642. (inputs `(("guile" ,%guile-static)))
  643. (outputs '("out"))
  644. (synopsis "Minimal statically-linked and relocatable Guile")))
  645. (define (tarball-package pkg)
  646. "Return a package containing a tarball of PKG."
  647. (package (inherit pkg)
  648. (name (string-append (package-name pkg) "-tarball"))
  649. (build-system trivial-build-system)
  650. (native-inputs `(("tar" ,tar)
  651. ("xz" ,xz)))
  652. (inputs `(("input" ,pkg)))
  653. (arguments
  654. (let ((name (package-name pkg))
  655. (version (package-version pkg)))
  656. `(#:modules ((guix build utils))
  657. #:builder
  658. (begin
  659. (use-modules (guix build utils))
  660. (let ((out (assoc-ref %outputs "out"))
  661. (input (assoc-ref %build-inputs "input"))
  662. (tar (assoc-ref %build-inputs "tar"))
  663. (xz (assoc-ref %build-inputs "xz")))
  664. (mkdir out)
  665. (set-path-environment-variable "PATH" '("bin") (list tar xz))
  666. (with-directory-excursion input
  667. (invoke "tar" "cJvf"
  668. (string-append out "/"
  669. ,name "-" ,version
  670. "-"
  671. ,(or (%current-target-system)
  672. (%current-system))
  673. ".tar.xz")
  674. "."
  675. ;; avoid non-determinism in the archive
  676. "--sort=name" "--mtime=@0"
  677. "--owner=root:0" "--group=root:0")))))))))
  678. (define %bootstrap-binaries-tarball
  679. ;; A tarball with the statically-linked bootstrap binaries.
  680. (tarball-package %static-binaries))
  681. (define %linux-libre-headers-bootstrap-tarball
  682. ;; A tarball with the statically-linked Linux-Libre-Headers programs.
  683. (tarball-package %linux-libre-headers-stripped))
  684. (define %binutils-bootstrap-tarball
  685. ;; A tarball with the statically-linked Binutils programs.
  686. (tarball-package %binutils-static-stripped))
  687. (define (%glibc-bootstrap-tarball)
  688. ;; A tarball with GNU libc's shared libraries, dynamic linker, and headers.
  689. (tarball-package (%glibc-stripped)))
  690. (define %gcc-bootstrap-tarball
  691. ;; A tarball with a dynamic-linked GCC and its headers.
  692. (tarball-package %gcc-stripped))
  693. (define %guile-bootstrap-tarball
  694. ;; A tarball with the statically-linked, relocatable Guile.
  695. (tarball-package %guile-static-stripped))
  696. (define %mescc-tools-bootstrap-tarball
  697. ;; A tarball with MesCC binary seed.
  698. (tarball-package %mescc-tools-static))
  699. (define %mes-bootstrap-tarball
  700. ;; A tarball with Mes ASCII Seed and binary Mes C Library.
  701. (tarball-package %mes-minimal-stripped))
  702. (define %bootstrap-tarballs
  703. ;; A single derivation containing all the bootstrap tarballs, for
  704. ;; convenience.
  705. (package
  706. (name "bootstrap-tarballs")
  707. (version "0")
  708. (source #f)
  709. (build-system trivial-build-system)
  710. (arguments
  711. `(#:modules ((guix build utils))
  712. #:builder
  713. (let ((out (assoc-ref %outputs "out")))
  714. (use-modules (guix build utils)
  715. (ice-9 match)
  716. (srfi srfi-26))
  717. (setvbuf (current-output-port) _IOLBF)
  718. (mkdir out)
  719. (chdir out)
  720. (for-each (match-lambda
  721. ((name . directory)
  722. (for-each (lambda (file)
  723. (format #t "~a -> ~a~%" file out)
  724. (symlink file (basename file)))
  725. (find-files directory "\\.tar\\."))))
  726. %build-inputs)
  727. #t)))
  728. (inputs `(("guile-tarball" ,%guile-bootstrap-tarball)
  729. ,@(match (%current-system)
  730. ((or "i686-linux" "x86_64-linux")
  731. `(("bootstrap-mescc-tools" ,%mescc-tools-bootstrap-tarball)
  732. ("bootstrap-mes" ,%mes-bootstrap-tarball)
  733. ("bootstrap-linux-libre-headers"
  734. ,%linux-libre-headers-bootstrap-tarball)))
  735. (_ `(("gcc-tarball" ,%gcc-bootstrap-tarball)
  736. ("binutils-tarball" ,%binutils-bootstrap-tarball)
  737. ("glibc-tarball" ,(%glibc-bootstrap-tarball)))))
  738. ("coreutils&co-tarball" ,%bootstrap-binaries-tarball)))
  739. (synopsis "Tarballs containing all the bootstrap binaries")
  740. (description synopsis)
  741. (home-page #f)
  742. (license gpl3+)))
  743. ;;; make-bootstrap.scm ends here