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