1{ stdenv, fetchurl, noSysDirs
2, langC ? true, langCC ? true, langFortran ? false, langTreelang ? false
3, langJava ? false
4, langVhdl ? false
5, profiledCompiler ? false
6, staticCompiler ? false
7, enableShared ? true
8, texinfo ? null
9, gmp, mpfr
10, bison ? null, flex ? null
11, zlib ? null, boehmgc ? null
12, enableMultilib ? false
13, name ? "gcc"
14, cross ? null
15, binutilsCross ? null
16, libcCross ? null
17, crossStageStatic ? true
18, gnat ? null
19}:
20
21assert langTreelang -> bison != null && flex != null;
22
23assert cross != null -> profiledCompiler == false && enableMultilib == true;
24assert (cross != null && crossStageStatic) -> (langCC == false && langFortran
25== false && langTreelang == false);
26
27assert langVhdl -> gnat != null;
28
29with stdenv.lib;
30
31let
32 version = "4.3.6";
33
34 crossConfigureFlags =
35 "--target=${cross.config}" +
36 (if crossStageStatic then
37 " --disable-libssp --disable-nls" +
38 " --without-headers" +
39 " --disable-threads " +
40 " --disable-libmudflap " +
41 " --disable-libgomp " +
42 " --disable-shared"
43 else
44 " --with-headers=${libcCross}/include" +
45 " --enable-__cxa_atexit" +
46 " --enable-long-long" +
47 " --enable-threads=posix" +
48 " --enable-nls"
49 );
50 stageNameAddon = if crossStageStatic then "-stage-static" else
51 "-stage-final";
52 crossNameAddon = if cross != null then "-${cross.config}" + stageNameAddon else "";
53in
54
55stdenv.mkDerivation ({
56 name = "${name}-${version}" + crossNameAddon;
57
58 builder = ./builder.sh;
59
60 src =
61 optional /*langC*/ true (fetchurl {
62 url = "mirror://gcc/releases/gcc-${version}/gcc-core-${version}.tar.bz2";
63 sha256 = "0ygrfw3hgp48hkqipbl9lw38f27npigc2sm6f01g9iswpq1igbw6";
64 }) ++
65 optional langCC (fetchurl {
66 url = "mirror://gcc/releases/gcc-${version}/gcc-g++-${version}.tar.bz2";
67 sha256 = "105xz3991b57zx3146xwlpchdb2sjmlknclvi1iac2gawm4mhxhf";
68 }) ++
69 optional langFortran (fetchurl {
70 url = "mirror://gcc/releases/gcc-${version}/gcc-fortran-${version}.tar.bz2";
71 sha256 = "12bqvf53hvhrwjnh101vn9frb5g8cr98cra4f11dzhzs4ppydpi1";
72 }) ++
73 optional langJava (fetchurl {
74 url = "mirror://gcc/releases/gcc-${version}/gcc-java-${version}.tar.bz2";
75 sha256 = "03w6jln9gmdv149s774rlw4rzi2zhbqna54r86cd6mql8flmy7fs";
76 });
77
78 patches =
79 [ ./pass-cxxcpp.patch ./libmudflap-cpp.patch ./siginfo_t_fix.patch ]
80 ++ optional noSysDirs ./no-sys-dirs.patch
81 ++ optional (noSysDirs && langFortran) ./no-sys-dirs-fortran.patch
82 ++ optional langJava ./java-jvgenmain-link.patch
83 ++ optional langVhdl ./ghdl-ortho-cflags.patch
84 ++ optional langVhdl ./ghdl-runtime-o2.patch;
85
86 inherit noSysDirs profiledCompiler staticCompiler crossStageStatic
87 binutilsCross libcCross;
88 targetConfig = if cross != null then cross.config else null;
89
90 buildInputs = [texinfo gmp mpfr]
91 ++ (optionals langTreelang [bison flex])
92 ++ (optional (zlib != null) zlib)
93 ++ (optional (boehmgc != null) boehmgc)
94 ++ (optionals (cross != null) [binutilsCross])
95 ++ (optionals langVhdl [gnat])
96 ;
97
98 configureFlags = "
99 ${if enableMultilib then "" else "--disable-multilib"}
100 ${if enableShared then "" else "--disable-shared"}
101 --disable-libstdcxx-pch
102 --with-system-zlib
103 --enable-languages=${
104 concatStrings (intersperse ","
105 ( optional langC "c"
106 ++ optional langCC "c++"
107 ++ optional langFortran "fortran"
108 ++ optional langJava "java"
109 ++ optional langTreelang "treelang"
110 ++ optional langVhdl "vhdl"
111 )
112 )
113 }
114 ${if stdenv.isi686 then "--with-arch=i686" else ""}
115 ${if cross != null then crossConfigureFlags else ""}
116 ";
117 #Above I added a hack on making the build different than the host.
118
119 # Needed for the cross compilation to work
120 AR = "ar";
121 LD = "ld";
122 CC = "gcc";
123
124 NIX_EXTRA_LDFLAGS = if staticCompiler then "-static" else "";
125
126 inherit gmp mpfr;
127
128 passthru = { inherit langC langCC langFortran langVhdl langTreelang
129 enableMultilib; };
130
131 # ghdl does not build fine with parallel building
132 enableParallelBuilding = !langVhdl;
133
134 meta = {
135 homepage = "http://gcc.gnu.org/";
136 license = "GPL/LGPL";
137 description = "GNU Compiler Collection, 4.3.x";
138 maintainers = with stdenv.lib.maintainers; [viric];
139 platforms = with stdenv.lib.platforms; linux;
140 };
141
142} // (if langJava then {
143 postConfigure = ''
144 make configure-gcc
145 sed -i gcc/Makefile -e 's@^CFLAGS = .*@& -I${zlib}/include@ ; s@^LDFLAGS = .*@& -L${zlib}/lib@'
146 sed -i gcc/Makefile -e 's@^CFLAGS = .*@& -I${boehmgc}/include@ ; s@^LDFLAGS = .*@& -L${boehmgc}/lib -lgc@'
147 '';
148} else {})
149// (if langVhdl then rec {
150 name = "ghdl-0.29";
151
152 ghdlSrc = fetchurl {
153 url = "http://ghdl.free.fr/ghdl-0.29.tar.bz2";
154 sha256 = "15mlinr1lwljwll9ampzcfcrk9bk0qpdks1kxlvb70xf9zhh2jva";
155 };
156
157 # Ghdl has some timestamps checks, storing file timestamps in '.cf' files.
158 # As we will change the timestamps to 1970-01-01 00:00:01, we also set the
159 # content of that .cf to that value. This way ghdl does not complain on
160 # the installed object files from the basic libraries (ieee, ...)
161 postInstallGhdl = ''
162 pushd $out
163 find . -name "*.cf" -exec \
164 sed 's/[0-9]*\.000" /19700101000001.000" /g' -i {} \;
165 popd
166 '';
167
168 postUnpack = ''
169 tar xvf ${ghdlSrc}
170 mv ghdl-*/vhdl gcc*/gcc
171 rm -Rf ghdl-*
172 '';
173
174 passthru.isGNU = true;
175
176 meta = {
177 homepage = "http://ghdl.free.fr/";
178 license = stdenv.lib.licenses.gpl2Plus;
179 description = "Complete VHDL simulator, using the GCC technology";
180 maintainers = with stdenv.lib.maintainers; [viric];
181 platforms = with stdenv.lib.platforms; linux;
182 };
183
184} else {}))