Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at netboot-syslinux-multiplatform 162 lines 5.5 kB view raw
1{ lib, stdenv, targetPackages 2 3# Build time 4, fetchurl, fetchpatch, pkg-config, perl, texinfo, setupDebugInfoDirs, buildPackages 5 6# Run time 7, ncurses, readline, gmp, mpfr, expat, libipt, zlib, zstd, dejagnu, sourceHighlight 8 9, pythonSupport ? stdenv.hostPlatform == stdenv.buildPlatform && !stdenv.hostPlatform.isCygwin, python3 ? null 10, enableDebuginfod ? lib.meta.availableOn stdenv.hostPlatform elfutils, elfutils 11, guile ? null 12, hostCpuOnly ? false 13, safePaths ? [ 14 # $debugdir:$datadir/auto-load are whitelisted by default by GDB 15 "$debugdir" "$datadir/auto-load" 16 # targetPackages so we get the right libc when cross-compiling and using buildPackages.gdb 17 targetPackages.stdenv.cc.cc.lib 18 ] 19, writeScript 20}: 21 22let 23 basename = "gdb"; 24 targetPrefix = lib.optionalString (stdenv.targetPlatform != stdenv.hostPlatform) 25 "${stdenv.targetPlatform.config}-"; 26in 27 28assert pythonSupport -> python3 != null; 29 30stdenv.mkDerivation rec { 31 pname = targetPrefix + basename + lib.optionalString hostCpuOnly "-host-cpu-only"; 32 version = "13.1"; 33 34 src = fetchurl { 35 url = "mirror://gnu/gdb/${basename}-${version}.tar.xz"; 36 hash = "sha256-EVrVwY1ppr4qsViC02XdoqIhHBT0gLNQLG66V24ulaA="; 37 }; 38 39 postPatch = lib.optionalString stdenv.isDarwin '' 40 substituteInPlace gdb/darwin-nat.c \ 41 --replace '#include "bfd/mach-o.h"' '#include "mach-o.h"' 42 '' + lib.optionalString stdenv.hostPlatform.isMusl '' 43 substituteInPlace sim/erc32/erc32.c --replace sys/fcntl.h fcntl.h 44 substituteInPlace sim/erc32/interf.c --replace sys/fcntl.h fcntl.h 45 substituteInPlace sim/erc32/sis.c --replace sys/fcntl.h fcntl.h 46 substituteInPlace sim/ppc/emul_unix.c --replace sys/termios.h termios.h 47 ''; 48 49 patches = [ 50 ./debug-info-from-env.patch 51 52 # Backport musl fix 53 (fetchpatch { 54 url = "https://sourceware.org/git/?p=binutils-gdb.git;a=patch;h=2e977d9901393ea1bacbe1896af0929e968bc811"; 55 hash = "sha256-/+UYjiOxrszJy1x8xavs63/ptNZ+ISIAQhG+i86VDpA="; 56 }) 57 ] ++ lib.optionals stdenv.isDarwin [ 58 ./darwin-target-match.patch 59 ]; 60 61 nativeBuildInputs = [ pkg-config texinfo perl setupDebugInfoDirs ]; 62 63 buildInputs = [ ncurses readline gmp mpfr expat libipt zlib zstd guile sourceHighlight ] 64 ++ lib.optional pythonSupport python3 65 ++ lib.optional doCheck dejagnu 66 ++ lib.optional enableDebuginfod (elfutils.override { enableDebuginfod = true; }); 67 68 propagatedNativeBuildInputs = [ setupDebugInfoDirs ]; 69 70 depsBuildBuild = [ buildPackages.stdenv.cc ]; 71 72 enableParallelBuilding = true; 73 74 # darwin build fails with format hardening since v7.12 75 hardeningDisable = lib.optionals stdenv.isDarwin [ "format" ]; 76 77 env.NIX_CFLAGS_COMPILE = "-Wno-format-nonliteral"; 78 79 configurePlatforms = [ "build" "host" "target" ]; 80 81 preConfigure = '' 82 # remove precompiled docs, required for man gdbinit to mention /etc/gdb/gdbinit 83 rm gdb/doc/*.info* 84 rm gdb/doc/*.5 85 rm gdb/doc/*.1 86 # fix doc build https://sourceware.org/bugzilla/show_bug.cgi?id=27808 87 rm gdb/doc/GDBvn.texi 88 89 # GDB have to be built out of tree. 90 mkdir _build 91 cd _build 92 ''; 93 configureScript = "../configure"; 94 95 configureFlags = with lib; [ 96 # Set the program prefix to the current targetPrefix. 97 # This ensures that the prefix always conforms to 98 # nixpkgs' expectations instead of relying on the build 99 # system which only receives `config` which is merely a 100 # subset of the platform description. 101 "--program-prefix=${targetPrefix}" 102 103 "--disable-werror" 104 ] ++ lib.optional (!hostCpuOnly) "--enable-targets=all" ++ [ 105 "--enable-64-bit-bfd" 106 "--disable-install-libbfd" 107 "--disable-shared" "--enable-static" 108 "--with-system-zlib" 109 "--with-system-readline" 110 111 "--with-system-gdbinit=/etc/gdb/gdbinit" 112 "--with-system-gdbinit-dir=/etc/gdb/gdbinit.d" 113 114 "--with-gmp=${gmp.dev}" 115 "--with-mpfr=${mpfr.dev}" 116 "--with-expat" "--with-libexpat-prefix=${expat.dev}" 117 "--with-auto-load-safe-path=${builtins.concatStringsSep ":" safePaths}" 118 ] ++ lib.optional (!pythonSupport) "--without-python" 119 ++ lib.optional stdenv.hostPlatform.isMusl "--disable-nls" 120 ++ lib.optional stdenv.hostPlatform.isStatic "--disable-inprocess-agent" 121 ++ lib.optional enableDebuginfod "--with-debuginfod=yes"; 122 123 postInstall = 124 '' # Remove Info files already provided by Binutils and other packages. 125 rm -v $out/share/info/bfd.info 126 ''; 127 128 # TODO: Investigate & fix the test failures. 129 doCheck = false; 130 131 passthru = { 132 updateScript = writeScript "update-gdb" '' 133 #!/usr/bin/env nix-shell 134 #!nix-shell -i bash -p curl pcre common-updater-scripts 135 136 set -eu -o pipefail 137 138 # Expect the text in format of '<h3>GDB version 12.1</h3>' 139 new_version="$(curl -s https://www.sourceware.org/gdb/ | 140 pcregrep -o1 '<h3>GDB version ([0-9.]+)</h3>')" 141 update-source-version ${pname} "$new_version" 142 ''; 143 }; 144 145 meta = with lib; { 146 description = "The GNU Project debugger"; 147 148 longDescription = '' 149 GDB, the GNU Project debugger, allows you to see what is going 150 on `inside' another program while it executes -- or what another 151 program was doing at the moment it crashed. 152 ''; 153 154 homepage = "https://www.gnu.org/software/gdb/"; 155 156 license = lib.licenses.gpl3Plus; 157 158 # GDB upstream does not support ARM darwin 159 platforms = with platforms; linux ++ cygwin ++ ["x86_64-darwin"]; 160 maintainers = with maintainers; [ pierron globin lsix ]; 161 }; 162}