gnu: gcc: Do not always disable RUNPATH validation.
[guix.git] / gnu / packages / gcc.scm
blobca85073ea492b18456d367a0347ec8225273de4c
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2012, 2013, 2014, 2015 Ludovic Courtès <ludo@gnu.org>
3 ;;; Copyright © 2014, 2015 Mark H Weaver <mhw@netris.org>
4 ;;; Copyright © 2014 Ricardo Wurmus <rekado@elephly.net>
5 ;;; Copyright © 2015 Andreas Enge <andreas@enge.fr>
6 ;;;
7 ;;; This file is part of GNU Guix.
8 ;;;
9 ;;; GNU Guix is free software; you can redistribute it and/or modify it
10 ;;; under the terms of the GNU General Public License as published by
11 ;;; the Free Software Foundation; either version 3 of the License, or (at
12 ;;; your option) any later version.
13 ;;;
14 ;;; GNU Guix is distributed in the hope that it will be useful, but
15 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 ;;; GNU General Public License for more details.
18 ;;;
19 ;;; You should have received a copy of the GNU General Public License
20 ;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.
22 (define-module (gnu packages gcc)
23   #:use-module ((guix licenses)
24                 #:select (gpl3+ gpl2+ lgpl2.1+ lgpl2.0+))
25   #:use-module (gnu packages)
26   #:use-module (gnu packages bootstrap)
27   #:use-module (gnu packages compression)
28   #:use-module (gnu packages multiprecision)
29   #:use-module (gnu packages texinfo)
30   #:use-module (gnu packages elf)
31   #:use-module (gnu packages perl)
32   #:use-module (guix packages)
33   #:use-module (guix download)
34   #:use-module (guix build-system gnu)
35   #:use-module (guix build-system trivial)
36   #:use-module (guix utils)
37   #:use-module (ice-9 regex))
39 (define %gcc-infrastructure
40   ;; Base URL for GCC's infrastructure.
41   "ftp://gcc.gnu.org/pub/gcc/infrastructure/")
43 (define (gcc-configure-flags-for-triplet target)
44   "Return a list of additional GCC `configure' flags for TARGET, a GNU triplet.
46 The purpose of this procedure is to translate extended GNU triplets---e.g.,
47 where the OS part is overloaded to denote a specific ABI---into GCC
48 `configure' options.  We take extended GNU triplets that glibc recognizes."
49   (cond ((string-match "^mips64el.*gnuabin?64$" target)
50          ;; Triplets recognized by glibc as denoting the N64 ABI; see
51          ;; ports/sysdeps/mips/preconfigure.
52          '("--with-abi=64"))
54         ((string-match "^arm.*-gnueabihf$" target)
55          '("--with-arch=armv7-a"
56            "--with-float=hard"
57            "--with-mode=thumb"
59            ;; See <https://wiki.debian.org/ArmHardFloatPort/VfpComparison#FPU>
60            "--with-fpu=vfpv3-d16"))
62         (else
63          ;; TODO: Add `arm.*-gnueabi', etc.
64          '())))
66 (define-public gcc-4.7
67   (let* ((stripped? #t)                           ; TODO: make this a parameter
68          (install-target
69           (lambda ()
70             ;; The 'install-strip' rule uses the native 'strip' instead of
71             ;; 'TARGET-strip' when cross-compiling.  Thus, use 'install' in that
72             ;; case.
73             (if (and stripped? (not (%current-target-system)))
74                 "install-strip"
75                 "install")))
76          (maybe-target-tools
77           (lambda ()
78             ;; Return the `_FOR_TARGET' variables that are needed when
79             ;; cross-compiling GCC.
80             (let ((target (%current-target-system)))
81               (if target
82                   (map (lambda (var tool)
83                          (string-append (string-append var "_FOR_TARGET")
84                                         "=" target "-" tool))
85                        '("CC"  "CXX" "LD" "AR" "NM" "RANLIB" "STRIP")
86                        '("gcc" "g++" "ld" "ar" "nm" "ranlib" "strip"))
87                   '()))))
88          (libdir
89           (let ((base '(or (assoc-ref outputs "lib")
90                            (assoc-ref outputs "out"))))
91             (lambda ()
92               ;; Return the directory that contains lib/libgcc_s.so et al.
93               (if (%current-target-system)
94                   `(string-append ,base "/" ,(%current-target-system))
95                   base))))
96          (configure-flags
97           (lambda ()
98             ;; This is terrible.  Since we have two levels of quasiquotation,
99             ;; we have to do this convoluted thing just so we can insert the
100             ;; contents of (maybe-target-tools).
101             (list 'quasiquote
102                   (append
103                    '("--enable-plugin"
104                      "--enable-languages=c,c++"
105                      "--disable-multilib"
107                      ;; No pre-compiled libstdc++ headers, to save space.
108                      "--disable-libstdcxx-pch"
110                      "--with-local-prefix=/no-gcc-local-prefix"
112                      ;; With a separate "lib" output, the build system
113                      ;; incorrectly guesses GPLUSPLUS_INCLUDE_DIR, so force
114                      ;; it.  (Don't use a versioned sub-directory, that's
115                      ;; unnecessary.)
116                      ,(string-append "--with-gxx-include-dir="
117                                      (assoc-ref %outputs "out")
118                                      "/include/c++")
120                      ,(let ((libc (assoc-ref %build-inputs "libc")))
121                         (if libc
122                             (string-append "--with-native-system-header-dir=" libc
123                                            "/include")
124                             "--without-headers")))
126                    ;; Pass the right options for the target triplet.
127                    (let ((triplet
128                           (or (%current-target-system)
129                               (nix-system->gnu-triplet (%current-system)))))
130                      (gcc-configure-flags-for-triplet triplet))
132                    (maybe-target-tools))))))
133     (package
134       (name "gcc")
135       (version "4.7.4")
136       (source (origin
137                (method url-fetch)
138                (uri (string-append "mirror://gnu/gcc/gcc-"
139                                    version "/gcc-" version ".tar.bz2"))
140                (sha256
141                 (base32
142                  "10k2k71kxgay283ylbbhhs51cl55zn2q38vj5pk4k950qdnirrlj"))))
143       (build-system gnu-build-system)
145       ;; Separate out the run-time support libraries because all the
146       ;; dynamic-linked objects depend on it.
147       (outputs '("out"                     ; commands, etc. (60+ MiB)
148                  "lib"))                   ; libgcc_s, libgomp, etc. (15+ MiB)
150       (inputs `(("gmp" ,gmp)
151                 ("mpfr" ,mpfr)
152                 ("mpc" ,mpc)
153                 ("isl" ,isl)
154                 ("cloog" ,cloog)
155                 ("libelf" ,libelf)
156                 ("zlib" ,zlib)))
158       ;; GCC is one of the few packages that doesn't ship .info files.
159       (native-inputs `(("texinfo" ,texinfo)))
161       (arguments
162        `(#:out-of-source? #t
163          #:strip-binaries? ,stripped?
164          #:configure-flags ,(configure-flags)
165          #:make-flags
166          ;; None of the flags below are needed when doing a Canadian cross.
167          ;; TODO: Simplify this.
168          ,(if (%current-target-system)
169               (if stripped?
170                   ''("CFLAGS=-g0 -O2")
171                   ''())
172               `(let* ((libc        (assoc-ref %build-inputs "libc"))
173                       (libc-native (or (assoc-ref %build-inputs "libc-native")
174                                        libc)))
175                  `(,@(if libc
176                          (list (string-append "LDFLAGS_FOR_TARGET="
177                                               "-B" libc "/lib "
178                                               "-Wl,-dynamic-linker "
179                                               "-Wl," libc
180                                               ,(glibc-dynamic-linker)))
181                          '())
183                    ;; Native programs like 'genhooks' also need that right.
184                    ,(string-append "LDFLAGS="
185                                    "-Wl,-rpath=" libc-native "/lib "
186                                    "-Wl,-dynamic-linker "
187                                    "-Wl," libc-native ,(glibc-dynamic-linker))
188                    ,(string-append "BOOT_CFLAGS=-O2 "
189                                    ,(if stripped? "-g0" "-g")))))
191          #:tests? #f
193          #:phases
194          (alist-cons-before
195           'configure 'pre-configure
196           (lambda* (#:key inputs outputs #:allow-other-keys)
197             (let ((libdir ,(libdir))
198                   (libc   (assoc-ref inputs "libc")))
199               (when libc
200                 ;; The following is not performed for `--without-headers'
201                 ;; cross-compiler builds.
203                 ;; Join multi-line definitions of GLIBC_DYNAMIC_LINKER* into a
204                 ;; single line, to allow the next step to work properly.
205                 (for-each
206                  (lambda (x)
207                    (substitute* (find-files "gcc/config"
208                                             "^linux(64|-elf|-eabi)?\\.h$")
209                      (("(#define GLIBC_DYNAMIC_LINKER.*)\\\\\n$" _ line)
210                       line)))
211                  '(1 2 3))
213                 ;; Fix the dynamic linker's file name.
214                 (substitute* (find-files "gcc/config"
215                                          "^linux(64|-elf|-eabi)?\\.h$")
216                   (("#define GLIBC_DYNAMIC_LINKER([^ ]*).*$" _ suffix)
217                    (format #f "#define GLIBC_DYNAMIC_LINKER~a \"~a\"~%"
218                            suffix
219                            (string-append libc ,(glibc-dynamic-linker)))))
221                 ;; Tell where to find libstdc++, libc, and `?crt*.o', except
222                 ;; `crt{begin,end}.o', which come with GCC.
223                 (substitute* (find-files "gcc/config"
224                                          "^gnu-user.*\\.h$")
225                   (("#define GNU_USER_TARGET_LIB_SPEC (.*)$" _ suffix)
226                    ;; Help libgcc_s.so be found (see also below.)  Always use
227                    ;; '-lgcc_s' so that libgcc_s.so is always found by those
228                    ;; programs that use 'pthread_cancel' (glibc dlopens
229                    ;; libgcc_s.so when pthread_cancel support is needed, but
230                    ;; having it in the application's RUNPATH isn't enough; see
231                    ;; <http://sourceware.org/ml/libc-help/2013-11/msg00023.html>.)
232                    ;;
233                    ;; NOTE: The '-lgcc_s' added below needs to be removed in a
234                    ;; later phase of %gcc-static.  If you change the string
235                    ;; below, make sure to update the relevant code in
236                    ;; %gcc-static package as needed.
237                    (format #f "#define GNU_USER_TARGET_LIB_SPEC \
238 \"-L~a/lib %{!static:-rpath=~a/lib %{!static-libgcc:-rpath=~a/lib64 -rpath=~a/lib -lgcc_s}} \" ~a"
239                            libc libc libdir libdir suffix))
240                   (("#define GNU_USER_TARGET_STARTFILE_SPEC.*$" line)
241                    (format #f "#define STANDARD_STARTFILE_PREFIX_1 \"~a/lib\"
242 #define STANDARD_STARTFILE_PREFIX_2 \"\"
244                            libc line))))
246               ;; Don't retain a dependency on the build-time sed.
247               (substitute* "fixincludes/fixincl.x"
248                 (("static char const sed_cmd_z\\[\\] =.*;")
249                  "static char const sed_cmd_z[] = \"sed\";"))
251               ;; Add a RUNPATH to libstdc++.so so that it finds libgcc_s.
252               ;; See <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=32354>
253               ;; and <http://bugs.gnu.org/20358>.
254               (substitute* "libstdc++-v3/src/Makefile.in"
255                 (("^OPT_LDFLAGS = ")
256                  "OPT_LDFLAGS = -Wl,-rpath=$(libdir) "))
258               ;; Move libstdc++*-gdb.py to the "lib" output to avoid a
259               ;; circularity between "out" and "lib".  (Note:
260               ;; --with-python-dir is useless because it imposes $(prefix) as
261               ;; the parent directory.)
262               (substitute* "libstdc++-v3/python/Makefile.in"
263                 (("pythondir = .*$")
264                  (string-append "pythondir = " libdir "/share"
265                                 "/gcc-$(gcc_version)/python\n")))
267               ;; Avoid another circularity between the outputs: this #define
268               ;; ends up in auto-host.h in the "lib" output, referring to
269               ;; "out".  (This variable is used to augment cpp's search path,
270               ;; but there's nothing useful to look for here.)
271               (substitute* "gcc/config.in"
272                 (("PREFIX_INCLUDE_DIR")
273                  "PREFIX_INCLUDE_DIR_isnt_necessary_here"))))
275           (alist-cons-after
276            'configure 'post-configure
277            (lambda _
278              ;; Don't store configure flags, to avoid retaining references to
279              ;; build-time dependencies---e.g., `--with-ppl=/gnu/store/xxx'.
280              (substitute* "Makefile"
281                (("^TOPLEVEL_CONFIGURE_ARGUMENTS=(.*)$" _ rest)
282                 "TOPLEVEL_CONFIGURE_ARGUMENTS=\n")))
283            (alist-replace 'install
284                           (lambda* (#:key outputs #:allow-other-keys)
285                             (zero?
286                              (system* "make" ,(install-target))))
287                           %standard-phases)))))
289       (native-search-paths
290        (list (search-path-specification
291               (variable "CPATH")
292               (files '("include")))
293              (search-path-specification
294               (variable "LIBRARY_PATH")
295               (files '("lib" "lib64")))))
297       (properties `((gcc-libc . ,(assoc-ref inputs "libc"))))
298       (synopsis "GNU Compiler Collection")
299       (description
300        "GCC is the GNU Compiler Collection.  It provides compiler front-ends
301 for several languages, including C, C++, Objective-C, Fortran, Java, Ada, and
302 Go.  It also includes runtime support libraries for these languages.")
303       (license gpl3+)
304       (home-page "http://gcc.gnu.org/"))))
306 (define-public gcc-4.8
307   (package (inherit gcc-4.7)
308     (version "4.8.4")
309     (source (origin
310              (method url-fetch)
311              (uri (string-append "mirror://gnu/gcc/gcc-"
312                                  version "/gcc-" version ".tar.bz2"))
313              (sha256
314               (base32
315                "15c6gwm6dzsaagamxkak5smdkf1rdfbqqjs9jdbrp3lbg4ism02a"))
316              (patches (list (search-patch "gcc-arm-link-spec-fix.patch")))))))
318 (define-public gcc-4.9
319   (package (inherit gcc-4.7)
320     (version "4.9.2")
321     (source (origin
322              (method url-fetch)
323              (uri (string-append "mirror://gnu/gcc/gcc-"
324                                  version "/gcc-" version ".tar.bz2"))
325              (sha256
326               (base32
327                "1pbjp4blk2ycaa6r3jmw4ky5f1s9ji3klbqgv8zs2sl5jn1cj810"))
328              (patches (list (search-patch "gcc-arm-link-spec-fix.patch")))))))
330 (define* (custom-gcc gcc name languages #:key (separate-lib-output? #t))
331   "Return a custom version of GCC that supports LANGUAGES."
332   (package (inherit gcc)
333     (name name)
334     (outputs (if separate-lib-output?
335                  (package-outputs gcc)
336                  (delete "lib" (package-outputs gcc))))
337     (arguments
338      (substitute-keyword-arguments `(#:modules ((guix build gnu-build-system)
339                                                 (guix build utils)
340                                                 (ice-9 regex)
341                                                 (srfi srfi-1)
342                                                 (srfi srfi-26))
343                                                ,@(package-arguments gcc))
344        ((#:configure-flags flags)
345         `(cons (string-append "--enable-languages="
346                               ,(string-join languages ","))
347                (remove (cut string-match "--enable-languages.*" <>)
348                        ,flags)))))))
350 (define-public gfortran-4.8
351   (custom-gcc gcc-4.8 "gfortran" '("fortran")))
353 (define-public gccgo-4.8
354   (custom-gcc gcc-4.8 "gccgo" '("go")
355               ;; Suppress the separate "lib" output, because otherwise the
356               ;; "lib" and "out" outputs would refer to each other, creating
357               ;; a cyclic dependency.  <http://debbugs.gnu.org/18101>
358               #:separate-lib-output? #f))
360 (define javac.in
361   (origin
362     (method url-fetch)
363     (uri (string-append "http://sources.gentoo.org/cgi-bin/viewvc.cgi/"
364                         "gentoo-x86/dev-java/gcj-jdk/files/javac.in?revision=1.1"))
365     (file-name "javac.in")
366     (sha256 (base32
367               "1c3dk4z5yfj6ic2fn3lyxs27n6pmn2wy9k0r1s17lnkf1bzkrciv"))))
369 (define-public gcj-4.8
370   (package (inherit gcc-4.8)
371     (name "gcj")
372     (inputs
373      `(("fastjar" ,fastjar)
374        ("perl" ,perl)
375        ("javac.in" ,javac.in)
376        ("ecj-bootstrap" ,ecj-bootstrap-4.8)
377        ,@(package-inputs gcc-4.8)))
378     ;; Suppress the separate "lib" output, because otherwise the
379     ;; "lib" and "out" outputs would refer to each other, creating
380     ;; a cyclic dependency.  <http://debbugs.gnu.org/18101>
381     (outputs
382      (delete "lib" (package-outputs gcc-4.8)))
383     (arguments
384      (substitute-keyword-arguments `(#:modules ((guix build gnu-build-system)
385                                                 (guix build utils)
386                                                 (ice-9 regex)
387                                                 (srfi srfi-1)
388                                                 (srfi srfi-26))
389                                                ,@(package-arguments gcc-4.8))
390        ((#:configure-flags flags)
391         `(let ((ecj (assoc-ref %build-inputs "ecj-bootstrap")))
392            `("--enable-java-home"
393              "--enable-gjdoc"
394              ,(string-append "--with-ecj-jar=" ecj)
395              "--enable-languages=java"
396              ,@(remove (cut string-match "--enable-languages.*" <>)
397                        ,flags))))
398         ((#:phases phases)
399          `(alist-cons-after
400            'install 'install-javac-and-javap-wrappers
401            (lambda _
402              (let* ((javac  (assoc-ref %build-inputs "javac.in"))
403                     (ecj    (assoc-ref %build-inputs "ecj-bootstrap"))
404                     (gcj    (assoc-ref %outputs "out"))
405                     (gcjbin (string-append gcj "/bin/"))
406                     (jvm    (string-append gcj "/lib/jvm/"))
407                     (target (string-append jvm "/bin/javac")))
409                (symlink (string-append gcjbin "jcf-dump")
410                         (string-append jvm "/bin/javap"))
412                (copy-file ecj (string-append gcj "/share/java/ecj.jar"))
414                ;; Create javac wrapper from the template javac.in by
415                ;; replacing the @VARIABLES@ with paths.
416                (copy-file javac target)
417                (patch-shebang target)
418                (substitute* target
419                  (("@JAVA@")
420                   (string-append jvm "/bin/java"))
421                  (("@ECJ_JAR@")
422                   (string-append gcj "/share/java/ecj.jar"))
423                  (("@RT_JAR@")
424                   (string-append jvm "/jre/lib/rt.jar"))
425                  (("@TOOLS_JAR@")
426                   (string-append jvm "/lib/tools.jar")))
427                (chmod target #o755)
428                #t))
429            ,phases))))))
431 (define ecj-bootstrap-4.8
432   (origin
433     (method url-fetch)
434     (uri "ftp://sourceware.org/pub/java/ecj-4.8.jar")
435     (sha256
436      (base32
437       "10fpqfbdzff1zcbxzh66xc8xbij9saykcj4xzm19wk9p3n7i5zcq"))))
439 (define-public gcc-objc-4.8
440   (custom-gcc gcc-4.8 "gcc-objc" '("objc")))
442 (define-public gcc-objc++-4.8
443   (custom-gcc gcc-4.8 "gcc-objc++" '("obj-c++")))
445 (define-public isl
446   (package
447     (name "isl")
448     (version "0.11.1")
449     (source (origin
450              (method url-fetch)
451              (uri (list (string-append
452                          "http://isl.gforge.inria.fr/isl-"
453                          version
454                          ".tar.bz2")
455                         (string-append %gcc-infrastructure
456                                        name "-" version ".tar.gz")))
457              (sha256
458               (base32
459                "13d9cqa5rzhbjq0xf0b2dyxag7pqa72xj9dhsa03m8ccr1a4npq9"))))
460     (build-system gnu-build-system)
461     (inputs `(("gmp" ,gmp)))
462     (home-page "http://isl.gforge.inria.fr/")
463     (synopsis
464      "Manipulating sets and relations of integer points \
465 bounded by linear constraints")
466     (description
467      "isl is a library for manipulating sets and relations of integer points
468 bounded by linear constraints.  Supported operations on sets include
469 intersection, union, set difference, emptiness check, convex hull, (integer)
470 affine hull, integer projection, computing the lexicographic minimum using
471 parametric integer programming, coalescing and parametric vertex
472 enumeration.  It also includes an ILP solver based on generalized basis
473 reduction, transitive closures on maps (which may encode infinite graphs),
474 dependence analysis and bounds on piecewise step-polynomials.")
475     (license lgpl2.1+)))
477 (define-public cloog
478   (package
479     (name "cloog")
480     (version "0.18.0")
481     (source
482      (origin
483       (method url-fetch)
484       (uri (list (string-append
485                   "http://www.bastoul.net/cloog/pages/download/count.php3?url=cloog-"
486                   version
487                   ".tar.gz")
488                  (string-append %gcc-infrastructure
489                                 name "-" version ".tar.gz")))
490       (sha256
491        (base32
492         "0a12rwfwp22zd0nlld0xyql11cj390rrq1prw35yjsw8wzfshjhw"))
493       (file-name (string-append name "-" version ".tar.gz"))))
494     (build-system gnu-build-system)
495     (inputs `(("gmp" ,gmp)
496               ("isl" ,isl)))
497     (arguments '(#:configure-flags '("--with-isl=system")))
498     (home-page "http://www.cloog.org/")
499     (synopsis "Library to generate code for scanning Z-polyhedra")
500     (description
501      "CLooG is a free software library to generate code for scanning
502 Z-polyhedra.  That is, it finds a code (e.g., in C, FORTRAN...) that
503 reaches each integral point of one or more parameterized polyhedra.
504 CLooG has been originally written to solve the code generation problem
505 for optimizing compilers based on the polytope model.  Nevertheless it
506 is used now in various area e.g., to build control automata for
507 high-level synthesis or to find the best polynomial approximation of a
508 function.  CLooG may help in any situation where scanning polyhedra
509 matters.  While the user has full control on generated code quality,
510 CLooG is designed to avoid control overhead and to produce a very
511 effective code.")
512     (license gpl2+)))