gnu: gcc-5.1: Add specific libvtv patch.
[jackhill/guix/guix.git] / gnu / packages / gcc.scm
index 279cc8d..4512e54 100644 (file)
@@ -1,5 +1,8 @@
 ;;; GNU Guix --- Functional package management for GNU
-;;; Copyright © 2012, 2013 Ludovic Courtès <ludo@gnu.org>
+;;; Copyright © 2012, 2013, 2014, 2015 Ludovic Courtès <ludo@gnu.org>
+;;; Copyright © 2014, 2015 Mark H Weaver <mhw@netris.org>
+;;; Copyright © 2014 Ricardo Wurmus <rekado@elephly.net>
+;;; Copyright © 2015 Andreas Enge <andreas@enge.fr>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
   #:use-module (gnu packages multiprecision)
   #:use-module (gnu packages texinfo)
   #:use-module (gnu packages elf)
+  #:use-module (gnu packages perl)
   #:use-module (guix packages)
   #:use-module (guix download)
   #:use-module (guix build-system gnu)
+  #:use-module (guix build-system trivial)
   #:use-module (guix utils)
   #:use-module (ice-9 regex))
 
@@ -35,7 +40,7 @@
   ;; Base URL for GCC's infrastructure.
   "ftp://gcc.gnu.org/pub/gcc/infrastructure/")
 
-(define-public (gcc-configure-flags-for-triplet target)
+(define (gcc-configure-flags-for-triplet target)
   "Return a list of additional GCC `configure' flags for TARGET, a GNU triplet.
 
 The purpose of this procedure is to translate extended GNU triplets---e.g.,
@@ -45,12 +50,29 @@ where the OS part is overloaded to denote a specific ABI---into GCC
          ;; Triplets recognized by glibc as denoting the N64 ABI; see
          ;; ports/sysdeps/mips/preconfigure.
          '("--with-abi=64"))
+
+        ((string-match "^arm.*-gnueabihf$" target)
+         '("--with-arch=armv7-a"
+           "--with-float=hard"
+           "--with-mode=thumb"
+
+           ;; See <https://wiki.debian.org/ArmHardFloatPort/VfpComparison#FPU>
+           "--with-fpu=vfpv3-d16"))
+
         (else
-         ;; TODO: Add `armel.*gnueabi', `hf', etc.
+         ;; TODO: Add `arm.*-gnueabi', etc.
          '())))
 
 (define-public gcc-4.7
   (let* ((stripped? #t)                           ; TODO: make this a parameter
+         (install-target
+          (lambda ()
+            ;; The 'install-strip' rule uses the native 'strip' instead of
+            ;; 'TARGET-strip' when cross-compiling.  Thus, use 'install' in that
+            ;; case.
+            (if (and stripped? (not (%current-target-system)))
+                "install-strip"
+                "install")))
          (maybe-target-tools
           (lambda ()
             ;; Return the `_FOR_TARGET' variables that are needed when
@@ -63,6 +85,14 @@ where the OS part is overloaded to denote a specific ABI---into GCC
                        '("CC"  "CXX" "LD" "AR" "NM" "RANLIB" "STRIP")
                        '("gcc" "g++" "ld" "ar" "nm" "ranlib" "strip"))
                   '()))))
+         (libdir
+          (let ((base '(or (assoc-ref outputs "lib")
+                           (assoc-ref outputs "out"))))
+            (lambda ()
+              ;; Return the directory that contains lib/libgcc_s.so et al.
+              (if (%current-target-system)
+                  `(string-append ,base "/" ,(%current-target-system))
+                  base))))
          (configure-flags
           (lambda ()
             ;; This is terrible.  Since we have two levels of quasiquotation,
@@ -79,30 +109,44 @@ where the OS part is overloaded to denote a specific ABI---into GCC
 
                      "--with-local-prefix=/no-gcc-local-prefix"
 
+                     ;; With a separate "lib" output, the build system
+                     ;; incorrectly guesses GPLUSPLUS_INCLUDE_DIR, so force
+                     ;; it.  (Don't use a versioned sub-directory, that's
+                     ;; unnecessary.)
+                     ,(string-append "--with-gxx-include-dir="
+                                     (assoc-ref %outputs "out")
+                                     "/include/c++")
+
                      ,(let ((libc (assoc-ref %build-inputs "libc")))
                         (if libc
                             (string-append "--with-native-system-header-dir=" libc
                                            "/include")
                             "--without-headers")))
 
-                   ;; When cross-compiling GCC, pass the right options for the
-                   ;; target triplet.
-                   (or (and=> (%current-target-system)
-                              gcc-configure-flags-for-triplet)
-                       '())
+                   ;; Pass the right options for the target triplet.
+                   (let ((triplet
+                          (or (%current-target-system)
+                              (nix-system->gnu-triplet (%current-system)))))
+                     (gcc-configure-flags-for-triplet triplet))
 
                    (maybe-target-tools))))))
     (package
       (name "gcc")
-      (version "4.7.3")
+      (version "4.7.4")
       (source (origin
                (method url-fetch)
                (uri (string-append "mirror://gnu/gcc/gcc-"
                                    version "/gcc-" version ".tar.bz2"))
                (sha256
                 (base32
-                 "1hx9h64ivarlzi4hxvq42as5m9vlr5cyzaaq4gzj4i619zmkfz1g"))))
+                 "10k2k71kxgay283ylbbhhs51cl55zn2q38vj5pk4k950qdnirrlj"))))
       (build-system gnu-build-system)
+
+      ;; Separate out the run-time support libraries because all the
+      ;; dynamic-linked objects depend on it.
+      (outputs '("out"                     ; commands, etc. (60+ MiB)
+                 "lib"))                   ; libgcc_s, libgomp, etc. (15+ MiB)
+
       (inputs `(("gmp" ,gmp)
                 ("mpfr" ,mpfr)
                 ("mpc" ,mpc)
@@ -119,39 +163,56 @@ where the OS part is overloaded to denote a specific ABI---into GCC
          #:strip-binaries? ,stripped?
          #:configure-flags ,(configure-flags)
          #:make-flags
-         (let* ((libc        (assoc-ref %build-inputs "libc"))
-                (libc-native (or (assoc-ref %build-inputs "libc-native")
-                                 libc)))
-           `(,@(if libc
-                   (list (string-append "LDFLAGS_FOR_TARGET="
-                                        "-B" libc "/lib "
-                                        "-Wl,-dynamic-linker "
-                                        "-Wl," libc
-                                        ,(glibc-dynamic-linker)))
-                   '())
-
-             ;; Native programs like 'genhooks' also need that right.
-             ,(string-append "LDFLAGS="
-                              "-Wl,-rpath=" libc-native "/lib "
-                             "-Wl,-dynamic-linker "
-                             "-Wl," libc-native ,(glibc-dynamic-linker))
-             ,(string-append "BOOT_CFLAGS=-O2 "
-                             ,(if stripped? "-g0" "-g"))))
+         ;; None of the flags below are needed when doing a Canadian cross.
+         ;; TODO: Simplify this.
+         ,(if (%current-target-system)
+              (if stripped?
+                  ''("CFLAGS=-g0 -O2")
+                  ''())
+              `(let* ((libc        (assoc-ref %build-inputs "libc"))
+                      (libc-native (or (assoc-ref %build-inputs "libc-native")
+                                       libc)))
+                 `(,@(if libc
+                         (list (string-append "LDFLAGS_FOR_TARGET="
+                                              "-B" libc "/lib "
+                                              "-Wl,-dynamic-linker "
+                                              "-Wl," libc
+                                              ,(glibc-dynamic-linker)))
+                         '())
+
+                   ;; Native programs like 'genhooks' also need that right.
+                   ,(string-append "LDFLAGS="
+                                   "-Wl,-rpath=" libc-native "/lib "
+                                   "-Wl,-dynamic-linker "
+                                   "-Wl," libc-native ,(glibc-dynamic-linker))
+                   ,(string-append "BOOT_CFLAGS=-O2 "
+                                   ,(if stripped? "-g0" "-g")))))
 
          #:tests? #f
+
          #:phases
          (alist-cons-before
           'configure 'pre-configure
           (lambda* (#:key inputs outputs #:allow-other-keys)
-            (let ((out  (assoc-ref outputs "out"))
-                  (libc (assoc-ref inputs "libc")))
+            (let ((libdir ,(libdir))
+                  (libc   (assoc-ref inputs "libc")))
               (when libc
                 ;; The following is not performed for `--without-headers'
                 ;; cross-compiler builds.
 
+                ;; Join multi-line definitions of GLIBC_DYNAMIC_LINKER* into a
+                ;; single line, to allow the next step to work properly.
+                (for-each
+                 (lambda (x)
+                   (substitute* (find-files "gcc/config"
+                                            "^linux(64|-elf|-eabi)?\\.h$")
+                     (("(#define GLIBC_DYNAMIC_LINKER.*)\\\\\n$" _ line)
+                      line)))
+                 '(1 2 3))
+
                 ;; Fix the dynamic linker's file name.
                 (substitute* (find-files "gcc/config"
-                                         "^linux(64|-elf)?\\.h$")
+                                         "^linux(64|-elf|-eabi)?\\.h$")
                   (("#define GLIBC_DYNAMIC_LINKER([^ ]*).*$" _ suffix)
                    (format #f "#define GLIBC_DYNAMIC_LINKER~a \"~a\"~%"
                            suffix
@@ -168,9 +229,14 @@ where the OS part is overloaded to denote a specific ABI---into GCC
                    ;; libgcc_s.so when pthread_cancel support is needed, but
                    ;; having it in the application's RUNPATH isn't enough; see
                    ;; <http://sourceware.org/ml/libc-help/2013-11/msg00023.html>.)
+                   ;;
+                   ;; NOTE: The '-lgcc_s' added below needs to be removed in a
+                   ;; later phase of %gcc-static.  If you change the string
+                   ;; below, make sure to update the relevant code in
+                   ;; %gcc-static package as needed.
                    (format #f "#define GNU_USER_TARGET_LIB_SPEC \
 \"-L~a/lib %{!static:-rpath=~a/lib %{!static-libgcc:-rpath=~a/lib64 -rpath=~a/lib -lgcc_s}} \" ~a"
-                           libc libc out out suffix))
+                           libc libc libdir libdir suffix))
                   (("#define GNU_USER_TARGET_STARTFILE_SPEC.*$" line)
                    (format #f "#define STANDARD_STARTFILE_PREFIX_1 \"~a/lib\"
 #define STANDARD_STARTFILE_PREFIX_2 \"\"
@@ -180,32 +246,53 @@ where the OS part is overloaded to denote a specific ABI---into GCC
               ;; Don't retain a dependency on the build-time sed.
               (substitute* "fixincludes/fixincl.x"
                 (("static char const sed_cmd_z\\[\\] =.*;")
-                 "static char const sed_cmd_z[] = \"sed\";"))))
+                 "static char const sed_cmd_z[] = \"sed\";"))
+
+              ;; Add a RUNPATH to libstdc++.so so that it finds libgcc_s.
+              ;; See <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=32354>
+              ;; and <http://bugs.gnu.org/20358>.
+              (substitute* "libstdc++-v3/src/Makefile.in"
+                (("^OPT_LDFLAGS = ")
+                 "OPT_LDFLAGS = -Wl,-rpath=$(libdir) "))
+
+              ;; Move libstdc++*-gdb.py to the "lib" output to avoid a
+              ;; circularity between "out" and "lib".  (Note:
+              ;; --with-python-dir is useless because it imposes $(prefix) as
+              ;; the parent directory.)
+              (substitute* "libstdc++-v3/python/Makefile.in"
+                (("pythondir = .*$")
+                 (string-append "pythondir = " libdir "/share"
+                                "/gcc-$(gcc_version)/python\n")))
+
+              ;; Avoid another circularity between the outputs: this #define
+              ;; ends up in auto-host.h in the "lib" output, referring to
+              ;; "out".  (This variable is used to augment cpp's search path,
+              ;; but there's nothing useful to look for here.)
+              (substitute* "gcc/config.in"
+                (("PREFIX_INCLUDE_DIR")
+                 "PREFIX_INCLUDE_DIR_isnt_necessary_here"))))
 
           (alist-cons-after
            'configure 'post-configure
            (lambda _
              ;; Don't store configure flags, to avoid retaining references to
-             ;; build-time dependencies---e.g., `--with-ppl=/nix/store/xxx'.
+             ;; build-time dependencies---e.g., `--with-ppl=/gnu/store/xxx'.
              (substitute* "Makefile"
                (("^TOPLEVEL_CONFIGURE_ARGUMENTS=(.*)$" _ rest)
                 "TOPLEVEL_CONFIGURE_ARGUMENTS=\n")))
            (alist-replace 'install
                           (lambda* (#:key outputs #:allow-other-keys)
                             (zero?
-                             (system* "make"
-                                      ,(if stripped?
-                                           "install-strip"
-                                           "install"))))
+                             (system* "make" ,(install-target))))
                           %standard-phases)))))
 
       (native-search-paths
        (list (search-path-specification
               (variable "CPATH")
-              (directories '("include")))
+              (files '("include")))
              (search-path-specification
               (variable "LIBRARY_PATH")
-              (directories '("lib" "lib64")))))
+              (files '("lib" "lib64")))))
 
       (properties `((gcc-libc . ,(assoc-ref inputs "libc"))))
       (synopsis "GNU Compiler Collection")
@@ -218,19 +305,55 @@ Go.  It also includes runtime support libraries for these languages.")
 
 (define-public gcc-4.8
   (package (inherit gcc-4.7)
-    (version "4.8.2")
+    (version "4.8.4")
     (source (origin
-             (method url-fetch)
-             (uri (string-append "mirror://gnu/gcc/gcc-"
-                                 version "/gcc-" version ".tar.bz2"))
-             (sha256
-              (base32
-               "1j6dwgby4g3p3lz7zkss32ghr45zpdidrg8xvazvn91lqxv25p09"))))))
+              (method url-fetch)
+              (uri (string-append "mirror://gnu/gcc/gcc-"
+                                  version "/gcc-" version ".tar.bz2"))
+              (sha256
+               (base32
+                "15c6gwm6dzsaagamxkak5smdkf1rdfbqqjs9jdbrp3lbg4ism02a"))
 
-(define (custom-gcc gcc name languages)
+              ;; ARM 'link' spec issue reported at
+              ;; <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65711> and
+              ;; <https://gcc.gnu.org/ml/gcc-patches/2015-04/msg01387.html>.
+              (patches (list (search-patch "gcc-arm-link-spec-fix.patch")))))))
+
+(define-public gcc-4.9
+  (package (inherit gcc-4.8)
+    (version "4.9.2")
+    (source (origin
+              (method url-fetch)
+              (uri (string-append "mirror://gnu/gcc/gcc-"
+                                  version "/gcc-" version ".tar.bz2"))
+              (sha256
+               (base32
+                "1pbjp4blk2ycaa6r3jmw4ky5f1s9ji3klbqgv8zs2sl5jn1cj810"))
+              (patches (map search-patch
+                            '("gcc-arm-link-spec-fix.patch"
+                              "gcc-libvtv-runpath.patch")))))))
+
+(define-public gcc-5.1
+  (package (inherit gcc-4.9)
+    (version "5.1.0")
+    (source (origin
+              (method url-fetch)
+              (uri (string-append "mirror://gnu/gcc/gcc-"
+                                  version "/gcc-" version ".tar.bz2"))
+              (sha256
+               (base32
+                "1bd5vj4px3s8nlakbgrh38ynxq4s654m6nxz7lrj03mvkkwgvnmp"))
+              (patches (map search-patch
+                            '("gcc-arm-link-spec-fix.patch"
+                              "gcc-5.0-libvtv-runpath.patch")))))))
+
+(define* (custom-gcc gcc name languages #:key (separate-lib-output? #t))
   "Return a custom version of GCC that supports LANGUAGES."
   (package (inherit gcc)
     (name name)
+    (outputs (if separate-lib-output?
+                 (package-outputs gcc)
+                 (delete "lib" (package-outputs gcc))))
     (arguments
      (substitute-keyword-arguments `(#:modules ((guix build gnu-build-system)
                                                 (guix build utils)
@@ -248,7 +371,101 @@ Go.  It also includes runtime support libraries for these languages.")
   (custom-gcc gcc-4.8 "gfortran" '("fortran")))
 
 (define-public gccgo-4.8
-  (custom-gcc gcc-4.8 "gccgo" '("go")))
+  (custom-gcc gcc-4.8 "gccgo" '("go")
+              ;; Suppress the separate "lib" output, because otherwise the
+              ;; "lib" and "out" outputs would refer to each other, creating
+              ;; a cyclic dependency.  <http://debbugs.gnu.org/18101>
+              #:separate-lib-output? #f))
+
+(define javac.in
+  (origin
+    (method url-fetch)
+    (uri (string-append "http://sources.gentoo.org/cgi-bin/viewvc.cgi/"
+                        "gentoo-x86/dev-java/gcj-jdk/files/javac.in?revision=1.1"))
+    (file-name "javac.in")
+    (sha256 (base32
+              "1c3dk4z5yfj6ic2fn3lyxs27n6pmn2wy9k0r1s17lnkf1bzkrciv"))))
+
+(define-public gcj-4.8
+  (package (inherit gcc-4.8)
+    (name "gcj")
+    (inputs
+     `(("fastjar" ,fastjar)
+       ("perl" ,perl)
+       ("javac.in" ,javac.in)
+       ("ecj-bootstrap" ,ecj-bootstrap-4.8)
+       ,@(package-inputs gcc-4.8)))
+    ;; Suppress the separate "lib" output, because otherwise the
+    ;; "lib" and "out" outputs would refer to each other, creating
+    ;; a cyclic dependency.  <http://debbugs.gnu.org/18101>
+    (outputs
+     (delete "lib" (package-outputs gcc-4.8)))
+    (arguments
+     (substitute-keyword-arguments `(#:modules ((guix build gnu-build-system)
+                                                (guix build utils)
+                                                (ice-9 regex)
+                                                (srfi srfi-1)
+                                                (srfi srfi-26))
+                                               ,@(package-arguments gcc-4.8))
+       ((#:configure-flags flags)
+        `(let ((ecj (assoc-ref %build-inputs "ecj-bootstrap")))
+           `("--enable-java-home"
+             "--enable-gjdoc"
+             ,(string-append "--with-ecj-jar=" ecj)
+             "--enable-languages=java"
+             ,@(remove (cut string-match "--enable-languages.*" <>)
+                       ,flags))))
+        ((#:phases phases)
+         `(alist-cons-after
+           'install 'install-javac-and-javap-wrappers
+           (lambda _
+             (let* ((javac  (assoc-ref %build-inputs "javac.in"))
+                    (ecj    (assoc-ref %build-inputs "ecj-bootstrap"))
+                    (gcj    (assoc-ref %outputs "out"))
+                    (gcjbin (string-append gcj "/bin/"))
+                    (jvm    (string-append gcj "/lib/jvm/"))
+                    (target (string-append jvm "/bin/javac")))
+
+               (symlink (string-append gcjbin "jcf-dump")
+                        (string-append jvm "/bin/javap"))
+
+               (copy-file ecj (string-append gcj "/share/java/ecj.jar"))
+
+               ;; Create javac wrapper from the template javac.in by
+               ;; replacing the @VARIABLES@ with paths.
+               (copy-file javac target)
+               (patch-shebang target)
+               (substitute* target
+                 (("@JAVA@")
+                  (string-append jvm "/bin/java"))
+                 (("@ECJ_JAR@")
+                  (string-append gcj "/share/java/ecj.jar"))
+                 (("@RT_JAR@")
+                  (string-append jvm "/jre/lib/rt.jar"))
+                 (("@TOOLS_JAR@")
+                  (string-append jvm "/lib/tools.jar")))
+               (chmod target #o755)
+               #t))
+           (alist-cons-after
+            'install 'remove-broken-or-conflicting-files
+            (lambda _
+              (let ((out (assoc-ref %outputs "out")))
+                (for-each
+                 delete-file
+                 (append (find-files (string-append out "/lib/jvm/jre/lib")
+                                     "libjawt.so")
+                         (find-files (string-append out "/bin")
+                                     ".*(c\\+\\+|cpp|g\\+\\+|gcc.*)"))))
+              #t)
+            ,phases)))))))
+
+(define ecj-bootstrap-4.8
+  (origin
+    (method url-fetch)
+    (uri "ftp://sourceware.org/pub/java/ecj-4.8.jar")
+    (sha256
+     (base32
+      "10fpqfbdzff1zcbxzh66xc8xbij9saykcj4xzm19wk9p3n7i5zcq"))))
 
 (define-public gcc-objc-4.8
   (custom-gcc gcc-4.8 "gcc-objc" '("objc")))
@@ -275,15 +492,15 @@ Go.  It also includes runtime support libraries for these languages.")
     (inputs `(("gmp" ,gmp)))
     (home-page "http://isl.gforge.inria.fr/")
     (synopsis
-     "A library for manipulating sets and relations of integer points bounded
-by linear constraints")
+     "Manipulating sets and relations of integer points \
+bounded by linear constraints")
     (description
      "isl is a library for manipulating sets and relations of integer points
-bounded by linear constraints. Supported operations on sets include
+bounded by linear constraints.  Supported operations on sets include
 intersection, union, set difference, emptiness check, convex hull, (integer)
 affine hull, integer projection, computing the lexicographic minimum using
 parametric integer programming, coalescing and parametric vertex
-enumeration. It also includes an ILP solver based on generalized basis
+enumeration.  It also includes an ILP solver based on generalized basis
 reduction, transitive closures on maps (which may encode infinite graphs),
 dependence analysis and bounds on piecewise step-polynomials.")
     (license lgpl2.1+)))
@@ -310,7 +527,7 @@ dependence analysis and bounds on piecewise step-polynomials.")
               ("isl" ,isl)))
     (arguments '(#:configure-flags '("--with-isl=system")))
     (home-page "http://www.cloog.org/")
-    (synopsis "A library to generate code for scanning Z-polyhedra")
+    (synopsis "Library to generate code for scanning Z-polyhedra")
     (description
      "CLooG is a free software library to generate code for scanning
 Z-polyhedra.  That is, it finds a code (e.g., in C, FORTRAN...) that