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
|
{
lib,
stdenv,
mkDerivation,
bsdSetupHook,
openbsdSetupHook,
makeMinimal,
install,
flex,
byacc,
gencat,
rpcgen,
lorder,
csu,
include,
ctags,
tsort,
llvmPackages,
fetchpatch,
}:
mkDerivation rec {
pname = "libc";
path = "lib/libc";
extraPaths = [
"lib/csu/os-note-elf.h"
"sys/arch"
"lib/libm"
"lib/libpthread"
"lib/librpcsvc"
"lib/librpcsvc"
"lib/librthread"
"lib/libutil"
];
patches = [
./netbsd-make-to-lower.patch
./disable-librebuild.patch
(fetchpatch {
url = "https://marc.info/?l=openbsd-tech&m=171575286706032&q=raw";
sha256 = "sha256-2fqabJZLUvXUIWe5WZ4NrTOwgQCXqH49Wo0hAPu5lu0=";
})
];
nativeBuildInputs = [
bsdSetupHook
openbsdSetupHook
makeMinimal
install
flex
byacc
gencat
rpcgen
ctags
lorder
tsort
];
buildInputs = [
include
csu
];
env.NIX_CFLAGS_COMPILE = builtins.toString [
"-B${csu}/lib"
"-Wno-error"
];
# Suppress lld >= 16 undefined version errors
# https://github.com/freebsd/freebsd-src/commit/2ba84b4bcdd6012e8cfbf8a0d060a4438623a638
env.NIX_LDFLAGS = lib.optionalString (stdenv.hostPlatform.linker == "lld") "--undefined-version";
makeFlags = [
"STRIP=-s" # flag to install, not command
"COMPILER_VERSION=clang"
"LIBC_TAGS=no"
];
postInstall = ''
symlink_so () {
pushd $out/lib
ln -s "lib$1".so.* "lib$1.so"
popd
}
symlink_so c
pushd ${include}
find . -type d -exec mkdir -p $out/\{} \;
find . \( -type f -o -type l \) -exec cp -pr \{} $out/\{} \;
popd
substituteInPlace $out/include/sys/time.h --replace "defined (_LIBC)" "true"
pushd ${csu}
find . -type d -exec mkdir -p $out/\{} \;
find . \( -type f -o -type l \) -exec cp -pr \{} $out/\{} \;
popd
NIX_CFLAGS_COMPILE+=" -B$out/lib"
NIX_CFLAGS_COMPILE+=" -I$out/include"
NIX_LDFLAGS+=" -L$out/lib"
make -C $BSDSRCDIR/lib/libm $makeFlags
make -C $BSDSRCDIR/lib/libm $makeFlags install
symlink_so m
make -C $BSDSRCDIR/lib/librthread $makeFlags
make -C $BSDSRCDIR/lib/librthread $makeFlags install
symlink_so pthread
make -C $BSDSRCDIR/lib/librpcsvc $makeFlags
make -C $BSDSRCDIR/lib/librpcsvc $makeFlags install
symlink_so rpcsv
make -C $BSDSRCDIR/lib/libutil $makeFlags
make -C $BSDSRCDIR/lib/libutil $makeFlags install
symlink_so util
'';
}
|