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