nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at netboot-syslinux-multiplatform 309 lines 11 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 = "7"; 45 version = "${majorVersion}.5.0"; 46 47 inherit (stdenv) buildPlatform hostPlatform targetPlatform; 48 49 patches = 50 [ # https://gcc.gnu.org/ml/gcc-patches/2018-02/msg00633.html 51 ./riscv-pthread-reentrant.patch 52 # https://gcc.gnu.org/ml/gcc-patches/2018-03/msg00297.html 53 ./riscv-no-relax.patch 54 # Fix for asan w/glibc-2.34. Although there's no upstream backport to v7, 55 # the patch from gcc 8 seems to work perfectly fine. 56 ./gcc8-asan-glibc-2.34.patch 57 58 ./0001-Fix-build-for-glibc-2.31.patch 59 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 67 ../9/fix-struct-redefinition-on-glibc-2.36.patch 68 ../install-info-files-serially.patch 69 ] 70 ++ optional (targetPlatform != hostPlatform) ../libstdc++-target.patch 71 ++ optionals targetPlatform.isNetBSD [ 72 ../libstdc++-netbsd-ctypes.patch 73 ] 74 ++ optional noSysDirs ../no-sys-dirs.patch 75 ++ optional (hostPlatform != buildPlatform) (fetchpatch { # XXX: Refine when this should be applied 76 url = "https://git.busybox.net/buildroot/plain/package/gcc/7.1.0/0900-remove-selftests.patch?id=11271540bfe6adafbc133caf6b5b902a816f5f02"; 77 sha256 = "0mrvxsdwip2p3l17dscpc1x8vhdsciqw1z5q9i6p5g9yg1cqnmgs"; 78 }) 79 ++ optional langFortran ../gfortran-driving.patch 80 ++ optional (targetPlatform.libc == "musl" && targetPlatform.isPower) ../ppc-musl.patch 81 ++ optional (targetPlatform.libc == "musl" && targetPlatform.isx86_32) (fetchpatch { 82 url = "https://git.alpinelinux.org/aports/plain/main/gcc/gcc-6.1-musl-libssp.patch?id=5e4b96e23871ee28ef593b439f8c07ca7c7eb5bb"; 83 sha256 = "1jf1ciz4gr49lwyh8knfhw6l5gvfkwzjy90m7qiwkcbsf4a3fqn2"; 84 }) 85 ++ optional (targetPlatform.libc == "musl") ../libgomp-dont-force-initial-exec.patch 86 87 # Obtain latest patch with ../update-mcfgthread-patches.sh 88 ++ optional (!crossStageStatic && targetPlatform.isMinGW && threadsCross.model == "mcf") ./Added-mcf-thread-model-support-from-mcfgthread.patch 89 90 ++ [ ../libsanitizer-no-cyclades-9.patch ]; 91 92 /* Cross-gcc settings (build == host != target) */ 93 crossMingw = targetPlatform != hostPlatform && targetPlatform.libc == "msvcrt"; 94 stageNameAddon = if crossStageStatic then "stage-static" else "stage-final"; 95 crossNameAddon = optionalString (targetPlatform != hostPlatform) "${targetPlatform.config}-${stageNameAddon}-"; 96 97 callFile = lib.callPackageWith { 98 # lets 99 inherit 100 majorVersion 101 version 102 buildPlatform 103 hostPlatform 104 targetPlatform 105 patches 106 crossMingw 107 stageNameAddon 108 crossNameAddon 109 ; 110 # inherit generated with 'nix eval --json --impure --expr "with import ./. {}; lib.attrNames (lib.functionArgs gcc7.cc.override)" | jq '.[]' --raw-output' 111 inherit 112 binutils 113 buildPackages 114 cloog 115 crossStageStatic 116 enableLTO 117 enableMultilib 118 enablePlugin 119 enableShared 120 fetchpatch 121 fetchurl 122 gettext 123 gmp 124 gnused 125 isl 126 langC 127 langCC 128 langFortran 129 langGo 130 langJit 131 langObjC 132 langObjCpp 133 lib 134 libcCross 135 libmpc 136 mpfr 137 name 138 noSysDirs 139 patchelf 140 perl 141 profiledCompiler 142 reproducibleBuild 143 staticCompiler 144 stdenv 145 targetPackages 146 texinfo 147 threadsCross 148 which 149 zip 150 zlib 151 ; 152 }; 153 154in 155 156stdenv.mkDerivation ({ 157 pname = "${crossNameAddon}${name}"; 158 inherit version; 159 160 builder = ../builder.sh; 161 162 src = fetchurl { 163 url = "mirror://gcc/releases/gcc-${version}/gcc-${version}.tar.xz"; 164 sha256 = "0qg6kqc5l72hpnj4vr6l0p69qav0rh4anlkk3y55540zy3klc6dq"; 165 }; 166 167 inherit patches; 168 169 outputs = [ "out" "man" "info" ] ++ lib.optional (!langJit) "lib"; 170 setOutputFlags = false; 171 NIX_NO_SELF_RPATH = true; 172 173 libc_dev = stdenv.cc.libc_dev; 174 175 hardeningDisable = [ "format" "pie" ]; 176 177 postPatch = '' 178 configureScripts=$(find . -name configure) 179 for configureScript in $configureScripts; do 180 patchShebangs $configureScript 181 done 182 '' 183 # This should kill all the stdinc frameworks that gcc and friends like to 184 # insert into default search paths. 185 + lib.optionalString hostPlatform.isDarwin '' 186 substituteInPlace gcc/config/darwin-c.c \ 187 --replace 'if (stdinc)' 'if (0)' 188 189 substituteInPlace libgcc/config/t-slibgcc-darwin \ 190 --replace "-install_name @shlib_slibdir@/\$(SHLIB_INSTALL_NAME)" "-install_name ''${!outputLib}/lib/\$(SHLIB_INSTALL_NAME)" 191 192 substituteInPlace libgfortran/configure \ 193 --replace "-install_name \\\$rpath/\\\$soname" "-install_name ''${!outputLib}/lib/\\\$soname" 194 '' 195 + ( 196 lib.optionalString (targetPlatform != hostPlatform || stdenv.cc.libc != null) 197 # On NixOS, use the right path to the dynamic linker instead of 198 # `/lib/ld*.so'. 199 (let 200 libc = if libcCross != null then libcCross else stdenv.cc.libc; 201 in 202 ( 203 '' echo "fixing the \`GLIBC_DYNAMIC_LINKER', \`UCLIBC_DYNAMIC_LINKER', and \`MUSL_DYNAMIC_LINKER' macros..." 204 for header in "gcc/config/"*-gnu.h "gcc/config/"*"/"*.h 205 do 206 grep -q _DYNAMIC_LINKER "$header" || continue 207 echo " fixing \`$header'..." 208 sed -i "$header" \ 209 -e 's|define[[:blank:]]*\([UCG]\+\)LIBC_DYNAMIC_LINKER\([0-9]*\)[[:blank:]]"\([^\"]\+\)"$|define \1LIBC_DYNAMIC_LINKER\2 "${libc.out}\3"|g' \ 210 -e 's|define[[:blank:]]*MUSL_DYNAMIC_LINKER\([0-9]*\)[[:blank:]]"\([^\"]\+\)"$|define MUSL_DYNAMIC_LINKER\1 "${libc.out}\2"|g' 211 done 212 '' 213 + lib.optionalString (targetPlatform.libc == "musl") 214 '' 215 sed -i gcc/config/linux.h -e '1i#undef LOCAL_INCLUDE_DIR' 216 '' 217 )) 218 ) 219 + lib.optionalString targetPlatform.isAvr '' 220 makeFlagsArray+=( 221 'LIMITS_H_TEST=false' 222 ) 223 ''; 224 225 inherit noSysDirs staticCompiler crossStageStatic 226 libcCross crossMingw; 227 228 inherit (callFile ../common/dependencies.nix { }) 229 depsBuildBuild nativeBuildInputs depsBuildTarget buildInputs depsTargetTarget; 230 231 env.NIX_CFLAGS_COMPILE = lib.optionalString (stdenv.cc.isClang && langFortran) "-Wno-unused-command-line-argument"; 232 NIX_LDFLAGS = lib.optionalString hostPlatform.isSunOS "-lm"; 233 234 preConfigure = callFile ../common/pre-configure.nix { }; 235 236 dontDisableStatic = true; 237 238 configurePlatforms = [ "build" "host" "target" ]; 239 240 configureFlags = (callFile ../common/configure-flags.nix { }) 241 ++ optional (targetPlatform.isAarch64) "--enable-fix-cortex-a53-843419" 242 ++ optional targetPlatform.isNetBSD "--disable-libcilkrts" 243 ; 244 245 targetConfig = if targetPlatform != hostPlatform then targetPlatform.config else null; 246 247 buildFlags = optional 248 (targetPlatform == hostPlatform && hostPlatform == buildPlatform) 249 (if profiledCompiler then "profiledbootstrap" else "bootstrap"); 250 251 inherit (callFile ../common/strip-attributes.nix { }) 252 stripDebugList 253 stripDebugListTarget 254 preFixup; 255 256 doCheck = false; # requires a lot of tools, causes a dependency cycle for stdenv 257 258 # https://gcc.gnu.org/install/specific.html#x86-64-x-solaris210 259 ${if hostPlatform.system == "x86_64-solaris" then "CC" else null} = "gcc -m64"; 260 261 # Setting $CPATH and $LIBRARY_PATH to make sure both `gcc' and `xgcc' find the 262 # library headers and binaries, regarless of the language being compiled. 263 # 264 # Likewise, the LTO code doesn't find zlib. 265 # 266 # Cross-compiling, we need gcc not to read ./specs in order to build the g++ 267 # compiler (after the specs for the cross-gcc are created). Having 268 # LIBRARY_PATH= makes gcc read the specs from ., and the build breaks. 269 270 CPATH = optionals (targetPlatform == hostPlatform) (makeSearchPathOutput "dev" "include" ([] 271 ++ optional (zlib != null) zlib 272 )); 273 274 LIBRARY_PATH = optionals (targetPlatform == hostPlatform) (makeLibraryPath (optional (zlib != null) zlib)); 275 276 inherit (callFile ../common/extra-target-flags.nix { }) 277 EXTRA_FLAGS_FOR_TARGET 278 EXTRA_LDFLAGS_FOR_TARGET 279 ; 280 281 passthru = { 282 inherit langC langCC langObjC langObjCpp langFortran langGo version; 283 isGNU = true; 284 hardeningUnsupportedFlags = [ "fortify3" ]; 285 }; 286 287 enableParallelBuilding = true; 288 inherit enableShared enableMultilib; 289 290 meta = { 291 inherit (callFile ../common/meta.nix { }) 292 homepage 293 license 294 description 295 longDescription 296 platforms 297 maintainers 298 ; 299 badPlatforms = [ "aarch64-darwin" ]; 300 }; 301} 302 303// optionalAttrs (targetPlatform != hostPlatform && targetPlatform.libc == "msvcrt" && crossStageStatic) { 304 makeFlags = [ "all-gcc" "all-target-libgcc" ]; 305 installTargets = "install-gcc install-target-libgcc"; 306} 307 308// optionalAttrs (enableMultilib) { dontMoveLib64 = true; } 309)