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