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.

924 lines
38 KiB

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