Merge pull request #119126 from fabaff/pycomfoconnect
[NixPkgs.git] / pkgs / development / compilers / gcc / 4.8 / default.nix
blob6a2121a829812787f7529a04b491e1bc23f82405
1 { lib, stdenv, targetPackages, fetchurl, fetchpatch, noSysDirs
2 , langC ? true, langCC ? true, langFortran ? false
3 , langObjC ? stdenv.targetPlatform.isDarwin
4 , langObjCpp ? stdenv.targetPlatform.isDarwin
5 , langJava ? false
6 , langGo ? false
7 , profiledCompiler ? false
8 , langJit ? false
9 , staticCompiler ? false
10 , # N.B. the defult is intentionally not from an `isStatic`. See
11   # https://gcc.gnu.org/install/configure.html - this is about target
12   # platform libraries not host platform ones unlike normal. But since
13   # we can't rebuild those without also rebuilding the compiler itself,
14   # we opt to always build everything unlike our usual policy.
15   enableShared ? true
16 , enableLTO ? true
17 , texinfo ? null
18 , perl ? null # optional, for texi2pod (then pod2man); required for Java
19 , gmp, mpfr, libmpc, gettext, which, patchelf
20 , libelf                      # optional, for link-time optimizations (LTO)
21 , cloog ? null, isl ? null # optional, for the Graphite optimization framework.
22 , zlib ? null, boehmgc ? null
23 , zip ? null, unzip ? null, pkg-config ? null
24 , gtk2 ? null, libart_lgpl ? null
25 , libX11 ? null, libXt ? null, libSM ? null, libICE ? null, libXtst ? null
26 , libXrender ? null, xorgproto ? null
27 , libXrandr ? null, libXi ? null
28 , x11Support ? langJava
29 , enableMultilib ? false
30 , enablePlugin ? stdenv.hostPlatform == stdenv.buildPlatform # Whether to support user-supplied plug-ins
31 , name ? "gcc"
32 , libcCross ? null
33 , threadsCross ? null # for MinGW
34 , crossStageStatic ? false
35 , # Strip kills static libs of other archs (hence no cross)
36   stripped ? stdenv.hostPlatform == stdenv.buildPlatform
37           && stdenv.targetPlatform == stdenv.hostPlatform
38 , gnused ? null
39 , buildPackages
42 assert langJava     -> zip != null && unzip != null
43                        && zlib != null && boehmgc != null
44                        && perl != null;  # for `--enable-java-home'
46 # We enable the isl cloog backend.
47 assert cloog != null -> isl != null;
49 # LTO needs libelf and zlib.
50 assert libelf != null -> zlib != null;
52 # Make sure we get GNU sed.
53 assert stdenv.hostPlatform.isDarwin -> gnused != null;
55 # The go frontend is written in c++
56 assert langGo -> langCC;
58 # threadsCross is just for MinGW
59 assert threadsCross != null -> stdenv.targetPlatform.isWindows;
61 with lib;
62 with builtins;
64 let majorVersion = "4";
65     version = "${majorVersion}.8.5";
67     inherit (stdenv) buildPlatform hostPlatform targetPlatform;
69     patches = [ ../parallel-bconfig.patch ]
70       ++ optional (targetPlatform != hostPlatform) ../libstdc++-target.patch
71       ++ optional noSysDirs ../no-sys-dirs.patch
72       ++ optional langFortran ../gfortran-driving.patch
73       ++ optional hostPlatform.isDarwin ../gfortran-darwin-NXConstStr.patch
74       ++ [(fetchpatch {
75           name = "libc_name_p.diff"; # needed to build with gcc6
76           url = "https://gcc.gnu.org/git/?p=gcc.git;a=commitdiff_plain;h=ec1cc0263f1";
77           sha256 = "01jd7pdarh54ki498g6sz64ijl9a1l5f9v8q2696aaxalvh2vwzl";
78           excludes = [ "gcc/cp/ChangeLog" ];
79         })]
80       ++ [ # glibc-2.26
81         ../struct-ucontext-4.8.patch
82         ../sigsegv-not-declared.patch
83         ../res_state-not-declared.patch
84       ];
86     javaEcj = fetchurl {
87       # The `$(top_srcdir)/ecj.jar' file is automatically picked up at
88       # `configure' time.
90       # XXX: Eventually we might want to take it from upstream.
91       url = "ftp://sourceware.org/pub/java/ecj-4.3.jar";
92       sha256 = "0jz7hvc0s6iydmhgh5h2m15yza7p2rlss2vkif30vm9y77m97qcx";
93     };
95     # Antlr (optional) allows the Java `gjdoc' tool to be built.  We want a
96     # binary distribution here to allow the whole chain to be bootstrapped.
97     javaAntlr = fetchurl {
98       url = "https://www.antlr.org/download/antlr-4.4-complete.jar";
99       sha256 = "02lda2imivsvsis8rnzmbrbp8rh1kb8vmq4i67pqhkwz7lf8y6dz";
100     };
102     xlibs = [
103       libX11 libXt libSM libICE libXtst libXrender libXrandr libXi
104       xorgproto
105     ];
107     javaAwtGtk = langJava && x11Support;
109     /* Cross-gcc settings (build == host != target) */
110     crossMingw = targetPlatform != hostPlatform && targetPlatform.libc == "msvcrt";
111     stageNameAddon = if crossStageStatic then "stage-static" else "stage-final";
112     crossNameAddon = optionalString (targetPlatform != hostPlatform) "${targetPlatform.config}-${stageNameAddon}-";
116 # We need all these X libraries when building AWT with GTK.
117 assert x11Support -> (filter (x: x == null) ([ gtk2 libart_lgpl ] ++ xlibs)) == [];
119 stdenv.mkDerivation ({
120   pname = "${crossNameAddon}${name}${if stripped then "" else "-debug"}";
121   inherit version;
123   builder = ../builder.sh;
125   src = fetchurl {
126     url = "mirror://gnu/gcc/gcc-${version}/gcc-${version}.tar.bz2";
127     sha256 = "08yggr18v373a1ihj0rg2vd6psnic42b518xcgp3r9k81xz1xyr2";
128   };
130   inherit patches;
132   hardeningDisable = [ "format" "pie" ];
134   outputs = [ "out" "lib" "man" "info" ];
135   setOutputFlags = false;
136   NIX_NO_SELF_RPATH = true;
138   libc_dev = stdenv.cc.libc_dev;
140   postPatch =
141     if targetPlatform != hostPlatform || stdenv.cc.libc != null then
142       # On NixOS, use the right path to the dynamic linker instead of
143       # `/lib/ld*.so'.
144       let
145         libc = if libcCross != null then libcCross else stdenv.cc.libc;
146       in
147         '' echo "fixing the \`GLIBC_DYNAMIC_LINKER' and \`UCLIBC_DYNAMIC_LINKER' macros..."
148            for header in "gcc/config/"*-gnu.h "gcc/config/"*"/"*.h
149            do
150              grep -q LIBC_DYNAMIC_LINKER "$header" || continue
151              echo "  fixing \`$header'..."
152              sed -i "$header" \
153                  -e 's|define[[:blank:]]*\([UCG]\+\)LIBC_DYNAMIC_LINKER\([0-9]*\)[[:blank:]]"\([^\"]\+\)"$|define \1LIBC_DYNAMIC_LINKER\2 "${libc.out}\3"|g'
154            done
155         ''
156     else null;
158   inherit noSysDirs staticCompiler langJava crossStageStatic
159     libcCross crossMingw;
161   depsBuildBuild = [ buildPackages.stdenv.cc ];
162   nativeBuildInputs = [ texinfo which gettext ]
163     ++ (optional (perl != null) perl)
164     ++ (optional javaAwtGtk pkg-config);
166   # For building runtime libs
167   depsBuildTarget =
168     (
169       if hostPlatform == buildPlatform then [
170         targetPackages.stdenv.cc.bintools # newly-built gcc will be used
171       ] else assert targetPlatform == hostPlatform; [ # build != host == target
172         stdenv.cc
173       ]
174     )
175     ++ optional targetPlatform.isLinux patchelf;
177   buildInputs = [
178     gmp mpfr libmpc libelf
179     targetPackages.stdenv.cc.bintools # For linking code at run-time
180   ] ++ (optional (cloog != null) cloog)
181     ++ (optional (isl != null) isl)
182     ++ (optional (zlib != null) zlib)
183     ++ (optionals langJava [ boehmgc zip unzip ])
184     ++ (optionals javaAwtGtk ([ gtk2 libart_lgpl ] ++ xlibs))
185     # The builder relies on GNU sed (for instance, Darwin's `sed' fails with
186     # "-i may not be used with stdin"), and `stdenvNative' doesn't provide it.
187     ++ (optional hostPlatform.isDarwin gnused)
188     ;
190   depsTargetTarget = optional (!crossStageStatic && threadsCross != null) threadsCross;
192   preConfigure = import ../common/pre-configure.nix {
193     inherit lib;
194     inherit version hostPlatform langJava langGo;
195   };
197   dontDisableStatic = true;
199   # TODO(@Ericson2314): Always pass "--target" and always prefix.
200   configurePlatforms = [ "build" "host" ] ++ lib.optional (targetPlatform != hostPlatform) "target";
202   configureFlags = import ../common/configure-flags.nix {
203     inherit
204       lib
205       stdenv
206       targetPackages
207       crossStageStatic libcCross
208       version
210       gmp mpfr libmpc libelf isl
211       cloog
213       enableLTO
214       enableMultilib
215       enablePlugin
216       enableShared
218       langC
219       langCC
220       langFortran
221       langJava javaAwtGtk javaAntlr javaEcj
222       langGo
223       langObjC
224       langObjCpp
225       langJit
226       ;
227   };
229   targetConfig = if targetPlatform != hostPlatform then targetPlatform.config else null;
231   buildFlags = optional
232     (targetPlatform == hostPlatform && hostPlatform == buildPlatform)
233     (if profiledCompiler then "profiledbootstrap" else "bootstrap");
235   dontStrip = !stripped;
237   doCheck = false; # requires a lot of tools, causes a dependency cycle for stdenv
239   installTargets = optional stripped "install-strip";
241   # https://gcc.gnu.org/install/specific.html#x86-64-x-solaris210
242   ${if hostPlatform.system == "x86_64-solaris" then "CC" else null} = "gcc -m64";
244   # Setting $CPATH and $LIBRARY_PATH to make sure both `gcc' and `xgcc' find the
245   # library headers and binaries, regarless of the language being compiled.
246   #
247   # Note: When building the Java AWT GTK peer, the build system doesn't honor
248   # `--with-gmp' et al., e.g., when building
249   # `libjava/classpath/native/jni/java-math/gnu_java_math_GMP.c', so we just add
250   # them to $CPATH and $LIBRARY_PATH in this case.
251   #
252   # Likewise, the LTO code doesn't find zlib.
253   #
254   # Cross-compiling, we need gcc not to read ./specs in order to build the g++
255   # compiler (after the specs for the cross-gcc are created). Having
256   # LIBRARY_PATH= makes gcc read the specs from ., and the build breaks.
258   CPATH = optionals (targetPlatform == hostPlatform) (makeSearchPathOutput "dev" "include" ([]
259     ++ optional (zlib != null) zlib
260     ++ optional langJava boehmgc
261     ++ optionals javaAwtGtk xlibs
262     ++ optionals javaAwtGtk [ gmp mpfr ]
263   ));
265   LIBRARY_PATH = optionals (targetPlatform == hostPlatform) (makeLibraryPath ([]
266     ++ optional (zlib != null) zlib
267     ++ optional langJava boehmgc
268     ++ optionals javaAwtGtk xlibs
269     ++ optionals javaAwtGtk [ gmp mpfr ]
270   ));
272   inherit
273     (import ../common/extra-target-flags.nix {
274       inherit lib stdenv crossStageStatic libcCross threadsCross;
275     })
276     EXTRA_FLAGS_FOR_TARGET
277     EXTRA_LDFLAGS_FOR_TARGET
278     ;
280   passthru = {
281     inherit langC langCC langObjC langObjCpp langFortran langGo version;
282     isGNU = true;
283     hardeningUnsupportedFlags = [ "stackprotector" ];
284   };
286   enableParallelBuilding = true;
287   inherit enableMultilib;
289   inherit (stdenv) is64bit;
291   meta = {
292     homepage = "https://gcc.gnu.org/";
293     license = lib.licenses.gpl3Plus;  # runtime support libraries are typically LGPLv3+
294     description = "GNU Compiler Collection, version ${version}"
295       + (if stripped then "" else " (with debugging info)");
297     longDescription = ''
298       The GNU Compiler Collection includes compiler front ends for C, C++,
299       Objective-C, Fortran, OpenMP for C/C++/Fortran, Java, and Ada, as well
300       as libraries for these languages (libstdc++, libgcj, libgomp,...).
302       GCC development is a part of the GNU Project, aiming to improve the
303       compiler used in the GNU system including the GNU/Linux variant.
304     '';
306     maintainers = with lib.maintainers; [ peti veprbl ];
308     platforms =
309       lib.platforms.linux ++
310       lib.platforms.freebsd ++
311       lib.platforms.illumos ++
312       lib.platforms.darwin;
313     badPlatforms = [ "x86_64-darwin" ];
314   };
317 // optionalAttrs (targetPlatform != hostPlatform && targetPlatform.libc == "msvcrt" && crossStageStatic) {
318   makeFlags = [ "all-gcc" "all-target-libgcc" ];
319   installTargets = "install-gcc install-target-libgcc";
322 // optionalAttrs (enableMultilib) { dontMoveLib64 = true; }