nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at netboot-syslinux-multiplatform 357 lines 12 kB view raw
1{ lib, stdenv, targetPackages, fetchurl, fetchpatch, noSysDirs 2, langC ? true, langCC ? true, langFortran ? false 3, langAda ? false 4, langObjC ? stdenv.targetPlatform.isDarwin 5, langObjCpp ? stdenv.targetPlatform.isDarwin 6, langD ? false 7, langGo ? false 8, reproducibleBuild ? true 9, profiledCompiler ? false 10, langJit ? false 11, staticCompiler ? false 12, enableShared ? !stdenv.targetPlatform.isStatic 13, enableLTO ? !stdenv.hostPlatform.isStatic 14, texinfo ? null 15, perl ? null # optional, for texi2pod (then pod2man) 16, gmp, mpfr, libmpc, gettext, which, patchelf, binutils 17, isl ? null # optional, for the Graphite optimization framework. 18, zlib ? null 19, libucontext ? null 20, gnat-bootstrap ? null 21, enableMultilib ? false 22, enablePlugin ? stdenv.hostPlatform == stdenv.buildPlatform # Whether to support user-supplied plug-ins 23, name ? "gcc" 24, libcCross ? null 25, threadsCross ? null # for MinGW 26, crossStageStatic ? false 27, gnused ? null 28, cloog # unused; just for compat with gcc4, as we override the parameter on some places 29, buildPackages 30, libxcrypt 31, disableGdbPlugin ? !enablePlugin 32, nukeReferences 33, callPackage 34}: 35 36# Make sure we get GNU sed. 37assert stdenv.buildPlatform.isDarwin -> gnused != null; 38 39# The go frontend is written in c++ 40assert langGo -> langCC; 41assert langAda -> gnat-bootstrap != null; 42 43# TODO: fixup D bootstapping, probably by using gdc11 (and maybe other changes). 44# error: GDC is required to build d 45assert !langD; 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 = "13"; 58 version = "${majorVersion}.1.0"; 59 disableBootstrap = !stdenv.hostPlatform.isDarwin && !profiledCompiler; 60 61 inherit (stdenv) buildPlatform hostPlatform targetPlatform; 62 63 patches = 64 optional (targetPlatform != hostPlatform) ../libstdc++-target.patch 65 ++ optional noSysDirs ../gcc-12-no-sys-dirs.patch 66 ++ optional noSysDirs ../no-sys-dirs-riscv.patch 67 ++ [ 68 ../gnat-cflags-11.patch 69 ../gcc-12-gfortran-driving.patch 70 ../ppc-musl.patch 71 ] 72 # We only apply this patch when building a native toolchain for aarch64-darwin, as it breaks building 73 # a foreign one: https://github.com/iains/gcc-12-branch/issues/18 74 ++ optional (stdenv.isDarwin && stdenv.isAarch64 && buildPlatform == hostPlatform && hostPlatform == targetPlatform) (fetchpatch { 75 name = "gcc-13-darwin-aarch64-support.patch"; 76 url = "https://github.com/Homebrew/formula-patches/raw/5c206c47e2a08d522ec9795bb314346fff5fc4c5/gcc/gcc-13.1.0.diff"; 77 sha256 = "sha256-sMgA7nwE2ULa54t5g6VE6eJQYa69XvQrefi9U9f2t4g="; 78 }) 79 ++ optional langD ../libphobos.patch 80 81 # backport fixes to build gccgo with musl libc 82 ++ optionals (langGo && stdenv.hostPlatform.isMusl) [ 83 (fetchpatch { 84 excludes = [ "gcc/go/gofrontend/MERGE" ]; 85 url = "https://github.com/gcc-mirror/gcc/commit/cf79b1117bd177d3d4c6ed24b6fa243c3628ac2d.diff"; 86 hash = "sha256-mS5ZiYi5D8CpGXrWg3tXlbhp4o86ew1imCTwaHLfl+I="; 87 }) 88 (fetchpatch { 89 excludes = [ "gcc/go/gofrontend/MERGE" ]; 90 url = "https://github.com/gcc-mirror/gcc/commit/7f195a2270910a6ed08bd76e3a16b0a6503f9faf.diff"; 91 hash = "sha256-Ze/cFM0dQofKH00PWPDoklXUlwWhwA1nyTuiDAZ6FKo="; 92 }) 93 (fetchpatch { 94 excludes = [ "gcc/go/gofrontend/MERGE" ]; 95 url = "https://github.com/gcc-mirror/gcc/commit/762fd5e5547e464e25b4bee435db6df4eda0de90.diff"; 96 hash = "sha256-o28upwTcHAnHG2Iq0OewzwSBEhHs+XpBGdIfZdT81pk="; 97 }) 98 (fetchpatch { 99 excludes = [ "gcc/go/gofrontend/MERGE" ]; 100 url = "https://github.com/gcc-mirror/gcc/commit/e73d9fcafbd07bc3714fbaf8a82db71d50015c92.diff"; 101 hash = "sha256-1SjYCVHLEUihdON2TOC3Z2ufM+jf2vH0LvYtZL+c1Fo="; 102 }) 103 (fetchpatch { 104 excludes = [ "gcc/go/gofrontend/MERGE" ]; 105 url = "https://github.com/gcc-mirror/gcc/commit/b6c6a3d64f2e4e9347733290aca3c75898c44b2e.diff"; 106 hash = "sha256-RycJ3YCHd3MXtYFjxP0zY2Wuw7/C4bWoBAQtTKJZPOQ="; 107 }) 108 (fetchpatch { 109 excludes = [ "gcc/go/gofrontend/MERGE" ]; 110 url = "https://github.com/gcc-mirror/gcc/commit/2b1a604a9b28fbf4f382060bebd04adb83acc2f9.diff"; 111 hash = "sha256-WiBQG0Xbk75rHk+AMDvsbrm+dc7lDH0EONJXSdEeMGE="; 112 }) 113 (fetchpatch { 114 url = "https://github.com/gcc-mirror/gcc/commit/c86b726c048eddc1be320c0bf64a897658bee13d.diff"; 115 hash = "sha256-QSIlqDB6JRQhbj/c3ejlmbfWz9l9FurdSWxpwDebnlI="; 116 }) 117 ] 118 119 # Fix detection of bootstrap compiler Ada support (cctools as) on Nix Darwin 120 ++ optional (stdenv.isDarwin && langAda) ../ada-cctools-as-detection-configure.patch 121 122 # Use absolute path in GNAT dylib install names on Darwin 123 ++ optional (stdenv.isDarwin && langAda) ../gnat-darwin-dylib-install-name.patch 124 125 # Obtain latest patch with ../update-mcfgthread-patches.sh 126 ++ optional (!crossStageStatic && targetPlatform.isMinGW && threadsCross.model == "mcf") ./Added-mcf-thread-model-support-from-mcfgthread.patch; 127 128 /* Cross-gcc settings (build == host != target) */ 129 crossMingw = targetPlatform != hostPlatform && targetPlatform.libc == "msvcrt"; 130 stageNameAddon = if crossStageStatic then "stage-static" else "stage-final"; 131 crossNameAddon = optionalString (targetPlatform != hostPlatform) "${targetPlatform.config}-${stageNameAddon}-"; 132 133 callFile = lib.callPackageWith { 134 # lets 135 inherit 136 majorVersion 137 version 138 buildPlatform 139 hostPlatform 140 targetPlatform 141 patches 142 crossMingw 143 stageNameAddon 144 crossNameAddon 145 ; 146 # inherit generated with 'nix eval --json --impure --expr "with import ./. {}; lib.attrNames (lib.functionArgs gcc13.cc.override)" | jq '.[]' --raw-output' 147 inherit 148 binutils 149 buildPackages 150 cloog 151 crossStageStatic 152 disableBootstrap 153 disableGdbPlugin 154 enableLTO 155 enableMultilib 156 enablePlugin 157 enableShared 158 fetchpatch 159 fetchurl 160 gettext 161 gmp 162 gnat-bootstrap 163 gnused 164 isl 165 langAda 166 langC 167 langCC 168 langD 169 langFortran 170 langGo 171 langJit 172 langObjC 173 langObjCpp 174 lib 175 libcCross 176 libmpc 177 libucontext 178 libxcrypt 179 mpfr 180 name 181 noSysDirs 182 nukeReferences 183 patchelf 184 perl 185 profiledCompiler 186 reproducibleBuild 187 staticCompiler 188 stdenv 189 targetPackages 190 texinfo 191 threadsCross 192 which 193 zip 194 zlib 195 ; 196 }; 197 198in 199 200lib.pipe (stdenv.mkDerivation ({ 201 pname = "${crossNameAddon}${name}"; 202 inherit version; 203 204 builder = ../builder.sh; 205 206 src = fetchurl { 207 url = "mirror://gcc/releases/gcc-${version}/gcc-${version}.tar.xz"; 208 sha256 = "sha256-YdaE8Kpedqxlha2ImKJCeq3ol57V5/hUkihsTfwT7oY="; 209 }; 210 211 inherit patches; 212 213 outputs = [ "out" "man" "info" ] ++ lib.optional (!langJit) "lib"; 214 setOutputFlags = false; 215 NIX_NO_SELF_RPATH = true; 216 217 libc_dev = stdenv.cc.libc_dev; 218 219 hardeningDisable = [ "format" "pie" ]; 220 221 postPatch = '' 222 configureScripts=$(find . -name configure) 223 for configureScript in $configureScripts; do 224 patchShebangs $configureScript 225 done 226 '' 227 # This should kill all the stdinc frameworks that gcc and friends like to 228 # insert into default search paths. 229 + lib.optionalString hostPlatform.isDarwin '' 230 substituteInPlace gcc/config/darwin-c.cc \ 231 --replace 'if (stdinc)' 'if (0)' 232 233 substituteInPlace libgcc/config/t-slibgcc-darwin \ 234 --replace "-install_name @shlib_slibdir@/\$(SHLIB_INSTALL_NAME)" "-install_name ''${!outputLib}/lib/\$(SHLIB_INSTALL_NAME)" 235 236 substituteInPlace libgfortran/configure \ 237 --replace "-install_name \\\$rpath/\\\$soname" "-install_name ''${!outputLib}/lib/\\\$soname" 238 '' 239 + ( 240 lib.optionalString (targetPlatform != hostPlatform || stdenv.cc.libc != null) 241 # On NixOS, use the right path to the dynamic linker instead of 242 # `/lib/ld*.so'. 243 (let 244 libc = if libcCross != null then libcCross else stdenv.cc.libc; 245 in 246 ( 247 '' echo "fixing the \`GLIBC_DYNAMIC_LINKER', \`UCLIBC_DYNAMIC_LINKER', and \`MUSL_DYNAMIC_LINKER' macros..." 248 for header in "gcc/config/"*-gnu.h "gcc/config/"*"/"*.h 249 do 250 grep -q _DYNAMIC_LINKER "$header" || continue 251 echo " fixing \`$header'..." 252 sed -i "$header" \ 253 -e 's|define[[:blank:]]*\([UCG]\+\)LIBC_DYNAMIC_LINKER\([0-9]*\)[[:blank:]]"\([^\"]\+\)"$|define \1LIBC_DYNAMIC_LINKER\2 "${libc.out}\3"|g' \ 254 -e 's|define[[:blank:]]*MUSL_DYNAMIC_LINKER\([0-9]*\)[[:blank:]]"\([^\"]\+\)"$|define MUSL_DYNAMIC_LINKER\1 "${libc.out}\2"|g' 255 done 256 '' 257 + lib.optionalString (targetPlatform.libc == "musl") 258 '' 259 sed -i gcc/config/linux.h -e '1i#undef LOCAL_INCLUDE_DIR' 260 '' 261 ) 262 )) 263 + lib.optionalString targetPlatform.isAvr '' 264 makeFlagsArray+=( 265 '-s' # workaround for hitting hydra log limit 266 'LIMITS_H_TEST=false' 267 ) 268 ''; 269 270 inherit noSysDirs staticCompiler crossStageStatic 271 libcCross crossMingw; 272 273 inherit (callFile ../common/dependencies.nix { }) depsBuildBuild nativeBuildInputs depsBuildTarget buildInputs depsTargetTarget; 274 275 NIX_LDFLAGS = lib.optionalString hostPlatform.isSunOS "-lm"; 276 277 278 preConfigure = (callFile ../common/pre-configure.nix { }) + '' 279 ln -sf ${libxcrypt}/include/crypt.h libsanitizer/sanitizer_common/crypt.h 280 ''; 281 282 dontDisableStatic = true; 283 284 configurePlatforms = [ "build" "host" "target" ]; 285 286 configureFlags = callFile ../common/configure-flags.nix { }; 287 288 targetConfig = if targetPlatform != hostPlatform then targetPlatform.config else null; 289 290 buildFlags = 291 # we do not yet have Nix-driven profiling 292 assert profiledCompiler -> !disableBootstrap; 293 let target = 294 lib.optionalString (profiledCompiler) "profiled" + 295 lib.optionalString (targetPlatform == hostPlatform && hostPlatform == buildPlatform && !disableBootstrap) "bootstrap"; 296 in lib.optional (target != "") target; 297 298 inherit (callFile ../common/strip-attributes.nix { }) 299 stripDebugList 300 stripDebugListTarget 301 preFixup; 302 303 # https://gcc.gnu.org/install/specific.html#x86-64-x-solaris210 304 ${if hostPlatform.system == "x86_64-solaris" then "CC" else null} = "gcc -m64"; 305 306 # Setting $CPATH and $LIBRARY_PATH to make sure both `gcc' and `xgcc' find the 307 # library headers and binaries, regarless of the language being compiled. 308 # 309 # Likewise, the LTO code doesn't find zlib. 310 # 311 # Cross-compiling, we need gcc not to read ./specs in order to build the g++ 312 # compiler (after the specs for the cross-gcc are created). Having 313 # LIBRARY_PATH= makes gcc read the specs from ., and the build breaks. 314 315 CPATH = optionals (targetPlatform == hostPlatform) (makeSearchPathOutput "dev" "include" ([] 316 ++ optional (zlib != null) zlib 317 )); 318 319 LIBRARY_PATH = optionals (targetPlatform == hostPlatform) (makeLibraryPath (optional (zlib != null) zlib)); 320 321 inherit (callFile ../common/extra-target-flags.nix { }) 322 EXTRA_FLAGS_FOR_TARGET 323 EXTRA_LDFLAGS_FOR_TARGET 324 ; 325 326 passthru = { 327 inherit langC langCC langObjC langObjCpp langAda langFortran langGo langD version; 328 isGNU = true; 329 }; 330 331 enableParallelBuilding = true; 332 inherit enableShared enableMultilib; 333 334 meta = { 335 inherit (callFile ../common/meta.nix { }) 336 homepage 337 license 338 description 339 longDescription 340 platforms 341 maintainers 342 ; 343 }; 344} 345 346// optionalAttrs (targetPlatform != hostPlatform && targetPlatform.libc == "msvcrt" && crossStageStatic) { 347 makeFlags = [ "all-gcc" "all-target-libgcc" ]; 348 installTargets = "install-gcc install-target-libgcc"; 349} 350 351// optionalAttrs (enableMultilib) { dontMoveLib64 = true; } 352)) 353[ 354 (callPackage ../common/libgcc.nix { inherit langC langCC langJit; }) 355 (callPackage ../common/checksum.nix { inherit langC langCC; }) 356] 357