1{ lib
2, stdenv
3, fetchFromGitHub
4, installShellFiles
5, pcre
6, python3
7, libxslt
8, docbook_xsl
9, docbook_xml_dtd_45
10, which
11, pkg-config
12}:
13
14stdenv.mkDerivation rec {
15 pname = "cppcheck";
16 version = "2.10.3";
17
18 src = fetchFromGitHub {
19 owner = "danmar";
20 repo = "cppcheck";
21 rev = version;
22 hash = "sha256-M63uHhyEDmuWrEu7Y3Zks1Eq5WgenSlqWln2DMBj3fU=";
23 };
24
25 strictDeps = true;
26 nativeBuildInputs = [ pkg-config installShellFiles libxslt docbook_xsl docbook_xml_dtd_45 which python3 ];
27 buildInputs = [ pcre (python3.withPackages (ps: [ps.pygments])) ];
28
29 makeFlags = [ "PREFIX=$(out)" "MATCHCOMPILER=yes" "FILESDIR=$(out)/share/cppcheck" "HAVE_RULES=yes" ];
30
31 outputs = [ "out" "man" ];
32
33 enableParallelBuilding = true;
34
35 postPatch = ''
36 substituteInPlace Makefile \
37 --replace 'PCRE_CONFIG = $(shell which pcre-config)' 'PCRE_CONFIG = $(PKG_CONFIG) libpcre'
38 '';
39
40 postBuild = ''
41 make DB2MAN=${docbook_xsl}/xml/xsl/docbook/manpages/docbook.xsl man
42 '';
43
44 postInstall = ''
45 installManPage cppcheck.1
46 '';
47
48 # test/testcondition.cpp:4949(TestCondition::alwaysTrueContainer): Assertion failed.
49 doCheck = !(stdenv.isLinux && stdenv.isAarch64);
50
51 doInstallCheck = true;
52 installCheckPhase = ''
53 runHook preInstallCheck
54
55 echo 'int main() {}' > ./installcheck.cpp
56 $out/bin/cppcheck ./installcheck.cpp > /dev/null
57
58 runHook postInstallCheck
59 '';
60
61 meta = with lib; {
62 description = "A static analysis tool for C/C++ code";
63 longDescription = ''
64 Check C/C++ code for memory leaks, mismatching allocation-deallocation,
65 buffer overruns and more.
66 '';
67 homepage = "http://cppcheck.sourceforge.net/";
68 license = licenses.gpl3Plus;
69 platforms = platforms.unix;
70 maintainers = with maintainers; [ joachifm ];
71 };
72}