1{ stdenv, fetchurl, noSysDirs
2, langC ? true, langCC ? true, langFortran ? false
3, langJava ? false
4, langAda ? false
5, langVhdl ? false
6, profiledCompiler ? false
7, staticCompiler ? false
8, enableShared ? true
9, texinfo ? null
10, gmp, mpfr, gettext, which
11, ppl ? null, cloogppl ? null # used by the Graphite optimization framework
12, zlib ? null, boehmgc ? null
13, zip ? null, unzip ? null, pkgconfig ? null, gtk ? null, libart_lgpl ? null
14, libX11 ? null, libXt ? null, libSM ? null, libICE ? null, libXtst ? null
15, libXrender ? null, xproto ? null, renderproto ? null, xextproto ? null
16, libXrandr ? null, libXi ? null, inputproto ? null, randrproto ? null
17, gnatboot ? null
18, enableMultilib ? false
19, name ? "gcc"
20, cross ? null
21, binutilsCross ? null
22, libcCross ? null
23, crossStageStatic ? true
24, gnat ? null
25}:
26
27assert langJava -> zip != null && unzip != null
28 && zlib != null && boehmgc != null;
29assert langAda -> gnatboot != null;
30assert langVhdl -> gnat != null;
31
32with stdenv.lib;
33
34let version = "4.4.7";
35 javaEcj = fetchurl {
36 # The `$(top_srcdir)/ecj.jar' file is automatically picked up at
37 # `configure' time.
38
39 # XXX: Eventually we might want to take it from upstream.
40 url = "ftp://sourceware.org/pub/java/ecj-4.3.jar";
41 sha256 = "0jz7hvc0s6iydmhgh5h2m15yza7p2rlss2vkif30vm9y77m97qcx";
42 };
43
44 # Antlr (optional) allows the Java `gjdoc' tool to be built. We want a
45 # binary distribution here to allow the whole chain to be bootstrapped.
46 javaAntlr = fetchurl {
47 url = http://www.antlr.org/download/antlr-3.1.3.jar;
48 sha256 = "1f41j0y4kjydl71lqlvr73yagrs2jsg1fjymzjz66mjy7al5lh09";
49 };
50
51 xlibs = [
52 libX11 libXt libSM libICE libXtst libXrender libXrandr libXi
53 xproto renderproto xextproto inputproto randrproto
54 ];
55
56 javaAwtGtk = langJava && gtk != null;
57
58 /* Cross-gcc settings */
59 gccArch = stdenv.lib.attrByPath [ "gcc" "arch" ] null cross;
60 gccCpu = stdenv.lib.attrByPath [ "gcc" "cpu" ] null cross;
61 gccAbi = stdenv.lib.attrByPath [ "gcc" "abi" ] null cross;
62 withArch = if gccArch != null then " --with-arch=${gccArch}" else "";
63 withCpu = if gccCpu != null then " --with-cpu=${gccCpu}" else "";
64 withAbi = if gccAbi != null then " --with-abi=${gccAbi}" else "";
65
66 crossConfigureFlags =
67 "--target=${cross.config}" +
68 withArch +
69 withCpu +
70 withAbi +
71 (if crossStageStatic then
72 " --disable-libssp --disable-nls" +
73 " --without-headers" +
74 " --disable-threads " +
75 " --disable-libmudflap " +
76 " --disable-libgomp " +
77 " --disable-shared" +
78 " --disable-decimal-float" # libdecnumber requires libc
79 else
80 " --with-headers=${libcCross}/include" +
81 " --enable-__cxa_atexit" +
82 " --enable-long-long" +
83 " --enable-threads=posix" +
84 " --enable-nls" +
85 " --disable-decimal-float" # No final libdecnumber (it may work only in 386)
86 );
87 stageNameAddon = if crossStageStatic then "-stage-static" else
88 "-stage-final";
89 crossNameAddon = if cross != null then "-${cross.config}" + stageNameAddon else "";
90
91in
92
93# We need all these X libraries when building AWT with GTK+.
94assert gtk != null -> (filter (x: x == null) xlibs) == [];
95
96stdenv.mkDerivation ({
97 name = "${name}-${version}" + crossNameAddon;
98
99 builder = ./builder.sh;
100
101 src = (import ./sources.nix) {
102 inherit fetchurl optional version;
103 inherit langC langCC langFortran langJava langAda;
104 };
105
106 patches =
107 [ ./pass-cxxcpp.patch
108
109 # libmudflap and libstdc++ receive the build CPP,
110 # and not the target.
111 # http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42279
112 ./target-cpp.patch
113
114 # Bad mixture of build/target flags
115 ./libstdc++-target.patch
116
117 # Compatibility with newer Glibc.
118 ./siginfo_t_fix.patch
119 ]
120 ++ optional noSysDirs ./no-sys-dirs.patch
121 # The GNAT Makefiles did not pay attention to CFLAGS_FOR_TARGET for its
122 # target libraries and tools.
123 ++ optional langAda ./gnat-cflags.patch
124 ++ optional langVhdl ./ghdl-ortho-cflags.patch
125 ++ optional (cross != null && cross.arch == "sparc64") ./pr41818.patch;
126
127 inherit noSysDirs profiledCompiler staticCompiler langJava crossStageStatic
128 libcCross;
129
130 nativeBuildInputs = [ texinfo which ];
131
132 buildInputs = [ gmp mpfr gettext ]
133 ++ (optional (ppl != null) ppl)
134 ++ (optional (cloogppl != null) cloogppl)
135 ++ (optional (zlib != null) zlib)
136 ++ (optional (boehmgc != null) boehmgc)
137 ++ (optionals langJava [zip unzip])
138 ++ (optionals javaAwtGtk ([gtk pkgconfig libart_lgpl] ++ xlibs))
139 ++ (optionals (cross != null) [binutilsCross])
140 ++ (optionals langAda [gnatboot])
141 ++ (optionals langVhdl [gnat])
142 ;
143
144 configureFlags = "
145 ${if enableMultilib then "" else "--disable-multilib"}
146 ${if enableShared then "" else "--disable-shared"}
147 ${if ppl != null then "--with-ppl=${ppl}" else ""}
148 ${if cloogppl != null then "--with-cloog=${cloogppl}" else ""}
149 ${if langJava then "--with-ecj-jar=${javaEcj}" else ""}
150 ${if javaAwtGtk then "--enable-java-awt=gtk" else ""}
151 ${if langJava && javaAntlr != null then "--with-antlr-jar=${javaAntlr}" else ""}
152 --with-gmp=${gmp}
153 --with-mpfr=${mpfr}
154 --disable-libstdcxx-pch
155 --without-included-gettext
156 --with-system-zlib
157 --enable-languages=${
158 concatStrings (intersperse ","
159 ( optional langC "c"
160 ++ optional langCC "c++"
161 ++ optional langFortran "fortran"
162 ++ optional langJava "java"
163 ++ optional langAda "ada"
164 ++ optional langVhdl "vhdl"
165 )
166 )
167 }
168 ${if langAda then " --enable-libada" else ""}
169 ${if cross == null && stdenv.isi686 then "--with-arch=i686" else ""}
170 ${if cross != null then crossConfigureFlags else ""}
171 ";
172
173 targetConfig = if cross != null then cross.config else null;
174
175 # Needed for the cross compilation to work
176 AR = "ar";
177 LD = "ld";
178 CC = "gcc";
179
180 crossAttrs = {
181 AR = "${stdenv.cross.config}-ar";
182 LD = "${stdenv.cross.config}-ld";
183 CC = "${stdenv.cross.config}-gcc";
184 CXX = "${stdenv.cross.config}-gcc";
185 AR_FOR_TARGET = "${stdenv.cross.config}-ar";
186 LD_FOR_TARGET = "${stdenv.cross.config}-ld";
187 CC_FOR_TARGET = "${stdenv.cross.config}-gcc";
188 NM_FOR_TARGET = "${stdenv.cross.config}-nm";
189 CXX_FOR_TARGET = "${stdenv.cross.config}-g++";
190 # If we are making a cross compiler, cross != null
191 NIX_CC_CROSS = if cross == null then "${stdenv.ccCross}" else "";
192 configureFlags = "
193 ${if enableMultilib then "" else "--disable-multilib"}
194 ${if enableShared then "" else "--disable-shared"}
195 ${if ppl != null then "--with-ppl=${ppl.crossDrv}" else ""}
196 ${if cloogppl != null then "--with-cloog=${cloogppl.crossDrv}" else ""}
197 ${if langJava then "--with-ecj-jar=${javaEcj.crossDrv}" else ""}
198 ${if javaAwtGtk then "--enable-java-awt=gtk" else ""}
199 ${if langJava && javaAntlr != null then "--with-antlr-jar=${javaAntlr.crossDrv}" else ""}
200 --with-gmp=${gmp.crossDrv}
201 --with-mpfr=${mpfr.crossDrv}
202 --disable-libstdcxx-pch
203 --without-included-gettext
204 --with-system-zlib
205 --enable-languages=${
206 concatStrings (intersperse ","
207 ( optional langC "c"
208 ++ optional langCC "c++"
209 ++ optional langFortran "fortran"
210 ++ optional langJava "java"
211 ++ optional langAda "ada"
212 ++ optional langVhdl "vhdl"
213 )
214 )
215 }
216 ${if langAda then " --enable-libada" else ""}
217 ${if cross == null && stdenv.isi686 then "--with-arch=i686" else ""}
218 ${if cross != null then crossConfigureFlags else ""}
219 --target=${stdenv.cross.config}
220 ";
221 };
222
223 # Setting $CPATH and $LIBRARY_PATH to make sure both `gcc' and `xgcc' find
224 # the library headers and binaries, regarless of the language being
225 # compiled.
226
227 # Note: When building the Java AWT GTK+ peer, the build system doesn't
228 # honor `--with-gmp' et al., e.g., when building
229 # `libjava/classpath/native/jni/java-math/gnu_java_math_GMP.c', so we just
230 # add them to $CPATH and $LIBRARY_PATH in this case.
231
232 CPATH = concatStrings
233 (intersperse ":" (map (x: x + "/include")
234 (optionals langJava [ boehmgc zlib ]
235 ++ optionals javaAwtGtk xlibs
236 ++ optionals javaAwtGtk [ gmp mpfr ])));
237
238 LIBRARY_PATH = concatStrings
239 (intersperse ":" (map (x: x + "/lib")
240 (optionals langJava [ boehmgc zlib ]
241 ++ optionals javaAwtGtk xlibs
242 ++ optionals javaAwtGtk [ gmp mpfr ])));
243
244
245 passthru = { inherit langC langCC langAda langFortran langVhdl
246 enableMultilib version; isGNU = true; };
247
248 # ghdl does not build fine with parallel building
249 # http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46173
250 #enableParallelBuilding = !langVhdl && !langAda;
251
252 meta = {
253 homepage = http://gcc.gnu.org/;
254 license = stdenv.lib.licenses.gpl3Plus; # runtime support libraries are typically LGPLv3+
255 description = "GNU Compiler Collection, version ${version}";
256
257 longDescription = ''
258 The GNU Compiler Collection includes compiler front ends for C, C++,
259 Objective-C, Fortran, OpenMP for C/C++/Fortran, Java, and Ada, as well
260 as libraries for these languages (libstdc++, libgcj, libgomp,...).
261
262 GCC development is a part of the GNU Project, aiming to improve the
263 compiler used in the GNU system including the GNU/Linux variant.
264 '';
265
266 maintainers = [
267 # Add your name here!
268 stdenv.lib.maintainers.viric
269 ];
270
271 # Volunteers needed for the {Cyg,Dar}win ports of *PPL.
272 # gnatboot is not available out of linux platforms, so we disable the darwin build
273 # for the gnat (ada compiler).
274 platforms = stdenv.lib.platforms.linux ++ optionals (langAda == false) [ "i686-darwin" ];
275 };
276}
277// (if langVhdl then rec {
278 name = "ghdl-0.29";
279
280 ghdlSrc = fetchurl {
281 url = "http://ghdl.free.fr/ghdl-0.29.tar.bz2";
282 sha256 = "15mlinr1lwljwll9ampzcfcrk9bk0qpdks1kxlvb70xf9zhh2jva";
283 };
284
285 # Ghdl has some timestamps checks, storing file timestamps in '.cf' files.
286 # As we will change the timestamps to 1970-01-01 00:00:01, we also set the
287 # content of that .cf to that value. This way ghdl does not complain on
288 # the installed object files from the basic libraries (ieee, ...)
289 postInstallGhdl = ''
290 pushd $out
291 find . -name "*.cf" -exec \
292 sed 's/[0-9]*\.000" /19700101000001.000" /g' -i {} \;
293 popd
294 '';
295
296 postUnpack = ''
297 tar xvf ${ghdlSrc}
298 mv ghdl-*/vhdl gcc*/gcc
299 rm -Rf ghdl-*
300 '';
301
302 meta = {
303 homepage = "http://ghdl.free.fr/";
304 license = stdenv.lib.licenses.gpl2Plus;
305 description = "Complete VHDL simulator, using the GCC technology (gcc ${version})";
306 maintainers = with stdenv.lib.maintainers; [viric];
307 platforms = with stdenv.lib.platforms; linux;
308 };
309
310} else {}))