about summary refs log tree commit diff
path: root/pkgs/development/tools/packcc/default.nix
blob: 0f756388be3bdb7dcf47ef86154adc06904ff187 (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
{
  bats,
  fetchFromGitHub,
  lib,
  packcc,
  python3,
  stdenv,
  testers,
  uncrustify,
}:

stdenv.mkDerivation rec {
  pname = "packcc";
  version = "2.0.2";

  src = fetchFromGitHub {
    owner = "arithy";
    repo = "packcc";
    rev = "v${version}";
    hash = "sha256-k1C/thvr/5fYrgu/j8YN3kwXp4k26sC9AhYhYAKQuX0=";
  };

  postPatch = ''
    patchShebangs tests
  '';

  dontConfigure = true;

  preBuild = ''
    cd build/${
      if stdenv.cc.isGNU then
        "gcc"
      else if stdenv.cc.isClang then
        "clang"
      else
        throw "Unsupported C compiler"
    }
  '';

  doCheck = true;

  nativeCheckInputs = [
    bats
    uncrustify
    python3
  ];

  preCheck =
    ''
      # Style tests will always fail because upstream uses an older version of
      # uncrustify.
      rm -rf ../../tests/style.d
    ''
    + lib.optionalString stdenv.cc.isClang ''
      export NIX_CFLAGS_COMPILE+=' -Wno-error=strict-prototypes -Wno-error=int-conversion'
    '';

  installPhase = ''
    runHook preInstall
    install -Dm755 release/bin/packcc $out/bin/packcc
    runHook postInstall
  '';

  passthru.tests.version = testers.testVersion { package = packcc; };

  meta = with lib; {
    description = "Parser generator for C";
    longDescription = ''
      PackCC is a parser generator for C. Its main features are as follows:
      - Generates your parser in C from a grammar described in a PEG,
      - Gives your parser great efficiency by packrat parsing,
      - Supports direct and indirect left-recursive grammar rules.
    '';
    homepage = "https://github.com/arithy/packcc";
    changelog = "https://github.com/arithy/packcc/releases/tag/${src.rev}";
    license = licenses.mit;
    maintainers = with maintainers; [ azahi ];
    platforms = platforms.unix;
    mainProgram = "packcc";
  };
}