summaryrefslogtreecommitdiffstats
path: root/pkgs/by-name/c9/c99sh/package.nix
blob: ad578c879673c402e79c3819b93427d6f11d89ed (plain)
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,
  stdenvNoCC,
  fetchFromGitHub,
  patsh,
  bashNonInteractive,
  pkg-config,
  gcc,
  gsl,
  targetPackages,
  cc ? targetPackages.stdenv.cc,
  nix-update-script,
}:

stdenvNoCC.mkDerivation (finalAttrs: {
  pname = "c99sh";
  version = "1.1.1";

  src = fetchFromGitHub {
    owner = "RhysU";
    repo = "c99sh";
    tag = "v${finalAttrs.version}";
    hash = "sha256-nLq6J1PRROTOSvScyyXUqwtj10MEfQCHC8YYNd+JxkA=";
  };

  strictDeps = true;

  nativeBuildInputs = [ patsh ];

  # Used by `patsh`
  buildInputs = [
    bashNonInteractive
    pkg-config
  ];

  postPatch = ''
    patsh c99sh \
      --force --store-dir ${builtins.storeDir} --path "$HOST_PATH"

    patchShebangs .

    substituteInPlace c99sh \
      --replace-fail -cc -${lib.getExe' cc "cc"} \
      --replace-fail -c++ -${lib.getExe' cc "c++"}
  '';

  # FIXME: `patchShebangs` doesn't function in cross-builds
  doCheck = !stdenvNoCC.hostPlatform.isDarwin;

  nativeCheckInputs = [
    pkg-config
    gcc
  ];

  checkInputs = [ gsl ];

  checkPhase = ''
    runHook preCheck

    ./tests

    runHook postCheck
  '';

  installPhase = ''
    runHook preInstall

    mkdir --parents $out/bin
    cp --no-dereference c*sh $out/bin # c11sh and cxxsh

    runHook postInstall
  '';

  passthru.updateScript = nix-update-script { };

  meta = {
    description = "Shebang-friendly script for \"interpreting\" C files";
    longDescription = ''
      Shebang-friendly script for \"interpreting\" single C99, C11,
      and C++ files, including rcfile support
    '';
    homepage = "https://github.com/RhysU/c99sh";
    license = lib.licenses.bsd2;
    maintainers = with lib.maintainers; [ yiyu ];
    mainProgram = "c99sh";
    platforms = lib.platforms.all;
  };
})