gnu: Move GCC to its own module.
[jackhill/guix/guix.git] / gnu / packages / gcc.scm
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2012, 2013 Ludovic Courtès <ludo@gnu.org>
3 ;;;
4 ;;; This file is part of GNU Guix.
5 ;;;
6 ;;; GNU Guix is free software; you can redistribute it and/or modify it
7 ;;; under the terms of the GNU General Public License as published by
8 ;;; the Free Software Foundation; either version 3 of the License, or (at
9 ;;; your option) any later version.
10 ;;;
11 ;;; GNU Guix is distributed in the hope that it will be useful, but
12 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ;;; GNU General Public License for more details.
15 ;;;
16 ;;; You should have received a copy of the GNU General Public License
17 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
18
19 (define-module (gnu packages gcc)
20 #:use-module (guix licenses)
21 #:use-module (gnu packages)
22 #:use-module (gnu packages bootstrap)
23 #:use-module (gnu packages compression)
24 #:use-module (gnu packages multiprecision)
25 #:use-module (guix packages)
26 #:use-module (guix download)
27 #:use-module (guix build-system gnu))
28
29 (define-public gcc-4.7
30 (let ((stripped? #t)) ; TODO: make this a parameter
31 (package
32 (name "gcc")
33 (version "4.7.2")
34 (source (origin
35 (method url-fetch)
36 (uri (string-append "mirror://gnu/gcc/gcc-"
37 version "/gcc-" version ".tar.bz2"))
38 (sha256
39 (base32
40 "115h03hil99ljig8lkrq4qk426awmzh0g99wrrggxf8g07bq74la"))))
41 (build-system gnu-build-system)
42 (inputs `(("gmp" ,gmp)
43 ("mpfr" ,mpfr)
44 ("mpc" ,mpc))) ; TODO: libelf, ppl, cloog, zlib, etc.
45 (arguments
46 `(#:out-of-source? #t
47 #:strip-binaries? ,stripped?
48 #:configure-flags
49 `("--enable-plugin"
50 "--enable-languages=c,c++"
51 "--disable-multilib"
52
53 "--with-local-prefix=/no-gcc-local-prefix"
54
55 ,(let ((libc (assoc-ref %build-inputs "libc")))
56 (if libc
57 (string-append "--with-native-system-header-dir=" libc
58 "/include")
59 "--without-headers")))
60 #:make-flags
61 (let ((libc (assoc-ref %build-inputs "libc")))
62 `(,@(if libc
63 (list (string-append "LDFLAGS_FOR_BUILD="
64 "-L" libc "/lib "
65 "-Wl,-dynamic-linker "
66 "-Wl," libc
67 ,(glibc-dynamic-linker)))
68 '())
69 ,(string-append "BOOT_CFLAGS=-O2 "
70 ,(if stripped? "-g0" "-g"))))
71
72 #:tests? #f
73 #:phases
74 (alist-cons-before
75 'configure 'pre-configure
76 (lambda* (#:key inputs outputs #:allow-other-keys)
77 (let ((out (assoc-ref outputs "out"))
78 (libc (assoc-ref inputs "libc")))
79 (when libc
80 ;; The following is not performed for `--without-headers'
81 ;; cross-compiler builds.
82
83 ;; Fix the dynamic linker's file name.
84 (substitute* (find-files "gcc/config"
85 "^linux(64|-elf)?\\.h$")
86 (("#define GLIBC_DYNAMIC_LINKER([^ ]*).*$" _ suffix)
87 (format #f "#define GLIBC_DYNAMIC_LINKER~a \"~a\"~%"
88 suffix
89 (string-append libc ,(glibc-dynamic-linker)))))
90
91 ;; Tell where to find libstdc++, libc, and `?crt*.o', except
92 ;; `crt{begin,end}.o', which come with GCC.
93 (substitute* (find-files "gcc/config"
94 "^(gnu-user(64)?|linux-elf)\\.h$")
95 (("#define LIB_SPEC (.*)$" _ suffix)
96 ;; Note that with this "lib" spec, we may still add a
97 ;; RUNPATH to GCC even when `libgcc_s' is not NEEDED.
98 ;; There's not much that can be done to avoid it, though.
99 (format #f "#define LIB_SPEC \"-L~a/lib %{!static:-rpath=~a/lib \
100 %{!static-libgcc:-rpath=~a/lib64 -rpath=~a/lib}} \" ~a~%"
101 libc libc out out suffix))
102 (("#define STARTFILE_SPEC.*$" line)
103 (format #f "#define STANDARD_STARTFILE_PREFIX_1 \"~a/lib\"
104 #define STANDARD_STARTFILE_PREFIX_2 \"\"
105 ~a~%"
106 libc line))))
107
108 ;; Don't retain a dependency on the build-time sed.
109 (substitute* "fixincludes/fixincl.x"
110 (("static char const sed_cmd_z\\[\\] =.*;")
111 "static char const sed_cmd_z[] = \"sed\";"))))
112
113 (alist-cons-after
114 'configure 'post-configure
115 (lambda _
116 ;; Don't store configure flags, to avoid retaining references to
117 ;; build-time dependencies---e.g., `--with-ppl=/nix/store/xxx'.
118 (substitute* "Makefile"
119 (("^TOPLEVEL_CONFIGURE_ARGUMENTS=(.*)$" _ rest)
120 "TOPLEVEL_CONFIGURE_ARGUMENTS=\n")))
121 (alist-replace 'install
122 (lambda* (#:key outputs #:allow-other-keys)
123 (zero?
124 (system* "make"
125 ,(if stripped?
126 "install-strip"
127 "install"))))
128 %standard-phases)))))
129
130 (properties `((gcc-libc . ,(assoc-ref inputs "libc"))))
131 (synopsis "The GNU Compiler Collection")
132 (description
133 "The GNU Compiler Collection includes compiler front ends for C, C++,
134 Objective-C, Fortran, OpenMP for C/C++/Fortran, Java, and Ada, as well as
135 libraries for these languages (libstdc++, libgcj, libgomp,...).
136
137 GCC development is a part of the GNU Project, aiming to improve the compiler
138 used in the GNU system including the GNU/Linux variant.")
139 (license gpl3+)
140 (home-page "http://gcc.gnu.org/"))))