about summary refs log tree commit diff
path: root/pkgs/os-specific/bsd/freebsd/pkgs/libc/package.nix
blob: 0225d44be4c3b08fa6520c2b7c2dc15502315a87 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
{ lib, stdenv, mkDerivation

, bsdSetupHook, freebsdSetupHook
, makeMinimal
, install
, flex, byacc, gencat, rpcgen

, csu, include
}:

mkDerivation rec {
  pname = "libc";
  path = "lib/libc";
  extraPaths = [
    "etc/group"
    "etc/master.passwd"
    "etc/shells"
    "lib/libmd"
    "lib/libutil"
    "lib/msun"
    "sys/kern"
    "sys/libkern"
    "sys/sys"
    "sys/crypto/chacha20"
    "include/rpcsvc"
    "contrib/jemalloc"
    "contrib/gdtoa"
    "contrib/libc-pwcache"
    "contrib/libc-vis"
    "contrib/tzcode/stdtime"

    # libthr
    "lib/libthr"
    "lib/libthread_db"
    "libexec/rtld-elf"

    # librpcsvc
    "lib/librpcsvc"

    # librt
    "lib/librt"

    # libcrypt
    "lib/libcrypt"
    "lib/libmd"
    "sys/crypto/sha2"
  ];

  patches = [
    # Hack around broken propogating MAKEFLAGS to submake, just inline logic
    ./libc-msun-arch-subdir.patch

    # Don't force -lcompiler-rt, we don't actually call it that
    ./libc-no-force--lcompiler-rt.patch

    # Fix extra include dir to get rpcsvc headers.
    ./librpcsvc-include-subdir.patch
  ];

  postPatch = ''
    substituteInPlace $COMPONENT_PATH/Makefile --replace '.include <src.opts.mk>' ""
  '';

  nativeBuildInputs = [
    bsdSetupHook freebsdSetupHook
    makeMinimal
    install

    flex byacc gencat rpcgen
  ];
  buildInputs = [ include csu ];
  env.NIX_CFLAGS_COMPILE = "-B${csu}/lib";

  # Suppress lld >= 16 undefined version errors
  # https://github.com/freebsd/freebsd-src/commit/2ba84b4bcdd6012e8cfbf8a0d060a4438623a638
  env.NIX_LDFLAGS = lib.optionalString (stdenv.targetPlatform.linker == "lld") "--undefined-version";

  makeFlags = [
    "STRIP=-s" # flag to install, not command
    # lib/libc/gen/getgrent.c has sketchy cast from `void *` to enum
    "MK_WERROR=no"
  ];

  MK_SYMVER = "yes";
  MK_SSP = "yes";
  MK_NLS = "yes";
  MK_ICONV = "no"; # TODO make srctop
  MK_NS_CACHING = "yes";
  MK_INET6_SUPPORT = "yes";
  MK_HESIOD = "yes";
  MK_NIS = "yes";
  MK_HYPERV = "yes";
  MK_FP_LIBC = "yes";

  MK_TCSH = "no";
  MK_MALLOC_PRODUCTION = "yes";

  MK_TESTS = "no";

  postInstall = ''
    pushd ${include}
    find . -type d -exec mkdir -p $out/\{} \;
    find . \( -type f -o -type l \) -exec cp -pr \{} $out/\{} \;
    popd

    pushd ${csu}
    find . -type d -exec mkdir -p $out/\{} \;
    find . \( -type f -o -type l \) -exec cp -pr \{} $out/\{} \;
    popd

    sed -i -e 's| [^ ]*/libc_nonshared.a||' $out/lib/libc.so

    $CC -nodefaultlibs -lgcc -shared -o $out/lib/libgcc_s.so

    NIX_CFLAGS_COMPILE+=" -B$out/lib"
    NIX_CFLAGS_COMPILE+=" -I$out/include"
    NIX_LDFLAGS+=" -L$out/lib"

    make -C $BSDSRCDIR/lib/libthr $makeFlags
    make -C $BSDSRCDIR/lib/libthr $makeFlags install

    make -C $BSDSRCDIR/lib/msun $makeFlags
    make -C $BSDSRCDIR/lib/msun $makeFlags install

    make -C $BSDSRCDIR/lib/librpcsvc $makeFlags
    make -C $BSDSRCDIR/lib/librpcsvc $makeFlags install

    make -C $BSDSRCDIR/lib/libutil $makeFlags
    make -C $BSDSRCDIR/lib/libutil $makeFlags install

    make -C $BSDSRCDIR/lib/librt $makeFlags
    make -C $BSDSRCDIR/lib/librt $makeFlags install

    make -C $BSDSRCDIR/lib/libcrypt $makeFlags
    make -C $BSDSRCDIR/lib/libcrypt $makeFlags install
  '';

  meta.platforms = lib.platforms.freebsd;
}