about summary refs log tree commit diff
path: root/nixpkgs/pkgs/os-specific/linux/minimal-bootstrap/gnused/default.nix
blob: b5647b96ee3c561ec30bf2b89f0cb25e036d9e94 (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
{ lib
, buildPlatform
, hostPlatform
, fetchurl
, bash
, gnumake
, mesBootstrap ? false, tinycc ? null
, gcc ? null, glibc ? null, binutils ? null, gnused ? null, linux-headers, gnugrep
}:
assert mesBootstrap -> tinycc != null;
assert !mesBootstrap -> gcc != null && glibc != null && binutils != null && gnused != null;
let
  pname = "gnused" + lib.optionalString mesBootstrap "-mes";
  # last version that can be compiled with mes-libc
  version = "4.0.9";

  src = fetchurl {
    url = "mirror://gnu/sed/sed-${version}.tar.gz";
    sha256 = "0006gk1dw2582xsvgx6y6rzs9zw8b36rhafjwm288zqqji3qfrf3";
  };

  # Thanks to the live-bootstrap project!
  # See https://github.com/fosslinux/live-bootstrap/blob/1bc4296091c51f53a5598050c8956d16e945b0f5/sysa/sed-4.0.9/sed-4.0.9.kaem
  makefile = fetchurl {
    url = "https://github.com/fosslinux/live-bootstrap/raw/1bc4296091c51f53a5598050c8956d16e945b0f5/sysa/sed-4.0.9/mk/main.mk";
    sha256 = "0w1f5ri0g5zla31m6l6xyzbqwdvandqfnzrsw90dd6ak126w3mya";
  };
in
bash.runCommand "${pname}-${version}" {
  inherit pname version;

  nativeBuildInputs = [
    gnumake
  ] ++ lib.optionals mesBootstrap [
    tinycc.compiler
  ] ++ lib.optionals (!mesBootstrap) [
    gcc
    glibc
    binutils
    gnused
    gnugrep
  ];

  passthru.tests.get-version = result:
    bash.runCommand "${pname}-get-version-${version}" {} ''
      ${result}/bin/sed --version
      mkdir ''${out}
    '';

  meta = with lib; {
    description = "GNU sed, a batch stream editor";
    homepage = "https://www.gnu.org/software/sed";
    license = licenses.gpl3Plus;
    maintainers = teams.minimal-bootstrap.members;
    mainProgram = "sed";
    platforms = platforms.unix;
  };
} (''
  # Unpack
  ungz --file ${src} --output sed.tar
  untar --file sed.tar
  rm sed.tar
  cd sed-${version}

'' + lib.optionalString mesBootstrap ''
  # Configure
  cp ${makefile} Makefile
  catm config.h

  # Build
  make \
    CC="tcc -B ${tinycc.libs}/lib" \
    LIBC=mes

'' + lib.optionalString (!mesBootstrap) ''
  # Configure
  export CC="gcc -I${glibc}/include -I${linux-headers}/include"
  export LIBRARY_PATH="${glibc}/lib"
  export LIBS="-lc -lnss_files -lnss_dns -lresolv"
  chmod +x configure
  ./configure \
    --build=${buildPlatform.config} \
    --host=${hostPlatform.config} \
    --disable-shared \
    --disable-nls \
    --disable-dependency-tracking \
    --without-included-regex \
    --prefix=$out

  # Build
  make

'' + ''
  # Install
  make install PREFIX=$out
'')