--- /dev/null
+# Copyright 1999-2019 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=7
+PYTHON_COMPAT=( python{2_7,3_5,3_6,3_7} )
+inherit distutils-r1 qmake-utils toolchain-funcs
+
+DESCRIPTION="Static analyzer of C/C++ code"
+HOMEPAGE="https://github.com/danmar/cppcheck"
+SRC_URI="${HOMEPAGE}/archive/${PV}.tar.gz -> ${P}.tar.gz"
+
+LICENSE="GPL-3+"
+SLOT="0"
+KEYWORDS="~amd64 ~arm ~arm64 ~hppa ~ppc64 ~sparc ~x86"
+IUSE="htmlreport pcre qt5"
+
+RDEPEND="
+ dev-libs/tinyxml2:=
+ htmlreport? ( dev-python/pygments[${PYTHON_USEDEP}] )
+ pcre? ( dev-libs/libpcre )
+ qt5? (
+ dev-qt/qtcore:5
+ dev-qt/qtgui:5
+ dev-qt/qtprintsupport:5
+ )
+"
+DEPEND="${RDEPEND}
+ app-text/docbook-xsl-stylesheets
+ dev-libs/libxslt
+ virtual/pkgconfig
+"
+PATCHES=(
+ "${FILESDIR}"/${PN}-1.88-tinyxml2.patch
+ "${FILESDIR}"/${PN}-1.88-ldflags.patch
+)
+
+src_prepare() {
+ default
+
+ rm -r externals/tinyxml || die
+}
+
+src_configure() {
+ tc-export CXX PKG_CONFIG
+ export LIBS="$(${PKG_CONFIG} --libs tinyxml2)"
+
+ emake dmake
+ ./dmake || die
+
+ if use pcre ; then
+ sed -e '/HAVE_RULES=/s:=no:=yes:' \
+ -i Makefile || die
+ fi
+
+ if use qt5 ; then
+ pushd gui || die
+ eqmake5
+ popd || die
+ fi
+}
+
+src_compile() {
+ emake ${PN} man \
+ CFGDIR="${EROOT}/usr/share/${PN}/cfg" \
+ DB2MAN="${EROOT}/usr/share/sgml/docbook/xsl-stylesheets/manpages/docbook.xsl"
+
+ if use qt5 ; then
+ pushd gui || die
+ emake
+ popd || die
+ fi
+
+ if use htmlreport ; then
+ pushd htmlreport || die
+ distutils-r1_src_compile
+ popd || die
+ fi
+}
+
+src_test() {
+ # safe final version
+ mv -v ${PN}{,.final} || die
+ mv -v lib/library.o{,.final} || die
+ mv -v cli/cppcheckexecutor.o{,.final} || die
+ #trigger recompile with CFGDIR inside ${S}
+ emake check CFGDIR="${S}/cfg"
+ # restore
+ mv -v ${PN}{.final,} || die
+ mv -v lib/library.o{.final,} || die
+ mv -v cli/cppcheckexecutor.o{.final,} || die
+}
+
+src_install() {
+ # it's not autotools-based, so "${ED}" here, not "${D}", bug 531760
+ emake install DESTDIR="${ED}"
+
+ insinto "/usr/share/${PN}/cfg"
+ doins cfg/*.cfg
+ if use qt5 ; then
+ dobin gui/${PN}-gui
+ dodoc gui/{projectfile.txt,gui.${PN}}
+ fi
+ if use htmlreport ; then
+ pushd htmlreport || die
+ distutils-r1_src_install
+ popd || die
+ find "${D}" -name "*.egg-info" -delete
+ else
+ rm "${ED}/usr/bin/cppcheck-htmlreport" || die
+ fi
+ doman ${PN}.1
+ dodoc -r tools/triage
+}
--- /dev/null
+diff --git a/tools/dmake.cpp b/tools/dmake.cpp
+index c3afd26..5c3a0a6 100644
+--- a/tools/dmake.cpp
++++ b/tools/dmake.cpp
+@@ -370,10 +370,10 @@ int main(int argc, char **argv)
+ fout << ".PHONY: run-dmake tags\n\n";
+ fout << "\n###### Targets\n\n";
+ fout << "cppcheck: $(LIBOBJ) $(CLIOBJ) $(EXTOBJ)\n";
+- fout << "\t$(CXX) $(CPPFLAGS) $(CXXFLAGS) -o $@ $^ $(LIBS) $(LDFLAGS) $(RDYNAMIC)\n\n";
++ fout << "\t$(CXX) $(CPPFLAGS) $(CXXFLAGS) -o $@ $^ $(LDFLAGS) $(RDYNAMIC) $(LIBS)\n\n";
+ fout << "all:\tcppcheck testrunner\n\n";
+ fout << "testrunner: $(TESTOBJ) $(LIBOBJ) $(EXTOBJ) cli/threadexecutor.o cli/cmdlineparser.o cli/cppcheckexecutor.o cli/filelister.o\n";
+- fout << "\t$(CXX) $(CPPFLAGS) $(CXXFLAGS) -o $@ $^ $(LIBS) $(LDFLAGS) $(RDYNAMIC)\n\n";
++ fout << "\t$(CXX) $(CPPFLAGS) $(CXXFLAGS) -o $@ $^ $(LDFLAGS) $(RDYNAMIC) $(LIBS)\n\n";
+ fout << "test:\tall\n";
+ fout << "\t./testrunner\n\n";
+ fout << "check:\tall\n";
--- /dev/null
+diff --git a/gui/gui.pro b/gui/gui.pro
+index 0cbaebf..cb381dd 100644
+--- a/gui/gui.pro
++++ b/gui/gui.pro
+@@ -15,6 +15,7 @@ contains(LINKCORE, [yY][eE][sS]) {
+ DEFINES += CPPCHECKLIB_IMPORT
+ }
+ LIBS += -L$$PWD/../externals
++LIBS += $(shell $(PKG_CONFIG) --libs tinyxml2)
+
+ DESTDIR = .
+ RCC_DIR = temp
+diff --git a/tools/dmake.cpp b/tools/dmake.cpp
+index 298cb98..c3afd26 100644
+--- a/tools/dmake.cpp
++++ b/tools/dmake.cpp
+@@ -122,7 +122,6 @@ int main(int argc, char **argv)
+
+ std::vector<std::string> extfiles;
+ extfiles.push_back("externals/simplecpp/simplecpp.cpp");
+- extfiles.push_back("externals/tinyxml/tinyxml2.cpp");
+
+ std::vector<std::string> clifiles;
+ getCppFiles(clifiles, "cli/", false);
+@@ -171,7 +170,6 @@ int main(int argc, char **argv)
+ std::ofstream fout1("test/testfiles.pri");
+ if (fout1.is_open()) {
+ fout1 << "# no manual edits - this file is autogenerated by dmake\n\n";
+- fout1 << "INCLUDEPATH += ../externals/tinyxml\n";
+ fout1 << "\n\nSOURCES += ";
+ for (unsigned int i = 0; i < testfiles.size(); ++i) {
+ const std::string filename(testfiles[i].substr(5));
+@@ -341,9 +339,9 @@ int main(int argc, char **argv)
+ << "endif\n\n";
+
+ makeConditionalVariable(fout, "PREFIX", "/usr");
+- makeConditionalVariable(fout, "INCLUDE_FOR_LIB", "-Ilib -isystem externals -isystem externals/simplecpp -isystem externals/tinyxml");
+- makeConditionalVariable(fout, "INCLUDE_FOR_CLI", "-Ilib -isystem externals/simplecpp -isystem externals/tinyxml");
+- makeConditionalVariable(fout, "INCLUDE_FOR_TEST", "-Ilib -Icli -isystem externals/simplecpp -isystem externals/tinyxml");
++ makeConditionalVariable(fout, "INCLUDE_FOR_LIB", "-Ilib -isystem externals -isystem externals/simplecpp");
++ makeConditionalVariable(fout, "INCLUDE_FOR_CLI", "-Ilib -isystem externals/simplecpp");
++ makeConditionalVariable(fout, "INCLUDE_FOR_TEST", "-Ilib -Icli -isystem externals/simplecpp");
+
+ fout << "BIN=$(DESTDIR)$(PREFIX)/bin\n\n";
+ fout << "# For 'make man': sudo apt-get install xsltproc docbook-xsl docbook-xml on Linux\n";
+diff --git a/oss-fuzz/Makefile b/oss-fuzz/Makefile
+index 81cf654..26f9da9 100644
+--- a/oss-fuzz/Makefile
++++ b/oss-fuzz/Makefile
+@@ -6,8 +6,8 @@
+ # make CXX=clang++-6.0 CXXFLAGS="-fsanitize=address" fuzz-client
+
+ CPPCHECK_DIR=..
+-INCLUDE_DIR=-I ${CPPCHECK_DIR}/lib -I ${CPPCHECK_DIR}/externals/simplecpp -I ${CPPCHECK_DIR}/externals/tinyxml -I ${CPPCHECK_DIR}/externals
+-SRC_FILES=main.cpp type2.cpp ${CPPCHECK_DIR}/externals/simplecpp/simplecpp.cpp ${CPPCHECK_DIR}/externals/tinyxml/tinyxml2.cpp ${CPPCHECK_DIR}/lib/*.cpp
++INCLUDE_DIR=-I ${CPPCHECK_DIR}/lib -I ${CPPCHECK_DIR}/externals/simplecpp -I ${CPPCHECK_DIR}/externals
++SRC_FILES=main.cpp type2.cpp ${CPPCHECK_DIR}/externals/simplecpp/simplecpp.cpp ${CPPCHECK_DIR}/lib/*.cpp
+
+ all: oss-fuzz-client translate
+
+diff --git a/Makefile b/Makefile
+index 372647e..9d65717 100644
+--- a/Makefile
++++ b/Makefile
+@@ -179,8 +179,7 @@ LIBOBJ = $(libcppdir)/analyzerinfo.o \
+ $(libcppdir)/tokenlist.o \
+ $(libcppdir)/valueflow.o
+
+-EXTOBJ = externals/simplecpp/simplecpp.o \
+- externals/tinyxml/tinyxml2.o
++EXTOBJ = externals/simplecpp/simplecpp.o
+
+ CLIOBJ = cli/cmdlineparser.o \
+ cli/cppcheckexecutor.o \
+@@ -689,9 +688,6 @@ test/testvarid.o: test/testvarid.cpp lib/platform.h lib/config.h lib/settings.h
+ externals/simplecpp/simplecpp.o: externals/simplecpp/simplecpp.cpp externals/simplecpp/simplecpp.h
+ $(CXX) $(CPPFLAGS) $(CFG) $(CXXFLAGS) -w $(UNDEF_STRICT_ANSI) -c -o externals/simplecpp/simplecpp.o externals/simplecpp/simplecpp.cpp
+
+-externals/tinyxml/tinyxml2.o: externals/tinyxml/tinyxml2.cpp externals/tinyxml/tinyxml2.h
+- $(CXX) $(CPPFLAGS) $(CFG) $(CXXFLAGS) -w $(UNDEF_STRICT_ANSI) -c -o externals/tinyxml/tinyxml2.o externals/tinyxml/tinyxml2.cpp
+-
+ tools/clang-ast.o: tools/clang-ast.cpp
+ $(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CFG) $(CXXFLAGS) $(UNDEF_STRICT_ANSI) -c -o tools/clang-ast.o tools/clang-ast.cpp
+
+diff --git a/externals/externals.pri b/externals/externals.pri
+index 7f0be8d..b1e94e0 100644
+--- a/externals/externals.pri
++++ b/externals/externals.pri
+@@ -1,9 +1,6 @@
+ INCLUDEPATH += $${PWD} \\r
+- $${PWD}/simplecpp \\r
+- $${PWD}/tinyxml\r
++ $${PWD}/simplecpp\r
+ \r
+-HEADERS += $${PWD}/simplecpp/simplecpp.h \\r
+- $${PWD}/tinyxml/tinyxml2.h\r
++HEADERS += $${PWD}/simplecpp/simplecpp.h\r
+ \r
+-SOURCES += $${PWD}/simplecpp/simplecpp.cpp \\r
+- $${PWD}/tinyxml/tinyxml2.cpp\r
++SOURCES += $${PWD}/simplecpp/simplecpp.cpp\r