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