1{
2 stdenv,
3 lib,
4 fetchFromGitHub,
5 autoreconfHook,
6 buildPackages,
7 xz,
8 testers,
9}:
10
11stdenv.mkDerivation (finalAttrs: {
12 pname = "libunwind";
13 version = "1.8.2";
14
15 src = fetchFromGitHub {
16 owner = "libunwind";
17 repo = "libunwind";
18 rev = "v${finalAttrs.version}";
19 hash = "sha256-MsUReXFHlj15SgEZHOYhdSfAbSeVVl8LCi4NnUwvhpw=";
20 };
21
22 postPatch =
23 if (stdenv.cc.isClang || stdenv.hostPlatform.isStatic) then
24 ''
25 substituteInPlace configure.ac --replace "-lgcc_s" ""
26 ''
27 else
28 lib.optionalString stdenv.hostPlatform.isMusl ''
29 substituteInPlace configure.ac --replace "-lgcc_s" "-lgcc_eh"
30 '';
31
32 nativeBuildInputs = [ autoreconfHook ];
33
34 outputs = [
35 "out"
36 "dev"
37 "devman"
38 ];
39
40 configureFlags = [
41 # Starting from 1.8.1 libunwind installs testsuite by default.
42 # As we don't run the tests we disable it (this also fixes circular
43 # reference install failure).
44 "--disable-tests"
45 # Without latex2man, no man pages are installed despite being
46 # prebuilt in the source tarball.
47 "LATEX2MAN=${buildPackages.coreutils}/bin/true"
48 ]
49 # See https://github.com/libunwind/libunwind/issues/693
50 ++ lib.optionals (with stdenv.hostPlatform; isAarch64 && isMusl && !isStatic) [
51 "CFLAGS=-mno-outline-atomics"
52 ];
53
54 propagatedBuildInputs = [ xz ];
55
56 enableParallelBuilding = true;
57
58 postInstall = ''
59 find $out -name \*.la | while read file; do
60 sed -i 's,-llzma,${xz.out}/lib/liblzma.la,' $file
61 done
62 '';
63
64 doCheck = false; # fails
65
66 passthru.tests.pkg-config = testers.hasPkgConfigModules {
67 package = finalAttrs.finalPackage;
68 versionCheck = true;
69 };
70
71 meta = with lib; {
72 homepage = "https://www.nongnu.org/libunwind";
73 description = "Portable and efficient API to determine the call-chain of a program";
74 maintainers = with maintainers; [ orivej ];
75 pkgConfigModules = [
76 "libunwind"
77 "libunwind-coredump"
78 "libunwind-generic"
79 "libunwind-ptrace"
80 "libunwind-setjmp"
81 ];
82 # https://github.com/libunwind/libunwind#libunwind
83 platforms = [
84 "aarch64-linux"
85 "armv5tel-linux"
86 "armv6l-linux"
87 "armv7a-linux"
88 "armv7l-linux"
89 "i686-freebsd"
90 "i686-linux"
91 "loongarch64-linux"
92 "mips64el-linux"
93 "mipsel-linux"
94 "powerpc64-linux"
95 "powerpc64le-linux"
96 "riscv64-linux"
97 "s390x-linux"
98 "x86_64-freebsd"
99 "x86_64-linux"
100 "x86_64-solaris"
101 ];
102 license = licenses.mit;
103 };
104})