gnu: emacs-consult: Fix grammar.
[jackhill/guix/guix.git] / gnu / packages / gcc.scm
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 Ludovic Courtès <ludo@gnu.org>
3 ;;; Copyright © 2014, 2015, 2018 Mark H Weaver <mhw@netris.org>
4 ;;; Copyright © 2014, 2015, 2016, 2017, 2019 Ricardo Wurmus <rekado@elephly.net>
5 ;;; Copyright © 2015 Andreas Enge <andreas@enge.fr>
6 ;;; Copyright © 2015, 2016, 2017, 2018, 2020, 2021 Efraim Flashner <efraim@flashner.co.il>
7 ;;; Copyright © 2016 Carlos Sánchez de La Lama <csanchezdll@gmail.com>
8 ;;; Copyright © 2018 Tobias Geerinckx-Rice <me@tobias.gr>
9 ;;; Copyright © 2018, 2020 Marius Bakke <mbakke@fastmail.com>
10 ;;; Copyright © 2020 Joseph LaFreniere <joseph@lafreniere.xyz>
11 ;;; Copyright © 2020 Guy Fleury Iteriteka <gfleury@disroot.org>
12 ;;; Copyright © 2020 Simon Tournier <zimon.toutoune@gmail.com>
13 ;;; Copyright © 2021 Chris Marusich <cmmarusich@gmail.com>
14 ;;;
15 ;;; This file is part of GNU Guix.
16 ;;;
17 ;;; GNU Guix is free software; you can redistribute it and/or modify it
18 ;;; under the terms of the GNU General Public License as published by
19 ;;; the Free Software Foundation; either version 3 of the License, or (at
20 ;;; your option) any later version.
21 ;;;
22 ;;; GNU Guix is distributed in the hope that it will be useful, but
23 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
24 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 ;;; GNU General Public License for more details.
26 ;;;
27 ;;; You should have received a copy of the GNU General Public License
28 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
29
30 (define-module (gnu packages gcc)
31 #:use-module ((guix licenses)
32 #:select (gpl3+ gpl2+ lgpl2.1+ lgpl2.0+ fdl1.3+))
33 #:use-module (gnu packages)
34 #:use-module (gnu packages bootstrap)
35 #:use-module (gnu packages compression)
36 #:use-module (gnu packages multiprecision)
37 #:use-module (gnu packages texinfo)
38 #:use-module (gnu packages dejagnu)
39 #:use-module (gnu packages documentation)
40 #:use-module (gnu packages xml)
41 #:use-module (gnu packages docbook)
42 #:use-module (gnu packages graphviz)
43 #:use-module (gnu packages elf)
44 #:use-module (gnu packages perl)
45 #:use-module (guix packages)
46 #:use-module (guix download)
47 #:use-module (guix build-system gnu)
48 #:use-module (guix build-system trivial)
49 #:use-module (guix utils)
50 #:use-module (srfi srfi-1)
51 #:use-module (ice-9 regex))
52
53 (define %gcc-infrastructure
54 ;; Base URL for GCC's infrastructure.
55 "mirror://gcc/infrastructure/")
56
57 (define (gcc-configure-flags-for-triplet target)
58 "Return a list of additional GCC `configure' flags for TARGET, a GNU triplet.
59
60 The purpose of this procedure is to translate extended GNU triplets---e.g.,
61 where the OS part is overloaded to denote a specific ABI---into GCC
62 `configure' options. We take extended GNU triplets that glibc recognizes."
63 (cond ((string-match "^mips64el.*gnuabin?64$" target)
64 ;; Triplets recognized by glibc as denoting the N64 ABI; see
65 ;; ports/sysdeps/mips/preconfigure.
66 '("--with-abi=64"))
67
68 ((string-match "^arm.*-gnueabihf$" target)
69 '("--with-arch=armv7-a"
70 "--with-float=hard"
71 "--with-mode=thumb"
72 "--with-fpu=neon"))
73
74 ((and (string-suffix? "-gnu" target)
75 (not (string-contains target "-linux")))
76 ;; Cross-compilation of libcilkrts in GCC 5.5.0 to GNU/Hurd fails
77 ;; with:
78 ;; libcilkrts/runtime/os-unix.c:388:2: error: #error "Unknown architecture"
79 ;; Cilk has been removed from GCC 8 anyway.
80 '("--disable-libcilkrts"))
81
82 (else
83 ;; TODO: Add `arm.*-gnueabi', etc.
84 '())))
85
86 (define-public gcc-4.7
87 (let* ((stripped? #t) ;whether to strip the compiler, not the libraries
88 (maybe-target-tools
89 (lambda ()
90 ;; Return the `_FOR_TARGET' variables that are needed when
91 ;; cross-compiling GCC.
92 (let ((target (%current-target-system)))
93 (if target
94 (map (lambda (var tool)
95 (string-append (string-append var "_FOR_TARGET")
96 "=" target "-" tool))
97 '("CC" "CXX" "LD" "AR" "NM" "OBJDUMP" "RANLIB" "STRIP")
98 '("gcc" "g++" "ld" "ar" "nm" "objdump" "ranlib" "strip"))
99 '()))))
100 (libdir
101 (let ((base '(or (assoc-ref outputs "lib")
102 (assoc-ref outputs "out"))))
103 (lambda ()
104 ;; Return the directory that contains lib/libgcc_s.so et al.
105 (if (%current-target-system)
106 `(string-append ,base "/" ,(%current-target-system))
107 base))))
108 (configure-flags
109 (lambda ()
110 ;; This is terrible. Since we have two levels of quasiquotation,
111 ;; we have to do this convoluted thing just so we can insert the
112 ;; contents of (maybe-target-tools).
113 (list 'quasiquote
114 (append
115 '("--enable-plugin"
116 "--enable-languages=c,c++"
117 "--disable-multilib"
118 "--with-system-zlib"
119
120 ;; No pre-compiled libstdc++ headers, to save space.
121 "--disable-libstdcxx-pch"
122
123 "--with-local-prefix=/no-gcc-local-prefix"
124
125 ;; With a separate "lib" output, the build system
126 ;; incorrectly guesses GPLUSPLUS_INCLUDE_DIR, so force
127 ;; it. (Don't use a versioned sub-directory, that's
128 ;; unnecessary.)
129 ,(string-append "--with-gxx-include-dir="
130 (assoc-ref %outputs "out")
131 "/include/c++")
132
133 ,(let ((libc (assoc-ref %build-inputs "libc")))
134 (if libc
135 (string-append "--with-native-system-header-dir=" libc
136 "/include")
137 "--without-headers")))
138
139 ;; Pass the right options for the target triplet.
140 (let ((triplet
141 (or (%current-target-system)
142 (nix-system->gnu-triplet (%current-system)))))
143 (gcc-configure-flags-for-triplet triplet))
144
145 (maybe-target-tools))))))
146 (hidden-package
147 (package
148 (name "gcc")
149 (version "4.7.4")
150 (source (origin
151 (method url-fetch)
152 (uri (string-append "mirror://gnu/gcc/gcc-"
153 version "/gcc-" version ".tar.bz2"))
154 (sha256
155 (base32
156 "10k2k71kxgay283ylbbhhs51cl55zn2q38vj5pk4k950qdnirrlj"))
157 (patches (search-patches "gcc-4-compile-with-gcc-5.patch"
158 "gcc-fix-texi2pod.patch"))))
159 (build-system gnu-build-system)
160
161 ;; Separate out the run-time support libraries because all the
162 ;; dynamic-linked objects depend on it.
163 (outputs '("out" ;commands, etc. (60+ MiB)
164 "lib" ;libgcc_s, libgomp, etc. (15+ MiB)
165 "debug")) ;debug symbols of run-time libraries
166
167 (inputs `(("gmp" ,gmp)
168 ("mpfr" ,mpfr)
169 ("mpc" ,mpc)
170 ("libelf" ,libelf)
171 ("zlib" ,zlib)))
172
173 ;; GCC < 5 is one of the few packages that doesn't ship .info files.
174 ;; Newer texinfos fail to build the manual, so we use an older one.
175 (native-inputs `(("perl" ,perl) ;for manpages
176 ("texinfo" ,texinfo-5)))
177
178 (arguments
179 `(#:out-of-source? #t
180 #:configure-flags ,(configure-flags)
181 #:make-flags
182 ;; None of the flags below are needed when doing a Canadian cross.
183 ;; TODO: Simplify this.
184 ,(if (%current-target-system)
185 (if stripped?
186 ''("CFLAGS=-g0 -O2")
187 ''())
188 `(let* ((libc (assoc-ref %build-inputs "libc"))
189 (libc-native (or (assoc-ref %build-inputs "libc-native")
190 libc)))
191 `(,@(if libc
192 (list (string-append "LDFLAGS_FOR_TARGET="
193 "-B" libc "/lib "
194 "-Wl,-dynamic-linker "
195 "-Wl," libc
196 ,(glibc-dynamic-linker)))
197 '())
198
199 ;; Native programs like 'genhooks' also need that right.
200 ,(string-append "LDFLAGS="
201 "-Wl,-rpath=" libc-native "/lib "
202 "-Wl,-dynamic-linker "
203 "-Wl," libc-native ,(glibc-dynamic-linker))
204 ,(string-append "BOOT_CFLAGS=-O2 "
205 ,(if stripped? "-g0" "-g")))))
206
207 #:tests? #f
208
209 #:phases
210 (modify-phases %standard-phases
211 (add-before 'configure 'pre-configure
212 (lambda* (#:key inputs outputs #:allow-other-keys)
213 (let ((libdir ,(libdir))
214 (libc (assoc-ref inputs "libc")))
215 (when libc
216 ;; The following is not performed for `--without-headers'
217 ;; cross-compiler builds.
218
219 ;; Join multi-line definitions of GLIBC_DYNAMIC_LINKER* into a
220 ;; single line, to allow the next step to work properly.
221 (for-each
222 (lambda (x)
223 (substitute* (find-files "gcc/config"
224 "^(linux|gnu|sysv4)(64|-elf|-eabi)?\\.h$")
225 (("(#define (GLIBC|GNU_USER)_DYNAMIC_LINKER.*)\\\\\n$" _ line)
226 line)))
227 '(1 2 3))
228
229 ;; Fix the dynamic linker's file name.
230 (substitute* (find-files "gcc/config"
231 "^(linux|gnu|sysv4)(64|-elf|-eabi)?\\.h$")
232 (("#define (GLIBC|GNU_USER)_DYNAMIC_LINKER([^ \t]*).*$"
233 _ gnu-user suffix)
234 (format #f "#define ~a_DYNAMIC_LINKER~a \"~a\"~%"
235 gnu-user suffix
236 (string-append libc ,(glibc-dynamic-linker)))))
237
238 ;; Tell where to find libstdc++, libc, and `?crt*.o', except
239 ;; `crt{begin,end}.o', which come with GCC.
240 (substitute* (find-files "gcc/config"
241 "^gnu-user.*\\.h$")
242 (("#define GNU_USER_TARGET_LIB_SPEC (.*)$" _ suffix)
243 ;; Help libgcc_s.so be found (see also below.) Always use
244 ;; '-lgcc_s' so that libgcc_s.so is always found by those
245 ;; programs that use 'pthread_cancel' (glibc dlopens
246 ;; libgcc_s.so when pthread_cancel support is needed, but
247 ;; having it in the application's RUNPATH isn't enough; see
248 ;; <http://sourceware.org/ml/libc-help/2013-11/msg00023.html>.)
249 ;;
250 ;; NOTE: The '-lgcc_s' added below needs to be removed in a
251 ;; later phase of %gcc-static. If you change the string
252 ;; below, make sure to update the relevant code in
253 ;; %gcc-static package as needed.
254 (format #f "#define GNU_USER_TARGET_LIB_SPEC \
255 \"-L~a/lib %{!static:-rpath=~a/lib %{!static-libgcc:-rpath=~a/lib -lgcc_s}} \" ~a"
256 libc libc libdir suffix))
257 (("#define GNU_USER_TARGET_STARTFILE_SPEC.*$" line)
258 (format #f "#define STANDARD_STARTFILE_PREFIX_1 \"~a/lib\"
259 #define STANDARD_STARTFILE_PREFIX_2 \"\"
260 ~a"
261 libc line)))
262
263 ;; The rs6000 (a.k.a. powerpc) config in GCC does not use
264 ;; GNU_USER_* defines. Do the above for this case.
265 (substitute*
266 "gcc/config/rs6000/sysv4.h"
267 (("#define LIB_LINUX_SPEC (.*)$" _ suffix)
268 (format #f "#define LIB_LINUX_SPEC \
269 \"-L~a/lib %{!static:-rpath=~a/lib %{!static-libgcc:-rpath=~a/lib -lgcc_s}} \" ~a"
270 libc libc libdir suffix))
271 (("#define STARTFILE_LINUX_SPEC.*$" line)
272 (format #f "#define STANDARD_STARTFILE_PREFIX_1 \"~a/lib\"
273 #define STANDARD_STARTFILE_PREFIX_2 \"\"
274 ~a"
275 libc line))))
276
277 ;; TODO: Make this unconditional in core-updates.
278 ,@(if (target-powerpc?)
279 `((when (file-exists? "gcc/config/rs6000")
280 ;; Force powerpc libdir to be /lib and not /lib64
281 (substitute* (find-files "gcc/config/rs6000")
282 (("/lib64") "/lib"))))
283 `())
284
285 ;; Don't retain a dependency on the build-time sed.
286 (substitute* "fixincludes/fixincl.x"
287 (("static char const sed_cmd_z\\[\\] =.*;")
288 "static char const sed_cmd_z[] = \"sed\";"))
289
290 ;; Aarch64 support didn't land in GCC until the 4.8 series.
291 (when (file-exists? "gcc/config/aarch64")
292 ;; Force Aarch64 libdir to be /lib and not /lib64
293 (substitute* "gcc/config/aarch64/t-aarch64-linux"
294 (("lib64") "lib")))
295
296 (when (file-exists? "libbacktrace")
297 ;; GCC 4.8+ comes with libbacktrace. By default it builds
298 ;; with -Werror, which fails with a -Wcast-qual error in glibc
299 ;; 2.21's stdlib-bsearch.h. Remove -Werror.
300 (substitute* "libbacktrace/configure"
301 (("WARN_FLAGS=(.*)-Werror" _ flags)
302 (string-append "WARN_FLAGS=" flags)))
303
304 (when (file-exists? "libsanitizer/libbacktrace")
305 ;; Same in libsanitizer's bundled copy (!) found in 4.9+.
306 (substitute* "libsanitizer/libbacktrace/Makefile.in"
307 (("-Werror")
308 ""))))
309
310 ;; Add a RUNPATH to libstdc++.so so that it finds libgcc_s.
311 ;; See <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=32354>
312 ;; and <http://bugs.gnu.org/20358>.
313 (substitute* "libstdc++-v3/src/Makefile.in"
314 (("^OPT_LDFLAGS = ")
315 "OPT_LDFLAGS = -Wl,-rpath=$(libdir) "))
316
317 ;; Move libstdc++*-gdb.py to the "lib" output to avoid a
318 ;; circularity between "out" and "lib". (Note:
319 ;; --with-python-dir is useless because it imposes $(prefix) as
320 ;; the parent directory.)
321 (substitute* "libstdc++-v3/python/Makefile.in"
322 (("pythondir = .*$")
323 (string-append "pythondir = " libdir "/share"
324 "/gcc-$(gcc_version)/python\n")))
325
326 ;; Avoid another circularity between the outputs: this #define
327 ;; ends up in auto-host.h in the "lib" output, referring to
328 ;; "out". (This variable is used to augment cpp's search path,
329 ;; but there's nothing useful to look for here.)
330 (substitute* "gcc/config.in"
331 (("PREFIX_INCLUDE_DIR")
332 "PREFIX_INCLUDE_DIR_isnt_necessary_here"))
333 #t)))
334
335 (add-after 'configure 'post-configure
336 (lambda _
337 ;; Don't store configure flags, to avoid retaining references to
338 ;; build-time dependencies---e.g., `--with-ppl=/gnu/store/xxx'.
339 (substitute* "Makefile"
340 (("^TOPLEVEL_CONFIGURE_ARGUMENTS=(.*)$" _ rest)
341 "TOPLEVEL_CONFIGURE_ARGUMENTS=\n"))
342 #t)))))
343
344 (native-search-paths
345 ;; Use the language-specific variables rather than 'CPATH' because they
346 ;; are equivalent to '-isystem' whereas 'CPATH' is equivalent to '-I'.
347 ;; The intent is to allow headers that are in the search path to be
348 ;; treated as "system headers" (headers exempt from warnings) just like
349 ;; the typical /usr/include headers on an FHS system.
350 (list (search-path-specification
351 (variable "C_INCLUDE_PATH")
352 (files '("include")))
353 (search-path-specification
354 (variable "CPLUS_INCLUDE_PATH")
355 ;; Add 'include/c++' here so that <cstdlib>'s "#include_next
356 ;; <stdlib.h>" finds GCC's <stdlib.h>, not libc's.
357 (files '("include/c++" "include")))
358 (search-path-specification
359 (variable "LIBRARY_PATH")
360 (files '("lib" "lib64")))))
361
362 (properties `((gcc-libc . ,(assoc-ref inputs "libc"))))
363 (synopsis "GNU Compiler Collection")
364 (description
365 "GCC is the GNU Compiler Collection. It provides compiler front-ends
366 for several languages, including C, C++, Objective-C, Fortran, Java, Ada, and
367 Go. It also includes runtime support libraries for these languages.")
368 (license gpl3+)
369 (supported-systems (delete "aarch64-linux" %supported-systems))
370 (home-page "https://gcc.gnu.org/")))))
371
372 (define-public gcc-4.8
373 (package (inherit gcc-4.7)
374 (version "4.8.5")
375 (source (origin
376 (method url-fetch)
377 (uri (string-append "mirror://gnu/gcc/gcc-"
378 version "/gcc-" version ".tar.bz2"))
379 (sha256
380 (base32
381 "08yggr18v373a1ihj0rg2vd6psnic42b518xcgp3r9k81xz1xyr2"))
382 (patches (search-patches "gcc-arm-link-spec-fix.patch"
383 "gcc-4.8-libsanitizer-fix.patch"
384 "gcc-asan-missing-include.patch"
385 "gcc-fix-texi2pod.patch"))
386 (modules '((guix build utils)))
387 ;; This is required for building with glibc-2.26.
388 ;; https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81712
389 (snippet
390 '(begin
391 (for-each
392 (lambda (dir)
393 (substitute* (string-append "libgcc/config/"
394 dir "/linux-unwind.h")
395 (("struct ucontext") "ucontext_t")))
396 '("aarch64" "alpha" "bfin" "i386" "m68k"
397 "pa" "sh" "tilepro" "xtensa"))
398 #t))))
399 (supported-systems %supported-systems)
400 (inputs
401 `(("isl" ,isl-0.11)
402 ("cloog" ,cloog)
403 ,@(package-inputs gcc-4.7)))))
404
405 (define-public gcc-4.9
406 (package (inherit gcc-4.8)
407 (version "4.9.4")
408 (source (origin
409 (method url-fetch)
410 (uri (string-append "mirror://gnu/gcc/gcc-"
411 version "/gcc-" version ".tar.bz2"))
412 (sha256
413 (base32
414 "14l06m7nvcvb0igkbip58x59w3nq6315k6jcz3wr9ch1rn9d44bc"))
415 (patches (search-patches "gcc-4.9-libsanitizer-fix.patch"
416 "gcc-4.9-libsanitizer-ustat.patch"
417 "gcc-4.9-libsanitizer-mode-size.patch"
418 "gcc-arm-bug-71399.patch"
419 "gcc-asan-missing-include.patch"
420 "gcc-libvtv-runpath.patch"
421 "gcc-fix-texi2pod.patch"))
422 (modules '((guix build utils)))
423 ;; This is required for building with glibc-2.26.
424 ;; https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81712
425 (snippet
426 '(begin
427 (for-each
428 (lambda (dir)
429 (substitute* (string-append "libgcc/config/"
430 dir "/linux-unwind.h")
431 (("struct ucontext") "ucontext_t")))
432 '("aarch64" "alpha" "bfin" "i386" "m68k" "nios2"
433 "pa" "sh" "tilepro" "xtensa"))
434 #t))))
435 ;; Override inherited texinfo-5 with latest version.
436 (native-inputs `(("perl" ,perl) ;for manpages
437 ("texinfo" ,texinfo)))
438 (arguments
439 (if (%current-target-system)
440 (package-arguments gcc-4.8)
441 ;; For native builds of GCC 4.9 and GCC 5, the C++ include path needs
442 ;; to be adjusted so it does not interfere with GCC's own build processes.
443 (substitute-keyword-arguments (package-arguments gcc-4.8)
444 ((#:modules modules %gnu-build-system-modules)
445 `((srfi srfi-1)
446 ,@modules))
447 ((#:phases phases)
448 `(modify-phases ,phases
449 (add-after 'set-paths 'adjust-CPLUS_INCLUDE_PATH
450 (lambda* (#:key inputs #:allow-other-keys)
451 (let ((libc (assoc-ref inputs "libc"))
452 (gcc (assoc-ref inputs "gcc")))
453 (setenv "CPLUS_INCLUDE_PATH"
454 (string-join (fold delete
455 (string-split (getenv "CPLUS_INCLUDE_PATH")
456 #\:)
457 (list (string-append libc "/include")
458 (string-append gcc "/include/c++")))
459 ":"))
460 (format #t
461 "environment variable `CPLUS_INCLUDE_PATH' changed to ~a~%"
462 (getenv "CPLUS_INCLUDE_PATH"))
463 #t))))))))))
464
465 (define-public gcc-5
466 ;; Note: GCC >= 5 ships with .info files but 'make install' fails to install
467 ;; them in a VPATH build.
468 (package (inherit gcc-4.9)
469 (version "5.5.0")
470 (source (origin
471 (method url-fetch)
472 (uri (string-append "mirror://gnu/gcc/gcc-"
473 version "/gcc-" version ".tar.xz"))
474 (sha256
475 (base32
476 "11zd1hgzkli3b2v70qsm2hyqppngd4616qc96lmm9zl2kl9yl32k"))
477 (patches (search-patches "gcc-arm-bug-71399.patch"
478 "gcc-libsanitizer-ustat.patch"
479 "gcc-strmov-store-file-names.patch"
480 "gcc-5.0-libvtv-runpath.patch"
481 "gcc-5-source-date-epoch-1.patch"
482 "gcc-5-source-date-epoch-2.patch"
483 "gcc-6-libsanitizer-mode-size.patch"
484 "gcc-fix-texi2pod.patch"
485 "gcc-5-hurd.patch"))
486 (modules '((guix build utils)))
487 (snippet
488 ;; Fix 'libcc1/configure' error when cross-compiling GCC.
489 ;; Without that, 'libcc1/configure' wrongfully determines that
490 ;; '-rdynamic' support is missing because $gcc_cv_objdump is
491 ;; empty:
492 ;;
493 ;; https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67590
494 ;; http://cgit.openembedded.org/openembedded-core/commit/?id=f6e47aa9b12f9ab61530c40e0343f451699d9077
495 '(begin
496 (substitute* "libcc1/configure"
497 (("\\$gcc_cv_objdump -T")
498 "$OBJDUMP_FOR_TARGET -T"))
499 #t))))
500 (inputs
501 `(;; GCC5 needs <isl/band.h> which is removed in later versions.
502 ("isl" ,isl-0.18)
503 ,@(package-inputs gcc-4.7)))))
504
505 (define-public gcc-6
506 (package
507 (inherit gcc-5)
508 (version "6.5.0")
509 (source (origin
510 (method url-fetch)
511 (uri (string-append "mirror://gnu/gcc/gcc-"
512 version "/gcc-" version ".tar.xz"))
513 (sha256
514 (base32
515 "0i89fksfp6wr1xg9l8296aslcymv2idn60ip31wr9s4pwin7kwby"))
516 (patches (search-patches "gcc-strmov-store-file-names.patch"
517 "gcc-6-libsanitizer-mode-size.patch"
518 "gcc-6-source-date-epoch-1.patch"
519 "gcc-6-source-date-epoch-2.patch"
520 "gcc-5.0-libvtv-runpath.patch"))))
521
522 ;; GCC 4.9 and 5 has a workaround that is not needed for GCC 6 and later.
523 (arguments (package-arguments gcc-4.8))
524
525 (inputs
526 `(("isl" ,isl)
527
528 ;; XXX: This gross hack allows us to have libstdc++'s <bits/c++config.h>
529 ;; in the search path, thereby avoiding misconfiguration of libstdc++:
530 ;; <https://bugs.gnu.org/42392>.
531 ("libstdc++" ,libstdc++-headers)
532
533 ,@(package-inputs gcc-4.7)))))
534
535 (define-public gcc-7
536 (package
537 (inherit gcc-6)
538 (version "7.5.0")
539 (source (origin
540 (method url-fetch)
541 (uri (string-append "mirror://gnu/gcc/gcc-"
542 version "/gcc-" version ".tar.xz"))
543 (sha256
544 (base32
545 "0qg6kqc5l72hpnj4vr6l0p69qav0rh4anlkk3y55540zy3klc6dq"))
546 (patches (search-patches "gcc-strmov-store-file-names.patch"
547 "gcc-7-libsanitizer-mode-size.patch"
548 "gcc-5.0-libvtv-runpath.patch"))))
549 (description
550 "GCC is the GNU Compiler Collection. It provides compiler front-ends
551 for several languages, including C, C++, Objective-C, Fortran, Ada, and Go.
552 It also includes runtime support libraries for these languages.")))
553
554 (define-public gcc-8
555 (package
556 (inherit gcc-7)
557 (version "8.4.0")
558 (source (origin
559 (method url-fetch)
560 (uri (string-append "mirror://gnu/gcc/gcc-"
561 version "/gcc-" version ".tar.xz"))
562 (sha256
563 (base32
564 "1m1d3gfix56w4aq8myazzfffkl8bqcrx4jhhapnjf7qfs596w2p3"))
565 (patches (search-patches "gcc-8-strmov-store-file-names.patch"
566 "gcc-5.0-libvtv-runpath.patch"))))))
567
568 (define-public gcc-9
569 (package
570 (inherit gcc-8)
571 (version "9.3.0")
572 (source (origin
573 (method url-fetch)
574 (uri (string-append "mirror://gnu/gcc/gcc-"
575 version "/gcc-" version ".tar.xz"))
576 (sha256
577 (base32
578 "1la2yy27ziasyf0jvzk58y1i5b5bq2h176qil550bxhifs39gqbi"))
579 (patches (search-patches "gcc-9-strmov-store-file-names.patch"
580 "gcc-9-asan-fix-limits-include.patch"
581 "gcc-5.0-libvtv-runpath.patch"))))))
582
583 (define-public gcc-10
584 (package
585 (inherit gcc-8)
586 (version "10.3.0")
587 (source (origin
588 (method url-fetch)
589 (uri (string-append "mirror://gnu/gcc/gcc-"
590 version "/gcc-" version ".tar.xz"))
591 (sha256
592 (base32
593 "0i6378ig6h397zkhd7m4ccwjx5alvzrf2hm27p1pzwjhlv0h9x34"))
594 (patches (search-patches "gcc-9-strmov-store-file-names.patch"
595 "gcc-5.0-libvtv-runpath.patch"))))))
596
597 ;; Note: When changing the default gcc version, update
598 ;; the gcc-toolchain-* definitions.
599 (define-public gcc gcc-7)
600
601 (define-public (make-libstdc++ gcc)
602 "Return a libstdc++ package based on GCC. The primary use case is when
603 using compilers other than GCC."
604 (package
605 (inherit gcc)
606 (name "libstdc++")
607 (arguments
608 `(#:out-of-source? #t
609 #:phases
610 ;; TODO: Use the target-powerpc arm for everyone.
611 ,(if (target-powerpc?)
612 `(modify-phases %standard-phases
613 ;; Force rs6000 (i.e., powerpc) libdir to be /lib and not /lib64.
614 (add-before 'chdir 'fix-rs6000-libdir
615 (lambda _
616 (when (file-exists? "gcc/config/rs6000")
617 (substitute* (find-files "gcc/config/rs6000")
618 (("/lib64") "/lib")))
619 #t))
620 (add-before 'configure 'chdir
621 (lambda _
622 (chdir "libstdc++-v3")
623 #t)))
624 `(alist-cons-before 'configure 'chdir
625 (lambda _
626 (chdir "libstdc++-v3")
627 #t)
628 %standard-phases))
629
630 #:configure-flags `("--disable-libstdcxx-pch"
631 ,(string-append "--with-gxx-include-dir="
632 (assoc-ref %outputs "out")
633 "/include"))))
634 (outputs '("out" "debug"))
635 (inputs '())
636 (native-inputs '())
637 (propagated-inputs '())
638 (synopsis "GNU C++ standard library")))
639
640 (define libstdc++
641 ;; Libstdc++ matching the default GCC.
642 (make-libstdc++ gcc))
643
644 (define libstdc++-headers
645 ;; XXX: This package is for internal use to work around
646 ;; <https://bugs.gnu.org/42392> (see above). The main difference compared
647 ;; to the libstdc++ headers that come with 'gcc' is that <bits/c++config.h>
648 ;; is right under include/c++ and not under
649 ;; include/c++/x86_64-unknown-linux-gnu (aka. GPLUSPLUS_TOOL_INCLUDE_DIR).
650 (package
651 (inherit libstdc++)
652 (name "libstdc++-headers")
653 (outputs '("out"))
654 (build-system trivial-build-system)
655 (arguments
656 '(#:builder (let* ((out (assoc-ref %outputs "out"))
657 (libstdc++ (assoc-ref %build-inputs "libstdc++")))
658 (mkdir out)
659 (mkdir (string-append out "/include"))
660 (symlink (string-append libstdc++ "/include")
661 (string-append out "/include/c++")))))
662 (inputs `(("libstdc++" ,libstdc++)))
663 (synopsis "Headers of GNU libstdc++")))
664
665 (define-public libstdc++-4.9
666 (make-libstdc++ gcc-4.9))
667
668 (define (make-libiberty gcc)
669 "Return a libiberty package based on GCC."
670 (package
671 (inherit gcc)
672 (name "libiberty")
673 (arguments
674 `(#:out-of-source? #t
675 #:phases
676 (modify-phases %standard-phases
677 (add-before 'configure 'chdir
678 (lambda _
679 (chdir "libiberty")
680 #t))
681 (replace 'install
682 (lambda* (#:key outputs #:allow-other-keys)
683 (let* ((out (assoc-ref outputs "out"))
684 (lib (string-append out "/lib/"))
685 (include (string-append out "/include/")))
686 (install-file "libiberty.a" lib)
687 (install-file "../include/libiberty.h" include))
688 #t)))))
689 (inputs '())
690 (outputs '("out"))
691 (native-inputs '())
692 (propagated-inputs '())
693 (properties '())
694 (synopsis "Collection of subroutines used by various GNU programs")))
695
696 (define-public libiberty
697 (make-libiberty gcc))
698
699 (define* (custom-gcc gcc name languages
700 #:optional
701 (search-paths (package-native-search-paths gcc))
702 #:key (separate-lib-output? #t))
703 "Return a custom version of GCC that supports LANGUAGES. Use SEARCH-PATHS
704 as the 'native-search-paths' field."
705 (package (inherit gcc)
706 (name name)
707 (outputs (if separate-lib-output?
708 (package-outputs gcc)
709 (delete "lib" (package-outputs gcc))))
710 (native-search-paths search-paths)
711 (properties (alist-delete 'hidden? (package-properties gcc)))
712 (arguments
713 (substitute-keyword-arguments (package-arguments gcc)
714 ((#:modules modules %gnu-build-system-modules)
715 `(,@modules
716 (srfi srfi-1)
717 (srfi srfi-26)
718 (ice-9 regex)))
719 ((#:configure-flags flags)
720 `(cons (string-append "--enable-languages="
721 ,(string-join languages ","))
722 (remove (cut string-match "--enable-languages.*" <>)
723 ,flags)))
724 ((#:phases phases)
725 `(modify-phases ,phases
726 (add-after 'install 'remove-broken-or-conflicting-files
727 (lambda* (#:key outputs #:allow-other-keys)
728 (for-each delete-file
729 (find-files (string-append (assoc-ref outputs "out") "/bin")
730 ".*(c\\+\\+|cpp|g\\+\\+|gcov|gcc|gcc-.*)"))
731 #t))))))))
732
733 (define %generic-search-paths
734 ;; This is the language-neutral search path for GCC. Entries in $CPATH are
735 ;; not considered "system headers", which means GCC can raise warnings for
736 ;; issues in those headers. 'CPATH' is the only one that works for
737 ;; front-ends not in the C family.
738 (list (search-path-specification
739 (variable "CPATH")
740 (files '("include")))
741 (search-path-specification
742 (variable "LIBRARY_PATH")
743 (files '("lib" "lib64")))))
744
745 (define-public gfortran
746 (hidden-package
747 (custom-gcc (package
748 (inherit gcc)
749 ;; XXX: Remove LIBSTDC++-HEADERS from the inputs just to
750 ;; avoid a rebuild of all the GFORTRAN dependents.
751 ;; TODO: Remove this hack on the next rebuild cycle.
752 (inputs (alist-delete "libstdc++" (package-inputs gcc))))
753 "gfortran" '("fortran")
754 %generic-search-paths)))
755
756 (define-public gdc-10
757 (hidden-package
758 (custom-gcc gcc-10 "gdc" '("d")
759 %generic-search-paths)))
760
761 (define-public libgccjit
762 (package
763 (inherit gcc-9)
764 (name "libgccjit")
765 (outputs (delete "lib" (package-outputs gcc)))
766 (properties (alist-delete 'hidden? (package-properties gcc)))
767 (arguments
768 (substitute-keyword-arguments `(#:modules ((guix build gnu-build-system)
769 (guix build utils)
770 (ice-9 regex)
771 (srfi srfi-1)
772 (srfi srfi-26))
773 ,@(package-arguments gcc))
774 ((#:configure-flags flags)
775 `(append `("--enable-host-shared"
776 ,(string-append "--enable-languages=jit"))
777 (remove (cut string-match "--enable-languages.*" <>)
778 ,flags)))
779 ((#:phases phases)
780 `(modify-phases ,phases
781 (add-after 'install 'remove-broken-or-conflicting-files
782 (lambda* (#:key outputs #:allow-other-keys)
783 (for-each delete-file
784 (find-files (string-append (assoc-ref outputs "out") "/bin")
785 ".*(c\\+\\+|cpp|g\\+\\+|gcov|gcc|gcc-.*)"))
786 #t))))))
787 (synopsis "GCC library generating machine code on-the-fly at runtime")
788 (description
789 "This package is part of the GNU Compiler Collection and provides an
790 embeddable library for generating machine code on-the-fly at runtime. This
791 shared library can then be dynamically-linked into bytecode interpreters and
792 other such programs that want to generate machine code on-the-fly at run-time.
793 It can also be used for ahead-of-time code generation for building standalone
794 compilers. The just-in-time (jit) part of the name is now something of a
795 misnomer.")))
796
797
798 (define-public gccgo-4.9
799 (custom-gcc (package
800 (inherit gcc-4.9)
801 (synopsis "Go frontend to GCC")
802 (description
803 "This package is part of the GNU Compiler Collection and
804 provides the GNU compiler for the Go programming language."))
805 "gccgo" '("go")
806 %generic-search-paths
807 ;; Suppress the separate "lib" output, because otherwise the
808 ;; "lib" and "out" outputs would refer to each other, creating
809 ;; a cyclic dependency. <http://debbugs.gnu.org/18101>
810 #:separate-lib-output? #f))
811
812 (define %objc-search-paths
813 (list (search-path-specification
814 (variable "OBJC_INCLUDE_PATH")
815 (files '("include")))
816 (search-path-specification
817 (variable "LIBRARY_PATH")
818 (files '("lib" "lib64")))))
819
820 (define-public gcc-objc-4.8
821 (custom-gcc gcc-4.8 "gcc-objc" '("objc")
822 %objc-search-paths))
823
824 (define-public gcc-objc-4.9
825 (custom-gcc gcc-4.9 "gcc-objc" '("objc")
826 %objc-search-paths))
827
828 (define-public gcc-objc-5
829 (custom-gcc gcc-5 "gcc-objc" '("objc")
830 %objc-search-paths))
831
832 (define-public gcc-objc-6
833 (custom-gcc gcc-6 "gcc-objc" '("objc")
834 %objc-search-paths))
835
836 (define-public gcc-objc-7
837 (custom-gcc gcc-7 "gcc-objc" '("objc")
838 %objc-search-paths))
839
840 (define-public gcc-objc-8
841 (custom-gcc gcc-8 "gcc-objc" '("objc")
842 %objc-search-paths))
843
844 (define-public gcc-objc-9
845 (custom-gcc gcc-9 "gcc-objc" '("objc")
846 %objc-search-paths))
847
848 (define-public gcc-objc-10
849 (custom-gcc gcc-10 "gcc-objc" '("objc")
850 %objc-search-paths))
851
852 (define-public gcc-objc gcc-objc-7)
853
854 (define %objc++-search-paths
855 (list (search-path-specification
856 (variable "OBJCPLUS_INCLUDE_PATH")
857 (files '("include")))
858 (search-path-specification
859 (variable "LIBRARY_PATH")
860 (files '("lib" "lib64")))))
861
862 (define-public gcc-objc++-4.8
863 (custom-gcc gcc-4.8 "gcc-objc++" '("obj-c++")
864 %objc++-search-paths))
865
866 (define-public gcc-objc++-4.9
867 (custom-gcc gcc-4.9 "gcc-objc++" '("obj-c++")
868 %objc++-search-paths))
869
870 (define-public gcc-objc++-5
871 (custom-gcc gcc-5 "gcc-objc++" '("obj-c++")
872 %objc++-search-paths))
873
874 (define-public gcc-objc++-6
875 (custom-gcc gcc-6 "gcc-objc++" '("obj-c++")
876 %objc++-search-paths))
877
878 (define-public gcc-objc++-7
879 (custom-gcc gcc-7 "gcc-objc++" '("obj-c++")
880 %objc++-search-paths))
881
882 (define-public gcc-objc++-8
883 (custom-gcc gcc-8 "gcc-objc++" '("obj-c++")
884 %objc++-search-paths))
885
886 (define-public gcc-objc++-9
887 (custom-gcc gcc-9 "gcc-objc++" '("obj-c++")
888 %objc++-search-paths))
889
890 (define-public gcc-objc++-10
891 (custom-gcc gcc-10 "gcc-objc++" '("obj-c++")
892 %objc++-search-paths))
893
894 (define-public gcc-objc++ gcc-objc++-7)
895
896 (define (make-libstdc++-doc gcc)
897 "Return a package with the libstdc++ documentation for GCC."
898 (package
899 (inherit gcc)
900 (name "libstdc++-doc")
901 (version (package-version gcc))
902 (synopsis "GNU libstdc++ documentation")
903 (outputs '("out"))
904 (native-inputs `(("doxygen" ,doxygen)
905 ("texinfo" ,texinfo)
906 ("libxml2" ,libxml2)
907 ("libxslt" ,libxslt)
908 ("docbook-xml" ,docbook-xml)
909 ("docbook-xsl" ,docbook-xsl)
910 ("graphviz" ,graphviz))) ;for 'dot', invoked by 'doxygen'
911 (inputs '())
912 (propagated-inputs '())
913 (arguments
914 '(#:out-of-source? #t
915 #:tests? #f ;it's just documentation
916 #:phases (modify-phases %standard-phases
917 (add-before 'configure 'chdir
918 (lambda _
919 (chdir "libstdc++-v3")
920 #t))
921 (add-before 'configure 'set-xsl-directory
922 (lambda* (#:key inputs #:allow-other-keys)
923 (let ((docbook (assoc-ref inputs "docbook-xsl")))
924 (substitute* (find-files "doc"
925 "^Makefile\\.in$")
926 (("@XSL_STYLE_DIR@")
927 (string-append
928 docbook "/xml/xsl/"
929 (strip-store-file-name docbook))))
930 #t)))
931 (replace 'build
932 (lambda _
933 ;; XXX: There's also a 'doc-info' target, but it
934 ;; relies on docbook2X, which itself relies on
935 ;; DocBook 4.1.2, which is not really usable
936 ;; (lacks a catalog.xml.)
937 (invoke "make"
938 "doc-html"
939 "doc-man")))
940 (replace 'install
941 (lambda* (#:key outputs #:allow-other-keys)
942 (let ((out (assoc-ref outputs "out")))
943 (invoke "make"
944 "doc-install-html"
945 "doc-install-man")))))))
946 (properties (alist-delete 'hidden? (package-properties gcc)))))
947
948 (define-public libstdc++-doc-5
949 (make-libstdc++-doc gcc-5))
950
951 (define-public libstdc++-doc-9
952 (make-libstdc++-doc gcc-9))
953
954 (define-public isl
955 (package
956 (name "isl")
957 (version "0.22.1")
958 (source (origin
959 (method url-fetch)
960 (uri (list (string-append
961 "http://isl.gforge.inria.fr/isl-"
962 version
963 ".tar.bz2")
964 (string-append %gcc-infrastructure
965 name "-" version ".tar.bz2")))
966 (sha256
967 (base32
968 "1kf54jib0nind1pvakblnfhimmwzm0y1llz8470ag0di5vwqwrhs"))))
969 (build-system gnu-build-system)
970 (outputs '("out" "static"))
971 (arguments
972 '(#:phases (modify-phases %standard-phases
973 (add-after 'install 'move-static-library
974 (lambda* (#:key outputs #:allow-other-keys)
975 (let* ((out (assoc-ref outputs "out"))
976 (static (assoc-ref outputs "static"))
977 (source (string-append out "/lib/libisl.a"))
978 (target (string-append static "/lib/libisl.a")))
979 (mkdir-p (dirname target))
980 (link source target)
981 (delete-file source)
982
983 ;; Remove reference to libisl.a from the .la file so
984 ;; libtool looks for it in the usual locations.
985 (substitute* (string-append out "/lib/libisl.la")
986 (("^old_library=.*")
987 "old_library=''\n"))
988 #t))))))
989 (inputs `(("gmp" ,gmp)))
990 (home-page "http://isl.gforge.inria.fr/")
991 (synopsis
992 "Manipulating sets and relations of integer points \
993 bounded by linear constraints")
994 (description
995 "isl is a library for manipulating sets and relations of integer points
996 bounded by linear constraints. Supported operations on sets include
997 intersection, union, set difference, emptiness check, convex hull, (integer)
998 affine hull, integer projection, computing the lexicographic minimum using
999 parametric integer programming, coalescing and parametric vertex
1000 enumeration. It also includes an ILP solver based on generalized basis
1001 reduction, transitive closures on maps (which may encode infinite graphs),
1002 dependence analysis and bounds on piecewise step-polynomials.")
1003 (license lgpl2.1+)))
1004
1005 (define-public isl-0.18
1006 (package
1007 (inherit isl)
1008 (version "0.18")
1009 (source (origin
1010 (method url-fetch)
1011 (uri (list (string-append "http://isl.gforge.inria.fr/isl-"
1012 version ".tar.bz2")
1013 (string-append %gcc-infrastructure
1014 "isl-" version ".tar.bz2")))
1015 (sha256
1016 (base32
1017 "06ybml6llhi4i56q90jnimbcgk1lpcdwhy9nxdxra2hxz3bhz2vb"))))))
1018
1019 (define-public isl-0.11
1020 (package
1021 (inherit isl)
1022 (name "isl")
1023 (version "0.11.1")
1024 (source (origin
1025 (method url-fetch)
1026 (uri (list (string-append
1027 "http://isl.gforge.inria.fr/isl-"
1028 version
1029 ".tar.bz2")
1030 (string-append %gcc-infrastructure
1031 name "-" version ".tar.bz2")))
1032 (sha256
1033 (base32
1034 "13d9cqa5rzhbjq0xf0b2dyxag7pqa72xj9dhsa03m8ccr1a4npq9"))
1035 (patches (search-patches "isl-0.11.1-aarch64-support.patch"))))))
1036
1037 (define-public cloog
1038 (package
1039 (name "cloog")
1040 (version "0.18.0")
1041 (source
1042 (origin
1043 (method url-fetch)
1044 (uri (list (string-append
1045 "http://www.bastoul.net/cloog/pages/download/count.php3?url=cloog-"
1046 version
1047 ".tar.gz")
1048 (string-append %gcc-infrastructure
1049 name "-" version ".tar.gz")))
1050 (sha256
1051 (base32
1052 "0a12rwfwp22zd0nlld0xyql11cj390rrq1prw35yjsw8wzfshjhw"))
1053 (file-name (string-append name "-" version ".tar.gz"))))
1054 (build-system gnu-build-system)
1055 (inputs `(("gmp" ,gmp)
1056 ("isl" ,isl-0.11)))
1057 (arguments '(#:configure-flags '("--with-isl=system")))
1058 (home-page "http://www.cloog.org/")
1059 (synopsis "Library to generate code for scanning Z-polyhedra")
1060 (description
1061 "CLooG is a free software library to generate code for scanning
1062 Z-polyhedra. That is, it finds a code (e.g., in C, FORTRAN...) that
1063 reaches each integral point of one or more parameterized polyhedra.
1064 CLooG has been originally written to solve the code generation problem
1065 for optimizing compilers based on the polytope model. Nevertheless it
1066 is used now in various area e.g., to build control automata for
1067 high-level synthesis or to find the best polynomial approximation of a
1068 function. CLooG may help in any situation where scanning polyhedra
1069 matters. While the user has full control on generated code quality,
1070 CLooG is designed to avoid control overhead and to produce a very
1071 effective code.")
1072 (license gpl2+)))
1073
1074 (define-public gnu-c-manual
1075 (package
1076 (name "gnu-c-manual")
1077 (version "0.2.5")
1078 (source (origin
1079 (method url-fetch)
1080 (uri (string-append "mirror://gnu/gnu-c-manual/gnu-c-manual-"
1081 version ".tar.gz"))
1082 (sha256
1083 (base32
1084 "1sfsj9256w18qzylgag2h5h377aq8in8929svblfnj9svfriqcys"))))
1085 (build-system gnu-build-system)
1086 (native-inputs `(("texinfo" ,texinfo)))
1087 (arguments
1088 '(#:phases (modify-phases %standard-phases
1089 (delete 'configure)
1090 (delete 'check)
1091 (replace 'build
1092 (lambda _
1093 (invoke "make"
1094 "gnu-c-manual.info"
1095 "gnu-c-manual.html")))
1096 (replace 'install
1097 (lambda* (#:key outputs #:allow-other-keys)
1098 (let* ((out (assoc-ref outputs "out"))
1099 (info (string-append out "/share/info"))
1100 (html (string-append
1101 out "/share/doc/gnu-c-manual")))
1102 (mkdir-p info)
1103 (mkdir-p html)
1104
1105 (for-each (lambda (file)
1106 (copy-file file
1107 (string-append info "/"
1108 file)))
1109 (find-files "." "\\.info(-[0-9])?$"))
1110 (for-each (lambda (file)
1111 (copy-file file
1112 (string-append html "/"
1113 file)))
1114 (find-files "." "\\.html$"))
1115 #t))))))
1116 (synopsis "Reference manual for the C programming language")
1117 (description
1118 "This is a reference manual for the C programming language, as
1119 implemented by the GNU C Compiler (gcc). As a reference, it is not intended
1120 to be a tutorial of the language. Rather, it outlines all of the constructs
1121 of the language. Library functions are not included.")
1122 (home-page "https://www.gnu.org/software/gnu-c-manual/")
1123 (license fdl1.3+)))