Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at netboot-syslinux-multiplatform 273 lines 10 kB view raw
1let 2 withGold = platform: platform.parsed.kernel.execFormat.name == "elf" && !platform.isRiscV && !platform.isLoongArch64; 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, zlib 19 20, enableGold ? withGold stdenv.targetPlatform 21, enableShared ? !stdenv.hostPlatform.isStatic 22 # WARN: Enabling all targets increases output size to a multiple. 23, withAllTargets ? false 24}: 25 26# WARN: configure silently disables ld.gold if it's unsupported, so we need to 27# make sure that intent matches result ourselves. 28assert enableGold -> withGold stdenv.targetPlatform; 29 30 31let 32 inherit (stdenv) buildPlatform hostPlatform targetPlatform; 33 34 version = "2.40"; 35 36 srcs = { 37 normal = fetchurl { 38 url = "mirror://gnu/binutils/binutils-${version}.tar.bz2"; 39 hash = "sha256-+CmOsVOks30RLpRapcsoUAQLzyaj6mW1pxXIOv4F5Io="; 40 }; 41 vc4-none = fetchFromGitHub { 42 owner = "itszor"; 43 repo = "binutils-vc4"; 44 rev = "708acc851880dbeda1dd18aca4fd0a95b2573b36"; 45 sha256 = "1kdrz6fki55lm15rwwamn74fnqpy0zlafsida2zymk76n3656c63"; 46 }; 47 }; 48 49 #INFO: The targetPrefix prepended to binary names to allow multiple binuntils 50 # on the PATH to both be usable. 51 targetPrefix = lib.optionalString (targetPlatform != hostPlatform) "${targetPlatform.config}-"; 52in 53 54stdenv.mkDerivation (finalAttrs: { 55 pname = targetPrefix + "binutils"; 56 inherit version; 57 58 # HACK: Ensure that we preserve source from bootstrap binutils to not rebuild LLVM 59 src = stdenv.__bootPackages.binutils-unwrapped.src 60 or srcs.${targetPlatform.system} 61 or srcs.normal; 62 63 # WARN: this package is used for bootstrapping fetchurl, and thus cannot use 64 # fetchpatch! All mutable patches (generated by GitHub or cgit) that are 65 # needed here should be included directly in Nixpkgs as files. 66 patches = [ 67 # Make binutils output deterministic by default. 68 ./deterministic.patch 69 70 71 # Breaks nm BSD flag detection, heeds an upstream fix: 72 # https://sourceware.org/PR29547 73 ./0001-Revert-libtool.m4-fix-the-NM-nm-over-here-B-option-w.patch 74 ./0001-Revert-libtool.m4-fix-nm-BSD-flag-detection.patch 75 76 # Required for newer macos versions 77 ./0001-libtool.m4-update-macos-version-detection-block.patch 78 79 # For some reason bfd ld doesn't search DT_RPATH when cross-compiling. It's 80 # not clear why this behavior was decided upon but it has the unfortunate 81 # consequence that the linker will fail to find transitive dependencies of 82 # shared objects when cross-compiling. Consequently, we are forced to 83 # override this behavior, forcing ld to search DT_RPATH even when 84 # cross-compiling. 85 ./always-search-rpath.patch 86 87 # Avoid `lib -> out -> lib` reference. Normally `bfd-plugins` does 88 # not need to know binutils' BINDIR at all. It's an absolute path 89 # where libraries are stored. 90 ./plugins-no-BINDIR.patch 91 ] 92 ++ lib.optional targetPlatform.isiOS ./support-ios.patch 93 # Adds AVR-specific options to "size" for compatibility with Atmel's downstream distribution 94 # Patch from arch-community 95 # https://github.com/archlinux/svntogit-community/blob/c8d53dd1734df7ab15931f7fad0c9acb8386904c/trunk/avr-size.patch 96 ++ lib.optional targetPlatform.isAvr ./avr-size.patch 97 ++ lib.optional stdenv.targetPlatform.isWindows ./windres-locate-gcc.patch 98 ++ lib.optional stdenv.targetPlatform.isMips64n64 99 # this patch is from debian: 100 # https://sources.debian.org/data/main/b/binutils/2.38-3/debian/patches/mips64-default-n64.diff 101 (if stdenv.targetPlatform.isMusl 102 then substitute { src = ./mips64-default-n64.patch; replacements = [ "--replace" "gnuabi64" "muslabi64" ]; } 103 else ./mips64-default-n64.patch) 104 # This patch fixes a bug in 2.40 on MinGW, which breaks DXVK when cross-building from Darwin. 105 # See https://sourceware.org/bugzilla/show_bug.cgi?id=30079 106 ++ lib.optional stdenv.targetPlatform.isMinGW ./mingw-abort-fix.patch 107 ; 108 109 outputs = [ "out" "info" "man" "dev" ] 110 # Ideally we would like to always install 'lib' into a separate 111 # target. Unfortunately cross-compiled binutils installs libraries 112 # across both `$lib/lib/` and `$out/$target/lib` with a reference 113 # from $out to $lib. Probably a binutils bug: all libraries should go 114 # to $lib as binutils does not build target libraries. Let's make our 115 # life slightly simpler by installing everything into $out for 116 # cross-binutils. 117 ++ lib.optionals (targetPlatform == hostPlatform) [ "lib" ]; 118 119 strictDeps = true; 120 depsBuildBuild = [ buildPackages.stdenv.cc ]; 121 # texinfo was removed here in https://github.com/NixOS/nixpkgs/pull/210132 122 # to reduce rebuilds during stdenv bootstrap. Please don't add it back without 123 # checking the impact there first. 124 nativeBuildInputs = [ 125 bison 126 perl 127 ] 128 ++ lib.optionals targetPlatform.isiOS [ autoreconfHook ] 129 ++ lib.optionals buildPlatform.isDarwin [ autoconf269 automake gettext libtool ] 130 ++ lib.optionals targetPlatform.isVc4 [ flex ] 131 ; 132 133 buildInputs = [ zlib gettext ]; 134 135 inherit noSysDirs; 136 137 preConfigure = (lib.optionalString buildPlatform.isDarwin '' 138 for i in */configure.ac; do 139 pushd "$(dirname "$i")" 140 echo "Running autoreconf in $PWD" 141 # autoreconf doesn't work, don't know why 142 # autoreconf ''${autoreconfFlags:---install --force --verbose} 143 autoconf 144 popd 145 done 146 '') + '' 147 # Clear the default library search path. 148 if test "$noSysDirs" = "1"; then 149 echo 'NATIVE_LIB_DIRS=' >> ld/configure.tgt 150 fi 151 152 # Use symlinks instead of hard links to save space ("strip" in the 153 # fixup phase strips each hard link separately). 154 for i in binutils/Makefile.in gas/Makefile.in ld/Makefile.in gold/Makefile.in; do 155 sed -i "$i" -e 's|ln |ln -s |' 156 done 157 158 # autoreconfHook is not included for all targets. 159 # Call it here explicitly as well. 160 ${finalAttrs.postAutoreconf} 161 ''; 162 163 postAutoreconf = '' 164 # As we regenerated configure build system tries hard to use 165 # texinfo to regenerate manuals. Let's avoid the dependency 166 # on texinfo in bootstrap path and keep manuals unmodified. 167 touch gas/doc/.dirstamp 168 touch gas/doc/asconfig.texi 169 touch gas/doc/as.1 170 touch gas/doc/as.info 171 ''; 172 173 # As binutils takes part in the stdenv building, we don't want references 174 # to the bootstrap-tools libgcc (as uses to happen on arm/mips) 175 env.NIX_CFLAGS_COMPILE = 176 if hostPlatform.isDarwin 177 then "-Wno-string-plus-int -Wno-deprecated-declarations" 178 else "-static-libgcc"; 179 180 hardeningDisable = [ "format" "pie" ]; 181 182 configurePlatforms = [ "build" "host" "target" ]; 183 184 configureFlags = [ 185 "--enable-64-bit-bfd" 186 "--with-system-zlib" 187 188 "--enable-deterministic-archives" 189 "--disable-werror" 190 "--enable-fix-loongson2f-nop" 191 192 # Turn on --enable-new-dtags by default to make the linker set 193 # RUNPATH instead of RPATH on binaries. This is important because 194 # RUNPATH can be overridden using LD_LIBRARY_PATH at runtime. 195 "--enable-new-dtags" 196 197 # force target prefix. Some versions of binutils will make it empty if 198 # `--host` and `--target` are too close, even if Nixpkgs thinks the 199 # platforms are different (e.g. because not all the info makes the 200 # `config`). Other versions of binutils will always prefix if `--target` is 201 # passed, even if `--host` and `--target` are the same. The easiest thing 202 # for us to do is not leave it to chance, and force the program prefix to be 203 # what we want it to be. 204 "--program-prefix=${targetPrefix}" 205 206 # Unconditionally disable: 207 # - musl target needs porting: https://sourceware.org/PR29477 208 "--disable-gprofng" 209 210 # By default binutils searches $libdir for libraries. This brings in 211 # libbfd and libopcodes into a default visibility. Drop default lib 212 # path to force users to declare their use of these libraries. 213 "--with-lib-path=:" 214 ] 215 ++ lib.optionals withAllTargets [ "--enable-targets=all" ] 216 ++ lib.optionals enableGold [ "--enable-gold" "--enable-plugins" ] 217 ++ (if enableShared 218 then [ "--enable-shared" "--disable-static" ] 219 else [ "--disable-shared" "--enable-static" ]) 220 ; 221 222 # Fails 223 doCheck = false; 224 225 # Break dependency on pkgsBuildBuild.gcc when building a cross-binutils 226 stripDebugList = if stdenv.hostPlatform != stdenv.targetPlatform then "bin lib ${stdenv.hostPlatform.config}" else null; 227 228 # INFO: Otherwise it fails with: 229 # `./sanity.sh: line 36: $out/bin/size: not found` 230 doInstallCheck = (buildPlatform == hostPlatform) && (hostPlatform == targetPlatform); 231 232 enableParallelBuilding = true; 233 234 # For the same reason we don't split "lib" output we undo the $target/ 235 # prefix for installed headers and libraries we link: 236 # $out/$host/$target/lib/* to $out/lib/ 237 # $out/$host/$target/include/* to $dev/include/* 238 # TODO(trofi): fix installation paths upstream so we could remove this 239 # code and have "lib" output unconditionally. 240 postInstall = lib.optionalString (hostPlatform.config != targetPlatform.config) '' 241 ln -s $out/${hostPlatform.config}/${targetPlatform.config}/lib/* $out/lib/ 242 ln -s $out/${hostPlatform.config}/${targetPlatform.config}/include/* $dev/include/ 243 ''; 244 245 passthru = { 246 inherit targetPrefix; 247 hasGold = enableGold; 248 isGNU = true; 249 # Having --enable-plugins is not enough, system has to support 250 # dlopen() or equivalent. See config/plugins.m4 and configure.ac 251 # (around PLUGINS) for cases that support or not support plugins. 252 # No platform specific filters yet here. 253 hasPluginAPI = enableGold; 254 }; 255 256 meta = with lib; { 257 description = "Tools for manipulating binaries (linker, assembler, etc.)"; 258 longDescription = '' 259 The GNU Binutils are a collection of binary tools. The main 260 ones are `ld' (the GNU linker) and `as' (the GNU assembler). 261 They also include the BFD (Binary File Descriptor) library, 262 `gprof', `nm', `strip', etc. 263 ''; 264 homepage = "https://www.gnu.org/software/binutils/"; 265 license = licenses.gpl3Plus; 266 maintainers = with maintainers; [ ericson2314 lovesegfault ]; 267 platforms = platforms.unix; 268 269 # INFO: Give binutils a lower priority than gcc-wrapper to prevent a 270 # collision due to the ld/as wrappers/symlinks in the latter. 271 priority = 10; 272 }; 273})