1{ stdenv, lib, fetchurl, fetchpatch, autoreconfHook, xz, buildPackages }:
2
3stdenv.mkDerivation rec {
4 pname = "libunwind";
5 version = "1.6.2";
6
7 src = fetchurl {
8 url = "mirror://savannah/libunwind/${pname}-${version}.tar.gz";
9 sha256 = "sha256-SmrsZmmR+0XQiJxErt6K1usQgHHDVU/N/2cfnJR5SXY=";
10 };
11
12 patches = [
13 # Fix for aarch64 and non-4K pages. Remove once upgraded past 1.6.2.
14 (fetchpatch {
15 url = "https://github.com/libunwind/libunwind/commit/e85b65cec757ef589f28957d0c6c21c498a03bdf.patch";
16 sha256 = "1lnlygvhqrdrjgw303pg2k2k4ms4gaghpjsgmhk47q83vy1yjwfg";
17 })
18 ];
19
20 postPatch = if (stdenv.cc.isClang || stdenv.hostPlatform.isStatic) then ''
21 substituteInPlace configure.ac --replace "-lgcc_s" ""
22 '' else lib.optionalString stdenv.hostPlatform.isMusl ''
23 substituteInPlace configure.ac --replace "-lgcc_s" "-lgcc_eh"
24 '';
25
26 nativeBuildInputs = [ autoreconfHook ];
27
28 outputs = [ "out" "dev" "devman" ];
29
30 # Without latex2man, no man pages are installed despite being
31 # prebuilt in the source tarball.
32 configureFlags = [ "LATEX2MAN=${buildPackages.coreutils}/bin/true" ];
33
34 propagatedBuildInputs = [ xz ];
35
36 postInstall = ''
37 find $out -name \*.la | while read file; do
38 sed -i 's,-llzma,${xz.out}/lib/liblzma.la,' $file
39 done
40 '';
41
42 doCheck = false; # fails
43
44 meta = with lib; {
45 homepage = "https://www.nongnu.org/libunwind";
46 description = "A portable and efficient API to determine the call-chain of a program";
47 maintainers = with maintainers; [ orivej ];
48 # https://github.com/libunwind/libunwind#libunwind
49 platforms = [ "aarch64-linux" "armv5tel-linux" "armv6l-linux" "armv7a-linux" "armv7l-linux" "i686-freebsd13" "i686-linux" "mips64el-linux" "mipsel-linux" "powerpc64-linux" "powerpc64le-linux" "riscv64-linux" "x86_64-freebsd13" "x86_64-linux" "x86_64-solaris" ];
50 license = licenses.mit;
51 };
52}