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.
 
 
 
 
 
 

1049 lines
43 KiB

  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2012, 2013 Ludovic Courtès <ludo@gnu.org>
  3. ;;; Copyright © 2012 Nikita Karetnikov <nikita@karetnikov.org>
  4. ;;;
  5. ;;; This file is part of GNU Guix.
  6. ;;;
  7. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  8. ;;; under the terms of the GNU General Public License as published by
  9. ;;; the Free Software Foundation; either version 3 of the License, or (at
  10. ;;; your option) any later version.
  11. ;;;
  12. ;;; GNU Guix is distributed in the hope that it will be useful, but
  13. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  14. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. ;;; GNU General Public License for more details.
  16. ;;;
  17. ;;; You should have received a copy of the GNU General Public License
  18. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  19. (define-module (gnu packages base)
  20. #:use-module ((guix licenses)
  21. #:select (gpl3+ lgpl2.0+ public-domain))
  22. #:use-module (gnu packages)
  23. #:use-module (gnu packages acl)
  24. #:use-module (gnu packages bash)
  25. #:use-module (gnu packages bootstrap)
  26. #:use-module (gnu packages compression)
  27. #:use-module (gnu packages gcc)
  28. #:use-module (gnu packages gawk)
  29. #:use-module (gnu packages guile)
  30. #:use-module (gnu packages multiprecision)
  31. #:use-module (gnu packages perl)
  32. #:use-module (gnu packages linux)
  33. #:use-module (guix packages)
  34. #:use-module (guix download)
  35. #:use-module (guix build-system gnu)
  36. #:use-module (guix build-system trivial)
  37. #:use-module (guix utils)
  38. #:use-module (srfi srfi-1)
  39. #:use-module (srfi srfi-26)
  40. #:use-module (ice-9 match))
  41. ;;; Commentary:
  42. ;;;
  43. ;;; Base packages of the Guix-based GNU user-land software distribution.
  44. ;;;
  45. ;;; Code:
  46. (define-public hello
  47. (package
  48. (name "hello")
  49. (version "2.8")
  50. (source (origin
  51. (method url-fetch)
  52. (uri (string-append "mirror://gnu/hello/hello-" version
  53. ".tar.gz"))
  54. (sha256
  55. (base32 "0wqd8sjmxfskrflaxywc7gqw7sfawrfvdxd9skxawzfgyy0pzdz6"))))
  56. (build-system gnu-build-system)
  57. (arguments '(#:configure-flags
  58. `("--disable-dependency-tracking"
  59. ,(string-append "--with-gawk=" ; for illustration purposes
  60. (assoc-ref %build-inputs "gawk")))))
  61. (inputs `(("gawk" ,gawk)))
  62. (synopsis "Hello, GNU world: An example GNU package")
  63. (description
  64. "GNU Hello prints the message \"Hello, world!\" and then exits. It
  65. serves as an example of standard GNU coding practices. As such, it supports
  66. command-line arguments, multiple languages, and so on.")
  67. (home-page "http://www.gnu.org/software/hello/")
  68. (license gpl3+)))
  69. (define-public grep
  70. (package
  71. (name "grep")
  72. (version "2.15")
  73. (source (origin
  74. (method url-fetch)
  75. (uri (string-append "mirror://gnu/grep/grep-"
  76. version ".tar.xz"))
  77. (sha256
  78. (base32
  79. "052kjsafg2x7n2zpy3iw4pzwf8fdfng5pcvi9v3chx3rb1786nmz"))))
  80. (build-system gnu-build-system)
  81. (synopsis "Print lines matching a pattern")
  82. (description
  83. "grep is a tool for finding text inside files. Text is found by
  84. matching a pattern provided by the user in one or many files. The pattern
  85. may be provided as a basic, extended, or Perl-style regular expression, as
  86. well as a list of fixed strings. By default, the matching text is simply
  87. printed to the screen, however the output can be greatly customized to
  88. include, for example, line numbers.")
  89. (license gpl3+)
  90. (home-page "http://www.gnu.org/software/grep/")))
  91. (define-public sed
  92. (package
  93. (name "sed")
  94. (version "4.2.2")
  95. (source (origin
  96. (method url-fetch)
  97. (uri (string-append "mirror://gnu/sed/sed-" version
  98. ".tar.bz2"))
  99. (sha256
  100. (base32
  101. "1myvrmh99jsvk7v3d7crm0gcrq51hmmm1r2kjyyci152in1x2j7h"))))
  102. (build-system gnu-build-system)
  103. (synopsis "Stream editor")
  104. (arguments
  105. (if (%current-target-system)
  106. '()
  107. `(#:phases (alist-cons-before
  108. 'patch-source-shebangs 'patch-test-suite
  109. (lambda* (#:key inputs #:allow-other-keys)
  110. (let ((bash (assoc-ref inputs "bash")))
  111. (patch-makefile-SHELL "testsuite/Makefile.tests")
  112. (substitute* '("testsuite/bsd.sh"
  113. "testsuite/bug-regex9.c")
  114. (("/bin/sh")
  115. (string-append bash "/bin/bash")))))
  116. %standard-phases))))
  117. (description
  118. "Sed is a non-interactive, text stream editor. It receives a text
  119. input from a file or from standard input and it then applies a series of text
  120. editing commands to the stream and prints its output to standard output. It
  121. is often used for substituting text patterns in a stream.")
  122. (license gpl3+)
  123. (home-page "http://www.gnu.org/software/sed/")))
  124. (define-public tar
  125. (package
  126. (name "tar")
  127. (version "1.27")
  128. (source (origin
  129. (method url-fetch)
  130. (uri (string-append "mirror://gnu/tar/tar-"
  131. version ".tar.bz2"))
  132. (sha256
  133. (base32
  134. "0yrwmx2f721ahpnki4fnzvnmrd3md3bq417icb4wrjky7k3caf12"))))
  135. (build-system gnu-build-system)
  136. (synopsis "Managing tar archives")
  137. (description
  138. "Tar provides the ability to create tar archives, as well as the
  139. ability to extract, update or list files in an existing archive. It is
  140. useful for combining many files into one larger file, while maintaining
  141. directory structure and file information such as permissions and
  142. creation/modification dates.")
  143. (license gpl3+)
  144. (home-page "http://www.gnu.org/software/tar/")))
  145. (define-public patch
  146. (package
  147. (name "patch")
  148. (version "2.7.1")
  149. (source (origin
  150. (method url-fetch)
  151. (uri (string-append "mirror://gnu/patch/patch-"
  152. version ".tar.xz"))
  153. (sha256
  154. (base32
  155. "1sqckf560pzwgniy00vcpdv2c9c11s4cmhlm14yqgg8avd3bl94i"))))
  156. (build-system gnu-build-system)
  157. (native-inputs '()) ; FIXME: needs `ed' for the tests
  158. (arguments
  159. '(#:tests? #f)
  160. ;; TODO: When cross-compiling, add this:
  161. ;; '(#:configure-flags '("ac_cv_func_strnlen_working=yes"))
  162. )
  163. (synopsis "Apply differences to originals, with optional backups")
  164. (description
  165. "Patch is a program that applies changes to files based on differences
  166. laid out by the program \"diff\". The changes may be applied to one or more
  167. files depending on the contents of the diff file. It accepts several
  168. different diff formats. It may also be used to revert previously applied
  169. differences.")
  170. (license gpl3+)
  171. (home-page "http://savannah.gnu.org/projects/patch/")))
  172. (define-public diffutils
  173. (package
  174. (name "diffutils")
  175. (version "3.3")
  176. (source (origin
  177. (method url-fetch)
  178. (uri (string-append "mirror://gnu/diffutils/diffutils-"
  179. version ".tar.xz"))
  180. (sha256
  181. (base32
  182. "1761vymxbp4wb5rzjvabhdkskk95pghnn67464byvzb5mfl8jpm2"))))
  183. (build-system gnu-build-system)
  184. (synopsis "Comparing and merging files")
  185. (description
  186. "Diffutils is a package containing several tool for finding the
  187. differences between files. The diff command is used to show how two files
  188. differ, while cmp shows the offsets and line numbers where they differ.
  189. diff3 allows you to compare three files. Finally, sdiff offers an
  190. interactive means to merge two files.")
  191. (license gpl3+)
  192. (home-page "http://www.gnu.org/software/diffutils/")))
  193. (define-public findutils
  194. (package
  195. (name "findutils")
  196. (version "4.4.2")
  197. (source (origin
  198. (method url-fetch)
  199. (uri (string-append "mirror://gnu/findutils/findutils-"
  200. version ".tar.gz"))
  201. (sha256
  202. (base32
  203. "0amn0bbwqvsvvsh6drfwz20ydc2czk374lzw5kksbh6bf78k4ks3"))
  204. (patches (list (search-patch "findutils-absolute-paths.patch")))))
  205. (build-system gnu-build-system)
  206. (arguments
  207. ;; Work around cross-compilation failure.
  208. ;; See <http://savannah.gnu.org/bugs/?27299#comment1>.
  209. (if (%current-target-system)
  210. '(#:configure-flags '("gl_cv_func_wcwidth_works=yes"))
  211. '()))
  212. (synopsis "Operating on files matching given criteria")
  213. (description
  214. "Findutils supplies the basic file directory searching utilities of the
  215. GNU system. It consists of two primary searching utilities: \"find\"
  216. recursively searches for files in a directory according to given criteria and
  217. \"locate\" lists files in a database that match a query. Two auxiliary tools
  218. are included: \"updatedb\" updates a file name database and \"xargs\" may be used
  219. to apply commands to file search results.")
  220. (license gpl3+)
  221. (home-page "http://www.gnu.org/software/findutils/")))
  222. (define-public coreutils
  223. (package
  224. (name "coreutils")
  225. (version "8.21")
  226. (source (origin
  227. (method url-fetch)
  228. (uri (string-append "mirror://gnu/coreutils/coreutils-"
  229. version ".tar.xz"))
  230. (sha256
  231. (base32
  232. "064f512185iysqqcvhnhaf3bfmzrvcgs7n405qsyp99zmfyl9amd"))))
  233. (build-system gnu-build-system)
  234. (inputs `(("acl" ,acl) ; TODO: add SELinux
  235. ("gmp" ,gmp)
  236. ;; Perl is needed to run tests; remove it from cross builds.
  237. ,@(if (%current-target-system)
  238. '()
  239. `(("perl" ,perl)))))
  240. (outputs '("out" "debug"))
  241. (arguments
  242. `(#:parallel-build? #f ; help2man may be called too early
  243. #:phases (alist-cons-before
  244. 'build 'patch-shell-references
  245. (lambda* (#:key inputs #:allow-other-keys)
  246. (let ((bash (assoc-ref inputs "bash")))
  247. (substitute* (cons "src/split.c"
  248. (find-files "gnulib-tests"
  249. "\\.c$"))
  250. (("/bin/sh")
  251. (format #f "~a/bin/sh" bash)))
  252. (substitute* (find-files "tests" "\\.sh$")
  253. (("#!/bin/sh")
  254. (format #f "#!~a/bin/bash" bash)))))
  255. %standard-phases)))
  256. (synopsis "Core GNU utilities (file, text, shell)")
  257. (description
  258. "Coreutils includes all of the basic commandline tools that are
  259. expected in a POSIX system. These provide the basic file, shell and text
  260. manipulation functions of the GNU system. Most of these tools offer extended
  261. functionality beyond that which is outlined in the POSIX standard.")
  262. (license gpl3+)
  263. (home-page "http://www.gnu.org/software/coreutils/")))
  264. (define-public gnu-make
  265. (package
  266. (name "make")
  267. (version "4.0")
  268. (source (origin
  269. (method url-fetch)
  270. (uri (string-append "mirror://gnu/make/make-" version
  271. ".tar.bz2"))
  272. (sha256
  273. (base32
  274. "1nyvn8mknw0mf7727lprva3lisl1y0n03lvar342rrpdmz3qc1p6"))
  275. (patches (list (search-patch "make-impure-dirs.patch")))))
  276. (build-system gnu-build-system)
  277. (inputs `(("guile" ,guile-2.0)))
  278. (outputs '("out" "debug"))
  279. (arguments
  280. '(#:phases (alist-cons-before
  281. 'build 'set-default-shell
  282. (lambda* (#:key inputs #:allow-other-keys)
  283. ;; Change the default shell from /bin/sh.
  284. (let ((bash (assoc-ref inputs "bash")))
  285. (substitute* "job.c"
  286. (("default_shell\\[\\] =.*$")
  287. (format #f "default_shell[] = \"~a/bin/bash\";\n"
  288. bash)))))
  289. %standard-phases)))
  290. (synopsis "Remake files automatically")
  291. (description
  292. "Make is a program that is used to control the production of
  293. executables or other files from their source files. The process is
  294. controlled from a Makefile, in which the developer specifies how each file is
  295. generated from its source. It has powerful dependency resolution and the
  296. ability to determine when files have to be regenerated after their sources
  297. change.")
  298. (license gpl3+)
  299. (home-page "http://www.gnu.org/software/make/")))
  300. (define-public binutils
  301. (package
  302. (name "binutils")
  303. (version "2.23.2")
  304. (source (origin
  305. (method url-fetch)
  306. (uri (string-append "mirror://gnu/binutils/binutils-"
  307. version ".tar.bz2"))
  308. (sha256
  309. (base32
  310. "15qhbkz3r266xaa52slh857qn3abw7rb2x2jnhpfrafpzrb4x4gy"))
  311. (patches (list (search-patch "binutils-ld-new-dtags.patch")
  312. (search-patch "binutils-loongson-workaround.patch")
  313. (search-patch "binutils-loongson-madd-fix.patch")))))
  314. (build-system gnu-build-system)
  315. ;; Split Binutils in several outputs, mostly to avoid collisions in
  316. ;; user profiles with GCC---e.g., libiberty.a.
  317. (outputs '("out" ; ar, ld, binutils.info, etc.
  318. "lib")) ; libbfd.a, bfd.h, etc.
  319. ;; TODO: Add dependency on zlib + those for Gold.
  320. (arguments
  321. `(#:configure-flags '(;; Add `-static-libgcc' to not retain a dependency
  322. ;; on GCC when bootstrapping.
  323. "LDFLAGS=-static-libgcc"
  324. ;; Don't search under /usr/lib & co.
  325. "--with-lib-path=/no-ld-lib-path"
  326. ;; Glibc 2.17 has a "comparison of unsigned
  327. ;; expression >= 0 is always true" in wchar.h.
  328. "--disable-werror")))
  329. (synopsis "Binary utilities: bfd gas gprof ld")
  330. (description
  331. "GNU Binutils is a collection of tools for working with binary files.
  332. Most notable are \"ld\", a linker, and \"as\", an assembler. Several other tools
  333. are included, such as a program to display binary profiling information, a
  334. tool to list the strings in a binary file, and tools for working with
  335. archives.")
  336. (license gpl3+)
  337. (home-page "http://www.gnu.org/software/binutils/")))
  338. (define-public glibc
  339. (package
  340. (name "glibc")
  341. (version "2.18")
  342. (source (origin
  343. (method url-fetch)
  344. (uri (string-append "mirror://gnu/glibc/glibc-"
  345. version ".tar.xz"))
  346. (sha256
  347. (base32
  348. "18spla703zav8dq9fw7rbzkyv9qfisxb26p7amg1x3wjh7iy3d1c"))
  349. (patches (map search-patch
  350. '("glibc-no-ld-so-cache.patch"
  351. "glibc-ldd-x86_64.patch"
  352. "glibc-make-4.0.patch")))))
  353. (build-system gnu-build-system)
  354. ;; Glibc's <limits.h> refers to <linux/limit.h>, for instance, so glibc
  355. ;; users should automatically pull Linux headers as well.
  356. (propagated-inputs `(("linux-headers" ,linux-libre-headers)))
  357. ;; Store the locales separately (~100 MiB). Note that "out" retains a
  358. ;; reference to them anyway, so there's no space savings here.
  359. ;; TODO: Eventually we may want to add a $LOCALE_ARCHIVE search path like
  360. ;; Nixpkgs does.
  361. (outputs '("out" "locales" "debug"))
  362. (arguments
  363. `(#:out-of-source? #t
  364. #:configure-flags
  365. (list "--enable-add-ons"
  366. "--sysconfdir=/etc"
  367. (string-append "--localedir=" (assoc-ref %outputs "locales")
  368. "/share/locale")
  369. ;; `--localedir' is not honored, so work around it.
  370. ;; See <http://sourceware.org/ml/libc-alpha/2013-03/msg00093.html>.
  371. (string-append "libc_cv_localedir="
  372. (assoc-ref %outputs "locales")
  373. "/share/locale")
  374. (string-append "--with-headers="
  375. (assoc-ref %build-inputs "linux-headers")
  376. "/include")
  377. ;; The default is to assume a 2.4 Linux interface, but we'll
  378. ;; always use something newer. See "kernel-features.h" in the
  379. ;; GNU libc for details.
  380. "--enable-kernel=2.6.30"
  381. ;; Use our Bash instead of /bin/sh.
  382. (string-append "BASH_SHELL="
  383. (assoc-ref %build-inputs "bash")
  384. "/bin/bash")
  385. ;; XXX: Work around "undefined reference to `__stack_chk_guard'".
  386. "libc_cv_ssp=no")
  387. #:tests? #f ; XXX
  388. #:phases (alist-cons-before
  389. 'configure 'pre-configure
  390. (lambda* (#:key inputs outputs #:allow-other-keys)
  391. (let* ((out (assoc-ref outputs "out"))
  392. (bin (string-append out "/bin")))
  393. ;; Use `pwd', not `/bin/pwd'.
  394. (substitute* "configure"
  395. (("/bin/pwd") "pwd"))
  396. ;; Install the rpc data base file under `$out/etc/rpc'.
  397. ;; FIXME: Use installFlags = [ "sysconfdir=$(out)/etc" ];
  398. (substitute* "sunrpc/Makefile"
  399. (("^\\$\\(inst_sysconfdir\\)/rpc(.*)$" _ suffix)
  400. (string-append out "/etc/rpc" suffix "\n"))
  401. (("^install-others =.*$")
  402. (string-append "install-others = " out "/etc/rpc\n")))
  403. (substitute* "Makeconfig"
  404. ;; According to
  405. ;; <http://www.linuxfromscratch.org/lfs/view/stable/chapter05/glibc.html>,
  406. ;; linking against libgcc_s is not needed with GCC
  407. ;; 4.7.1.
  408. ((" -lgcc_s") ""))
  409. ;; Copy a statically-linked Bash in the output, with
  410. ;; no references to other store paths.
  411. (mkdir-p bin)
  412. (copy-file (string-append (assoc-ref inputs "static-bash")
  413. "/bin/bash")
  414. (string-append bin "/bash"))
  415. (remove-store-references (string-append bin "/bash"))
  416. (chmod (string-append bin "/bash") #o555)
  417. ;; Keep a symlink, for `patch-shebang' resolution.
  418. (with-directory-excursion bin
  419. (symlink "bash" "sh"))
  420. ;; Have `system' use that Bash.
  421. (substitute* "sysdeps/posix/system.c"
  422. (("#define[[:blank:]]+SHELL_PATH.*$")
  423. (format #f "#define SHELL_PATH \"~a/bin/bash\"\n"
  424. out)))
  425. ;; Same for `popen'.
  426. (substitute* "libio/iopopen.c"
  427. (("/bin/sh")
  428. (string-append out "/bin/bash")))))
  429. (alist-cons-after
  430. 'install 'install-locales
  431. (lambda _
  432. (zero? (system* "make" "localedata/install-locales")))
  433. %standard-phases))))
  434. (inputs `(("static-bash" ,(static-package bash-light))))
  435. (synopsis "The GNU C Library")
  436. (description
  437. "Any Unix-like operating system needs a C library: the library which
  438. defines the \"system calls\" and other basic facilities such as open, malloc,
  439. printf, exit...
  440. The GNU C library is used as the C library in the GNU system and most systems
  441. with the Linux kernel.")
  442. (license lgpl2.0+)
  443. (home-page "http://www.gnu.org/software/libc/")))
  444. (define-public tzdata
  445. (package
  446. (name "tzdata")
  447. (version "2013d")
  448. (source (origin
  449. (method url-fetch)
  450. (uri (string-append
  451. "http://www.iana.org/time-zones/repository/releases/tzdata"
  452. version ".tar.gz"))
  453. (sha256
  454. (base32
  455. "011v63ppr73vhjgxv00inkn5pc7z48i8lhbapkpdq3kfczq9c76d"))))
  456. (build-system gnu-build-system)
  457. (arguments
  458. '(#:tests? #f
  459. #:make-flags (let ((out (assoc-ref %outputs "out"))
  460. (tmp (getenv "TMPDIR")))
  461. (list (string-append "TOPDIR=" out)
  462. (string-append "TZDIR=" out "/share/zoneinfo")
  463. ;; Discard zic, dump, and tzselect, already
  464. ;; provided by glibc.
  465. (string-append "ETCDIR=" tmp "/etc")
  466. ;; Likewise for the C library routines.
  467. (string-append "LIBDIR=" tmp "/lib")
  468. (string-append "MANDIR=" tmp "/man")
  469. "AWK=awk"
  470. "CC=gcc"))
  471. #:modules ((guix build utils)
  472. (guix build gnu-build-system)
  473. (srfi srfi-1))
  474. #:phases
  475. (alist-replace
  476. 'unpack
  477. (lambda* (#:key inputs #:allow-other-keys)
  478. (and (zero? (system* "tar" "xvf" (assoc-ref inputs "source")))
  479. (zero? (system* "tar" "xvf" (assoc-ref inputs "tzcode")))))
  480. (alist-cons-after
  481. 'install 'post-install
  482. (lambda* (#:key outputs #:allow-other-keys)
  483. ;; Move data in the right place.
  484. (let ((out (assoc-ref outputs "out")))
  485. (copy-recursively (string-append out "/share/zoneinfo-posix")
  486. (string-append out "/share/zoneinfo/posix"))
  487. (copy-recursively (string-append out "/share/zoneinfo-leaps")
  488. (string-append out "/share/zoneinfo/right"))
  489. (delete-file-recursively (string-append out "/share/zoneinfo-posix"))
  490. (delete-file-recursively (string-append out "/share/zoneinfo-leaps"))))
  491. (alist-delete 'configure %standard-phases)))))
  492. (inputs `(("tzcode" ,(origin
  493. (method url-fetch)
  494. (uri (string-append
  495. "http://www.iana.org/time-zones/repository/releases/tzcode"
  496. version ".tar.gz"))
  497. (sha256
  498. (base32
  499. "1dh7nzmfxs8fps4bzcd2lz5fz24zxy2123a99avxsk34jh6bk7id"))))))
  500. (home-page "http://www.iana.org/time-zones")
  501. (synopsis "Database of current and historical time zones")
  502. (description "The Time Zone Database (often called tz or zoneinfo)
  503. contains code and data that represent the history of local time for many
  504. representative locations around the globe. It is updated periodically to
  505. reflect changes made by political bodies to time zone boundaries, UTC offsets,
  506. and daylight-saving rules.")
  507. (license public-domain)))
  508. ;;;
  509. ;;; Bootstrap packages.
  510. ;;;
  511. (define gnu-make-boot0
  512. (package-with-bootstrap-guile
  513. (package (inherit gnu-make)
  514. (name "make-boot0")
  515. (location (source-properties->location (current-source-location)))
  516. (arguments
  517. `(#:guile ,%bootstrap-guile
  518. #:implicit-inputs? #f
  519. #:tests? #f ; cannot run "make check"
  520. ,@(substitute-keyword-arguments (package-arguments gnu-make)
  521. ((#:phases phases)
  522. `(alist-replace
  523. 'build (lambda _
  524. ;; Don't attempt to build 'guile.c' since we don't
  525. ;; have Guile here.
  526. (substitute* "build.sh"
  527. (("guile\\.\\$\\{OBJEXT\\}") ""))
  528. (zero? (system* "./build.sh")))
  529. (alist-replace
  530. 'install (lambda* (#:key outputs #:allow-other-keys)
  531. (let* ((out (assoc-ref outputs "out"))
  532. (bin (string-append out "/bin")))
  533. (mkdir-p bin)
  534. (copy-file "make"
  535. (string-append bin "/make"))))
  536. ,phases))))))
  537. (inputs %bootstrap-inputs))))
  538. (define diffutils-boot0
  539. (package-with-bootstrap-guile
  540. (let ((p (package-with-explicit-inputs diffutils
  541. `(("make" ,gnu-make-boot0)
  542. ,@%bootstrap-inputs)
  543. #:guile %bootstrap-guile)))
  544. (package (inherit p)
  545. (location (source-properties->location (current-source-location)))
  546. (arguments `(#:tests? #f ; the test suite needs diffutils
  547. ,@(package-arguments p)))))))
  548. (define findutils-boot0
  549. (package-with-bootstrap-guile
  550. (package-with-explicit-inputs findutils
  551. `(("make" ,gnu-make-boot0)
  552. ("diffutils" ,diffutils-boot0) ; for tests
  553. ,@%bootstrap-inputs)
  554. (current-source-location)
  555. #:guile %bootstrap-guile)))
  556. (define %boot0-inputs
  557. `(("make" ,gnu-make-boot0)
  558. ("diffutils" ,diffutils-boot0)
  559. ("findutils" ,findutils-boot0)
  560. ,@%bootstrap-inputs))
  561. (define* (nix-system->gnu-triplet
  562. #:optional (system (%current-system)) (vendor "unknown"))
  563. "Return an a guess of the GNU triplet corresponding to Nix system
  564. identifier SYSTEM."
  565. (let* ((dash (string-index system #\-))
  566. (arch (substring system 0 dash))
  567. (os (substring system (+ 1 dash))))
  568. (string-append arch
  569. "-" vendor "-"
  570. (if (string=? os "linux")
  571. "linux-gnu"
  572. os))))
  573. (define* (boot-triplet #:optional (system (%current-system)))
  574. ;; Return the triplet used to create the cross toolchain needed in the
  575. ;; first bootstrapping stage.
  576. (nix-system->gnu-triplet system "guix"))
  577. ;; Following Linux From Scratch, build a cross-toolchain in stage 0. That
  578. ;; toolchain actually targets the same OS and arch, but it has the advantage
  579. ;; of being independent of the libc and tools in %BOOTSTRAP-INPUTS, since
  580. ;; GCC-BOOT0 (below) is built without any reference to the target libc.
  581. (define binutils-boot0
  582. (package-with-bootstrap-guile
  583. (package (inherit binutils)
  584. (name "binutils-cross-boot0")
  585. (arguments
  586. `(#:guile ,%bootstrap-guile
  587. #:implicit-inputs? #f
  588. ,@(substitute-keyword-arguments (package-arguments binutils)
  589. ((#:configure-flags cf)
  590. `(cons ,(string-append "--target=" (boot-triplet))
  591. ,cf)))))
  592. (inputs %boot0-inputs))))
  593. (define gcc-boot0
  594. (package-with-bootstrap-guile
  595. (package (inherit gcc-4.7)
  596. (name "gcc-cross-boot0")
  597. (arguments
  598. `(#:guile ,%bootstrap-guile
  599. #:implicit-inputs? #f
  600. #:modules ((guix build gnu-build-system)
  601. (guix build utils)
  602. (ice-9 regex)
  603. (srfi srfi-1)
  604. (srfi srfi-26))
  605. ,@(substitute-keyword-arguments (package-arguments gcc-4.7)
  606. ((#:configure-flags flags)
  607. `(append (list ,(string-append "--target=" (boot-triplet))
  608. ;; No libc yet.
  609. "--without-headers"
  610. ;; Disable features not needed at this stage.
  611. "--disable-shared"
  612. "--enable-languages=c"
  613. "--disable-libmudflap"
  614. "--disable-libgomp"
  615. "--disable-libssp"
  616. "--disable-libquadmath"
  617. "--disable-decimal-float")
  618. (remove (cut string-match "--enable-languages.*" <>)
  619. ,flags)))
  620. ((#:phases phases)
  621. `(alist-cons-after
  622. 'unpack 'unpack-gmp&co
  623. (lambda* (#:key inputs #:allow-other-keys)
  624. (let ((gmp (assoc-ref %build-inputs "gmp-source"))
  625. (mpfr (assoc-ref %build-inputs "mpfr-source"))
  626. (mpc (assoc-ref %build-inputs "mpc-source")))
  627. ;; To reduce the set of pre-built bootstrap inputs, build
  628. ;; GMP & co. from GCC.
  629. (for-each (lambda (source)
  630. (or (zero? (system* "tar" "xvf" source))
  631. (error "failed to unpack tarball"
  632. source)))
  633. (list gmp mpfr mpc))
  634. ;; Create symlinks like `gmp' -> `gmp-5.0.5'.
  635. ,@(map (lambda (lib)
  636. `(symlink ,(package-full-name lib)
  637. ,(package-name lib)))
  638. (list gmp mpfr mpc))
  639. ;; MPFR headers/lib are found under $(MPFR)/src, but
  640. ;; `configure' wrongfully tells MPC too look under
  641. ;; $(MPFR), so fix that.
  642. (substitute* "configure"
  643. (("extra_mpc_mpfr_configure_flags(.+)--with-mpfr-include=([^/]+)/mpfr(.*)--with-mpfr-lib=([^ ]+)/mpfr"
  644. _ equals include middle lib)
  645. (string-append "extra_mpc_mpfr_configure_flags" equals
  646. "--with-mpfr-include=" include
  647. "/mpfr/src" middle
  648. "--with-mpfr-lib=" lib
  649. "/mpfr/src"))
  650. (("gmpinc='-I([^ ]+)/mpfr -I([^ ]+)/mpfr" _ a b)
  651. (string-append "gmpinc='-I" a "/mpfr/src "
  652. "-I" b "/mpfr/src"))
  653. (("gmplibs='-L([^ ]+)/mpfr" _ a)
  654. (string-append "gmplibs='-L" a "/mpfr/src")))))
  655. (alist-cons-after
  656. 'install 'symlink-libgcc_eh
  657. (lambda* (#:key outputs #:allow-other-keys)
  658. (let ((out (assoc-ref outputs "out")))
  659. ;; Glibc wants to link against libgcc_eh, so provide
  660. ;; it.
  661. (with-directory-excursion
  662. (string-append out "/lib/gcc/"
  663. ,(boot-triplet)
  664. "/" ,(package-version gcc-4.7))
  665. (symlink "libgcc.a" "libgcc_eh.a"))))
  666. ,phases))))))
  667. (inputs `(("gmp-source" ,(package-source gmp))
  668. ("mpfr-source" ,(package-source mpfr))
  669. ("mpc-source" ,(package-source mpc))
  670. ("binutils-cross" ,binutils-boot0)
  671. ;; Call it differently so that the builder can check whether
  672. ;; the "libc" input is #f.
  673. ("libc-native" ,@(assoc-ref %boot0-inputs "libc"))
  674. ,@(alist-delete "libc" %boot0-inputs)))
  675. ;; No need for Texinfo at this stage.
  676. (native-inputs (alist-delete "texinfo"
  677. (package-native-inputs gcc-4.7))))))
  678. (define (linux-libre-headers-boot0)
  679. "Return Linux-Libre header files for the bootstrap environment."
  680. ;; Note: this is wrapped in a thunk to nicely handle circular dependencies
  681. ;; between (gnu packages linux) and this module.
  682. (package-with-bootstrap-guile
  683. (package (inherit linux-libre-headers)
  684. (arguments `(#:guile ,%bootstrap-guile
  685. #:implicit-inputs? #f
  686. ,@(package-arguments linux-libre-headers)))
  687. (native-inputs
  688. (let ((perl (package-with-explicit-inputs perl
  689. %boot0-inputs
  690. (current-source-location)
  691. #:guile %bootstrap-guile)))
  692. `(("perl" ,perl)
  693. ,@%boot0-inputs))))))
  694. (define %boot1-inputs
  695. ;; 2nd stage inputs.
  696. `(("gcc" ,gcc-boot0)
  697. ("binutils-cross" ,binutils-boot0)
  698. ;; Keep "binutils" here because the cross-gcc invokes `as', not the
  699. ;; cross-`as'.
  700. ,@%boot0-inputs))
  701. (define glibc-final-with-bootstrap-bash
  702. ;; The final libc, "cross-built". If everything went well, the resulting
  703. ;; store path has no dependencies. Actually, the really-final libc is
  704. ;; built just below; the only difference is that this one uses the
  705. ;; bootstrap Bash.
  706. (package-with-bootstrap-guile
  707. (package (inherit glibc)
  708. (name "glibc-intermediate")
  709. (arguments
  710. `(#:guile ,%bootstrap-guile
  711. #:implicit-inputs? #f
  712. ,@(substitute-keyword-arguments (package-arguments glibc)
  713. ((#:configure-flags flags)
  714. `(append (list ,(string-append "--host=" (boot-triplet))
  715. ,(string-append "--build="
  716. (nix-system->gnu-triplet))
  717. ;; Build Sun/ONC RPC support. In particular,
  718. ;; install rpc/*.h.
  719. "--enable-obsolete-rpc")
  720. ,flags)))))
  721. (propagated-inputs `(("linux-headers" ,(linux-libre-headers-boot0))))
  722. (inputs
  723. `( ;; A native GCC is needed to build `cross-rpcgen'.
  724. ("native-gcc" ,@(assoc-ref %boot0-inputs "gcc"))
  725. ;; Here, we use the bootstrap Bash, which is not satisfactory
  726. ;; because we don't want to depend on bootstrap tools.
  727. ("static-bash" ,@(assoc-ref %boot0-inputs "bash"))
  728. ,@%boot1-inputs
  729. ,@(alist-delete "static-bash"
  730. (package-inputs glibc))))))) ; patches
  731. (define (cross-gcc-wrapper gcc binutils glibc bash)
  732. "Return a wrapper for the pseudo-cross toolchain GCC/BINUTILS/GLIBC
  733. that makes it available under the native tool names."
  734. (package (inherit gcc-4.7)
  735. (name (string-append (package-name gcc) "-wrapped"))
  736. (source #f)
  737. (build-system trivial-build-system)
  738. (arguments
  739. `(#:guile ,%bootstrap-guile
  740. #:modules ((guix build utils))
  741. #:builder (begin
  742. (use-modules (guix build utils))
  743. (let* ((binutils (assoc-ref %build-inputs "binutils"))
  744. (gcc (assoc-ref %build-inputs "gcc"))
  745. (libc (assoc-ref %build-inputs "libc"))
  746. (bash (assoc-ref %build-inputs "bash"))
  747. (out (assoc-ref %outputs "out"))
  748. (bindir (string-append out "/bin"))
  749. (triplet ,(boot-triplet)))
  750. (mkdir-p bindir)
  751. (with-directory-excursion bindir
  752. (for-each (lambda (tool)
  753. (symlink (string-append binutils "/bin/"
  754. triplet "-" tool)
  755. tool))
  756. '("ar" "ranlib"))
  757. ;; GCC-BOOT0 is a libc-less cross-compiler, so it
  758. ;; needs to be told where to find the crt files and
  759. ;; the dynamic linker.
  760. (call-with-output-file "gcc"
  761. (lambda (p)
  762. (format p "#!~a/bin/bash
  763. exec ~a/bin/~a-gcc -B~a/lib -Wl,-dynamic-linker -Wl,~a/~a \"$@\"~%"
  764. bash
  765. gcc triplet
  766. libc libc
  767. ,(glibc-dynamic-linker))))
  768. (chmod "gcc" #o555))))))
  769. (native-inputs
  770. `(("binutils" ,binutils)
  771. ("gcc" ,gcc)
  772. ("libc" ,glibc)
  773. ("bash" ,bash)))
  774. (inputs '())))
  775. (define static-bash-for-glibc
  776. ;; A statically-linked Bash to be embedded in GLIBC-FINAL, for use by
  777. ;; system(3) & co.
  778. (let* ((gcc (cross-gcc-wrapper gcc-boot0 binutils-boot0
  779. glibc-final-with-bootstrap-bash
  780. (car (assoc-ref %boot1-inputs "bash"))))
  781. (bash (package (inherit bash-light)
  782. (arguments
  783. `(#:guile ,%bootstrap-guile
  784. ,@(package-arguments bash-light))))))
  785. (package-with-bootstrap-guile
  786. (package-with-explicit-inputs (static-package bash)
  787. `(("gcc" ,gcc)
  788. ("libc" ,glibc-final-with-bootstrap-bash)
  789. ,@(fold alist-delete %boot1-inputs
  790. '("gcc" "libc")))
  791. (current-source-location)))))
  792. (define-public glibc-final
  793. ;; The final glibc, which embeds the statically-linked Bash built above.
  794. (package (inherit glibc-final-with-bootstrap-bash)
  795. (name "glibc")
  796. (inputs `(("static-bash" ,static-bash-for-glibc)
  797. ,@(alist-delete
  798. "static-bash"
  799. (package-inputs glibc-final-with-bootstrap-bash))))))
  800. (define gcc-boot0-wrapped
  801. ;; Make the cross-tools GCC-BOOT0 and BINUTILS-BOOT0 available under the
  802. ;; non-cross names.
  803. (cross-gcc-wrapper gcc-boot0 binutils-boot0 glibc-final
  804. (car (assoc-ref %boot1-inputs "bash"))))
  805. (define %boot2-inputs
  806. ;; 3rd stage inputs.
  807. `(("libc" ,glibc-final)
  808. ("gcc" ,gcc-boot0-wrapped)
  809. ,@(fold alist-delete %boot1-inputs '("libc" "gcc"))))
  810. (define-public binutils-final
  811. (package-with-bootstrap-guile
  812. (package (inherit binutils)
  813. (arguments
  814. `(#:guile ,%bootstrap-guile
  815. #:implicit-inputs? #f
  816. ,@(package-arguments binutils)))
  817. (inputs %boot2-inputs))))
  818. (define-public gcc-final
  819. ;; The final GCC.
  820. (package (inherit gcc-boot0)
  821. (name "gcc")
  822. (arguments
  823. `(#:guile ,%bootstrap-guile
  824. #:implicit-inputs? #f
  825. ;; Build again GMP & co. within GCC's build process, because it's hard
  826. ;; to do outside (because GCC-BOOT0 is a cross-compiler, and thus
  827. ;; doesn't honor $LIBRARY_PATH, which breaks `gnu-build-system'.)
  828. ,@(substitute-keyword-arguments (package-arguments gcc-boot0)
  829. ((#:configure-flags boot-flags)
  830. (let loop ((args (package-arguments gcc-4.7)))
  831. (match args
  832. ((#:configure-flags normal-flags _ ...)
  833. normal-flags)
  834. ((_ rest ...)
  835. (loop rest)))))
  836. ((#:phases phases)
  837. `(alist-delete 'symlink-libgcc_eh ,phases)))))
  838. (inputs `(("gmp-source" ,(package-source gmp))
  839. ("mpfr-source" ,(package-source mpfr))
  840. ("mpc-source" ,(package-source mpc))
  841. ("binutils" ,binutils-final)
  842. ,@%boot2-inputs))))
  843. (define ld-wrapper-boot3
  844. ;; A linker wrapper that uses the bootstrap Guile.
  845. (package
  846. (name "ld-wrapper-boot3")
  847. (version "0")
  848. (source #f)
  849. (build-system trivial-build-system)
  850. (inputs `(("binutils" ,binutils-final)
  851. ("guile" ,%bootstrap-guile)
  852. ("bash" ,@(assoc-ref %boot2-inputs "bash"))
  853. ("wrapper" ,(search-path %load-path
  854. "gnu/packages/ld-wrapper.scm"))))
  855. (arguments
  856. `(#:guile ,%bootstrap-guile
  857. #:modules ((guix build utils))
  858. #:builder (begin
  859. (use-modules (guix build utils)
  860. (system base compile))
  861. (let* ((out (assoc-ref %outputs "out"))
  862. (bin (string-append out "/bin"))
  863. (ld (string-append bin "/ld"))
  864. (go (string-append bin "/ld.go")))
  865. (setvbuf (current-output-port) _IOLBF)
  866. (format #t "building ~s/bin/ld wrapper in ~s~%"
  867. (assoc-ref %build-inputs "binutils")
  868. out)
  869. (mkdir-p bin)
  870. (copy-file (assoc-ref %build-inputs "wrapper") ld)
  871. (substitute* ld
  872. (("@GUILE@")
  873. (string-append (assoc-ref %build-inputs "guile")
  874. "/bin/guile"))
  875. (("@BASH@")
  876. (string-append (assoc-ref %build-inputs "bash")
  877. "/bin/bash"))
  878. (("@LD@")
  879. (string-append (assoc-ref %build-inputs "binutils")
  880. "/bin/ld")))
  881. (chmod ld #o555)
  882. (compile-file ld #:output-file go)))))
  883. (synopsis "The linker wrapper")
  884. (description
  885. "The linker wrapper (or `ld-wrapper') wraps the linker to add any
  886. missing `-rpath' flags, and to detect any misuse of libraries outside of the
  887. store.")
  888. (home-page #f)
  889. (license gpl3+)))
  890. (define %boot3-inputs
  891. ;; 4th stage inputs.
  892. `(("gcc" ,gcc-final)
  893. ("ld-wrapper" ,ld-wrapper-boot3)
  894. ,@(alist-delete "gcc" %boot2-inputs)))
  895. (define-public bash-final
  896. ;; Link with `-static-libgcc' to make sure we don't retain a reference
  897. ;; to the bootstrap GCC.
  898. (package-with-bootstrap-guile
  899. (package-with-explicit-inputs (static-libgcc-package bash)
  900. %boot3-inputs
  901. (current-source-location)
  902. #:guile %bootstrap-guile)))
  903. (define %boot4-inputs
  904. ;; Now use the final Bash.
  905. `(("bash" ,bash-final)
  906. ,@(alist-delete "bash" %boot3-inputs)))
  907. (define-public guile-final
  908. (package-with-bootstrap-guile
  909. (package-with-explicit-inputs guile-2.0/fixed
  910. %boot4-inputs
  911. (current-source-location)
  912. #:guile %bootstrap-guile)))
  913. (define-public gnu-make-final
  914. ;; The final GNU Make, which uses the final Guile.
  915. (package-with-bootstrap-guile
  916. (package-with-explicit-inputs gnu-make
  917. `(("guile" ,guile-final)
  918. ,@%boot4-inputs)
  919. (current-source-location))))
  920. (define-public ld-wrapper
  921. ;; The final `ld' wrapper, which uses the final Guile.
  922. (package (inherit ld-wrapper-boot3)
  923. (name "ld-wrapper")
  924. (inputs `(("guile" ,guile-final)
  925. ("bash" ,bash-final)
  926. ,@(fold alist-delete (package-inputs ld-wrapper-boot3)
  927. '("guile" "bash"))))))
  928. (define-public %final-inputs
  929. ;; Final derivations used as implicit inputs by 'gnu-build-system'. We
  930. ;; still use 'package-with-bootstrap-guile' so that the bootstrap tools are
  931. ;; used for origins that have patches, thereby avoiding circular
  932. ;; dependencies.
  933. (let ((finalize (compose package-with-bootstrap-guile
  934. (cut package-with-explicit-inputs <> %boot4-inputs
  935. (current-source-location)))))
  936. `(,@(map (match-lambda
  937. ((name package)
  938. (list name (finalize package))))
  939. `(("tar" ,tar)
  940. ("gzip" ,gzip)
  941. ("bzip2" ,bzip2)
  942. ("xz" ,xz)
  943. ("diffutils" ,diffutils)
  944. ("patch" ,patch)
  945. ("coreutils" ,coreutils)
  946. ("sed" ,sed)
  947. ("grep" ,grep)
  948. ("findutils" ,findutils)
  949. ("gawk" ,gawk)))
  950. ("make" ,gnu-make-final)
  951. ("bash" ,bash-final)
  952. ("ld-wrapper" ,ld-wrapper)
  953. ("binutils" ,binutils-final)
  954. ("gcc" ,gcc-final)
  955. ("libc" ,glibc-final))))
  956. ;;; base.scm ends here