gnu-build-system: Add 'patch-usr-bin-file' to %standard-phases.
[jackhill/guix/guix.git] / gnu / packages / gcc.scm
CommitLineData
e9c0b944 1;;; GNU Guix --- Functional package management for GNU
6f58d582 2;;; Copyright © 2012, 2013, 2014 Ludovic Courtès <ludo@gnu.org>
e9c0b944
LC
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)
c6d7e299
LC
20 #:use-module ((guix licenses)
21 #:select (gpl3+ gpl2+ lgpl2.1+ lgpl2.0+))
e9c0b944
LC
22 #:use-module (gnu packages)
23 #:use-module (gnu packages bootstrap)
24 #:use-module (gnu packages compression)
25 #:use-module (gnu packages multiprecision)
c8ebc821 26 #:use-module (gnu packages texinfo)
3e778ad3 27 #:use-module (gnu packages elf)
e9c0b944
LC
28 #:use-module (guix packages)
29 #:use-module (guix download)
ca16cb96 30 #:use-module (guix build-system gnu)
fdd6c726 31 #:use-module (guix utils)
ca16cb96 32 #:use-module (ice-9 regex))
e9c0b944 33
832abc76
LC
34(define %gcc-infrastructure
35 ;; Base URL for GCC's infrastructure.
36 "ftp://gcc.gnu.org/pub/gcc/infrastructure/")
37
ca16cb96
LC
38(define-public (gcc-configure-flags-for-triplet target)
39 "Return a list of additional GCC `configure' flags for TARGET, a GNU triplet.
40
41The purpose of this procedure is to translate extended GNU triplets---e.g.,
42where the OS part is overloaded to denote a specific ABI---into GCC
43`configure' options. We take extended GNU triplets that glibc recognizes."
44 (cond ((string-match "^mips64el.*gnuabin?64$" target)
45 ;; Triplets recognized by glibc as denoting the N64 ABI; see
46 ;; ports/sysdeps/mips/preconfigure.
47 '("--with-abi=64"))
48 (else
49 ;; TODO: Add `armel.*gnueabi', `hf', etc.
50 '())))
51
e9c0b944 52(define-public gcc-4.7
de1d41f9 53 (let* ((stripped? #t) ; TODO: make this a parameter
6b9229ca 54 (install-target
5c860cec
LC
55 (lambda ()
56 ;; The 'install-strip' rule uses the native 'strip' instead of
57 ;; 'TARGET-strip' when cross-compiling. Thus, use 'install' in that
58 ;; case.
59 (if (and stripped? (not (%current-target-system)))
60 "install-strip"
61 "install")))
de1d41f9
LC
62 (maybe-target-tools
63 (lambda ()
64 ;; Return the `_FOR_TARGET' variables that are needed when
65 ;; cross-compiling GCC.
66 (let ((target (%current-target-system)))
67 (if target
68 (map (lambda (var tool)
69 (string-append (string-append var "_FOR_TARGET")
70 "=" target "-" tool))
71 '("CC" "CXX" "LD" "AR" "NM" "RANLIB" "STRIP")
72 '("gcc" "g++" "ld" "ar" "nm" "ranlib" "strip"))
73 '()))))
74 (configure-flags
75 (lambda ()
76 ;; This is terrible. Since we have two levels of quasiquotation,
77 ;; we have to do this convoluted thing just so we can insert the
78 ;; contents of (maybe-target-tools).
79 (list 'quasiquote
80 (append
81 '("--enable-plugin"
82 "--enable-languages=c,c++"
83 "--disable-multilib"
84
06213498
LC
85 ;; No pre-compiled libstdc++ headers, to save space.
86 "--disable-libstdcxx-pch"
87
de1d41f9
LC
88 "--with-local-prefix=/no-gcc-local-prefix"
89
84e6756c
LC
90 ;; With a separate "lib" output, the build system
91 ;; incorrectly guesses GPLUSPLUS_INCLUDE_DIR, so force
92 ;; it. (Don't use a versioned sub-directory, that's
93 ;; unnecessary.)
94 ,(string-append "--with-gxx-include-dir="
95 (assoc-ref %outputs "out")
96 "/include/c++")
97
de1d41f9
LC
98 ,(let ((libc (assoc-ref %build-inputs "libc")))
99 (if libc
100 (string-append "--with-native-system-header-dir=" libc
101 "/include")
102 "--without-headers")))
103
ca16cb96
LC
104 ;; When cross-compiling GCC, pass the right options for the
105 ;; target triplet.
106 (or (and=> (%current-target-system)
107 gcc-configure-flags-for-triplet)
108 '())
109
de1d41f9 110 (maybe-target-tools))))))
e9c0b944 111 (package
de1d41f9 112 (name "gcc")
d2e2f142 113 (version "4.7.4")
de1d41f9
LC
114 (source (origin
115 (method url-fetch)
116 (uri (string-append "mirror://gnu/gcc/gcc-"
117 version "/gcc-" version ".tar.bz2"))
118 (sha256
119 (base32
d2e2f142 120 "10k2k71kxgay283ylbbhhs51cl55zn2q38vj5pk4k950qdnirrlj"))))
de1d41f9 121 (build-system gnu-build-system)
84e6756c
LC
122
123 ;; Separate out the run-time support libraries because all the
124 ;; dynamic-linked objects depend on it.
125 (outputs '("out" ; commands, etc. (60+ MiB)
126 "lib")) ; libgcc_s, libgomp, etc. (15+ MiB)
127
de1d41f9
LC
128 (inputs `(("gmp" ,gmp)
129 ("mpfr" ,mpfr)
130 ("mpc" ,mpc)
131 ("isl" ,isl)
132 ("cloog" ,cloog)
133 ("libelf" ,libelf)
134 ("zlib" ,zlib)))
c8ebc821
LC
135
136 ;; GCC is one of the few packages that doesn't ship .info files.
137 (native-inputs `(("texinfo" ,texinfo)))
138
de1d41f9
LC
139 (arguments
140 `(#:out-of-source? #t
141 #:strip-binaries? ,stripped?
142 #:configure-flags ,(configure-flags)
143 #:make-flags
fd0b2766
LC
144 ;; None of the flags below are needed when doing a Canadian cross.
145 ;; TODO: Simplify this.
146 ,(if (%current-target-system)
147 (if stripped?
148 ''("CFLAGS=-g0 -O2")
149 ''())
150 `(let* ((libc (assoc-ref %build-inputs "libc"))
151 (libc-native (or (assoc-ref %build-inputs "libc-native")
152 libc)))
153 `(,@(if libc
154 (list (string-append "LDFLAGS_FOR_TARGET="
155 "-B" libc "/lib "
156 "-Wl,-dynamic-linker "
157 "-Wl," libc
158 ,(glibc-dynamic-linker)))
159 '())
160
161 ;; Native programs like 'genhooks' also need that right.
162 ,(string-append "LDFLAGS="
163 "-Wl,-rpath=" libc-native "/lib "
164 "-Wl,-dynamic-linker "
165 "-Wl," libc-native ,(glibc-dynamic-linker))
166 ,(string-append "BOOT_CFLAGS=-O2 "
167 ,(if stripped? "-g0" "-g")))))
de1d41f9
LC
168
169 #:tests? #f
170 #:phases
171 (alist-cons-before
172 'configure 'pre-configure
173 (lambda* (#:key inputs outputs #:allow-other-keys)
84e6756c
LC
174 (let ((libdir (or (assoc-ref outputs "lib")
175 (assoc-ref outputs "out")))
176 (libc (assoc-ref inputs "libc")))
de1d41f9
LC
177 (when libc
178 ;; The following is not performed for `--without-headers'
179 ;; cross-compiler builds.
180
181 ;; Fix the dynamic linker's file name.
182 (substitute* (find-files "gcc/config"
183 "^linux(64|-elf)?\\.h$")
184 (("#define GLIBC_DYNAMIC_LINKER([^ ]*).*$" _ suffix)
185 (format #f "#define GLIBC_DYNAMIC_LINKER~a \"~a\"~%"
186 suffix
187 (string-append libc ,(glibc-dynamic-linker)))))
188
189 ;; Tell where to find libstdc++, libc, and `?crt*.o', except
190 ;; `crt{begin,end}.o', which come with GCC.
191 (substitute* (find-files "gcc/config"
06213498
LC
192 "^gnu-user.*\\.h$")
193 (("#define GNU_USER_TARGET_LIB_SPEC (.*)$" _ suffix)
a7bf595f
LC
194 ;; Help libgcc_s.so be found (see also below.) Always use
195 ;; '-lgcc_s' so that libgcc_s.so is always found by those
196 ;; programs that use 'pthread_cancel' (glibc dlopens
197 ;; libgcc_s.so when pthread_cancel support is needed, but
198 ;; having it in the application's RUNPATH isn't enough; see
199 ;; <http://sourceware.org/ml/libc-help/2013-11/msg00023.html>.)
06213498 200 (format #f "#define GNU_USER_TARGET_LIB_SPEC \
a7bf595f 201\"-L~a/lib %{!static:-rpath=~a/lib %{!static-libgcc:-rpath=~a/lib64 -rpath=~a/lib -lgcc_s}} \" ~a"
84e6756c 202 libc libc libdir libdir suffix))
06213498 203 (("#define GNU_USER_TARGET_STARTFILE_SPEC.*$" line)
de1d41f9 204 (format #f "#define STANDARD_STARTFILE_PREFIX_1 \"~a/lib\"
e9c0b944 205#define STANDARD_STARTFILE_PREFIX_2 \"\"
06213498 206~a"
de1d41f9
LC
207 libc line))))
208
209 ;; Don't retain a dependency on the build-time sed.
210 (substitute* "fixincludes/fixincl.x"
211 (("static char const sed_cmd_z\\[\\] =.*;")
84e6756c
LC
212 "static char const sed_cmd_z[] = \"sed\";"))
213
214 ;; Move libstdc++*-gdb.py to the "lib" output to avoid a
215 ;; circularity between "out" and "lib". (Note:
216 ;; --with-python-dir is useless because it imposes $(prefix) as
217 ;; the parent directory.)
218 (substitute* "libstdc++-v3/python/Makefile.in"
219 (("pythondir = .*$")
220 (string-append "pythondir = " libdir "/share"
221 "/gcc-$(gcc_version)/python\n")))
222
223 ;; Avoid another circularity between the outputs: this #define
224 ;; ends up in auto-host.h in the "lib" output, referring to
225 ;; "out". (This variable is used to augment cpp's search path,
226 ;; but there's nothing useful to look for here.)
227 (substitute* "gcc/config.in"
228 (("PREFIX_INCLUDE_DIR")
229 "PREFIX_INCLUDE_DIR_isnt_necessary_here"))))
de1d41f9
LC
230
231 (alist-cons-after
232 'configure 'post-configure
233 (lambda _
234 ;; Don't store configure flags, to avoid retaining references to
6f58d582 235 ;; build-time dependencies---e.g., `--with-ppl=/gnu/store/xxx'.
de1d41f9
LC
236 (substitute* "Makefile"
237 (("^TOPLEVEL_CONFIGURE_ARGUMENTS=(.*)$" _ rest)
238 "TOPLEVEL_CONFIGURE_ARGUMENTS=\n")))
239 (alist-replace 'install
240 (lambda* (#:key outputs #:allow-other-keys)
241 (zero?
5c860cec 242 (system* "make" ,(install-target))))
de1d41f9
LC
243 %standard-phases)))))
244
245 (native-search-paths
246 (list (search-path-specification
247 (variable "CPATH")
248 (directories '("include")))
249 (search-path-specification
250 (variable "LIBRARY_PATH")
251 (directories '("lib" "lib64")))))
252
253 (properties `((gcc-libc . ,(assoc-ref inputs "libc"))))
254 (synopsis "GNU Compiler Collection")
255 (description
a22dc0c4
LC
256 "GCC is the GNU Compiler Collection. It provides compiler front-ends
257for several languages, including C, C++, Objective-C, Fortran, Java, Ada, and
79c311b8 258Go. It also includes runtime support libraries for these languages.")
de1d41f9
LC
259 (license gpl3+)
260 (home-page "http://gcc.gnu.org/"))))
832abc76 261
3b401612 262(define-public gcc-4.8
3b401612 263 (package (inherit gcc-4.7)
a43da8f9 264 (version "4.8.3")
3b401612
LC
265 (source (origin
266 (method url-fetch)
267 (uri (string-append "mirror://gnu/gcc/gcc-"
268 version "/gcc-" version ".tar.bz2"))
269 (sha256
270 (base32
a43da8f9 271 "07hg10zs7gnqz58my10ch0zygizqh0z0bz6pv4pgxx45n48lz3ka"))))))
3b401612 272
571aa6cd
LC
273(define-public gcc-4.9
274 (package (inherit gcc-4.7)
da9c8102 275 (version "4.9.1")
571aa6cd
LC
276 (source (origin
277 (method url-fetch)
278 (uri (string-append "mirror://gnu/gcc/gcc-"
279 version "/gcc-" version ".tar.bz2"))
280 (sha256
281 (base32
da9c8102 282 "0zki3ngi0gsidnmsp88mjl2868cc7cm5wm1vwqw6znja28d7hd6k"))))))
571aa6cd 283
c4df90a5 284(define* (custom-gcc gcc name languages #:key (separate-lib-output? #t))
fdd6c726
NK
285 "Return a custom version of GCC that supports LANGUAGES."
286 (package (inherit gcc)
287 (name name)
c4df90a5
MW
288 (outputs (if separate-lib-output?
289 (package-outputs gcc)
290 (delete "lib" (package-outputs gcc))))
fdd6c726
NK
291 (arguments
292 (substitute-keyword-arguments `(#:modules ((guix build gnu-build-system)
293 (guix build utils)
294 (ice-9 regex)
295 (srfi srfi-1)
296 (srfi srfi-26))
297 ,@(package-arguments gcc))
298 ((#:configure-flags flags)
299 `(cons (string-append "--enable-languages="
300 ,(string-join languages ","))
301 (remove (cut string-match "--enable-languages.*" <>)
302 ,flags)))))))
303
304(define-public gfortran-4.8
305 (custom-gcc gcc-4.8 "gfortran" '("fortran")))
306
307(define-public gccgo-4.8
c4df90a5
MW
308 (custom-gcc gcc-4.8 "gccgo" '("go")
309 ;; Suppress the separate "lib" output, because otherwise the
310 ;; "lib" and "out" outputs would refer to each other, creating
311 ;; a cyclic dependency. <http://debbugs.gnu.org/18101>
312 #:separate-lib-output? #f))
fdd6c726
NK
313
314(define-public gcc-objc-4.8
315 (custom-gcc gcc-4.8 "gcc-objc" '("objc")))
316
317(define-public gcc-objc++-4.8
318 (custom-gcc gcc-4.8 "gcc-objc++" '("obj-c++")))
319
832abc76
LC
320(define-public isl
321 (package
322 (name "isl")
323 (version "0.11.1")
324 (source (origin
325 (method url-fetch)
326 (uri (list (string-append
590a4904 327 "http://isl.gforge.inria.fr/isl-"
832abc76
LC
328 version
329 ".tar.bz2")
330 (string-append %gcc-infrastructure
331 name "-" version ".tar.gz")))
332 (sha256
333 (base32
334 "13d9cqa5rzhbjq0xf0b2dyxag7pqa72xj9dhsa03m8ccr1a4npq9"))))
335 (build-system gnu-build-system)
336 (inputs `(("gmp" ,gmp)))
590a4904 337 (home-page "http://isl.gforge.inria.fr/")
832abc76
LC
338 (synopsis
339 "A library for manipulating sets and relations of integer points bounded
340by linear constraints")
341 (description
342 "isl is a library for manipulating sets and relations of integer points
343bounded by linear constraints. Supported operations on sets include
344intersection, union, set difference, emptiness check, convex hull, (integer)
345affine hull, integer projection, computing the lexicographic minimum using
346parametric integer programming, coalescing and parametric vertex
347enumeration. It also includes an ILP solver based on generalized basis
348reduction, transitive closures on maps (which may encode infinite graphs),
349dependence analysis and bounds on piecewise step-polynomials.")
350 (license lgpl2.1+)))
351
352(define-public cloog
353 (package
354 (name "cloog")
355 (version "0.18.0")
356 (source
357 (origin
358 (method url-fetch)
359 (uri (list (string-append
360 "http://www.bastoul.net/cloog/pages/download/count.php3?url=cloog-"
361 version
362 ".tar.gz")
363 (string-append %gcc-infrastructure
364 name "-" version ".tar.gz")))
365 (sha256
366 (base32
367 "0a12rwfwp22zd0nlld0xyql11cj390rrq1prw35yjsw8wzfshjhw"))
368 (file-name (string-append name "-" version ".tar.gz"))))
369 (build-system gnu-build-system)
370 (inputs `(("gmp" ,gmp)
371 ("isl" ,isl)))
372 (arguments '(#:configure-flags '("--with-isl=system")))
373 (home-page "http://www.cloog.org/")
374 (synopsis "A library to generate code for scanning Z-polyhedra")
375 (description
376 "CLooG is a free software library to generate code for scanning
377Z-polyhedra. That is, it finds a code (e.g., in C, FORTRAN...) that
378reaches each integral point of one or more parameterized polyhedra.
379CLooG has been originally written to solve the code generation problem
380for optimizing compilers based on the polytope model. Nevertheless it
381is used now in various area e.g., to build control automata for
382high-level synthesis or to find the best polynomial approximation of a
383function. CLooG may help in any situation where scanning polyhedra
384matters. While the user has full control on generated code quality,
385CLooG is designed to avoid control overhead and to produce a very
386effective code.")
387 (license gpl2+)))
5c126b64 388