about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--cppcheck.nix74
-rw-r--r--grep.nix8
-rw-r--r--shell.nix27
3 files changed, 103 insertions, 6 deletions
diff --git a/cppcheck.nix b/cppcheck.nix
new file mode 100644
index 0000000..60991a7
--- /dev/null
+++ b/cppcheck.nix
@@ -0,0 +1,74 @@
+# Recipe for building cppcheck at specific revision
+#
+# SPDX-FileCopyrightText: 2012, 2014, 2016 Peter Simons
+# SPDX-FileCopyrightText: 2013 Bjørn Forsman
+# SPDX-FileCopyrightText: 2014 Linquize
+# SPDX-FileCopyrightText: 2014 Moritz Ulrich
+# SPDX-FileCopyrightText: 2014 Pascal Wittmann
+# SPDX-FileCopyrightText: 2014 Peter Simons
+# SPDX-FileCopyrightText: 2015-2017 Joachim Fasting
+# SPDX-FileCopyrightText: 2015 koral
+# SPDX-FileCopyrightText: 2016 Nikolay Amiantov
+# SPDX-FileCopyrightText: 2017 Guillaume Maudoux
+# SPDX-FileCopyrightText: 2018 Ignat Loskutov
+# SPDX-License-Identifier: MIT
+#
+# SPDX-FileCopyrightText: 2023 Nguyễn Gia Phong
+# SPDX-License-Identifier: AGPL-3.0-or-later
+
+{ lib, stdenv, fetchFromGitHub, fetchpatch, version, commit, hash, binRenameHook
+, docbook_xsl, docbook_xml_dtd_45, libxslt, python3, which, pcre }:
+
+stdenv.mkDerivation rec {
+  pname = "cppcheck";
+  inherit version;
+
+  src = fetchFromGitHub {
+    owner = "danmar";
+    repo = pname;
+    rev = commit;
+    inherit hash;
+  };
+
+  patches = [
+    (fetchpatch {
+      name = "glibc-2.34-compat.patch";
+      url = "https://github.com/danmar/cppcheck/commit/8869ee3554f19ce63892891a697378d8b745414b.patch";
+      hash = "sha256-K9+/2VIb5OFz+es8ZrprCBx8nkKZZycagw6ripWavPw=";
+    })
+  ];
+
+  # strictDeps = true;
+  nativeBuildInputs = [
+    binRenameHook docbook_xsl docbook_xml_dtd_45 libxslt python3 which
+  ];
+  buildInputs = [ pcre ];
+
+  makeFlags = [
+    "PREFIX=$(out)"
+    "MATCHCOMPILER=yes"
+    "FILESDIR=$(out)/cfg"
+    "HAVE_RULES=yes"
+  ];
+
+  enableParallelBuilding = true;
+
+  outputs = [ "out" "man" ];
+
+  postInstall = ''
+    make DB2MAN=${docbook_xsl}/xml/xsl/docbook/manpages/docbook.xsl man
+    mkdir -p $man/share/man/man1
+    cp cppcheck.1 $man/share/man/man1/cppcheck.1
+  '';
+
+  meta = with lib; {
+    description = "A static analysis tool for C/C++ code";
+    longDescription = ''
+      Check C/C++ code for memory leaks, mismatching allocation-deallocation,
+      buffer overruns and more.
+    '';
+    homepage = "https://cppcheck.sourceforge.net";
+    license = licenses.gpl3Plus;
+    platforms = platforms.unix;
+  };
+}
diff --git a/grep.nix b/grep.nix
index da0fab8..b430b50 100644
--- a/grep.nix
+++ b/grep.nix
@@ -9,11 +9,12 @@
 # SPDX-FileCopyrightText: 2023 Nguyễn Gia Phong
 # SPDX-License-Identifier: AGPL-3.0-or-later
 
-{ lib, stdenv, version, base, snapshot, pcre, libiconv }:
+{ lib, stdenv, version, base, snapshot, binRenameHook, pcre, libiconv }:
 stdenv.mkDerivation rec {
   pname = "grep";
   inherit version;
 
+  nativeBuildInputs = [ binRenameHook ];
   buildInputs = [ pcre libiconv ];
   hardeningDisable = [ "all" ];
 
@@ -27,11 +28,6 @@ stdenv.mkDerivation rec {
   preConfigure = ''
     export MKDIR_P="mkdir -p"
   '';
-  postInstall = ''
-    for i in $out/bin/*
-    do mv $i{,.${version}}
-    done
-  '';
   doCheck = false;
 
   meta = with lib; {
diff --git a/shell.nix b/shell.nix
index d94ae88..52541b8 100644
--- a/shell.nix
+++ b/shell.nix
@@ -5,6 +5,26 @@
 
 with import <nixpkgs> { };
 let
+  binRenameHook = version: writeTextFile {
+    name = "bin-rename-hook";
+    text = ''
+      #!${runtimeShell}
+      renameBinaries() {
+        for i in $out/bin/*
+        do mv $i{,.${version}}
+        done
+      }
+      preDistPhases+=(renameBinaries)
+    '';
+    executable = true;
+    destination = "/nix-support/setup-hook";
+  };
+  cppcheck = version: commit: hash: callPackage ./cppcheck.nix {
+    inherit version;
+    inherit commit;
+    inherit hash;
+    binRenameHook = binRenameHook version;
+  };
   grep-2_6 = fetchurl {
     url = "mirror://gnu/grep/grep-2.6.tar.xz";
     hash = "sha256-YsNien9DBt1gBAED27fZ8SIOSlTFV9ndDEwy9t1itRE=";
@@ -20,9 +40,16 @@ let
       url = "http://git.savannah.gnu.org/cgit/grep.git/snapshot/grep-${commit}.tar.gz";
       inherit hash;
     };
+    binRenameHook = binRenameHook version;
   };
 in mkShell {
   packages = [
+    (cppcheck "9261.buggy"
+      "4943771e41f76edc64b273c6b257ecc0ba778a20"
+      "sha256-mcE9Nq/OfNiLgz3PuZEUplFRMc7E2D7ALuFdNFT6iQI=")
+    (cppcheck "9261.fixed"
+      "00fae7fb428b0b055135d6b972a1b52dd2c08d03"
+      "sha256-jJY06u07fzd9AOd1pr7xM7Qdm6oDW1ehGEqKlxxHT6s=")
     (grep "8f08d8e2.parent" grep-2_6
       "c1cb19fe67f4c83f9232087ae03c178905d62b0d"
       "sha256-tT3H9pehJ8X6XPf6qyhUvjKspQZXvCd2I4uQQuabOn8=")