Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at netboot-syslinux-multiplatform 232 lines 8.1 kB view raw
1let 2 execFormatIsELF = platform: platform.parsed.kernel.execFormat.name == "elf"; 3in 4 5{ stdenv 6, autoreconfHook 7, autoconf269, automake, libtool 8, bison 9, buildPackages 10, fetchFromGitHub 11, fetchurl 12, flex 13, gettext 14, lib 15, noSysDirs 16, perl 17, substitute 18, texinfo 19, zlib 20 21, enableGold ? execFormatIsELF stdenv.targetPlatform 22, enableShared ? !stdenv.hostPlatform.isStatic 23 # WARN: Enabling all targets increases output size to a multiple. 24, withAllTargets ? false 25}: 26 27# WARN: configure silently disables ld.gold if it's unsupported, so we need to 28# make sure that intent matches result ourselves. 29assert enableGold -> execFormatIsELF stdenv.targetPlatform; 30 31 32let 33 inherit (stdenv) buildPlatform hostPlatform targetPlatform; 34 35 version = "2.38"; 36 37 srcs = { 38 normal = fetchurl { 39 url = "mirror://gnu/binutils/binutils-${version}.tar.bz2"; 40 sha256 = "sha256-Bw7HHPB3pqWOC5WfBaCaNQFTeMLYpR6Q866r/jBZDvg="; 41 }; 42 vc4-none = fetchFromGitHub { 43 owner = "itszor"; 44 repo = "binutils-vc4"; 45 rev = "708acc851880dbeda1dd18aca4fd0a95b2573b36"; 46 sha256 = "1kdrz6fki55lm15rwwamn74fnqpy0zlafsida2zymk76n3656c63"; 47 }; 48 }; 49 50 #INFO: The targetPrefix prepended to binary names to allow multiple binuntils 51 # on the PATH to both be usable. 52 targetPrefix = lib.optionalString (targetPlatform != hostPlatform) "${targetPlatform.config}-"; 53in 54 55stdenv.mkDerivation { 56 pname = targetPrefix + "binutils"; 57 inherit version; 58 59 # HACK: Ensure that we preserve source from bootstrap binutils to not rebuild LLVM 60 src = stdenv.__bootPackages.binutils-unwrapped_2_38.src 61 or srcs.${targetPlatform.system} 62 or srcs.normal; 63 64 # WARN: this package is used for bootstrapping fetchurl, and thus cannot use 65 # fetchpatch! All mutable patches (generated by GitHub or cgit) that are 66 # needed here should be included directly in Nixpkgs as files. 67 patches = [ 68 # Make binutils output deterministic by default. 69 ./deterministic.patch 70 71 72 # Breaks nm BSD flag detection 73 ./0001-Revert-libtool.m4-fix-nm-BSD-flag-detection.patch 74 75 # Required for newer macos versions 76 ./0001-libtool.m4-update-macos-version-detection-block.patch 77 78 # For some reason bfd ld doesn't search DT_RPATH when cross-compiling. It's 79 # not clear why this behavior was decided upon but it has the unfortunate 80 # consequence that the linker will fail to find transitive dependencies of 81 # shared objects when cross-compiling. Consequently, we are forced to 82 # override this behavior, forcing ld to search DT_RPATH even when 83 # cross-compiling. 84 ./always-search-rpath.patch 85 86 # Fixed in 2.39 87 # https://sourceware.org/bugzilla/show_bug.cgi?id=28885 88 # https://sourceware.org/git/?p=binutils-gdb.git;a=patch;h=99852365513266afdd793289813e8e565186c9e6 89 # https://github.com/NixOS/nixpkgs/issues/170946 90 ./deterministic-temp-prefixes.patch 91 ] 92 ++ lib.optional targetPlatform.isiOS ./support-ios.patch 93 ++ lib.optional stdenv.targetPlatform.isWindows ./windres-locate-gcc.patch 94 ++ lib.optional stdenv.targetPlatform.isMips64n64 95 # this patch is from debian: 96 # https://sources.debian.org/data/main/b/binutils/2.38-3/debian/patches/mips64-default-n64.diff 97 (if stdenv.targetPlatform.isMusl 98 then substitute { src = ./mips64-default-n64.patch; replacements = [ "--replace" "gnuabi64" "muslabi64" ]; } 99 else ./mips64-default-n64.patch) 100 # On PowerPC, when generating assembly code, GCC generates a `.machine` 101 # custom instruction which instructs the assembler to generate code for this 102 # machine. However, some GCC versions generate the wrong one, or make it 103 # too strict, which leads to some confusing "unrecognized opcode: wrtee" 104 # or "unrecognized opcode: eieio" errors. 105 # 106 # To remove when binutils 2.39 is released. 107 # 108 # Upstream commit: 109 # https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=cebc89b9328eab994f6b0314c263f94e7949a553 110 ++ lib.optional stdenv.targetPlatform.isPower ./ppc-make-machine-less-strict.patch 111 ; 112 113 outputs = [ "out" "info" "man" ]; 114 115 strictDeps = true; 116 depsBuildBuild = [ buildPackages.stdenv.cc ]; 117 nativeBuildInputs = [ 118 bison 119 perl 120 texinfo 121 ] 122 ++ lib.optionals targetPlatform.isiOS [ autoreconfHook ] 123 ++ lib.optionals buildPlatform.isDarwin [ autoconf269 automake gettext libtool ] 124 ++ lib.optionals targetPlatform.isVc4 [ flex ] 125 ; 126 127 buildInputs = [ zlib gettext ]; 128 129 inherit noSysDirs; 130 131 preConfigure = (lib.optionalString buildPlatform.isDarwin '' 132 for i in */configure.ac; do 133 pushd "$(dirname "$i")" 134 echo "Running autoreconf in $PWD" 135 # autoreconf doesn't work, don't know why 136 # autoreconf ''${autoreconfFlags:---install --force --verbose} 137 autoconf 138 popd 139 done 140 '') + '' 141 # Clear the default library search path. 142 if test "$noSysDirs" = "1"; then 143 echo 'NATIVE_LIB_DIRS=' >> ld/configure.tgt 144 fi 145 146 # Use symlinks instead of hard links to save space ("strip" in the 147 # fixup phase strips each hard link separately). 148 for i in binutils/Makefile.in gas/Makefile.in ld/Makefile.in gold/Makefile.in; do 149 sed -i "$i" -e 's|ln |ln -s |' 150 done 151 ''; 152 153 # As binutils takes part in the stdenv building, we don't want references 154 # to the bootstrap-tools libgcc (as uses to happen on arm/mips) 155 env.NIX_CFLAGS_COMPILE = 156 if hostPlatform.isDarwin 157 then "-Wno-string-plus-int -Wno-deprecated-declarations" 158 else "-static-libgcc"; 159 160 hardeningDisable = [ "format" "pie" ]; 161 162 configurePlatforms = [ "build" "host" "target" ]; 163 164 configureFlags = [ 165 "--enable-64-bit-bfd" 166 "--with-system-zlib" 167 168 "--enable-deterministic-archives" 169 "--disable-werror" 170 "--enable-fix-loongson2f-nop" 171 172 # Turn on --enable-new-dtags by default to make the linker set 173 # RUNPATH instead of RPATH on binaries. This is important because 174 # RUNPATH can be overridden using LD_LIBRARY_PATH at runtime. 175 "--enable-new-dtags" 176 177 # force target prefix. Some versions of binutils will make it empty if 178 # `--host` and `--target` are too close, even if Nixpkgs thinks the 179 # platforms are different (e.g. because not all the info makes the 180 # `config`). Other versions of binutils will always prefix if `--target` is 181 # passed, even if `--host` and `--target` are the same. The easiest thing 182 # for us to do is not leave it to chance, and force the program prefix to be 183 # what we want it to be. 184 "--program-prefix=${targetPrefix}" 185 ] 186 ++ lib.optionals withAllTargets [ "--enable-targets=all" ] 187 ++ lib.optionals enableGold [ "--enable-gold" "--enable-plugins" ] 188 ++ (if enableShared 189 then [ "--enable-shared" "--disable-static" ] 190 else [ "--disable-shared" "--enable-static" ]) 191 ; 192 193 # Fails 194 doCheck = false; 195 196 # Remove on next bump. It's a vestige of past conditional. Stays here to avoid 197 # mass rebuild. 198 postFixup = ""; 199 200 # Break dependency on pkgsBuildBuild.gcc when building a cross-binutils 201 stripDebugList = if stdenv.hostPlatform != stdenv.targetPlatform then "bin lib ${stdenv.hostPlatform.config}" else null; 202 203 # INFO: Otherwise it fails with: 204 # `./sanity.sh: line 36: $out/bin/size: not found` 205 doInstallCheck = (buildPlatform == hostPlatform) && (hostPlatform == targetPlatform); 206 207 enableParallelBuilding = true; 208 209 passthru = { 210 inherit targetPrefix; 211 hasGold = enableGold; 212 isGNU = true; 213 }; 214 215 meta = with lib; { 216 description = "Tools for manipulating binaries (linker, assembler, etc.)"; 217 longDescription = '' 218 The GNU Binutils are a collection of binary tools. The main 219 ones are `ld' (the GNU linker) and `as' (the GNU assembler). 220 They also include the BFD (Binary File Descriptor) library, 221 `gprof', `nm', `strip', etc. 222 ''; 223 homepage = "https://www.gnu.org/software/binutils/"; 224 license = licenses.gpl3Plus; 225 maintainers = with maintainers; [ ericson2314 lovesegfault ]; 226 platforms = platforms.unix; 227 228 # INFO: Give binutils a lower priority than gcc-wrapper to prevent a 229 # collision due to the ld/as wrappers/symlinks in the latter. 230 priority = 10; 231 }; 232}