nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at netboot-syslinux-multiplatform 353 lines 13 kB view raw
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, reproducibleBuild ? true 8, profiledCompiler ? false 9, langJit ? false 10, staticCompiler ? false 11, enableShared ? !stdenv.targetPlatform.isStatic 12, enableLTO ? !stdenv.hostPlatform.isStatic 13, texinfo ? null 14, perl ? null # optional, for texi2pod (then pod2man); required for Java 15, gmp, mpfr, libmpc, gettext, which, patchelf, binutils 16, cloog ? null, isl ? null # optional, for the Graphite optimization framework. 17, zlib ? null, boehmgc ? null 18, zip ? null, unzip ? null, pkg-config ? null 19, gtk2 ? null, libart_lgpl ? null 20, libX11 ? null, libXt ? null, libSM ? null, libICE ? null, libXtst ? null 21, libXrender ? null, xorgproto ? null 22, libXrandr ? null, libXi ? null 23, x11Support ? langJava 24, enableMultilib ? false 25, enablePlugin ? stdenv.hostPlatform == stdenv.buildPlatform # Whether to support user-supplied plug-ins 26, name ? "gcc" 27, libcCross ? null 28, threadsCross ? null # for MinGW 29, crossStageStatic ? false 30, gnused ? null 31, buildPackages 32}: 33 34assert langJava -> zip != null && unzip != null 35 && zlib != null && boehmgc != null 36 && perl != null; # for `--enable-java-home' 37 38# We enable the isl cloog backend. 39assert cloog != null -> isl != null; 40 41# Make sure we get GNU sed. 42assert stdenv.buildPlatform.isDarwin -> gnused != null; 43 44# The go frontend is written in c++ 45assert langGo -> langCC; 46 47# threadsCross is just for MinGW 48assert threadsCross != {} -> stdenv.targetPlatform.isWindows; 49 50# profiledCompiler builds inject non-determinism in one of the compilation stages. 51# If turned on, we can't provide reproducible builds anymore 52assert reproducibleBuild -> profiledCompiler == false; 53 54with lib; 55with builtins; 56 57let majorVersion = "4"; 58 version = "${majorVersion}.9.4"; 59 60 inherit (stdenv) buildPlatform hostPlatform targetPlatform; 61 62 patches = 63 [ ../9/fix-struct-redefinition-on-glibc-2.36.patch ../use-source-date-epoch.patch 64 ../parallel-bconfig.patch ./parallel-strsignal.patch 65 ./libsanitizer.patch 66 ../install-info-files-serially.patch 67 (fetchpatch { 68 name = "avoid-ustat-glibc-2.28.patch"; 69 url = "https://gitweb.gentoo.org/proj/gcc-patches.git/plain/4.9.4/gentoo/100_all_avoid-ustat-glibc-2.28.patch?id=55fcb515620a8f7d3bb77eba938aa0fcf0d67c96"; 70 sha256 = "0b32sb4psv5lq0ij9fwhi1b4pjbwdjnv24nqprsk14dsc6xmi1g0"; 71 }) 72 ] 73 ++ optional (targetPlatform != hostPlatform) ../libstdc++-target.patch 74 ++ optional noSysDirs ../no-sys-dirs.patch 75 ++ optional langFortran ../gfortran-driving.patch 76 ++ [ ../struct-ucontext.patch ../struct-sigaltstack-4.9.patch ] # glibc-2.26 77 # Retpoline patches pulled from the branch hjl/indirect/gcc-4_9-branch (by H.J. Lu, the author of GCC upstream retpoline commits) 78 ++ builtins.map ({commit, sha256}: fetchpatch {url = "https://github.com/hjl-tools/gcc/commit/${commit}.patch"; inherit sha256;}) 79 [{ commit = "e623d21608e96ecd6b65f0d06312117d20488a38"; sha256 = "1ix8i4d2r3ygbv7npmsdj790rhxqrnfwcqzv48b090r9c3ij8ay3"; } 80 { commit = "2015a09e332309f12de1dadfe179afa6a29368b8"; sha256 = "0xcfs0cbb63llj2gbcdrvxim79ax4k4aswn0a3yjavxsj71s1n91"; } 81 { commit = "6b11591f4494f705e8746e7d58b7f423191f4e92"; sha256 = "0aydyhsm2ig0khgbp27am7vq7liyqrq6kfhfi2ki0ij0ab1hfbga"; } 82 { commit = "203c7d9c3e9cb0f88816b481ef8e7e87b3ecc373"; sha256 = "0wqn16y7wy5kg8ngfcni5qdwfphl01axczibbk49bxclwnzvldqa"; } 83 { commit = "f039c6f284b2c9ce97c8353d6034978795c4872e"; sha256 = "13fkgdb17lpyxfksz1zanxhgpsm0jrss9w61nbl7an4im22hz7ci"; } 84 { commit = "ed42606bdab1c5d9e5ad828cd6fe1a0557f193b7"; sha256 = "0gdnn8v3p03imj3qga2mzdhpgbmjcklkxdl97jvz5xia2ikzknxm"; } 85 { commit = "5278e062ef292fd2fbf987d25389785f4c5c0f99"; sha256 = "0j81x758wf8v7j4rx5wc1cy7yhkvhlhv3wmnarwakxiwsspq0vrs"; } 86 { commit = "76f1ffbbb6cd9f6ecde6c82cd16e20a27242e890"; sha256 = "1py56y6gp7fjf4f8bbsfwh5bs1gnmlqda1ycsmnwlzfm0cshdp0c"; } 87 { commit = "4ca48b2b688b135c0390f54ea9077ef10aedd52c"; sha256 = "15r019pzr3k0lpgyvdc92c8fayw8b5lrzncna4bqmamcsdz7vsaw"; } 88 { commit = "98c7bf9ddc80db965d69d61521b1c7a1cec32d9a"; sha256 = "1d7pfdv1q23nf0wadw7jbp6d6r7pnzjpbyxgbdfv7j1vr9l1bp60"; } 89 { commit = "3dc76b53ad896494ca62550a7a752fecbca3f7a2"; sha256 = "0jvdzfpvfdmklfcjwqblwq1i22iqis7ljpvm7adra5d7zf2xk7xz"; } 90 { commit = "1e961ed49b18e176c7457f53df2433421387c23b"; sha256 = "04dnqqs4qsvz4g8cq6db5id41kzys7hzhcaycwmc9rpqygs2ajwz"; } 91 { commit = "e137c72d099f9b3b47f4cc718aa11eab14df1a9c"; sha256 = "1ms0dmz74yf6kwgjfs4d2fhj8y6mcp2n184r3jk44wx2xc24vgb2"; }] 92 93 ++ [ 94 ../libsanitizer-no-cyclades-9.patch 95 # gcc-11 compatibility 96 (fetchpatch { 97 name = "gcc4-char-reload.patch"; 98 url = "https://gcc.gnu.org/git/?p=gcc.git;a=commitdiff_plain;h=d57c99458933a21fdf94f508191f145ad8d5ec58"; 99 includes = [ "gcc/reload.h" ]; 100 sha256 = "sha256-66AMP7/ajunGKAN5WJz/yPn42URZ2KN51yPrFdsxEuM="; 101 }) 102 ]; 103 104 javaEcj = fetchurl { 105 # The `$(top_srcdir)/ecj.jar' file is automatically picked up at 106 # `configure' time. 107 108 # XXX: Eventually we might want to take it from upstream. 109 url = "ftp://sourceware.org/pub/java/ecj-4.3.jar"; 110 sha256 = "0jz7hvc0s6iydmhgh5h2m15yza7p2rlss2vkif30vm9y77m97qcx"; 111 }; 112 113 # Antlr (optional) allows the Java `gjdoc' tool to be built. We want a 114 # binary distribution here to allow the whole chain to be bootstrapped. 115 javaAntlr = fetchurl { 116 url = "https://www.antlr.org/download/antlr-4.4-complete.jar"; 117 sha256 = "02lda2imivsvsis8rnzmbrbp8rh1kb8vmq4i67pqhkwz7lf8y6dz"; 118 }; 119 120 xlibs = [ 121 libX11 libXt libSM libICE libXtst libXrender libXrandr libXi 122 xorgproto 123 ]; 124 125 javaAwtGtk = langJava && x11Support; 126 127 /* Cross-gcc settings (build == host != target) */ 128 crossMingw = targetPlatform != hostPlatform && targetPlatform.libc == "msvcrt"; 129 stageNameAddon = if crossStageStatic then "stage-static" else "stage-final"; 130 crossNameAddon = optionalString (targetPlatform != hostPlatform) "${targetPlatform.config}-${stageNameAddon}-"; 131 132 callFile = lib.callPackageWith { 133 # lets 134 inherit 135 majorVersion 136 version 137 buildPlatform 138 hostPlatform 139 targetPlatform 140 patches 141 javaEcj 142 javaAntlr 143 xlibs 144 javaAwtGtk 145 crossMingw 146 stageNameAddon 147 crossNameAddon 148 ; 149 # inherit generated with 'nix eval --json --impure --expr "with import ./. {}; lib.attrNames (lib.functionArgs gcc49.cc.override)" | jq '.[]' --raw-output' 150 inherit 151 binutils 152 boehmgc 153 buildPackages 154 cloog 155 crossStageStatic 156 enableLTO 157 enableMultilib 158 enablePlugin 159 enableShared 160 fetchpatch 161 fetchurl 162 gettext 163 gmp 164 gnused 165 gtk2 166 isl 167 langC 168 langCC 169 langFortran 170 langGo 171 langJava 172 langJit 173 langObjC 174 langObjCpp 175 lib 176 libICE 177 libSM 178 libX11 179 libXi 180 libXrandr 181 libXrender 182 libXt 183 libXtst 184 libart_lgpl 185 libcCross threadsCross 186 libmpc 187 mpfr 188 name 189 noSysDirs 190 patchelf 191 perl 192 pkg-config 193 profiledCompiler 194 reproducibleBuild 195 staticCompiler 196 stdenv 197 targetPackages 198 texinfo 199 unzip 200 which 201 x11Support 202 xorgproto 203 zip 204 zlib 205 ; 206 }; 207 208in 209 210# We need all these X libraries when building AWT with GTK. 211assert x11Support -> (filter (x: x == null) ([ gtk2 libart_lgpl ] ++ xlibs)) == []; 212 213stdenv.mkDerivation ({ 214 pname = "${crossNameAddon}${name}"; 215 inherit version; 216 217 builder = ../builder.sh; 218 219 src = fetchurl { 220 url = "mirror://gnu/gcc/gcc-${version}/gcc-${version}.tar.bz2"; 221 sha256 = "14l06m7nvcvb0igkbip58x59w3nq6315k6jcz3wr9ch1rn9d44bc"; 222 }; 223 224 inherit patches; 225 226 hardeningDisable = [ "format" "pie" ]; 227 228 # When targeting darwin, libgcc_ext.10.{4,5}.dylib are created as 229 # MH_DYLIB_STUB files, which install_name_tool can't change, so we 230 # get a cycle between $out and $lib. 231 outputs = if langJava || langGo || targetPlatform.isDarwin then ["out" "man" "info"] 232 else [ "out" "lib" "man" "info" ]; 233 setOutputFlags = false; 234 NIX_NO_SELF_RPATH = true; 235 236 libc_dev = stdenv.cc.libc_dev; 237 238 postPatch = 239 if targetPlatform != hostPlatform || stdenv.cc.libc != null then 240 # On NixOS, use the right path to the dynamic linker instead of 241 # `/lib/ld*.so'. 242 let 243 libc = if libcCross != null then libcCross else stdenv.cc.libc; 244 in 245 '' echo "fixing the \`GLIBC_DYNAMIC_LINKER' and \`UCLIBC_DYNAMIC_LINKER' macros..." 246 for header in "gcc/config/"*-gnu.h "gcc/config/"*"/"*.h 247 do 248 grep -q LIBC_DYNAMIC_LINKER "$header" || continue 249 echo " fixing \`$header'..." 250 sed -i "$header" \ 251 -e 's|define[[:blank:]]*\([UCG]\+\)LIBC_DYNAMIC_LINKER\([0-9]*\)[[:blank:]]"\([^\"]\+\)"$|define \1LIBC_DYNAMIC_LINKER\2 "${libc.out}\3"|g' 252 done 253 '' 254 else null; 255 256 inherit noSysDirs staticCompiler langJava crossStageStatic 257 libcCross crossMingw; 258 259 inherit (callFile ../common/dependencies.nix { }) 260 depsBuildBuild nativeBuildInputs depsBuildTarget buildInputs depsTargetTarget; 261 262 preConfigure = callFile ../common/pre-configure.nix { }; 263 264 dontDisableStatic = true; 265 266 configurePlatforms = [ "build" "host" "target" ]; 267 268 configureFlags = callFile ../common/configure-flags.nix { }; 269 270 targetConfig = if targetPlatform != hostPlatform then targetPlatform.config else null; 271 272 buildFlags = optional 273 (targetPlatform == hostPlatform && hostPlatform == buildPlatform) 274 (if profiledCompiler then "profiledbootstrap" else "bootstrap"); 275 276 inherit (callFile ../common/strip-attributes.nix { }) 277 stripDebugList 278 stripDebugListTarget 279 preFixup; 280 281 doCheck = false; # requires a lot of tools, causes a dependency cycle for stdenv 282 283 # https://gcc.gnu.org/install/specific.html#x86-64-x-solaris210 284 ${if hostPlatform.system == "x86_64-solaris" then "CC" else null} = "gcc -m64"; 285 286 # Setting $CPATH and $LIBRARY_PATH to make sure both `gcc' and `xgcc' find the 287 # library headers and binaries, regarless of the language being compiled. 288 # 289 # Note: When building the Java AWT GTK peer, the build system doesn't honor 290 # `--with-gmp' et al., e.g., when building 291 # `libjava/classpath/native/jni/java-math/gnu_java_math_GMP.c', so we just add 292 # them to $CPATH and $LIBRARY_PATH in this case. 293 # 294 # Likewise, the LTO code doesn't find zlib. 295 # 296 # Cross-compiling, we need gcc not to read ./specs in order to build the g++ 297 # compiler (after the specs for the cross-gcc are created). Having 298 # LIBRARY_PATH= makes gcc read the specs from ., and the build breaks. 299 300 CPATH = optionals (targetPlatform == hostPlatform) (makeSearchPathOutput "dev" "include" ([] 301 ++ optional (zlib != null) zlib 302 ++ optional langJava boehmgc 303 ++ optionals javaAwtGtk xlibs 304 ++ optionals javaAwtGtk [ gmp mpfr ] 305 )); 306 307 LIBRARY_PATH = optionals (targetPlatform == hostPlatform) (makeLibraryPath ([] 308 ++ optional (zlib != null) zlib 309 ++ optional langJava boehmgc 310 ++ optionals javaAwtGtk xlibs 311 ++ optionals javaAwtGtk [ gmp mpfr ] 312 )); 313 314 inherit (callFile ../common/extra-target-flags.nix { }) 315 EXTRA_FLAGS_FOR_TARGET 316 EXTRA_LDFLAGS_FOR_TARGET 317 ; 318 319 passthru = { 320 inherit langC langCC langObjC langObjCpp langFortran langGo version; 321 isGNU = true; 322 hardeningUnsupportedFlags = [ "fortify3" ]; 323 }; 324 325 enableParallelBuilding = true; 326 inherit enableShared enableMultilib; 327 328 meta = { 329 inherit (callFile ../common/meta.nix { }) 330 homepage 331 license 332 description 333 longDescription 334 platforms 335 maintainers 336 ; 337 badPlatforms = [ "aarch64-darwin" ]; 338 }; 339} 340 341// optionalAttrs (targetPlatform != hostPlatform && targetPlatform.libc == "msvcrt" && crossStageStatic) { 342 makeFlags = [ "all-gcc" "all-target-libgcc" ]; 343 installTargets = "install-gcc install-target-libgcc"; 344} 345 346// optionalAttrs (enableMultilib) { dontMoveLib64 = true; } 347 348// optionalAttrs (langJava) { 349 postFixup = '' 350 target="$(echo "$out/libexec/gcc"/*/*/ecj*)" 351 patchelf --set-rpath "$(patchelf --print-rpath "$target"):$out/lib" "$target" 352 '';} 353)