Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at flake-libs 226 lines 6.1 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.2"; 57 58 src = fetchurl { 59 url = "mirror://gnu/gdb/${basename}-${version}.tar.xz"; 60 hash = "sha256-QALLfyP0XDfHkFNqE6cglCzkvgQC2SnJCF6S8Q1IARk="; 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 [ 77 ./debug-info-from-env.patch 78 ] 79 ++ lib.optionals stdenv.hostPlatform.isDarwin [ 80 ./darwin-target-match.patch 81 ]; 82 83 nativeBuildInputs = [ 84 pkg-config 85 texinfo 86 perl 87 setupDebugInfoDirs 88 ]; 89 90 buildInputs = 91 [ 92 ncurses 93 readline 94 gmp 95 mpfr 96 expat 97 libipt 98 zlib 99 zstd 100 xz 101 guile 102 sourceHighlight 103 ] 104 ++ lib.optional pythonSupport python3 105 ++ lib.optional doCheck dejagnu 106 ++ lib.optional enableDebuginfod (elfutils.override { enableDebuginfod = true; }) 107 ++ lib.optional stdenv.hostPlatform.isDarwin libiconv; 108 109 propagatedNativeBuildInputs = [ setupDebugInfoDirs ]; 110 111 depsBuildBuild = [ buildPackages.stdenv.cc ]; 112 113 enableParallelBuilding = true; 114 115 # darwin build fails with format hardening since v7.12 116 hardeningDisable = lib.optionals stdenv.hostPlatform.isDarwin [ "format" ]; 117 118 env.NIX_CFLAGS_COMPILE = "-Wno-format-nonliteral"; 119 120 # Workaround for Apple Silicon, configurePlatforms must be disabled 121 configurePlatforms = 122 lib.optionals (!(stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isAarch64)) 123 [ 124 "build" 125 "host" 126 "target" 127 ]; 128 129 preConfigure = '' 130 # remove precompiled docs, required for man gdbinit to mention /etc/gdb/gdbinit 131 rm gdb/doc/*.info* 132 rm gdb/doc/*.5 133 rm gdb/doc/*.1 134 # fix doc build https://sourceware.org/bugzilla/show_bug.cgi?id=27808 135 rm gdb/doc/GDBvn.texi 136 137 # GDB have to be built out of tree. 138 mkdir _build 139 cd _build 140 ''; 141 configureScript = "../configure"; 142 143 configureFlags = 144 [ 145 # Set the program prefix to the current targetPrefix. 146 # This ensures that the prefix always conforms to 147 # nixpkgs' expectations instead of relying on the build 148 # system which only receives `config` which is merely a 149 # subset of the platform description. 150 "--program-prefix=${targetPrefix}" 151 152 "--disable-werror" 153 ] 154 ++ lib.optional (!hostCpuOnly) "--enable-targets=all" 155 ++ [ 156 "--enable-64-bit-bfd" 157 "--disable-install-libbfd" 158 "--disable-shared" 159 "--enable-static" 160 "--with-system-zlib" 161 "--with-system-readline" 162 163 "--with-system-gdbinit=/etc/gdb/gdbinit" 164 "--with-system-gdbinit-dir=/etc/gdb/gdbinit.d" 165 166 "--with-gmp=${gmp.dev}" 167 "--with-mpfr=${mpfr.dev}" 168 "--with-expat" 169 "--with-libexpat-prefix=${expat.dev}" 170 "--with-auto-load-safe-path=${builtins.concatStringsSep ":" safePaths}" 171 ] 172 ++ lib.optional (!pythonSupport) "--without-python" 173 ++ lib.optional stdenv.hostPlatform.isMusl "--disable-nls" 174 ++ lib.optional stdenv.hostPlatform.isStatic "--disable-inprocess-agent" 175 ++ lib.optional enableDebuginfod "--with-debuginfod=yes" 176 ++ lib.optional (!enableSim) "--disable-sim" 177 # Workaround for Apple Silicon, "--target" must be "faked", see eg: https://github.com/Homebrew/homebrew-core/pull/209753 178 ++ lib.optional ( 179 stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isAarch64 180 ) "--target=x86_64-apple-darwin"; 181 182 postInstall = '' 183 # Remove Info files already provided by Binutils and other packages. 184 rm -v $out/share/info/bfd.info 185 ''; 186 187 # TODO: Investigate & fix the test failures. 188 doCheck = false; 189 190 passthru = { 191 updateScript = writeScript "update-gdb" '' 192 #!/usr/bin/env nix-shell 193 #!nix-shell -i bash -p curl pcre common-updater-scripts 194 195 set -eu -o pipefail 196 197 # Expect the text in format of '<h3>GDB version 12.1</h3>' 198 new_version="$(curl -s https://www.sourceware.org/gdb/ | 199 pcregrep -o1 '<h3>GDB version ([0-9.]+)</h3>')" 200 update-source-version ${pname} "$new_version" 201 ''; 202 }; 203 204 meta = { 205 mainProgram = "gdb"; 206 207 description = "GNU Project debugger"; 208 209 longDescription = '' 210 GDB, the GNU Project debugger, allows you to see what is going 211 on `inside' another program while it executes -- or what another 212 program was doing at the moment it crashed. 213 ''; 214 215 homepage = "https://www.gnu.org/software/gdb/"; 216 217 license = lib.licenses.gpl3Plus; 218 219 platforms = with lib.platforms; linux ++ cygwin ++ freebsd ++ darwin; 220 maintainers = with lib.maintainers; [ 221 pierron 222 globin 223 lsix 224 ]; 225 }; 226}