summary refs log tree commit diff
path: root/pkgs/os-specific/linux/minimal-bootstrap/mes/libc.nix
blob: 807d043fa9e34854cf1c1dee9a1c896f2f58c999 (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
{ lib
, kaem
, ln-boot
, mes
, mes-libc
}:
let
  pname = "mes-libc";
  inherit (mes.compiler) version;

  sources = (import ./sources.nix).x86.linux.gcc;
  inherit (sources) libtcc1_SOURCES libc_gnu_SOURCES;

  # Concatenate all source files into a convenient bundle
  # "gcc" variants of source files (eg. "lib/linux/x86-mes-gcc") can also be
  # compiled by tinycc
  #
  # Passing this many arguments is too much for kaem so we need to split
  # the operation in two
  firstLibc = lib.take 100 libc_gnu_SOURCES;
  lastLibc = lib.drop 100 libc_gnu_SOURCES;
in
kaem.runCommand "${pname}-${version}" {
  inherit pname version;

  nativeBuildInputs = [ ln-boot ];

  passthru.CFLAGS = "-DHAVE_CONFIG_H=1 -I${mes-libc}/include -I${mes-libc}/include/linux/x86";

  meta = with lib; {
    description = "The Mes C Library";
    homepage = "https://www.gnu.org/software/mes";
    license = licenses.gpl3Plus;
    maintainers = teams.minimal-bootstrap.members;
    platforms = [ "i686-linux" ];
  };
} ''
  cd ${mes.srcPrefix}

  # mescc compiled libc.a
  mkdir -p ''${out}/lib/x86-mes

  # libc.c
  catm ''${TMPDIR}/first.c ${lib.concatStringsSep " " firstLibc}
  catm ''${out}/lib/libc.c ''${TMPDIR}/first.c ${lib.concatStringsSep " " lastLibc}

  # crt{1,n,i}.c
  cp lib/linux/x86-mes-gcc/crt1.c ''${out}/lib
  cp lib/linux/x86-mes-gcc/crtn.c ''${out}/lib
  cp lib/linux/x86-mes-gcc/crti.c ''${out}/lib

  # libtcc1.c
  catm ''${out}/lib/libtcc1.c ${lib.concatStringsSep " " libtcc1_SOURCES}

  # getopt.c
  cp lib/posix/getopt.c ''${out}/lib/libgetopt.c

  # Install headers
  ln -s ${mes.srcPrefix}/include ''${out}/include
''