nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at netboot-syslinux-multiplatform 320 lines 11 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, gnat-bootstrap ? null 20, enableMultilib ? false 21, enablePlugin ? stdenv.hostPlatform == stdenv.buildPlatform # Whether to support user-supplied plug-ins 22, name ? "gcc" 23, libcCross ? null 24, threadsCross ? null # for MinGW 25, crossStageStatic ? false 26, gnused ? null 27, cloog # unused; just for compat with gcc4, as we override the parameter on some places 28, buildPackages 29, libxcrypt 30, disableGdbPlugin ? !enablePlugin 31, nukeReferences 32, callPackage 33}: 34 35# Make sure we get GNU sed. 36assert stdenv.buildPlatform.isDarwin -> gnused != null; 37 38# The go frontend is written in c++ 39assert langGo -> langCC; 40assert langAda -> gnat-bootstrap != null; 41 42# threadsCross is just for MinGW 43assert threadsCross != {} -> stdenv.targetPlatform.isWindows; 44 45# profiledCompiler builds inject non-determinism in one of the compilation stages. 46# If turned on, we can't provide reproducible builds anymore 47assert reproducibleBuild -> profiledCompiler == false; 48 49with lib; 50with builtins; 51 52let majorVersion = "11"; 53 version = "${majorVersion}.3.0"; 54 disableBootstrap = !stdenv.hostPlatform.isDarwin; 55 56 inherit (stdenv) buildPlatform hostPlatform targetPlatform; 57 58 patches = [ 59 # Fix https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80431 60 (fetchurl { 61 name = "fix-bug-80431.patch"; 62 url = "https://gcc.gnu.org/git/?p=gcc.git;a=patch;h=de31f5445b12fd9ab9969dc536d821fe6f0edad0"; 63 sha256 = "0sd52c898msqg7m316zp0ryyj7l326cjcn2y19dcxqp15r74qj0g"; 64 }) 65 ./fix-struct-redefinition-on-glibc-2.36.patch 66 ../install-info-files-serially.patch 67 ] ++ optional (targetPlatform != hostPlatform) ../libstdc++-target.patch 68 ++ optional noSysDirs ../no-sys-dirs.patch 69 ++ optional (noSysDirs && hostPlatform.isRiscV) ../no-sys-dirs-riscv.patch 70 /* ++ optional (hostPlatform != buildPlatform) (fetchpatch { # XXX: Refine when this should be applied 71 url = "https://git.busybox.net/buildroot/plain/package/gcc/${version}/0900-remove-selftests.patch?id=11271540bfe6adafbc133caf6b5b902a816f5f02"; 72 sha256 = ""; # TODO: uncomment and check hash when available. 73 }) */ 74 ++ optional langAda ../gnat-cflags-11.patch 75 ++ optional langD ../libphobos.patch 76 ++ optional langFortran ../gfortran-driving.patch 77 ++ optional (targetPlatform.libc == "musl" && targetPlatform.isPower) ../ppc-musl.patch 78 79 ++ optionals stdenv.isDarwin [ 80 (fetchpatch { 81 # There are no upstream release tags in https://github.com/iains/gcc-11-branch. 82 # 2d280e7 is the commit from https://github.com/gcc-mirror/gcc/releases/tag/releases%2Fgcc-11.3.0 83 url = "https://github.com/iains/gcc-11-branch/compare/2d280e7eafc086e9df85f50ed1a6526d6a3a204d..gcc-11.3-darwin-r2.diff"; 84 sha256 = "sha256-LFAXUEoYD7YeCG8V9mWanygyQOI7U5OhCRIKOVCCDAg="; 85 }) 86 ] 87 # https://github.com/osx-cross/homebrew-avr/issues/280#issuecomment-1272381808 88 ++ optional (stdenv.isDarwin && targetPlatform.isAvr) ./avr-gcc-11.3-darwin.patch 89 90 # Obtain latest patch with ../update-mcfgthread-patches.sh 91 ++ optional (!crossStageStatic && targetPlatform.isMinGW && threadsCross.model == "mcf") ./Added-mcf-thread-model-support-from-mcfgthread.patch 92 93 # openjdk build fails without this on -march=opteron; is upstream in gcc12 94 ++ [ ./gcc-issue-103910.patch ]; 95 96 /* Cross-gcc settings (build == host != target) */ 97 crossMingw = targetPlatform != hostPlatform && targetPlatform.libc == "msvcrt"; 98 stageNameAddon = if crossStageStatic then "stage-static" else "stage-final"; 99 crossNameAddon = optionalString (targetPlatform != hostPlatform) "${targetPlatform.config}-${stageNameAddon}-"; 100 101 callFile = lib.callPackageWith { 102 # lets 103 inherit 104 majorVersion 105 version 106 buildPlatform 107 hostPlatform 108 targetPlatform 109 patches 110 crossMingw 111 stageNameAddon 112 crossNameAddon 113 ; 114 # inherit generated with 'nix eval --json --impure --expr "with import ./. {}; lib.attrNames (lib.functionArgs gcc11.cc.override)" | jq '.[]' --raw-output' 115 inherit 116 binutils 117 buildPackages 118 cloog 119 crossStageStatic 120 enableLTO 121 enableMultilib 122 enablePlugin 123 disableGdbPlugin 124 enableShared 125 disableBootstrap 126 fetchpatch 127 fetchurl 128 gettext 129 gmp 130 gnat-bootstrap 131 gnused 132 isl 133 langAda 134 langC 135 langCC 136 langD 137 langFortran 138 langGo 139 langJit 140 langObjC 141 langObjCpp 142 lib 143 libcCross 144 libmpc 145 libxcrypt 146 mpfr 147 name 148 noSysDirs 149 patchelf 150 perl 151 profiledCompiler 152 reproducibleBuild 153 staticCompiler 154 stdenv 155 targetPackages 156 texinfo 157 threadsCross 158 which 159 zip 160 zlib 161 ; 162 }; 163 164in 165 166lib.pipe (stdenv.mkDerivation ({ 167 pname = "${crossNameAddon}${name}"; 168 inherit version; 169 170 builder = ../builder.sh; 171 172 src = fetchurl { 173 url = "mirror://gcc/releases/gcc-${version}/gcc-${version}.tar.xz"; 174 sha256 = "sha256-tHzygYaR9bHiHfK7OMeV+sLPvWQO3i0KXhyJ4zijrDk="; 175 }; 176 177 inherit patches; 178 179 outputs = [ "out" "man" "info" ] ++ lib.optional (!langJit) "lib"; 180 setOutputFlags = false; 181 NIX_NO_SELF_RPATH = true; 182 183 libc_dev = stdenv.cc.libc_dev; 184 185 hardeningDisable = [ "format" "pie" ]; 186 187 postPatch = '' 188 configureScripts=$(find . -name configure) 189 for configureScript in $configureScripts; do 190 patchShebangs $configureScript 191 done 192 '' 193 # This should kill all the stdinc frameworks that gcc and friends like to 194 # insert into default search paths. 195 + lib.optionalString hostPlatform.isDarwin '' 196 substituteInPlace gcc/config/darwin-c.c \ 197 --replace 'if (stdinc)' 'if (0)' 198 199 substituteInPlace libgcc/config/t-slibgcc-darwin \ 200 --replace "-install_name @shlib_slibdir@/\$(SHLIB_INSTALL_NAME)" "-install_name ''${!outputLib}/lib/\$(SHLIB_INSTALL_NAME)" 201 202 substituteInPlace libgfortran/configure \ 203 --replace "-install_name \\\$rpath/\\\$soname" "-install_name ''${!outputLib}/lib/\\\$soname" 204 '' 205 + ( 206 lib.optionalString (targetPlatform != hostPlatform || stdenv.cc.libc != null) 207 # On NixOS, use the right path to the dynamic linker instead of 208 # `/lib/ld*.so'. 209 (let 210 libc = if libcCross != null then libcCross else stdenv.cc.libc; 211 in 212 ( 213 '' echo "fixing the \`GLIBC_DYNAMIC_LINKER', \`UCLIBC_DYNAMIC_LINKER', and \`MUSL_DYNAMIC_LINKER' macros..." 214 for header in "gcc/config/"*-gnu.h "gcc/config/"*"/"*.h 215 do 216 grep -q _DYNAMIC_LINKER "$header" || continue 217 echo " fixing \`$header'..." 218 sed -i "$header" \ 219 -e 's|define[[:blank:]]*\([UCG]\+\)LIBC_DYNAMIC_LINKER\([0-9]*\)[[:blank:]]"\([^\"]\+\)"$|define \1LIBC_DYNAMIC_LINKER\2 "${libc.out}\3"|g' \ 220 -e 's|define[[:blank:]]*MUSL_DYNAMIC_LINKER\([0-9]*\)[[:blank:]]"\([^\"]\+\)"$|define MUSL_DYNAMIC_LINKER\1 "${libc.out}\2"|g' 221 done 222 '' 223 + lib.optionalString (targetPlatform.libc == "musl") 224 '' 225 sed -i gcc/config/linux.h -e '1i#undef LOCAL_INCLUDE_DIR' 226 '' 227 )) 228 ) 229 + lib.optionalString targetPlatform.isAvr '' 230 makeFlagsArray+=( 231 '-s' # workaround for hitting hydra log limit 232 'LIMITS_H_TEST=false' 233 ) 234 ''; 235 236 inherit noSysDirs staticCompiler crossStageStatic 237 libcCross crossMingw; 238 239 inherit (callFile ../common/dependencies.nix { }) 240 depsBuildBuild nativeBuildInputs depsBuildTarget buildInputs depsTargetTarget; 241 242 NIX_LDFLAGS = lib.optionalString hostPlatform.isSunOS "-lm"; 243 244 preConfigure = (callFile ../common/pre-configure.nix { }) + '' 245 ln -sf ${libxcrypt}/include/crypt.h libsanitizer/sanitizer_common/crypt.h 246 ''; 247 248 dontDisableStatic = true; 249 250 configurePlatforms = [ "build" "host" "target" ]; 251 252 configureFlags = callFile ../common/configure-flags.nix { }; 253 254 targetConfig = if targetPlatform != hostPlatform then targetPlatform.config else null; 255 256 buildFlags = 257 let target = lib.optionalString (profiledCompiler) "profiled" 258 + lib.optionalString (targetPlatform == hostPlatform && hostPlatform == buildPlatform && !disableBootstrap) "bootstrap"; 259 in lib.optional (target != "") target; 260 261 inherit (callFile ../common/strip-attributes.nix { }) 262 stripDebugList 263 stripDebugListTarget 264 preFixup; 265 266 # https://gcc.gnu.org/install/specific.html#x86-64-x-solaris210 267 ${if hostPlatform.system == "x86_64-solaris" then "CC" else null} = "gcc -m64"; 268 269 # Setting $CPATH and $LIBRARY_PATH to make sure both `gcc' and `xgcc' find the 270 # library headers and binaries, regarless of the language being compiled. 271 # 272 # Likewise, the LTO code doesn't find zlib. 273 # 274 # Cross-compiling, we need gcc not to read ./specs in order to build the g++ 275 # compiler (after the specs for the cross-gcc are created). Having 276 # LIBRARY_PATH= makes gcc read the specs from ., and the build breaks. 277 278 CPATH = optionals (targetPlatform == hostPlatform) (makeSearchPathOutput "dev" "include" ([] 279 ++ optional (zlib != null) zlib 280 )); 281 282 LIBRARY_PATH = optionals (targetPlatform == hostPlatform) (makeLibraryPath (optional (zlib != null) zlib)); 283 284 inherit (callFile ../common/extra-target-flags.nix { }) 285 EXTRA_FLAGS_FOR_TARGET 286 EXTRA_LDFLAGS_FOR_TARGET 287 ; 288 289 passthru = { 290 inherit langC langCC langObjC langObjCpp langAda langFortran langGo langD version; 291 isGNU = true; 292 hardeningUnsupportedFlags = [ "fortify3" ]; 293 }; 294 295 enableParallelBuilding = true; 296 inherit enableShared enableMultilib; 297 298 meta = { 299 inherit (callFile ../common/meta.nix { }) 300 homepage 301 license 302 description 303 longDescription 304 platforms 305 maintainers 306 ; 307 }; 308} 309 310// optionalAttrs (targetPlatform != hostPlatform && targetPlatform.libc == "msvcrt" && crossStageStatic) { 311 makeFlags = [ "all-gcc" "all-target-libgcc" ]; 312 installTargets = "install-gcc install-target-libgcc"; 313} 314 315// optionalAttrs (enableMultilib) { dontMoveLib64 = true; } 316)) 317[ 318 (callPackage ../common/libgcc.nix { inherit langC langCC langJit; }) 319 (callPackage ../common/checksum.nix { inherit langC langCC; }) 320]