about summary refs log tree commit diff
path: root/pkgs/os-specific/bsd/openbsd/pkgs/libcMinimal/package.nix
blob: d8d6cc398e0de33d9079dc9cff5b76b0886366f3 (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
{
  lib,
  crossLibcStdenv,
  mkDerivation,
  bsdSetupHook,
  openbsdSetupHook,
  makeMinimal,
  install,
  flex,
  byacc,
  gencat,
  rpcgen,
  csu,
  include,
  ctags,
  tsort,
  llvmPackages,
  fetchpatch,
}:

mkDerivation {
  noLibc = true;
  path = "lib/libc";
  pname = "libcMinimal-openbsd";
  outputs = [
    "out"
    "dev"
    "man"
  ];
  extraPaths = [
    "lib/csu/os-note-elf.h"
    "sys/arch"
  ];

  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
    tsort
    gencat
  ];

  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 (
    crossLibcStdenv.hostPlatform.linker == "lld"
  ) "--undefined-version";

  makeFlags = [
    "COMPILER_VERSION=clang"
    "LIBC_TAGS=no"
  ];

  postInstall = ''
    pushd ${include}
    find include -type d -exec mkdir -p "$dev/{}" ';'
    find include '(' -type f -o -type l ')' -exec cp -pr "{}" "$dev/{}" ';'
    popd
    substituteInPlace "$dev/include/sys/time.h" --replace "defined (_LIBC)" "true"

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

  meta.platforms = lib.platforms.openbsd;
}