gnu: qemu: Remove dependency on Samba.
[jackhill/guix/guix.git] / gnu / packages / gcc.scm
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2012, 2013, 2014 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 #:select (gpl3+ gpl2+ lgpl2.1+ lgpl2.0+))
22 #:use-module (gnu packages)
23 #:use-module (gnu packages bootstrap)
24 #:use-module (gnu packages compression)
25 #:use-module (gnu packages multiprecision)
26 #:use-module (gnu packages texinfo)
27 #:use-module (gnu packages elf)
28 #:use-module (guix packages)
29 #:use-module (guix download)
30 #:use-module (guix build-system gnu)
31 #:use-module (guix utils)
32 #:use-module (ice-9 regex))
33
34 (define %gcc-infrastructure
35 ;; Base URL for GCC's infrastructure.
36 "ftp://gcc.gnu.org/pub/gcc/infrastructure/")
37
38 (define-public (gcc-configure-flags-for-triplet target)
39 "Return a list of additional GCC `configure' flags for TARGET, a GNU triplet.
40
41 The purpose of this procedure is to translate extended GNU triplets---e.g.,
42 where 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
52 (define-public gcc-4.7
53 (let* ((stripped? #t) ; TODO: make this a parameter
54 (install-target
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")))
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
85 ;; No pre-compiled libstdc++ headers, to save space.
86 "--disable-libstdcxx-pch"
87
88 "--with-local-prefix=/no-gcc-local-prefix"
89
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
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
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
110 (maybe-target-tools))))))
111 (package
112 (name "gcc")
113 (version "4.7.4")
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
120 "10k2k71kxgay283ylbbhhs51cl55zn2q38vj5pk4k950qdnirrlj"))))
121 (build-system gnu-build-system)
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
128 (inputs `(("gmp" ,gmp)
129 ("mpfr" ,mpfr)
130 ("mpc" ,mpc)
131 ("isl" ,isl)
132 ("cloog" ,cloog)
133 ("libelf" ,libelf)
134 ("zlib" ,zlib)))
135
136 ;; GCC is one of the few packages that doesn't ship .info files.
137 (native-inputs `(("texinfo" ,texinfo)))
138
139 (arguments
140 `(#:out-of-source? #t
141 #:strip-binaries? ,stripped?
142 #:configure-flags ,(configure-flags)
143 #:make-flags
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")))))
168
169 #:tests? #f
170 #:phases
171 (alist-cons-before
172 'configure 'pre-configure
173 (lambda* (#:key inputs outputs #:allow-other-keys)
174 (let ((libdir (or (assoc-ref outputs "lib")
175 (assoc-ref outputs "out")))
176 (libc (assoc-ref inputs "libc")))
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"
192 "^gnu-user.*\\.h$")
193 (("#define GNU_USER_TARGET_LIB_SPEC (.*)$" _ suffix)
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>.)
200 (format #f "#define GNU_USER_TARGET_LIB_SPEC \
201 \"-L~a/lib %{!static:-rpath=~a/lib %{!static-libgcc:-rpath=~a/lib64 -rpath=~a/lib -lgcc_s}} \" ~a"
202 libc libc libdir libdir suffix))
203 (("#define GNU_USER_TARGET_STARTFILE_SPEC.*$" line)
204 (format #f "#define STANDARD_STARTFILE_PREFIX_1 \"~a/lib\"
205 #define STANDARD_STARTFILE_PREFIX_2 \"\"
206 ~a"
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\\[\\] =.*;")
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"))))
230
231 (alist-cons-after
232 'configure 'post-configure
233 (lambda _
234 ;; Don't store configure flags, to avoid retaining references to
235 ;; build-time dependencies---e.g., `--with-ppl=/gnu/store/xxx'.
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?
242 (system* "make" ,(install-target))))
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
256 "GCC is the GNU Compiler Collection. It provides compiler front-ends
257 for several languages, including C, C++, Objective-C, Fortran, Java, Ada, and
258 Go. It also includes runtime support libraries for these languages.")
259 (license gpl3+)
260 (home-page "http://gcc.gnu.org/"))))
261
262 (define-public gcc-4.8
263 (package (inherit gcc-4.7)
264 (version "4.8.3")
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
271 "07hg10zs7gnqz58my10ch0zygizqh0z0bz6pv4pgxx45n48lz3ka"))))))
272
273 (define-public gcc-4.9
274 (package (inherit gcc-4.7)
275 (version "4.9.0")
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
282 "0mqjxpw2klskls00lwx1k24pnyzm3whqxg3hk74c3sddgfllgc5r"))))))
283
284 (define (custom-gcc gcc name languages)
285 "Return a custom version of GCC that supports LANGUAGES."
286 (package (inherit gcc)
287 (name name)
288 (arguments
289 (substitute-keyword-arguments `(#:modules ((guix build gnu-build-system)
290 (guix build utils)
291 (ice-9 regex)
292 (srfi srfi-1)
293 (srfi srfi-26))
294 ,@(package-arguments gcc))
295 ((#:configure-flags flags)
296 `(cons (string-append "--enable-languages="
297 ,(string-join languages ","))
298 (remove (cut string-match "--enable-languages.*" <>)
299 ,flags)))))))
300
301 (define-public gfortran-4.8
302 (custom-gcc gcc-4.8 "gfortran" '("fortran")))
303
304 (define-public gccgo-4.8
305 (custom-gcc gcc-4.8 "gccgo" '("go")))
306
307 (define-public gcc-objc-4.8
308 (custom-gcc gcc-4.8 "gcc-objc" '("objc")))
309
310 (define-public gcc-objc++-4.8
311 (custom-gcc gcc-4.8 "gcc-objc++" '("obj-c++")))
312
313 (define-public isl
314 (package
315 (name "isl")
316 (version "0.11.1")
317 (source (origin
318 (method url-fetch)
319 (uri (list (string-append
320 "http://isl.gforge.inria.fr/isl-"
321 version
322 ".tar.bz2")
323 (string-append %gcc-infrastructure
324 name "-" version ".tar.gz")))
325 (sha256
326 (base32
327 "13d9cqa5rzhbjq0xf0b2dyxag7pqa72xj9dhsa03m8ccr1a4npq9"))))
328 (build-system gnu-build-system)
329 (inputs `(("gmp" ,gmp)))
330 (home-page "http://isl.gforge.inria.fr/")
331 (synopsis
332 "A library for manipulating sets and relations of integer points bounded
333 by linear constraints")
334 (description
335 "isl is a library for manipulating sets and relations of integer points
336 bounded by linear constraints. Supported operations on sets include
337 intersection, union, set difference, emptiness check, convex hull, (integer)
338 affine hull, integer projection, computing the lexicographic minimum using
339 parametric integer programming, coalescing and parametric vertex
340 enumeration. It also includes an ILP solver based on generalized basis
341 reduction, transitive closures on maps (which may encode infinite graphs),
342 dependence analysis and bounds on piecewise step-polynomials.")
343 (license lgpl2.1+)))
344
345 (define-public cloog
346 (package
347 (name "cloog")
348 (version "0.18.0")
349 (source
350 (origin
351 (method url-fetch)
352 (uri (list (string-append
353 "http://www.bastoul.net/cloog/pages/download/count.php3?url=cloog-"
354 version
355 ".tar.gz")
356 (string-append %gcc-infrastructure
357 name "-" version ".tar.gz")))
358 (sha256
359 (base32
360 "0a12rwfwp22zd0nlld0xyql11cj390rrq1prw35yjsw8wzfshjhw"))
361 (file-name (string-append name "-" version ".tar.gz"))))
362 (build-system gnu-build-system)
363 (inputs `(("gmp" ,gmp)
364 ("isl" ,isl)))
365 (arguments '(#:configure-flags '("--with-isl=system")))
366 (home-page "http://www.cloog.org/")
367 (synopsis "A library to generate code for scanning Z-polyhedra")
368 (description
369 "CLooG is a free software library to generate code for scanning
370 Z-polyhedra. That is, it finds a code (e.g., in C, FORTRAN...) that
371 reaches each integral point of one or more parameterized polyhedra.
372 CLooG has been originally written to solve the code generation problem
373 for optimizing compilers based on the polytope model. Nevertheless it
374 is used now in various area e.g., to build control automata for
375 high-level synthesis or to find the best polynomial approximation of a
376 function. CLooG may help in any situation where scanning polyhedra
377 matters. While the user has full control on generated code quality,
378 CLooG is designed to avoid control overhead and to produce a very
379 effective code.")
380 (license gpl2+)))
381