1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2012, 2013, 2014, 2015 Ludovic Courtès <ludo@gnu.org>
3 ;;; Copyright © 2014, 2015 Mark H Weaver <mhw@netris.org>
4 ;;; Copyright © 2014 Ricardo Wurmus <rekado@elephly.net>
5 ;;; Copyright © 2015 Andreas Enge <andreas@enge.fr>
7 ;;; This file is part of GNU Guix.
9 ;;; GNU Guix is free software; you can redistribute it and/or modify it
10 ;;; under the terms of the GNU General Public License as published by
11 ;;; the Free Software Foundation; either version 3 of the License, or (at
12 ;;; your option) any later version.
14 ;;; GNU Guix is distributed in the hope that it will be useful, but
15 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;;; GNU General Public License for more details.
19 ;;; You should have received a copy of the GNU General Public License
20 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
22 (define-module (gnu packages gcc)
23 #:use-module ((guix licenses)
24 #:select (gpl3+ gpl2+ lgpl2.1+ lgpl2.0+ fdl1.3+))
25 #:use-module (gnu packages)
26 #:use-module (gnu packages bootstrap)
27 #:use-module (gnu packages compression)
28 #:use-module (gnu packages multiprecision)
29 #:use-module (gnu packages texinfo)
30 #:use-module (gnu packages doxygen)
31 #:use-module (gnu packages xml)
32 #:use-module (gnu packages docbook)
33 #:use-module (gnu packages graphviz)
34 #:use-module (gnu packages elf)
35 #:use-module (gnu packages perl)
36 #:use-module (guix packages)
37 #:use-module (guix download)
38 #:use-module (guix build-system gnu)
39 #:use-module (guix build-system trivial)
40 #:use-module (guix utils)
41 #:use-module (ice-9 regex))
43 (define %gcc-infrastructure
44 ;; Base URL for GCC's infrastructure.
45 "ftp://gcc.gnu.org/pub/gcc/infrastructure/")
47 (define (gcc-configure-flags-for-triplet target)
48 "Return a list of additional GCC `configure' flags for TARGET, a GNU triplet.
50 The purpose of this procedure is to translate extended GNU triplets---e.g.,
51 where the OS part is overloaded to denote a specific ABI---into GCC
52 `configure' options. We take extended GNU triplets that glibc recognizes."
53 (cond ((string-match "^mips64el.*gnuabin?64$" target)
54 ;; Triplets recognized by glibc as denoting the N64 ABI; see
55 ;; ports/sysdeps/mips/preconfigure.
58 ((string-match "^arm.*-gnueabihf$" target)
59 '("--with-arch=armv7-a"
65 ;; TODO: Add `arm.*-gnueabi', etc.
68 (define-public gcc-4.7
69 (let* ((stripped? #t) ;whether to strip the compiler, not the libraries
72 ;; Return the `_FOR_TARGET' variables that are needed when
73 ;; cross-compiling GCC.
74 (let ((target (%current-target-system)))
76 (map (lambda (var tool)
77 (string-append (string-append var "_FOR_TARGET")
79 '("CC" "CXX" "LD" "AR" "NM" "RANLIB" "STRIP")
80 '("gcc" "g++" "ld" "ar" "nm" "ranlib" "strip"))
83 (let ((base '(or (assoc-ref outputs "lib")
84 (assoc-ref outputs "out"))))
86 ;; Return the directory that contains lib/libgcc_s.so et al.
87 (if (%current-target-system)
88 `(string-append ,base "/" ,(%current-target-system))
92 ;; This is terrible. Since we have two levels of quasiquotation,
93 ;; we have to do this convoluted thing just so we can insert the
94 ;; contents of (maybe-target-tools).
98 "--enable-languages=c,c++"
101 ;; No pre-compiled libstdc++ headers, to save space.
102 "--disable-libstdcxx-pch"
104 "--with-local-prefix=/no-gcc-local-prefix"
106 ;; With a separate "lib" output, the build system
107 ;; incorrectly guesses GPLUSPLUS_INCLUDE_DIR, so force
108 ;; it. (Don't use a versioned sub-directory, that's
110 ,(string-append "--with-gxx-include-dir="
111 (assoc-ref %outputs "out")
114 ,(let ((libc (assoc-ref %build-inputs "libc")))
116 (string-append "--with-native-system-header-dir=" libc
118 "--without-headers")))
120 ;; Pass the right options for the target triplet.
122 (or (%current-target-system)
123 (nix-system->gnu-triplet (%current-system)))))
124 (gcc-configure-flags-for-triplet triplet))
126 (maybe-target-tools))))))
132 (uri (string-append "mirror://gnu/gcc/gcc-"
133 version "/gcc-" version ".tar.bz2"))
136 "10k2k71kxgay283ylbbhhs51cl55zn2q38vj5pk4k950qdnirrlj"))))
137 (build-system gnu-build-system)
139 ;; Separate out the run-time support libraries because all the
140 ;; dynamic-linked objects depend on it.
141 (outputs '("out" ;commands, etc. (60+ MiB)
142 "lib" ;libgcc_s, libgomp, etc. (15+ MiB)
143 "debug")) ;debug symbols of run-time libraries
145 (inputs `(("gmp" ,gmp)
153 ;; GCC is one of the few packages that doesn't ship .info files.
154 (native-inputs `(("texinfo" ,texinfo)))
157 `(#:out-of-source? #t
158 #:configure-flags ,(configure-flags)
160 ;; None of the flags below are needed when doing a Canadian cross.
161 ;; TODO: Simplify this.
162 ,(if (%current-target-system)
166 `(let* ((libc (assoc-ref %build-inputs "libc"))
167 (libc-native (or (assoc-ref %build-inputs "libc-native")
170 (list (string-append "LDFLAGS_FOR_TARGET="
172 "-Wl,-dynamic-linker "
174 ,(glibc-dynamic-linker)))
177 ;; Native programs like 'genhooks' also need that right.
178 ,(string-append "LDFLAGS="
179 "-Wl,-rpath=" libc-native "/lib "
180 "-Wl,-dynamic-linker "
181 "-Wl," libc-native ,(glibc-dynamic-linker))
182 ,(string-append "BOOT_CFLAGS=-O2 "
183 ,(if stripped? "-g0" "-g")))))
189 'configure 'pre-configure
190 (lambda* (#:key inputs outputs #:allow-other-keys)
191 (let ((libdir ,(libdir))
192 (libc (assoc-ref inputs "libc")))
194 ;; The following is not performed for `--without-headers'
195 ;; cross-compiler builds.
197 ;; Join multi-line definitions of GLIBC_DYNAMIC_LINKER* into a
198 ;; single line, to allow the next step to work properly.
201 (substitute* (find-files "gcc/config"
202 "^linux(64|-elf|-eabi)?\\.h$")
203 (("(#define GLIBC_DYNAMIC_LINKER.*)\\\\\n$" _ line)
207 ;; Fix the dynamic linker's file name.
208 (substitute* (find-files "gcc/config"
209 "^linux(64|-elf|-eabi)?\\.h$")
210 (("#define GLIBC_DYNAMIC_LINKER([^ ]*).*$" _ suffix)
211 (format #f "#define GLIBC_DYNAMIC_LINKER~a \"~a\"~%"
213 (string-append libc ,(glibc-dynamic-linker)))))
215 ;; Tell where to find libstdc++, libc, and `?crt*.o', except
216 ;; `crt{begin,end}.o', which come with GCC.
217 (substitute* (find-files "gcc/config"
219 (("#define GNU_USER_TARGET_LIB_SPEC (.*)$" _ suffix)
220 ;; Help libgcc_s.so be found (see also below.) Always use
221 ;; '-lgcc_s' so that libgcc_s.so is always found by those
222 ;; programs that use 'pthread_cancel' (glibc dlopens
223 ;; libgcc_s.so when pthread_cancel support is needed, but
224 ;; having it in the application's RUNPATH isn't enough; see
225 ;; <http://sourceware.org/ml/libc-help/2013-11/msg00023.html>.)
227 ;; NOTE: The '-lgcc_s' added below needs to be removed in a
228 ;; later phase of %gcc-static. If you change the string
229 ;; below, make sure to update the relevant code in
230 ;; %gcc-static package as needed.
231 (format #f "#define GNU_USER_TARGET_LIB_SPEC \
232 \"-L~a/lib %{!static:-rpath=~a/lib %{!static-libgcc:-rpath=~a/lib -lgcc_s}} \" ~a"
233 libc libc libdir suffix))
234 (("#define GNU_USER_TARGET_STARTFILE_SPEC.*$" line)
235 (format #f "#define STANDARD_STARTFILE_PREFIX_1 \"~a/lib\"
236 #define STANDARD_STARTFILE_PREFIX_2 \"\"
240 ;; Don't retain a dependency on the build-time sed.
241 (substitute* "fixincludes/fixincl.x"
242 (("static char const sed_cmd_z\\[\\] =.*;")
243 "static char const sed_cmd_z[] = \"sed\";"))
245 (when (file-exists? "libbacktrace")
246 ;; GCC 4.8+ comes with libbacktrace. By default it builds
247 ;; with -Werror, which fails with a -Wcast-qual error in glibc
248 ;; 2.21's stdlib-bsearch.h. Remove -Werror.
249 (substitute* "libbacktrace/configure"
250 (("WARN_FLAGS=(.*)-Werror" _ flags)
251 (string-append "WARN_FLAGS=" flags)))
253 (when (file-exists? "libsanitizer/libbacktrace")
254 ;; Same in libsanitizer's bundled copy (!) found in 4.9+.
255 (substitute* "libsanitizer/libbacktrace/Makefile.in"
259 ;; Add a RUNPATH to libstdc++.so so that it finds libgcc_s.
260 ;; See <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=32354>
261 ;; and <http://bugs.gnu.org/20358>.
262 (substitute* "libstdc++-v3/src/Makefile.in"
264 "OPT_LDFLAGS = -Wl,-rpath=$(libdir) "))
266 ;; Move libstdc++*-gdb.py to the "lib" output to avoid a
267 ;; circularity between "out" and "lib". (Note:
268 ;; --with-python-dir is useless because it imposes $(prefix) as
269 ;; the parent directory.)
270 (substitute* "libstdc++-v3/python/Makefile.in"
272 (string-append "pythondir = " libdir "/share"
273 "/gcc-$(gcc_version)/python\n")))
275 ;; Avoid another circularity between the outputs: this #define
276 ;; ends up in auto-host.h in the "lib" output, referring to
277 ;; "out". (This variable is used to augment cpp's search path,
278 ;; but there's nothing useful to look for here.)
279 (substitute* "gcc/config.in"
280 (("PREFIX_INCLUDE_DIR")
281 "PREFIX_INCLUDE_DIR_isnt_necessary_here"))))
284 'configure 'post-configure
286 ;; Don't store configure flags, to avoid retaining references to
287 ;; build-time dependencies---e.g., `--with-ppl=/gnu/store/xxx'.
288 (substitute* "Makefile"
289 (("^TOPLEVEL_CONFIGURE_ARGUMENTS=(.*)$" _ rest)
290 "TOPLEVEL_CONFIGURE_ARGUMENTS=\n")))
294 (list (search-path-specification
296 (files '("include")))
297 (search-path-specification
298 (variable "LIBRARY_PATH")
299 (files '("lib" "lib64")))))
301 (properties `((gcc-libc . ,(assoc-ref inputs "libc"))))
302 (synopsis "GNU Compiler Collection")
304 "GCC is the GNU Compiler Collection. It provides compiler front-ends
305 for several languages, including C, C++, Objective-C, Fortran, Java, Ada, and
306 Go. It also includes runtime support libraries for these languages.")
308 (home-page "http://gcc.gnu.org/"))))
310 (define-public gcc-4.8
311 (package (inherit gcc-4.7)
315 (uri (string-append "mirror://gnu/gcc/gcc-"
316 version "/gcc-" version ".tar.bz2"))
319 "08yggr18v373a1ihj0rg2vd6psnic42b518xcgp3r9k81xz1xyr2"))
320 (patches (list (search-patch "gcc-arm-link-spec-fix.patch")))))))
322 (define-public gcc-4.9
323 (package (inherit gcc-4.8)
327 (uri (string-append "mirror://gnu/gcc/gcc-"
328 version "/gcc-" version ".tar.bz2"))
331 "0zmnm00d2a1hsd41g34bhvxzvxisa2l584q3p447bd91lfjv4ci3"))
332 (patches (list (search-patch "gcc-libvtv-runpath.patch")))))))
334 (define-public gcc-5.1
335 (package (inherit gcc-4.9)
339 (uri (string-append "mirror://gnu/gcc/gcc-"
340 version "/gcc-" version ".tar.bz2"))
343 "1bd5vj4px3s8nlakbgrh38ynxq4s654m6nxz7lrj03mvkkwgvnmp"))
344 (patches (map search-patch
345 '("gcc-arm-link-spec-fix.patch"
346 "gcc-5.0-libvtv-runpath.patch")))))))
348 (define-public gcc gcc-4.9)
350 (define-public (make-libstdc++ gcc)
351 "Return a libstdc++ package based on GCC. The primary use case is when
352 using compilers other than GCC."
357 `(#:out-of-source? #t
358 #:phases (alist-cons-before
361 (chdir "libstdc++-v3"))
363 #:configure-flags `("--disable-libstdcxx-pch"
364 ,(string-append "--with-gxx-include-dir="
365 (assoc-ref %outputs "out")
367 (outputs '("out" "debug"))
370 (propagated-inputs '())
371 (synopsis "GNU C++ standard library")))
373 (define-public libstdc++-4.9
374 (make-libstdc++ gcc-4.9))
376 (define (make-libiberty gcc)
377 "Return a libiberty package based on GCC."
382 `(#:out-of-source? #t
384 (modify-phases %standard-phases
385 (add-before 'configure 'chdir
391 (lambda* (#:key outputs #:allow-other-keys)
392 (let* ((out (assoc-ref outputs "out"))
393 (lib (string-append out "/lib/"))
394 (include (string-append out "/include/")))
397 (copy-file "libiberty.a"
398 (string-append lib "libiberty.a"))
399 (copy-file "../include/libiberty.h"
400 (string-append include "libiberty.h"))
405 (propagated-inputs '())
406 (synopsis "Collection of subroutines used by various GNU programs")))
408 (define-public libiberty
409 (make-libiberty gcc))
411 (define* (custom-gcc gcc name languages #:key (separate-lib-output? #t))
412 "Return a custom version of GCC that supports LANGUAGES."
413 (package (inherit gcc)
415 (outputs (if separate-lib-output?
416 (package-outputs gcc)
417 (delete "lib" (package-outputs gcc))))
419 (substitute-keyword-arguments `(#:modules ((guix build gnu-build-system)
424 ,@(package-arguments gcc))
425 ((#:configure-flags flags)
426 `(cons (string-append "--enable-languages="
427 ,(string-join languages ","))
428 (remove (cut string-match "--enable-languages.*" <>)
431 (define-public gfortran-4.8
432 (custom-gcc gcc-4.8 "gfortran" '("fortran")))
434 (define-public gfortran-4.9
435 (custom-gcc gcc-4.9 "gfortran" '("fortran")))
437 (define-public gfortran
438 (custom-gcc gcc "gfortran" '("fortran")))
440 (define-public gccgo-4.8
441 (custom-gcc gcc-4.8 "gccgo" '("go")
442 ;; Suppress the separate "lib" output, because otherwise the
443 ;; "lib" and "out" outputs would refer to each other, creating
444 ;; a cyclic dependency. <http://debbugs.gnu.org/18101>
445 #:separate-lib-output? #f))
450 (uri (string-append "http://sources.gentoo.org/cgi-bin/viewvc.cgi/"
451 "gentoo-x86/dev-java/gcj-jdk/files/javac.in?revision=1.1"))
452 (file-name "javac.in")
454 "1c3dk4z5yfj6ic2fn3lyxs27n6pmn2wy9k0r1s17lnkf1bzkrciv"))))
456 (define-public gcj-4.8
457 (package (inherit gcc-4.8)
460 `(("fastjar" ,fastjar)
462 ("javac.in" ,javac.in)
463 ("ecj-bootstrap" ,ecj-bootstrap-4.8)
464 ,@(package-inputs gcc-4.8)))
465 ;; Suppress the separate "lib" output, because otherwise the
466 ;; "lib" and "out" outputs would refer to each other, creating
467 ;; a cyclic dependency. <http://debbugs.gnu.org/18101>
469 (delete "lib" (package-outputs gcc-4.8)))
471 (substitute-keyword-arguments `(#:modules ((guix build gnu-build-system)
476 ,@(package-arguments gcc-4.8))
477 ((#:configure-flags flags)
478 `(let ((ecj (assoc-ref %build-inputs "ecj-bootstrap")))
479 `("--enable-java-home"
481 ,(string-append "--with-ecj-jar=" ecj)
482 "--enable-languages=java"
483 ,@(remove (cut string-match "--enable-languages.*" <>)
486 `(modify-phases ,phases
488 'unpack 'add-lib-output-to-rpath
490 (substitute* "libjava/Makefile.in"
491 (("libgcj_bc_dummy_LINK = .* -shared" line)
492 (string-append line " -Wl,-rpath=$(libdir)"))
493 (("libgcj(_bc)?_la_LDFLAGS =" ldflags _)
494 (string-append ldflags " -Wl,-rpath=$(libdir)")))))
496 'install 'install-javac-and-javap-wrappers
498 (let* ((javac (assoc-ref %build-inputs "javac.in"))
499 (ecj (assoc-ref %build-inputs "ecj-bootstrap"))
500 (gcj (assoc-ref %outputs "out"))
501 (gcjbin (string-append gcj "/bin/"))
502 (jvm (string-append gcj "/lib/jvm/"))
503 (target (string-append jvm "/bin/javac")))
505 (symlink (string-append gcjbin "jcf-dump")
506 (string-append jvm "/bin/javap"))
508 (copy-file ecj (string-append gcj "/share/java/ecj.jar"))
510 ;; Create javac wrapper from the template javac.in by
511 ;; replacing the @VARIABLES@ with paths.
512 (copy-file javac target)
513 (patch-shebang target)
516 (string-append jvm "/bin/java"))
518 (string-append gcj "/share/java/ecj.jar"))
520 (string-append jvm "/jre/lib/rt.jar"))
522 (string-append jvm "/lib/tools.jar")))
526 'install 'remove-broken-or-conflicting-files
528 (let ((out (assoc-ref %outputs "out")))
531 (append (find-files (string-append out "/lib/jvm/jre/lib")
533 (find-files (string-append out "/bin")
534 ".*(c\\+\\+|cpp|g\\+\\+|gcc.*)"))))
537 (define ecj-bootstrap-4.8
540 (uri "ftp://sourceware.org/pub/java/ecj-4.8.jar")
543 "10fpqfbdzff1zcbxzh66xc8xbij9saykcj4xzm19wk9p3n7i5zcq"))))
545 (define-public gcc-objc-4.8
546 (custom-gcc gcc-4.8 "gcc-objc" '("objc")))
548 (define-public gcc-objc++-4.8
549 (custom-gcc gcc-4.8 "gcc-objc++" '("obj-c++")))
551 (define (make-libstdc++-doc gcc)
552 "Return a package with the libstdc++ documentation for GCC."
555 (name "libstdc++-doc")
556 (version (package-version gcc))
557 (synopsis "GNU libstdc++ documentation")
559 (native-inputs `(("doxygen" ,doxygen)
563 ("docbook-xml" ,docbook-xml)
564 ("docbook-xsl" ,docbook-xsl)
565 ("graphviz" ,graphviz))) ;for 'dot', invoked by 'doxygen'
567 (propagated-inputs '())
569 '(#:out-of-source? #t
570 #:tests? #f ;it's just documentation
571 #:phases (modify-phases %standard-phases
572 (add-before 'configure 'chdir
574 (chdir "libstdc++-v3")))
575 (add-before 'configure 'set-xsl-directory
576 (lambda* (#:key inputs #:allow-other-keys)
577 (let ((docbook (assoc-ref inputs "docbook-xsl")))
578 (substitute* (find-files "doc"
587 (%store-directory))))))))))
590 ;; XXX: There's also a 'doc-info' target, but it
591 ;; relies on docbook2X, which itself relies on
592 ;; DocBook 4.1.2, which is not really usable
593 ;; (lacks a catalog.xml.)
594 (zero? (system* "make"
598 (lambda* (#:key outputs #:allow-other-keys)
599 (let ((out (assoc-ref outputs "out")))
600 (zero? (system* "make"
602 "doc-install-man"))))))))))
604 (define-public libstdc++-doc-4.9
605 (make-libstdc++-doc gcc-4.9))
607 (define-public libstdc++-doc-5.1
608 (make-libstdc++-doc gcc-5.1))
616 (uri (list (string-append
617 "http://isl.gforge.inria.fr/isl-"
620 (string-append %gcc-infrastructure
621 name "-" version ".tar.gz")))
624 "13d9cqa5rzhbjq0xf0b2dyxag7pqa72xj9dhsa03m8ccr1a4npq9"))))
625 (build-system gnu-build-system)
626 (inputs `(("gmp" ,gmp)))
627 (home-page "http://isl.gforge.inria.fr/")
629 "Manipulating sets and relations of integer points \
630 bounded by linear constraints")
632 "isl is a library for manipulating sets and relations of integer points
633 bounded by linear constraints. Supported operations on sets include
634 intersection, union, set difference, emptiness check, convex hull, (integer)
635 affine hull, integer projection, computing the lexicographic minimum using
636 parametric integer programming, coalescing and parametric vertex
637 enumeration. It also includes an ILP solver based on generalized basis
638 reduction, transitive closures on maps (which may encode infinite graphs),
639 dependence analysis and bounds on piecewise step-polynomials.")
649 (uri (list (string-append
650 "http://www.bastoul.net/cloog/pages/download/count.php3?url=cloog-"
653 (string-append %gcc-infrastructure
654 name "-" version ".tar.gz")))
657 "0a12rwfwp22zd0nlld0xyql11cj390rrq1prw35yjsw8wzfshjhw"))
658 (file-name (string-append name "-" version ".tar.gz"))))
659 (build-system gnu-build-system)
660 (inputs `(("gmp" ,gmp)
662 (arguments '(#:configure-flags '("--with-isl=system")))
663 (home-page "http://www.cloog.org/")
664 (synopsis "Library to generate code for scanning Z-polyhedra")
666 "CLooG is a free software library to generate code for scanning
667 Z-polyhedra. That is, it finds a code (e.g., in C, FORTRAN...) that
668 reaches each integral point of one or more parameterized polyhedra.
669 CLooG has been originally written to solve the code generation problem
670 for optimizing compilers based on the polytope model. Nevertheless it
671 is used now in various area e.g., to build control automata for
672 high-level synthesis or to find the best polynomial approximation of a
673 function. CLooG may help in any situation where scanning polyhedra
674 matters. While the user has full control on generated code quality,
675 CLooG is designed to avoid control overhead and to produce a very
679 (define-public gnu-c-manual
681 (name "gnu-c-manual")
685 (uri (string-append "mirror://gnu/gnu-c-manual/gnu-c-manual-"
689 "0cf4503shr7hxkbrjfi9dky6q2lqk95bgbgbjmvj2s2x312kakd9"))))
690 (build-system gnu-build-system)
691 (native-inputs `(("texinfo" ,texinfo)))
693 '(#:phases (modify-phases %standard-phases
698 (zero? (system* "make"
700 "gnu-c-manual.html"))))
702 (lambda* (#:key outputs #:allow-other-keys)
703 (let* ((out (assoc-ref outputs "out"))
704 (info (string-append out "/share/info"))
706 out "/share/doc/gnu-c-manual")))
710 (for-each (lambda (file)
712 (string-append info "/"
714 (find-files "." "\\.info(-[0-9])?$"))
715 (for-each (lambda (file)
717 (string-append html "/"
719 (find-files "." "\\.html$"))
721 (synopsis "Reference manual for the C programming language")
723 "This is a reference manual for the C programming language, as
724 implemented by the GNU C Compiler (gcc). As a reference, it is not intended
725 to be a tutorial of the language. Rather, it outlines all of the constructs
726 of the language. Library functions are not included.")
727 (home-page "http://www.gnu.org/software/gnu-c-manual")