nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at netboot-syslinux-multiplatform 298 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 # unused; just for compat with gcc4, as we override the parameter on some places 28, buildPackages 29}: 30 31# Note: this package is used for bootstrapping fetchurl, and thus 32# cannot use fetchpatch! All mutable patches (generated by GitHub or 33# cgit) that are needed here should be included directly in Nixpkgs as 34# files. 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# threadsCross is just for MinGW 44assert threadsCross != {} -> stdenv.targetPlatform.isWindows; 45 46# profiledCompiler builds inject non-determinism in one of the compilation stages. 47# If turned on, we can't provide reproducible builds anymore 48assert reproducibleBuild -> profiledCompiler == false; 49 50with lib; 51with builtins; 52 53let majorVersion = "9"; 54 version = "${majorVersion}.5.0"; 55 56 inherit (stdenv) buildPlatform hostPlatform targetPlatform; 57 58 patches = [ 59 ./fix-struct-redefinition-on-glibc-2.36.patch 60 # Fix https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80431 61 (fetchurl { 62 name = "fix-bug-80431.patch"; 63 url = "https://gcc.gnu.org/git/?p=gcc.git;a=patch;h=de31f5445b12fd9ab9969dc536d821fe6f0edad0"; 64 sha256 = "0sd52c898msqg7m316zp0ryyj7l326cjcn2y19dcxqp15r74qj0g"; 65 }) 66 ../install-info-files-serially.patch 67 ] ++ optional (targetPlatform != hostPlatform) ../libstdc++-target.patch 68 ++ optional targetPlatform.isNetBSD ../libstdc++-netbsd-ctypes.patch 69 ++ optional noSysDirs ../no-sys-dirs.patch 70 ++ optional (noSysDirs && hostPlatform.isRiscV) ../no-sys-dirs-riscv-gcc9.patch 71 /* ++ optional (hostPlatform != buildPlatform) (fetchpatch { # XXX: Refine when this should be applied 72 url = "https://git.busybox.net/buildroot/plain/package/gcc/${version}/0900-remove-selftests.patch?id=11271540bfe6adafbc133caf6b5b902a816f5f02"; 73 sha256 = ""; # TODO: uncomment and check hash when available. 74 }) */ 75 ++ optional langAda ../gnat-cflags.patch 76 ++ optional langD ../libphobos.patch 77 ++ optional langFortran ../gfortran-driving.patch 78 ++ optional (targetPlatform.libc == "musl" && targetPlatform.isPower) ../ppc-musl.patch 79 80 # Obtain latest patch with ../update-mcfgthread-patches.sh 81 ++ optional (!crossStageStatic && targetPlatform.isMinGW && threadsCross.model == "mcf") ./Added-mcf-thread-model-support-from-mcfgthread.patch 82 ; 83 84 /* Cross-gcc settings (build == host != target) */ 85 crossMingw = targetPlatform != hostPlatform && targetPlatform.libc == "msvcrt"; 86 stageNameAddon = if crossStageStatic then "stage-static" else "stage-final"; 87 crossNameAddon = optionalString (targetPlatform != hostPlatform) "${targetPlatform.config}-${stageNameAddon}-"; 88 89 callFile = lib.callPackageWith { 90 # lets 91 inherit 92 majorVersion 93 version 94 buildPlatform 95 hostPlatform 96 targetPlatform 97 patches 98 crossMingw 99 stageNameAddon 100 crossNameAddon 101 ; 102 # inherit generated with 'nix eval --json --impure --expr "with import ./. {}; lib.attrNames (lib.functionArgs gcc9.cc.override)" | jq '.[]' --raw-output' 103 inherit 104 binutils 105 buildPackages 106 cloog 107 crossStageStatic 108 enableLTO 109 enableMultilib 110 enablePlugin 111 enableShared 112 fetchpatch 113 fetchurl 114 gettext 115 gmp 116 gnat-bootstrap 117 gnused 118 isl 119 langAda 120 langC 121 langCC 122 langD 123 langFortran 124 langGo 125 langJit 126 langObjC 127 langObjCpp 128 lib 129 libcCross 130 libmpc 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 = "13ygjmd938m0wmy946pxdhz9i1wq7z4w10l6pvidak0xxxj9yxi7"; 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 'LIMITS_H_TEST=false' 217 ) 218 ''; 219 220 inherit noSysDirs staticCompiler crossStageStatic 221 libcCross crossMingw; 222 223 inherit (callFile ../common/dependencies.nix { }) 224 depsBuildBuild nativeBuildInputs depsBuildTarget buildInputs depsTargetTarget; 225 226 NIX_LDFLAGS = lib.optionalString hostPlatform.isSunOS "-lm"; 227 228 preConfigure = callFile ../common/pre-configure.nix { }; 229 230 dontDisableStatic = true; 231 232 configurePlatforms = [ "build" "host" "target" ]; 233 234 configureFlags = callFile ../common/configure-flags.nix { }; 235 236 targetConfig = if targetPlatform != hostPlatform then targetPlatform.config else null; 237 238 buildFlags = optional 239 (targetPlatform == hostPlatform && hostPlatform == buildPlatform) 240 (if profiledCompiler then "profiledbootstrap" else "bootstrap"); 241 242 inherit (callFile ../common/strip-attributes.nix { }) 243 stripDebugList 244 stripDebugListTarget 245 preFixup; 246 247 # https://gcc.gnu.org/install/specific.html#x86-64-x-solaris210 248 ${if hostPlatform.system == "x86_64-solaris" then "CC" else null} = "gcc -m64"; 249 250 # Setting $CPATH and $LIBRARY_PATH to make sure both `gcc' and `xgcc' find the 251 # library headers and binaries, regarless of the language being compiled. 252 # 253 # Likewise, the LTO code doesn't find zlib. 254 # 255 # Cross-compiling, we need gcc not to read ./specs in order to build the g++ 256 # compiler (after the specs for the cross-gcc are created). Having 257 # LIBRARY_PATH= makes gcc read the specs from ., and the build breaks. 258 259 CPATH = optionals (targetPlatform == hostPlatform) (makeSearchPathOutput "dev" "include" ([] 260 ++ optional (zlib != null) zlib 261 )); 262 263 LIBRARY_PATH = optionals (targetPlatform == hostPlatform) (makeLibraryPath (optional (zlib != null) zlib)); 264 265 inherit (callFile ../common/extra-target-flags.nix { }) 266 EXTRA_FLAGS_FOR_TARGET 267 EXTRA_LDFLAGS_FOR_TARGET 268 ; 269 270 passthru = { 271 inherit langC langCC langObjC langObjCpp langAda langFortran langGo langD version; 272 isGNU = true; 273 hardeningUnsupportedFlags = [ "fortify3" ]; 274 }; 275 276 enableParallelBuilding = true; 277 inherit enableShared enableMultilib; 278 279 meta = { 280 inherit (callFile ../common/meta.nix { }) 281 homepage 282 license 283 description 284 longDescription 285 platforms 286 maintainers 287 ; 288 badPlatforms = [ "aarch64-darwin" ]; 289 }; 290} 291 292// optionalAttrs (targetPlatform != hostPlatform && targetPlatform.libc == "msvcrt" && crossStageStatic) { 293 makeFlags = [ "all-gcc" "all-target-libgcc" ]; 294 installTargets = "install-gcc install-target-libgcc"; 295} 296 297// optionalAttrs (enableMultilib) { dontMoveLib64 = true; } 298)