1{ lib, stdenv, fetchurl, fetchpatch, pkg-config, musl-fts
2, musl-obstack, m4, zlib, zstd, bzip2, bison, flex, gettext, xz, setupDebugInfoDirs
3, argp-standalone
4, enableDebuginfod ? true, sqlite, curl, libmicrohttpd, libarchive
5, gitUpdater
6}:
7
8# TODO: Look at the hardcoded paths to kernel, modules etc.
9stdenv.mkDerivation rec {
10 pname = "elfutils";
11 version = "0.190";
12
13 src = fetchurl {
14 url = "https://sourceware.org/elfutils/ftp/${version}/${pname}-${version}.tar.bz2";
15 hash = "sha256-jgCjqbXwS8HcJzroYoHS0m7UEgILOR/8wjGY8QIx1pI=";
16 };
17
18 patches = [
19 ./debug-info-from-env.patch
20 (fetchpatch {
21 name = "fix-aarch64_fregs.patch";
22 url = "https://git.alpinelinux.org/aports/plain/main/elfutils/fix-aarch64_fregs.patch?id=2e3d4976eeffb4704cf83e2cc3306293b7c7b2e9";
23 sha256 = "zvncoRkQx3AwPx52ehjA2vcFroF+yDC2MQR5uS6DATs=";
24 })
25 (fetchpatch {
26 name = "musl-asm-ptrace-h.patch";
27 url = "https://git.alpinelinux.org/aports/plain/main/elfutils/musl-asm-ptrace-h.patch?id=2e3d4976eeffb4704cf83e2cc3306293b7c7b2e9";
28 sha256 = "8D1wPcdgAkE/TNBOgsHaeTZYhd9l+9TrZg8d5C7kG6k=";
29 })
30 (fetchpatch {
31 name = "musl-macros.patch";
32 url = "https://git.alpinelinux.org/aports/plain/main/elfutils/musl-macros.patch?id=2e3d4976eeffb4704cf83e2cc3306293b7c7b2e9";
33 sha256 = "tp6O1TRsTAMsFe8vw3LMENT/vAu6OmyA8+pzgThHeA8=";
34 })
35 (fetchpatch {
36 name = "musl-strndupa.patch";
37 url = "https://git.alpinelinux.org/aports/plain/main/elfutils/musl-strndupa.patch?id=2e3d4976eeffb4704cf83e2cc3306293b7c7b2e9";
38 sha256 = "sha256-7daehJj1t0wPtQzTv+/Rpuqqs5Ng/EYnZzrcf2o/Lb0=";
39 })
40 ] ++ lib.optionals stdenv.hostPlatform.isMusl [ ./musl-error_h.patch ];
41
42 postPatch = ''
43 patchShebangs tests/*.sh
44 '' + lib.optionalString stdenv.hostPlatform.isRiscV ''
45 # disable failing test:
46 #
47 # > dwfl_thread_getframes: No DWARF information found
48 sed -i s/run-backtrace-dwarf.sh//g tests/Makefile.in
49 '';
50
51 outputs = [ "bin" "dev" "out" "man" ];
52
53 # We need bzip2 in NativeInputs because otherwise we can't unpack the src,
54 # as the host-bzip2 will be in the path.
55 nativeBuildInputs = [ m4 bison flex gettext bzip2 ]
56 ++ lib.optional enableDebuginfod pkg-config;
57 buildInputs = [ zlib zstd bzip2 xz ]
58 ++ lib.optionals stdenv.hostPlatform.isMusl [
59 argp-standalone
60 musl-fts
61 musl-obstack
62 ] ++ lib.optionals enableDebuginfod [
63 sqlite
64 curl
65 libmicrohttpd
66 libarchive
67 ];
68
69 propagatedNativeBuildInputs = [ setupDebugInfoDirs ];
70
71 configureFlags = [
72 "--program-prefix=eu-" # prevent collisions with binutils
73 "--enable-deterministic-archives"
74 (lib.enableFeature enableDebuginfod "libdebuginfod")
75 (lib.enableFeature enableDebuginfod "debuginfod")
76 ];
77
78 enableParallelBuilding = true;
79
80 # Backtrace unwinding tests rely on glibc-internal symbol names.
81 # Musl provides slightly different forms and fails.
82 # Let's disable tests there until musl support is fully upstreamed.
83 doCheck = !stdenv.hostPlatform.isMusl;
84 doInstallCheck = !stdenv.hostPlatform.isMusl;
85
86 passthru.updateScript = gitUpdater {
87 url = "https://sourceware.org/git/elfutils.git";
88 rev-prefix = "elfutils-";
89 };
90
91 meta = with lib; {
92 homepage = "https://sourceware.org/elfutils/";
93 description = "A set of utilities to handle ELF objects";
94 platforms = platforms.linux;
95 # https://lists.fedorahosted.org/pipermail/elfutils-devel/2014-November/004223.html
96 broken = stdenv.hostPlatform.isStatic;
97 # licenses are GPL2 or LGPL3+ for libraries, GPL3+ for bins,
98 # but since this package isn't split that way, all three are listed.
99 license = with licenses; [ gpl2Only lgpl3Plus gpl3Plus ];
100 maintainers = with maintainers; [ eelco r-burns ];
101 };
102}