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