about summary refs log tree commit diff
path: root/pkgs/by-name/cd/cdecl/package.nix
blob: 016a15e9bea0616dd7ba035085dd7f2772e16dc1 (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
{
  lib,
  stdenv,
  fetchFromGitHub,
  bison,
  flex,
  readline,
  ncurses,
}:

stdenv.mkDerivation {
  pname = "cdecl";
  version = "2.5-unstable-2024-05-07";

  src = fetchFromGitHub {
    owner = "ridiculousfish";
    repo = "cdecl-blocks";
    rev = "1e6e1596771183d9bb90bcf152d6bc2055219a7e";
    hash = "sha256-5XuiYkFe+QvVBRIXRieKoE0zbISMvU1iLgEfkw6GnlE=";
  };

  patches = [
    ./cdecl-2.5-lex.patch
    # when `USE_READLINE` is enabled, this option will not be present
    ./test_remove_interactive_line.patch
  ];

  prePatch = ''
    substituteInPlace cdecl.c \
      --replace 'getline' 'cdecl_getline'
  '';

  strictDeps = true;

  nativeBuildInputs = [
    bison
    flex
  ];

  buildInputs = [
    readline
    ncurses
  ];

  env = {
    NIX_CFLAGS_COMPILE = toString (
      [
        "-DBSD"
        "-DUSE_READLINE"
      ]
      ++ lib.optionals stdenv.cc.isClang [
        "-Wno-error=int-conversion"
        "-Wno-error=incompatible-function-pointer-types"
      ]
    );
    NIX_LDFLAGS = "-lreadline";
  };

  makeFlags = [
    "CC=${stdenv.cc.targetPrefix}cc"
    "PREFIX=${placeholder "out"}"
    "BINDIR=${placeholder "out"}/bin"
    "MANDIR=${placeholder "out"}/man1"
    "CATDIR=${placeholder "out"}/cat1"
  ];

  doCheck = true;
  checkTarget = "test";

  preInstall = ''
    mkdir -p $out/bin;
  '';

  meta = {
    description = "Translator English -- C/C++ declarations";
    homepage = "https://cdecl.org";
    license = lib.licenses.publicDomain;
    maintainers = with lib.maintainers; [ sigmanificient ];
    platforms = lib.platforms.unix;
    mainProgram = "cdecl";
  };
}