2010-01-23 09:54:51 +01:00
|
|
|
/*
|
|
|
|
* Cppcheck - A tool for static C/C++ code analysis
|
2023-01-28 10:16:34 +01:00
|
|
|
* Copyright (C) 2007-2023 Cppcheck team.
|
2010-01-23 09:54:51 +01:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Generate Makefile for cppcheck
|
|
|
|
|
|
|
|
#include <algorithm>
|
2022-09-27 20:06:15 +02:00
|
|
|
#include <array>
|
2022-02-02 22:31:51 +01:00
|
|
|
#include <fstream> // IWYU pragma: keep
|
2023-01-21 11:55:36 +01:00
|
|
|
#include <functional>
|
2010-01-23 09:54:51 +01:00
|
|
|
#include <iostream>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
2010-03-11 21:30:06 +01:00
|
|
|
|
2011-03-20 14:25:11 +01:00
|
|
|
#include "../cli/filelister.h"
|
2016-10-02 12:38:44 +02:00
|
|
|
#include "../lib/pathmatch.h"
|
2022-12-17 09:13:31 +01:00
|
|
|
#include "../lib/utils.h"
|
2010-01-23 09:54:51 +01:00
|
|
|
|
2015-01-08 23:58:00 +01:00
|
|
|
static std::string builddir(std::string filename)
|
2012-12-02 12:36:55 +01:00
|
|
|
{
|
|
|
|
if (filename.compare(0,4,"lib/") == 0)
|
2019-06-23 13:43:09 +02:00
|
|
|
filename = "$(libcppdir)" + filename.substr(3);
|
2012-12-02 12:36:55 +01:00
|
|
|
return filename;
|
|
|
|
}
|
|
|
|
|
2015-01-08 23:58:00 +01:00
|
|
|
static std::string objfile(std::string cppfile)
|
2010-01-23 09:54:51 +01:00
|
|
|
{
|
2017-05-27 04:15:54 +02:00
|
|
|
cppfile.erase(cppfile.rfind('.'));
|
2012-12-02 12:36:55 +01:00
|
|
|
return builddir(cppfile + ".o");
|
2010-01-23 09:54:51 +01:00
|
|
|
}
|
|
|
|
|
2019-08-14 20:53:51 +02:00
|
|
|
static std::string objfiles(const std::vector<std::string> &files)
|
|
|
|
{
|
|
|
|
std::string allObjfiles;
|
|
|
|
for (const std::string &file : files) {
|
|
|
|
if (file != files.front())
|
|
|
|
allObjfiles += std::string(14, ' ');
|
|
|
|
allObjfiles += objfile(file);
|
|
|
|
if (file != files.back())
|
|
|
|
allObjfiles += " \\\n";
|
|
|
|
}
|
|
|
|
return allObjfiles;
|
|
|
|
}
|
|
|
|
|
2015-01-08 23:58:00 +01:00
|
|
|
static void getDeps(const std::string &filename, std::vector<std::string> &depfiles)
|
2010-01-23 09:54:51 +01:00
|
|
|
{
|
2022-12-17 09:13:31 +01:00
|
|
|
static const std::array<std::string, 3> externalfolders{"externals/picojson", "externals/simplecpp", "externals/tinyxml2"};
|
2019-09-10 10:32:36 +02:00
|
|
|
|
2010-01-23 09:54:51 +01:00
|
|
|
// Is the dependency already included?
|
2022-12-30 15:13:47 +01:00
|
|
|
if (std::find(depfiles.cbegin(), depfiles.cend(), filename) != depfiles.cend())
|
2010-01-23 09:54:51 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
std::ifstream f(filename.c_str());
|
2021-08-07 20:51:18 +02:00
|
|
|
if (!f.is_open()) {
|
2019-09-10 10:32:36 +02:00
|
|
|
/*
|
|
|
|
* Recursively search for includes in other directories.
|
|
|
|
* Files are searched according to the following priority:
|
|
|
|
* [test, tools] -> cli -> lib -> externals
|
|
|
|
*/
|
|
|
|
if (filename.compare(0, 4, "cli/") == 0)
|
2017-05-27 04:15:54 +02:00
|
|
|
getDeps("lib" + filename.substr(filename.find('/')), depfiles);
|
2019-09-10 10:32:36 +02:00
|
|
|
else if (filename.compare(0, 5, "test/") == 0)
|
|
|
|
getDeps("cli" + filename.substr(filename.find('/')), depfiles);
|
|
|
|
else if (filename.compare(0, 6, "tools/") == 0)
|
|
|
|
getDeps("cli" + filename.substr(filename.find('/')), depfiles);
|
|
|
|
else if (filename.compare(0, 4, "lib/") == 0) {
|
|
|
|
for (const std::string & external : externalfolders)
|
|
|
|
getDeps(external + filename.substr(filename.find('/')), depfiles);
|
|
|
|
}
|
2010-01-23 09:54:51 +01:00
|
|
|
return;
|
|
|
|
}
|
2010-04-02 07:30:58 +02:00
|
|
|
if (filename.find(".c") == std::string::npos)
|
2010-01-23 09:54:51 +01:00
|
|
|
depfiles.push_back(filename);
|
|
|
|
|
|
|
|
std::string path(filename);
|
2017-05-27 04:15:54 +02:00
|
|
|
if (path.find('/') != std::string::npos)
|
|
|
|
path.erase(1 + path.rfind('/'));
|
2010-01-23 09:54:51 +01:00
|
|
|
|
|
|
|
std::string line;
|
2011-10-13 20:53:06 +02:00
|
|
|
while (std::getline(f, line)) {
|
2010-01-23 09:54:51 +01:00
|
|
|
std::string::size_type pos1 = line.find("#include \"");
|
2019-09-10 10:32:36 +02:00
|
|
|
char rightBracket = '\"';
|
|
|
|
if (pos1 == std::string::npos) {
|
|
|
|
pos1 = line.find("#include <");
|
|
|
|
rightBracket = '>';
|
|
|
|
if (pos1 == std::string::npos)
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2010-01-23 09:54:51 +01:00
|
|
|
pos1 += 10;
|
|
|
|
|
2022-10-02 07:12:40 +02:00
|
|
|
const std::string::size_type pos2 = line.find(rightBracket, pos1);
|
2022-12-17 09:13:31 +01:00
|
|
|
std::string hfile(path);
|
|
|
|
hfile += line.substr(pos1, pos2 - pos1);
|
|
|
|
|
|
|
|
const std::string::size_type traverse_pos = hfile.find("/../");
|
|
|
|
if (traverse_pos != std::string::npos) // TODO: Ugly fix
|
|
|
|
hfile.erase(0, 4 + traverse_pos);
|
|
|
|
// no need to look up extension-less headers
|
|
|
|
if (!endsWith(hfile, ".h"))
|
|
|
|
continue;
|
2010-01-23 09:54:51 +01:00
|
|
|
getDeps(hfile, depfiles);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-17 23:42:01 +02:00
|
|
|
static void compilefiles(std::ostream &fout, const std::vector<std::string> &files, const std::string &args)
|
2010-01-23 09:54:51 +01:00
|
|
|
{
|
2019-08-14 20:53:51 +02:00
|
|
|
for (const std::string &file : files) {
|
2022-10-02 07:12:40 +02:00
|
|
|
const bool external(file.compare(0,10,"externals/") == 0);
|
2019-08-14 20:53:51 +02:00
|
|
|
fout << objfile(file) << ": " << file;
|
2010-01-23 09:54:51 +01:00
|
|
|
std::vector<std::string> depfiles;
|
2019-08-14 20:53:51 +02:00
|
|
|
getDeps(file, depfiles);
|
2019-09-19 09:26:59 +02:00
|
|
|
std::sort(depfiles.begin(), depfiles.end());
|
2019-08-14 20:53:51 +02:00
|
|
|
for (const std::string &depfile : depfiles)
|
|
|
|
fout << " " << depfile;
|
2022-09-09 15:06:40 +02:00
|
|
|
fout << "\n\t$(CXX) " << args << " $(CPPFLAGS) $(CXXFLAGS)" << (external?" -w":"") << " -c -o $@ " << builddir(file) << "\n\n";
|
2010-01-23 09:54:51 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-18 21:52:14 +02:00
|
|
|
static std::string getCppFiles(std::vector<std::string> &files, const std::string &path, bool recursive)
|
2010-02-19 17:35:38 +01:00
|
|
|
{
|
2012-02-26 10:18:21 +01:00
|
|
|
std::map<std::string,size_t> filemap;
|
2015-03-05 06:48:44 +01:00
|
|
|
const std::set<std::string> extra;
|
2015-07-23 14:52:44 +02:00
|
|
|
const std::vector<std::string> masks;
|
|
|
|
const PathMatch matcher(masks);
|
2021-04-18 21:52:14 +02:00
|
|
|
std::string err = FileLister::addFiles(filemap, path, extra, recursive, matcher);
|
|
|
|
if (!err.empty())
|
|
|
|
return err;
|
2012-02-26 10:18:21 +01:00
|
|
|
|
|
|
|
// add *.cpp files to the "files" vector..
|
2019-08-14 20:53:51 +02:00
|
|
|
for (const std::pair<const std::string&, size_t> file : filemap) {
|
2022-12-17 09:13:31 +01:00
|
|
|
if (endsWith(file.first, ".cpp"))
|
2019-08-14 20:53:51 +02:00
|
|
|
files.push_back(file.first);
|
2010-02-19 17:35:38 +01:00
|
|
|
}
|
2021-04-18 21:52:14 +02:00
|
|
|
return "";
|
2010-02-19 17:35:38 +01:00
|
|
|
}
|
|
|
|
|
2010-09-19 13:05:46 +02:00
|
|
|
|
2011-10-17 20:18:36 +02:00
|
|
|
static void makeConditionalVariable(std::ostream &os, const std::string &variable, const std::string &defaultValue)
|
2010-09-19 13:05:46 +02:00
|
|
|
{
|
|
|
|
os << "ifndef " << variable << '\n'
|
2011-10-17 20:18:36 +02:00
|
|
|
<< " " << variable << '=' << defaultValue << '\n'
|
2010-09-19 13:05:46 +02:00
|
|
|
<< "endif\n"
|
|
|
|
<< "\n";
|
|
|
|
}
|
|
|
|
|
2023-01-21 11:55:36 +01:00
|
|
|
static int write_vcxproj(const std::string &proj_name, const std::function<void(std::string&)> &source_f, const std::function<void(std::string&)> &header_f)
|
|
|
|
{
|
|
|
|
std::string outstr;
|
|
|
|
|
|
|
|
{
|
|
|
|
// treat as binary to prevent inplicit line ending conversions
|
|
|
|
std::ifstream in(proj_name, std::ios::binary);
|
|
|
|
if (!in.is_open()) {
|
|
|
|
std::cerr << "Could not open " << proj_name << std::endl;
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string line;
|
|
|
|
bool in_itemgroup = false;
|
|
|
|
while (std::getline(in, line)) {
|
|
|
|
if (in_itemgroup) {
|
|
|
|
if (line.find("</ItemGroup>") == std::string::npos)
|
|
|
|
continue;
|
|
|
|
in_itemgroup = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// strip all remaining line endings
|
|
|
|
const std::string::size_type pos = line.find_last_not_of("\r\n");
|
|
|
|
if (pos != std::string::npos)
|
|
|
|
line.resize(pos+1, '\0');
|
|
|
|
|
|
|
|
outstr += line;
|
|
|
|
outstr += "\r\n";
|
|
|
|
|
|
|
|
if (line.find("<ItemGroup Label=\"SourceFiles\">") != std::string::npos) {
|
|
|
|
in_itemgroup = true;
|
|
|
|
|
|
|
|
source_f(outstr);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (line.find("<ItemGroup Label=\"HeaderFiles\">") != std::string::npos) {
|
|
|
|
in_itemgroup = true;
|
|
|
|
|
|
|
|
header_f(outstr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// strip trailing \r\n
|
|
|
|
{
|
|
|
|
const std::string::size_type pos = outstr.find_last_not_of("\r\n");
|
|
|
|
if (pos != std::string::npos)
|
|
|
|
outstr.resize(pos+1, '\0');
|
|
|
|
}
|
|
|
|
|
|
|
|
// treat as binary to prevent inplicit line ending conversions
|
|
|
|
std::ofstream out(proj_name, std::ios::binary|std::ios::trunc);
|
|
|
|
out << outstr;
|
|
|
|
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
enum ClType { Compile, Include, Precompile, PrecompileNoPCRE };
|
|
|
|
|
|
|
|
static std::string make_vcxproj_cl_entry(const std::string& file, ClType type)
|
|
|
|
{
|
|
|
|
std::string outstr;
|
|
|
|
if (type == Precompile || type == PrecompileNoPCRE) {
|
|
|
|
outstr += R"( <ClCompile Include=")";
|
|
|
|
outstr += file;
|
|
|
|
outstr += R"(">)";
|
|
|
|
outstr += "\r\n";
|
|
|
|
outstr += R"( <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>)";
|
|
|
|
outstr += "\r\n";
|
|
|
|
outstr += R"( <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>)";
|
|
|
|
outstr += "\r\n";
|
|
|
|
if (type == Precompile) {
|
|
|
|
outstr += R"( <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release-PCRE|Win32'">Create</PrecompiledHeader>)";
|
|
|
|
outstr += "\r\n";
|
|
|
|
outstr += R"( <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug-PCRE|Win32'">Create</PrecompiledHeader>)";
|
|
|
|
outstr += "\r\n";
|
|
|
|
}
|
|
|
|
outstr += R"( <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>)";
|
|
|
|
outstr += "\r\n";
|
|
|
|
outstr += R"( <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>)";
|
|
|
|
outstr += "\r\n";
|
|
|
|
if (type == Precompile) {
|
|
|
|
outstr += R"( <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release-PCRE|x64'">Create</PrecompiledHeader>)";
|
|
|
|
outstr += "\r\n";
|
|
|
|
outstr += R"( <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug-PCRE|x64'">Create</PrecompiledHeader>)";
|
|
|
|
outstr += "\r\n";
|
|
|
|
}
|
|
|
|
outstr += " </ClCompile>\r\n";
|
|
|
|
return outstr;
|
|
|
|
}
|
|
|
|
outstr += " <";
|
|
|
|
outstr += (type == Compile) ? "ClCompile" : "ClInclude";
|
|
|
|
outstr += R"( Include=")";
|
|
|
|
outstr += file;
|
|
|
|
outstr += R"(" />)";
|
|
|
|
outstr += "\r\n";
|
|
|
|
return outstr;
|
|
|
|
}
|
|
|
|
|
2010-03-09 08:10:05 +01:00
|
|
|
int main(int argc, char **argv)
|
2010-01-23 09:54:51 +01:00
|
|
|
{
|
2010-03-09 08:10:05 +01:00
|
|
|
const bool release(argc >= 2 && std::string(argv[1]) == "--release");
|
|
|
|
|
2010-01-23 09:54:51 +01:00
|
|
|
// Get files..
|
|
|
|
std::vector<std::string> libfiles;
|
2021-04-18 21:52:14 +02:00
|
|
|
std::string err = getCppFiles(libfiles, "lib/", false);
|
|
|
|
if (!err.empty()) {
|
|
|
|
std::cerr << err << std::endl;
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
2010-01-23 09:54:51 +01:00
|
|
|
|
2016-07-20 12:21:00 +02:00
|
|
|
std::vector<std::string> extfiles;
|
2021-04-18 21:52:14 +02:00
|
|
|
err = getCppFiles(extfiles, "externals/", true);
|
|
|
|
if (!err.empty()) {
|
|
|
|
std::cerr << err << std::endl;
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
2016-07-20 12:21:00 +02:00
|
|
|
|
2010-01-23 09:54:51 +01:00
|
|
|
std::vector<std::string> clifiles;
|
2021-04-18 21:52:14 +02:00
|
|
|
err = getCppFiles(clifiles, "cli/", false);
|
|
|
|
if (!err.empty()) {
|
|
|
|
std::cerr << err << std::endl;
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
2010-01-23 09:54:51 +01:00
|
|
|
|
|
|
|
std::vector<std::string> testfiles;
|
2021-04-18 21:52:14 +02:00
|
|
|
err = getCppFiles(testfiles, "test/", false);
|
|
|
|
if (!err.empty()) {
|
|
|
|
std::cerr << err << std::endl;
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
2014-05-04 12:02:55 +02:00
|
|
|
|
2014-05-03 18:54:48 +02:00
|
|
|
std::vector<std::string> toolsfiles;
|
2021-04-18 21:52:14 +02:00
|
|
|
err = getCppFiles(toolsfiles, "tools/", false);
|
|
|
|
if (!err.empty()) {
|
|
|
|
std::cerr << err << std::endl;
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
2010-01-23 09:54:51 +01:00
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
if (libfiles.empty() && clifiles.empty() && testfiles.empty()) {
|
2010-09-19 13:05:46 +02:00
|
|
|
std::cerr << "No files found. Are you in the correct directory?" << std::endl;
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
2023-01-21 11:55:36 +01:00
|
|
|
// TODO: add files without source via parsing
|
|
|
|
std::vector<std::string> libfiles_h;
|
|
|
|
for (const std::string &libfile : libfiles) {
|
|
|
|
std::string fname(libfile.substr(4));
|
|
|
|
fname.erase(fname.find(".cpp"));
|
|
|
|
libfiles_h.emplace_back(fname + ".h");
|
|
|
|
}
|
|
|
|
libfiles_h.emplace_back("analyzer.h");
|
|
|
|
libfiles_h.emplace_back("calculate.h");
|
|
|
|
libfiles_h.emplace_back("config.h");
|
|
|
|
libfiles_h.emplace_back("precompiled.h");
|
|
|
|
libfiles_h.emplace_back("smallvector.h");
|
|
|
|
libfiles_h.emplace_back("standards.h");
|
|
|
|
libfiles_h.emplace_back("tokenrange.h");
|
|
|
|
libfiles_h.emplace_back("valueptr.h");
|
|
|
|
libfiles_h.emplace_back("version.h");
|
|
|
|
std::sort(libfiles_h.begin(), libfiles_h.end());
|
|
|
|
|
|
|
|
std::vector<std::string> clifiles_h;
|
|
|
|
for (const std::string &clifile : clifiles) {
|
|
|
|
std::string fname(clifile.substr(4));
|
|
|
|
if (fname == "main.cpp")
|
|
|
|
continue;
|
|
|
|
fname.erase(fname.find(".cpp"));
|
|
|
|
clifiles_h.emplace_back(fname + ".h");
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<std::string> testfiles_h;
|
2023-01-27 08:18:32 +01:00
|
|
|
testfiles_h.emplace_back("fixture.h");
|
|
|
|
testfiles_h.emplace_back("helpers.h");
|
2023-01-21 11:55:36 +01:00
|
|
|
testfiles_h.emplace_back("options.h");
|
|
|
|
testfiles_h.emplace_back("precompiled.h");
|
|
|
|
testfiles_h.emplace_back("redirect.h");
|
|
|
|
std::sort(testfiles_h.begin(), testfiles_h.end());
|
|
|
|
|
|
|
|
// TODO: write filter files
|
|
|
|
// Visual Studio projects
|
|
|
|
write_vcxproj("cli/cli.vcxproj", [&](std::string &outstr){
|
|
|
|
for (const std::string &clifile: clifiles) {
|
2023-02-08 21:11:11 +01:00
|
|
|
const std::string c = clifile.substr(4);
|
|
|
|
outstr += make_vcxproj_cl_entry(c, c == "executor.cpp" ? Precompile : Compile);
|
2023-01-21 11:55:36 +01:00
|
|
|
}
|
|
|
|
}, [&](std::string &outstr){
|
|
|
|
for (const std::string &clifile_h: clifiles_h) {
|
|
|
|
outstr += make_vcxproj_cl_entry(clifile_h, Include);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
write_vcxproj("lib/cppcheck.vcxproj", [&](std::string &outstr){
|
|
|
|
outstr += make_vcxproj_cl_entry(R"(..\externals\simplecpp\simplecpp.cpp)", Compile);
|
|
|
|
outstr += make_vcxproj_cl_entry(R"(..\externals\tinyxml2\tinyxml2.cpp)", Compile);
|
|
|
|
|
|
|
|
for (const std::string &libfile: libfiles) {
|
|
|
|
const std::string l = libfile.substr(4);
|
|
|
|
outstr += make_vcxproj_cl_entry(l, l == "check.cpp" ? Precompile : Compile);
|
|
|
|
}
|
|
|
|
}, [&](std::string &outstr){
|
|
|
|
outstr += make_vcxproj_cl_entry(R"(..\externals\simplecpp\simplecpp.h)", Include);
|
|
|
|
outstr += make_vcxproj_cl_entry(R"(..\externals\tinyxml2\tinyxml2.h)", Include);
|
|
|
|
|
|
|
|
for (const std::string &libfile_h: libfiles_h) {
|
|
|
|
outstr += make_vcxproj_cl_entry(libfile_h, Include);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
write_vcxproj("test/testrunner.vcxproj", [&](std::string &outstr){
|
|
|
|
for (const std::string &clifile: clifiles) {
|
|
|
|
if (clifile == "cli/main.cpp")
|
|
|
|
continue;
|
|
|
|
const std::string c = R"(..\cli\)" + clifile.substr(4);
|
|
|
|
outstr += make_vcxproj_cl_entry(c, Compile);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const std::string &testfile: testfiles) {
|
|
|
|
const std::string t = testfile.substr(5);
|
2023-01-27 08:18:32 +01:00
|
|
|
outstr += make_vcxproj_cl_entry(t, t == "fixture.cpp" ? PrecompileNoPCRE : Compile);
|
2023-01-21 11:55:36 +01:00
|
|
|
}
|
|
|
|
}, [&](std::string &outstr){
|
|
|
|
for (const std::string &clifile_h: clifiles_h) {
|
|
|
|
const std::string c = R"(..\cli\)" + clifile_h;
|
|
|
|
outstr += make_vcxproj_cl_entry(c, Include);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const std::string &testfile_h: testfiles_h) {
|
|
|
|
outstr += make_vcxproj_cl_entry(testfile_h, Include);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2010-02-23 21:27:01 +01:00
|
|
|
// QMAKE - lib/lib.pri
|
|
|
|
{
|
|
|
|
std::ofstream fout1("lib/lib.pri");
|
2011-10-13 20:53:06 +02:00
|
|
|
if (fout1.is_open()) {
|
2010-02-23 21:27:01 +01:00
|
|
|
fout1 << "# no manual edits - this file is autogenerated by dmake\n\n";
|
2011-08-18 22:42:19 +02:00
|
|
|
fout1 << "include($$PWD/pcrerules.pri)\n";
|
2016-07-20 12:21:00 +02:00
|
|
|
fout1 << "include($$PWD/../externals/externals.pri)\n";
|
|
|
|
fout1 << "INCLUDEPATH += $$PWD\n";
|
2019-08-14 20:53:51 +02:00
|
|
|
fout1 << "HEADERS += ";
|
2023-01-21 11:55:36 +01:00
|
|
|
for (const std::string &libfile_h : libfiles_h) {
|
|
|
|
fout1 << "$${PWD}/" << libfile_h;
|
|
|
|
if (libfile_h != libfiles_h.back())
|
2019-08-14 20:53:51 +02:00
|
|
|
fout1 << " \\\n" << std::string(11, ' ');
|
2010-02-23 21:27:01 +01:00
|
|
|
}
|
|
|
|
fout1 << "\n\nSOURCES += ";
|
2019-08-14 20:53:51 +02:00
|
|
|
for (const std::string &libfile : libfiles) {
|
|
|
|
fout1 << "$${PWD}/" << libfile.substr(4);
|
|
|
|
if (libfile != libfiles.back())
|
2010-02-23 21:27:01 +01:00
|
|
|
fout1 << " \\\n" << std::string(11, ' ');
|
|
|
|
}
|
|
|
|
fout1 << "\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-19 13:05:46 +02:00
|
|
|
static const char makefile[] = "Makefile";
|
|
|
|
std::ofstream fout(makefile, std::ios_base::trunc);
|
2011-10-13 20:53:06 +02:00
|
|
|
if (!fout.is_open()) {
|
2010-09-19 13:05:46 +02:00
|
|
|
std::cerr << "An error occurred while trying to open "
|
|
|
|
<< makefile
|
|
|
|
<< ".\n";
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
2010-01-23 09:54:51 +01:00
|
|
|
|
2010-12-12 17:26:13 +01:00
|
|
|
fout << "# This file is generated by tools/dmake, do not edit.\n\n";
|
2022-09-09 15:06:40 +02:00
|
|
|
|
|
|
|
fout << "ifndef VERBOSE\n"
|
|
|
|
<< " VERBOSE=\n"
|
|
|
|
<< "endif\n";
|
|
|
|
|
2011-10-17 20:18:36 +02:00
|
|
|
fout << "# To compile with rules, use 'make HAVE_RULES=yes'\n";
|
|
|
|
makeConditionalVariable(fout, "HAVE_RULES", "no");
|
2010-12-12 17:26:13 +01:00
|
|
|
|
2022-09-09 15:06:40 +02:00
|
|
|
fout << "ifdef SRCDIR\n"
|
|
|
|
<< " $(error Usage of SRCDIR to activate match compiler has been removed. Use MATCHCOMPILER=yes instead.)\n"
|
|
|
|
<< "endif\n";
|
|
|
|
// avoid undefined variable
|
|
|
|
fout << "ifndef MATCHCOMPILER\n"
|
|
|
|
<< " MATCHCOMPILER=\n"
|
2019-06-23 13:43:09 +02:00
|
|
|
<< "endif\n";
|
2022-05-22 15:27:32 +02:00
|
|
|
// TODO: bail out when matchcompiler.py fails (i.e. invalid PYTHON_INTERPRETER specified)
|
|
|
|
// TODO: handle "PYTHON_INTERPRETER="
|
2022-09-09 15:06:40 +02:00
|
|
|
// use match compiler..
|
|
|
|
fout << "# use match compiler\n";
|
2019-06-23 13:43:09 +02:00
|
|
|
fout << "ifeq ($(MATCHCOMPILER),yes)\n"
|
2019-10-08 10:55:40 +02:00
|
|
|
<< " # Find available Python interpreter\n"
|
2022-05-22 15:27:32 +02:00
|
|
|
<< " ifeq ($(PYTHON_INTERPRETER),)\n"
|
2022-02-16 07:06:04 +01:00
|
|
|
<< " PYTHON_INTERPRETER := $(shell which python3)\n"
|
|
|
|
<< " endif\n"
|
2022-05-22 15:27:32 +02:00
|
|
|
<< " ifeq ($(PYTHON_INTERPRETER),)\n"
|
2022-02-11 19:37:32 +01:00
|
|
|
<< " PYTHON_INTERPRETER := $(shell which python)\n"
|
2019-10-08 10:55:40 +02:00
|
|
|
<< " endif\n"
|
2022-05-22 15:27:32 +02:00
|
|
|
<< " ifeq ($(PYTHON_INTERPRETER),)\n"
|
2019-10-08 10:55:40 +02:00
|
|
|
<< " $(error Did not find a Python interpreter)\n"
|
|
|
|
<< " endif\n"
|
2013-05-15 13:04:19 +02:00
|
|
|
<< " ifdef VERIFY\n"
|
2019-10-08 10:55:40 +02:00
|
|
|
<< " matchcompiler_S := $(shell $(PYTHON_INTERPRETER) tools/matchcompiler.py --verify)\n"
|
2013-05-15 13:04:19 +02:00
|
|
|
<< " else\n"
|
2019-10-08 10:55:40 +02:00
|
|
|
<< " matchcompiler_S := $(shell $(PYTHON_INTERPRETER) tools/matchcompiler.py)\n"
|
2013-05-15 13:04:19 +02:00
|
|
|
<< " endif\n"
|
2019-06-23 13:43:09 +02:00
|
|
|
<< " libcppdir:=build\n"
|
|
|
|
<< "else\n"
|
|
|
|
<< " libcppdir:=lib\n"
|
2012-12-02 12:36:55 +01:00
|
|
|
<< "endif\n\n";
|
|
|
|
|
2022-09-09 15:06:40 +02:00
|
|
|
// avoid undefined variable
|
|
|
|
fout << "ifndef CPPFLAGS\n"
|
|
|
|
<< " CPPFLAGS=\n"
|
|
|
|
<< "endif\n\n";
|
|
|
|
|
2019-08-17 10:53:07 +02:00
|
|
|
// explicit files dir..
|
|
|
|
fout << "ifdef FILESDIR\n"
|
2022-09-09 15:06:40 +02:00
|
|
|
<< " CPPFLAGS+=-DFILESDIR=\\\"$(FILESDIR)\\\"\n"
|
2013-12-28 12:15:08 +01:00
|
|
|
<< "endif\n\n";
|
|
|
|
|
2014-03-30 20:50:03 +02:00
|
|
|
// enable backtrac
|
|
|
|
fout << "RDYNAMIC=-rdynamic\n";
|
|
|
|
|
2014-03-31 03:06:57 +02:00
|
|
|
// The _GLIBCXX_DEBUG doesn't work in cygwin or other Win32 systems.
|
|
|
|
fout << "# Set the CPPCHK_GLIBCXX_DEBUG flag. This flag is not used in release Makefiles.\n"
|
2012-02-17 20:12:41 +01:00
|
|
|
<< "# The _GLIBCXX_DEBUG define doesn't work in Cygwin or other Win32 systems.\n"
|
2012-02-12 03:30:58 +01:00
|
|
|
<< "ifndef COMSPEC\n"
|
2022-09-09 15:06:40 +02:00
|
|
|
<< " ifeq ($(VERBOSE),1)\n"
|
|
|
|
<< " $(info COMSPEC not found)\n"
|
|
|
|
<< " endif\n"
|
2012-02-12 03:30:58 +01:00
|
|
|
<< " ifdef ComSpec\n"
|
2022-09-09 15:06:40 +02:00
|
|
|
<< " ifeq ($(VERBOSE),1)\n"
|
|
|
|
<< " $(info ComSpec found)\n"
|
|
|
|
<< " endif\n"
|
2012-02-12 03:30:58 +01:00
|
|
|
<< " #### ComSpec is defined on some WIN32's.\n"
|
2022-02-16 07:06:04 +01:00
|
|
|
<< " WINNT=1\n"
|
|
|
|
<< "\n"
|
2022-09-09 15:06:40 +02:00
|
|
|
<< " ifeq ($(VERBOSE),1)\n"
|
|
|
|
<< " $(info PATH=$(PATH))\n"
|
|
|
|
<< " endif\n"
|
|
|
|
<< "\n"
|
2022-02-16 07:06:04 +01:00
|
|
|
<< " ifneq (,$(findstring /cygdrive/,$(PATH)))\n"
|
2022-09-09 15:06:40 +02:00
|
|
|
<< " ifeq ($(VERBOSE),1)\n"
|
|
|
|
<< " $(info /cygdrive/ found in PATH)\n"
|
|
|
|
<< " endif\n"
|
2022-02-16 07:06:04 +01:00
|
|
|
<< " CYGWIN=1\n"
|
|
|
|
<< " endif # CYGWIN\n"
|
2012-02-12 03:30:58 +01:00
|
|
|
<< " endif # ComSpec\n"
|
|
|
|
<< "endif # COMSPEC\n"
|
|
|
|
<< "\n"
|
2022-02-16 07:06:04 +01:00
|
|
|
<< "ifdef WINNT\n"
|
2022-09-09 15:06:40 +02:00
|
|
|
<< " ifeq ($(VERBOSE),1)\n"
|
|
|
|
<< " $(info WINNT found)\n"
|
|
|
|
<< " endif\n"
|
2012-02-12 03:30:58 +01:00
|
|
|
<< " #### Maybe Windows\n"
|
|
|
|
<< " ifndef CPPCHK_GLIBCXX_DEBUG\n"
|
|
|
|
<< " CPPCHK_GLIBCXX_DEBUG=\n"
|
|
|
|
<< " endif # !CPPCHK_GLIBCXX_DEBUG\n"
|
2013-02-08 12:10:07 +01:00
|
|
|
<< "\n"
|
2022-09-09 15:06:40 +02:00
|
|
|
<< " ifeq ($(VERBOSE),1)\n"
|
|
|
|
<< " $(info MSYSTEM=$(MSYSTEM))\n"
|
2013-02-08 12:10:07 +01:00
|
|
|
<< " endif\n"
|
2022-09-09 15:06:40 +02:00
|
|
|
<< "\n"
|
|
|
|
<< " ifneq ($(MSYSTEM),MINGW32 MINGW64)\n"
|
|
|
|
<< " RDYNAMIC=\n"
|
|
|
|
<< " endif\n"
|
|
|
|
<< "\n"
|
|
|
|
<< " LDFLAGS+=-lshlwapi\n"
|
2022-02-16 07:06:04 +01:00
|
|
|
<< "else # !WINNT\n"
|
2022-09-09 15:06:40 +02:00
|
|
|
<< " ifeq ($(VERBOSE),1)\n"
|
|
|
|
<< " $(info WINNT not found)\n"
|
|
|
|
<< " endif\n"
|
|
|
|
<< "\n"
|
2012-02-12 03:30:58 +01:00
|
|
|
<< " uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not')\n"
|
|
|
|
<< "\n"
|
2022-09-09 15:06:40 +02:00
|
|
|
<< " ifeq ($(VERBOSE),1)\n"
|
|
|
|
<< " $(info uname_S=$(uname_S))\n"
|
|
|
|
<< " endif\n"
|
|
|
|
<< "\n"
|
2012-02-12 03:30:58 +01:00
|
|
|
<< " ifeq ($(uname_S),Linux)\n"
|
|
|
|
<< " ifndef CPPCHK_GLIBCXX_DEBUG\n"
|
|
|
|
<< " CPPCHK_GLIBCXX_DEBUG=-D_GLIBCXX_DEBUG\n"
|
|
|
|
<< " endif # !CPPCHK_GLIBCXX_DEBUG\n"
|
|
|
|
<< " endif # Linux\n"
|
|
|
|
<< "\n"
|
|
|
|
<< " ifeq ($(uname_S),GNU/kFreeBSD)\n"
|
|
|
|
<< " ifndef CPPCHK_GLIBCXX_DEBUG\n"
|
|
|
|
<< " CPPCHK_GLIBCXX_DEBUG=-D_GLIBCXX_DEBUG\n"
|
|
|
|
<< " endif # !CPPCHK_GLIBCXX_DEBUG\n"
|
|
|
|
<< " endif # GNU/kFreeBSD\n"
|
|
|
|
<< "\n"
|
2022-09-09 15:06:40 +02:00
|
|
|
<< " LDFLAGS+=-pthread\n"
|
2022-07-08 16:42:57 +02:00
|
|
|
<< "\n"
|
2022-02-16 07:06:04 +01:00
|
|
|
<< "endif # WINNT\n"
|
2012-02-12 03:30:58 +01:00
|
|
|
<< "\n";
|
|
|
|
|
2014-04-24 22:22:43 +02:00
|
|
|
// tinymxl2 requires __STRICT_ANSI__ to be undefined to compile under CYGWIN.
|
2022-02-16 07:06:04 +01:00
|
|
|
fout << "ifdef CYGWIN\n"
|
2022-09-09 15:06:40 +02:00
|
|
|
<< " ifeq ($(VERBOSE),1)\n"
|
|
|
|
<< " $(info CYGWIN found)\n"
|
|
|
|
<< " endif\n"
|
|
|
|
<< "\n"
|
|
|
|
<< " # Set the flag to address compile time warnings\n"
|
2022-02-16 07:06:04 +01:00
|
|
|
<< " # with tinyxml2 and Cygwin.\n"
|
2022-09-09 15:06:40 +02:00
|
|
|
<< " CPPFLAGS+=-U__STRICT_ANSI__\n"
|
2022-02-16 07:06:04 +01:00
|
|
|
<< " \n"
|
|
|
|
<< " # Increase stack size for Cygwin builds to avoid segmentation fault in limited recursive tests.\n"
|
|
|
|
<< " CXXFLAGS+=-Wl,--stack,8388608\n"
|
|
|
|
<< "endif # CYGWIN\n"
|
2014-04-24 22:22:43 +02:00
|
|
|
<< "\n";
|
|
|
|
|
2015-10-05 04:51:06 +02:00
|
|
|
// skip "-D_GLIBCXX_DEBUG" if clang, since it breaks the build
|
|
|
|
makeConditionalVariable(fout, "CXX", "g++");
|
2017-06-16 12:56:29 +02:00
|
|
|
fout << "ifeq (clang++, $(findstring clang++,$(CXX)))\n"
|
2015-10-05 04:51:06 +02:00
|
|
|
<< " CPPCHK_GLIBCXX_DEBUG=\n"
|
|
|
|
<< "endif\n";
|
|
|
|
|
2010-03-09 08:10:05 +01:00
|
|
|
// Makefile settings..
|
2011-10-13 20:53:06 +02:00
|
|
|
if (release) {
|
2018-04-09 22:28:41 +02:00
|
|
|
makeConditionalVariable(fout, "CXXFLAGS", "-std=c++0x -O2 -DNDEBUG -Wall -Wno-sign-compare");
|
2011-10-13 20:53:06 +02:00
|
|
|
} else {
|
2010-05-08 12:57:44 +02:00
|
|
|
// TODO: add more compiler warnings.
|
2011-10-30 18:34:49 +01:00
|
|
|
// -Wlogical-op : doesn't work on older GCC
|
|
|
|
// -Wsign-conversion : too many warnings
|
|
|
|
// -Wunreachable-code : some GCC versions report lots of warnings
|
2010-09-19 13:05:46 +02:00
|
|
|
makeConditionalVariable(fout, "CXXFLAGS",
|
2011-10-24 02:52:55 +02:00
|
|
|
"-pedantic "
|
2010-09-19 13:05:46 +02:00
|
|
|
"-Wall "
|
|
|
|
"-Wextra "
|
2011-10-24 02:52:55 +02:00
|
|
|
"-Wcast-qual "
|
2015-04-15 11:32:52 +02:00
|
|
|
// "-Wconversion " // danmar: gives fp. for instance: unsigned int sizeof_pointer = sizeof(void *);
|
2019-04-19 14:52:30 +02:00
|
|
|
"-Wno-deprecated-declarations "
|
2011-10-24 02:52:55 +02:00
|
|
|
"-Wfloat-equal "
|
2012-01-03 15:10:32 +01:00
|
|
|
// "-Wlogical-op "
|
2011-10-22 15:00:44 +02:00
|
|
|
"-Wmissing-declarations "
|
2011-10-24 02:52:55 +02:00
|
|
|
"-Wmissing-format-attribute "
|
|
|
|
"-Wno-long-long "
|
2015-06-30 20:38:15 +02:00
|
|
|
// "-Woverloaded-virtual " // danmar: we get fp when overloading analyseWholeProgram()
|
2011-10-24 02:52:55 +02:00
|
|
|
"-Wpacked "
|
|
|
|
"-Wredundant-decls "
|
2019-05-17 09:31:41 +02:00
|
|
|
"-Wundef "
|
2018-11-19 09:25:59 +01:00
|
|
|
"-Wno-shadow "
|
2012-01-03 15:10:32 +01:00
|
|
|
// "-Wsign-conversion "
|
2016-05-07 19:38:40 +02:00
|
|
|
// "-Wsign-promo "
|
2014-06-13 15:46:43 +02:00
|
|
|
"-Wno-missing-field-initializers "
|
|
|
|
"-Wno-missing-braces "
|
2011-10-24 07:09:14 +02:00
|
|
|
// "-Wunreachable-code "
|
2018-11-03 07:34:27 +01:00
|
|
|
"-Wno-sign-compare " // danmar: I don't like this warning, it's very rarely a bug
|
2016-01-08 11:40:54 +01:00
|
|
|
"-Wno-multichar "
|
2011-11-29 20:35:56 +01:00
|
|
|
"$(CPPCHK_GLIBCXX_DEBUG) "
|
2010-09-19 13:05:46 +02:00
|
|
|
"-g");
|
2010-05-08 12:57:44 +02:00
|
|
|
}
|
2011-04-19 20:53:40 +02:00
|
|
|
|
2017-06-16 12:56:29 +02:00
|
|
|
fout << "ifeq (g++, $(findstring g++,$(CXX)))\n"
|
2022-08-16 22:12:01 +02:00
|
|
|
<< " override CXXFLAGS += -std=gnu++0x -pipe\n"
|
2017-06-16 12:56:29 +02:00
|
|
|
<< "else ifeq (clang++, $(findstring clang++,$(CXX)))\n"
|
2015-11-10 21:07:06 +01:00
|
|
|
<< " override CXXFLAGS += -std=c++0x\n"
|
2015-11-14 07:53:34 +01:00
|
|
|
<< "else ifeq ($(CXX), c++)\n"
|
|
|
|
<< " ifeq ($(shell uname -s), Darwin)\n"
|
|
|
|
<< " override CXXFLAGS += -std=c++0x\n"
|
|
|
|
<< " endif\n"
|
2015-11-10 21:07:06 +01:00
|
|
|
<< "endif\n"
|
|
|
|
<< "\n";
|
|
|
|
|
2011-04-19 20:53:40 +02:00
|
|
|
fout << "ifeq ($(HAVE_RULES),yes)\n"
|
2022-11-25 15:11:57 +01:00
|
|
|
<< " PCRE_CONFIG = $(shell which pcre-config)\n"
|
|
|
|
<< " ifeq ($(PCRE_CONFIG),)\n"
|
|
|
|
<< " $(error Did not find pcre-config)\n"
|
|
|
|
<< " endif\n"
|
|
|
|
<< " override CXXFLAGS += -DHAVE_RULES -DTIXML_USE_STL $(shell $(PCRE_CONFIG) --cflags)\n"
|
2011-06-19 19:56:12 +02:00
|
|
|
<< " ifdef LIBS\n"
|
2022-11-25 15:11:57 +01:00
|
|
|
<< " LIBS += $(shell $(PCRE_CONFIG) --libs)\n"
|
2011-04-22 14:20:38 +02:00
|
|
|
<< " else\n"
|
2022-11-25 15:11:57 +01:00
|
|
|
<< " LIBS=$(shell $(PCRE_CONFIG) --libs)\n"
|
2011-04-19 20:53:40 +02:00
|
|
|
<< " endif\n"
|
|
|
|
<< "endif\n\n";
|
|
|
|
|
2010-09-19 13:05:46 +02:00
|
|
|
makeConditionalVariable(fout, "PREFIX", "/usr");
|
2020-11-16 09:11:08 +01:00
|
|
|
makeConditionalVariable(fout, "INCLUDE_FOR_LIB", "-Ilib -isystem externals -isystem externals/picojson -isystem externals/simplecpp -isystem externals/tinyxml2");
|
|
|
|
makeConditionalVariable(fout, "INCLUDE_FOR_CLI", "-Ilib -isystem externals/simplecpp -isystem externals/tinyxml2");
|
|
|
|
makeConditionalVariable(fout, "INCLUDE_FOR_TEST", "-Ilib -Icli -isystem externals/simplecpp -isystem externals/tinyxml2");
|
2011-02-11 19:31:37 +01:00
|
|
|
|
2010-09-19 13:05:46 +02:00
|
|
|
fout << "BIN=$(DESTDIR)$(PREFIX)/bin\n\n";
|
|
|
|
fout << "# For 'make man': sudo apt-get install xsltproc docbook-xsl docbook-xml on Linux\n";
|
2015-08-17 17:32:56 +02:00
|
|
|
fout << "DB2MAN?=/usr/share/sgml/docbook/stylesheet/xsl/nwalsh/manpages/docbook.xsl\n";
|
2010-02-23 18:37:46 +01:00
|
|
|
fout << "XP=xsltproc -''-nonet -''-param man.charmap.use.subset \"0\"\n";
|
|
|
|
fout << "MAN_SOURCE=man/cppcheck.1.xml\n\n";
|
2010-01-23 09:54:51 +01:00
|
|
|
|
|
|
|
fout << "\n###### Object Files\n\n";
|
2019-08-14 20:53:51 +02:00
|
|
|
fout << "LIBOBJ = " << objfiles(libfiles) << "\n\n";
|
|
|
|
fout << "EXTOBJ = " << objfiles(extfiles) << "\n\n";
|
|
|
|
fout << "CLIOBJ = " << objfiles(clifiles) << "\n\n";
|
|
|
|
fout << "TESTOBJ = " << objfiles(testfiles) << "\n\n";
|
2010-01-23 09:54:51 +01:00
|
|
|
|
2017-05-20 22:27:49 +02:00
|
|
|
fout << ".PHONY: run-dmake tags\n\n";
|
2010-01-23 09:54:51 +01:00
|
|
|
fout << "\n###### Targets\n\n";
|
2011-01-31 08:18:35 +01:00
|
|
|
fout << "cppcheck: $(LIBOBJ) $(CLIOBJ) $(EXTOBJ)\n";
|
2017-08-22 23:01:18 +02:00
|
|
|
fout << "\t$(CXX) $(CPPFLAGS) $(CXXFLAGS) -o $@ $^ $(LIBS) $(LDFLAGS) $(RDYNAMIC)\n\n";
|
2011-01-31 08:18:35 +01:00
|
|
|
fout << "all:\tcppcheck testrunner\n\n";
|
2022-08-16 22:03:44 +02:00
|
|
|
fout << "testrunner: $(TESTOBJ) $(LIBOBJ) $(EXTOBJ) cli/executor.o cli/processexecutor.o cli/threadexecutor.o cli/cmdlineparser.o cli/cppcheckexecutor.o cli/cppcheckexecutorseh.o cli/cppcheckexecutorsig.o cli/stacktrace.o cli/filelister.o\n";
|
2017-08-22 23:01:18 +02:00
|
|
|
fout << "\t$(CXX) $(CPPFLAGS) $(CXXFLAGS) -o $@ $^ $(LIBS) $(LDFLAGS) $(RDYNAMIC)\n\n";
|
2010-01-23 09:54:51 +01:00
|
|
|
fout << "test:\tall\n";
|
|
|
|
fout << "\t./testrunner\n\n";
|
2010-09-26 05:29:23 +02:00
|
|
|
fout << "check:\tall\n";
|
2017-01-29 15:41:26 +01:00
|
|
|
fout << "\t./testrunner -q\n\n";
|
2019-01-05 11:12:32 +01:00
|
|
|
fout << "checkcfg:\tcppcheck validateCFG\n";
|
2015-01-27 19:31:41 +01:00
|
|
|
fout << "\t./test/cfg/runtests.sh\n\n";
|
2020-05-19 20:14:29 +02:00
|
|
|
fout << "dmake:\ttools/dmake.o cli/filelister.o $(libcppdir)/pathmatch.o $(libcppdir)/path.o $(libcppdir)/utils.o externals/simplecpp/simplecpp.o\n";
|
2017-08-22 23:01:18 +02:00
|
|
|
fout << "\t$(CXX) $(CXXFLAGS) -o $@ $^ $(LDFLAGS)\n\n";
|
2015-09-05 17:12:15 +02:00
|
|
|
fout << "run-dmake: dmake\n";
|
2014-03-31 13:56:07 +02:00
|
|
|
fout << "\t./dmake\n\n";
|
2010-01-23 09:54:51 +01:00
|
|
|
fout << "clean:\n";
|
2022-05-22 15:27:32 +02:00
|
|
|
fout << "\trm -f build/*.cpp build/*.o lib/*.o cli/*.o test/*.o tools/*.o externals/*/*.o testrunner dmake cppcheck cppcheck.exe cppcheck.1\n\n";
|
2010-09-22 20:25:27 +02:00
|
|
|
fout << "man:\tman/cppcheck.1\n\n";
|
|
|
|
fout << "man/cppcheck.1:\t$(MAN_SOURCE)\n\n";
|
2010-02-23 18:37:46 +01:00
|
|
|
fout << "\t$(XP) $(DB2MAN) $(MAN_SOURCE)\n\n";
|
2010-10-12 14:04:06 +02:00
|
|
|
fout << "tags:\n";
|
2022-12-18 19:36:37 +01:00
|
|
|
fout << "\tctags -R --exclude=doxyoutput --exclude=test/cfg cli externals gui lib test\n\n";
|
2011-01-31 08:18:35 +01:00
|
|
|
fout << "install: cppcheck\n";
|
2010-02-23 18:37:46 +01:00
|
|
|
fout << "\tinstall -d ${BIN}\n";
|
2013-10-12 12:26:27 +02:00
|
|
|
fout << "\tinstall cppcheck ${BIN}\n";
|
2014-05-17 11:05:42 +02:00
|
|
|
fout << "\tinstall htmlreport/cppcheck-htmlreport ${BIN}\n";
|
2019-08-17 10:53:07 +02:00
|
|
|
fout << "ifdef FILESDIR\n";
|
|
|
|
fout << "\tinstall -d ${DESTDIR}${FILESDIR}\n";
|
|
|
|
fout << "\tinstall -d ${DESTDIR}${FILESDIR}/addons\n";
|
|
|
|
fout << "\tinstall -m 644 addons/*.py ${DESTDIR}${FILESDIR}/addons\n";
|
|
|
|
fout << "\tinstall -d ${DESTDIR}${FILESDIR}/cfg\n";
|
|
|
|
fout << "\tinstall -m 644 cfg/*.cfg ${DESTDIR}${FILESDIR}/cfg\n";
|
|
|
|
fout << "\tinstall -d ${DESTDIR}${FILESDIR}/platforms\n";
|
|
|
|
fout << "\tinstall -m 644 platforms/*.xml ${DESTDIR}${FILESDIR}/platforms\n";
|
|
|
|
fout << "else\n";
|
|
|
|
fout << "\t$(error FILESDIR must be set!)\n";
|
|
|
|
fout << "endif\n";
|
|
|
|
fout << "\n";
|
2018-10-19 09:49:44 +02:00
|
|
|
fout << "uninstall:\n";
|
|
|
|
fout << "\t@if test -d ${BIN}; then \\\n";
|
2019-08-17 10:53:07 +02:00
|
|
|
fout << "\t files=\"cppcheck cppcheck-htmlreport\"; \\\n";
|
2018-10-19 09:49:44 +02:00
|
|
|
fout << "\t echo '(' cd ${BIN} '&&' rm -f $$files ')'; \\\n";
|
|
|
|
fout << "\t ( cd ${BIN} && rm -f $$files ); \\\n";
|
|
|
|
fout << "\tfi\n";
|
2019-08-17 10:53:07 +02:00
|
|
|
fout << "ifdef FILESDIR \n";
|
|
|
|
fout << "\t@if test -d ${DESTDIR}${FILESDIR}; then \\\n";
|
|
|
|
fout << "\t echo rm -rf ${DESTDIR}${FILESDIR}; \\\n";
|
|
|
|
fout << "\t rm -rf ${DESTDIR}${FILESDIR}; \\\n";
|
|
|
|
fout << "\tfi\n";
|
|
|
|
fout << "endif\n";
|
2018-10-19 09:49:44 +02:00
|
|
|
fout << "ifdef CFGDIR \n";
|
|
|
|
fout << "\t@if test -d ${DESTDIR}${CFGDIR}; then \\\n";
|
|
|
|
fout << "\t files=\"`cd cfg 2>/dev/null && ls`\"; \\\n";
|
|
|
|
fout << "\t if test -n \"$$files\"; then \\\n";
|
|
|
|
fout << "\t echo '(' cd ${DESTDIR}${CFGDIR} '&&' rm -f $$files ')'; \\\n";
|
|
|
|
fout << "\t ( cd ${DESTDIR}${CFGDIR} && rm -f $$files ); \\\n";
|
|
|
|
fout << "\t fi; \\\n";
|
|
|
|
fout << "\tfi\n";
|
|
|
|
fout << "endif\n\n";
|
2017-05-24 00:24:06 +02:00
|
|
|
fout << "# Validation of library files:\n";
|
|
|
|
fout << "ConfigFiles := $(wildcard cfg/*.cfg)\n";
|
|
|
|
fout << "ConfigFilesCHECKED := $(patsubst %.cfg,%.checked,$(ConfigFiles))\n";
|
|
|
|
fout << ".PHONY: validateCFG\n";
|
|
|
|
fout << "%.checked:%.cfg\n";
|
|
|
|
fout << "\txmllint --noout --relaxng cfg/cppcheck-cfg.rng $<\n";
|
2019-11-17 16:25:10 +01:00
|
|
|
fout << "validateCFG: ${ConfigFilesCHECKED}\n";
|
|
|
|
fout << "\txmllint --noout cfg/cppcheck-cfg.rng\n\n";
|
2018-02-15 20:35:12 +01:00
|
|
|
fout << "# Validation of platforms files:\n";
|
|
|
|
fout << "PlatformFiles := $(wildcard platforms/*.xml)\n";
|
|
|
|
fout << "PlatformFilesCHECKED := $(patsubst %.xml,%.checked,$(PlatformFiles))\n";
|
|
|
|
fout << ".PHONY: validatePlatforms\n";
|
|
|
|
fout << "%.checked:%.xml\n";
|
|
|
|
fout << "\txmllint --noout --relaxng platforms/cppcheck-platforms.rng $<\n";
|
2022-08-06 19:56:32 +02:00
|
|
|
fout << "validatePlatforms: ${PlatformFilesCHECKED}\n";
|
|
|
|
fout << "\txmllint --noout platforms/cppcheck-platforms.rng\n";
|
|
|
|
fout << "\n";
|
2018-05-17 12:46:15 +02:00
|
|
|
fout << "# Validate XML output (to detect regressions)\n";
|
|
|
|
fout << "/tmp/errorlist.xml: cppcheck\n";
|
2018-09-24 13:13:05 +02:00
|
|
|
fout << "\t./cppcheck --errorlist >$@\n";
|
2018-05-24 16:12:43 +02:00
|
|
|
fout << "/tmp/example.xml: cppcheck\n";
|
2020-05-15 17:05:55 +02:00
|
|
|
fout << "\t./cppcheck --xml --enable=all --inconclusive --max-configs=1 samples 2>/tmp/example.xml\n";
|
2018-05-24 16:12:43 +02:00
|
|
|
fout << "createXMLExamples:/tmp/errorlist.xml /tmp/example.xml\n";
|
2018-06-06 15:25:09 +02:00
|
|
|
fout << ".PHONY: validateXML\n";
|
|
|
|
fout << "validateXML: createXMLExamples\n";
|
2019-12-02 22:03:59 +01:00
|
|
|
fout << "\txmllint --noout cppcheck-errors.rng\n";
|
2018-06-06 15:25:09 +02:00
|
|
|
fout << "\txmllint --noout --relaxng cppcheck-errors.rng /tmp/errorlist.xml\n";
|
|
|
|
fout << "\txmllint --noout --relaxng cppcheck-errors.rng /tmp/example.xml\n";
|
2018-10-22 13:14:48 +02:00
|
|
|
fout << "\ncheckCWEEntries: /tmp/errorlist.xml\n";
|
2022-05-22 15:27:32 +02:00
|
|
|
// TODO: handle "PYTHON_INTERPRETER="
|
|
|
|
fout << "\t$(eval PYTHON_INTERPRETER := $(if $(PYTHON_INTERPRETER),$(PYTHON_INTERPRETER),$(shell which python3)))\n";
|
|
|
|
fout << "\t$(eval PYTHON_INTERPRETER := $(if $(PYTHON_INTERPRETER),$(PYTHON_INTERPRETER),$(shell which python)))\n";
|
|
|
|
fout << "\t$(eval PYTHON_INTERPRETER := $(if $(PYTHON_INTERPRETER),$(PYTHON_INTERPRETER),$(error Did not find a Python interpreter)))\n";
|
|
|
|
fout << "\t$(PYTHON_INTERPRETER) tools/listErrorsWithoutCWE.py -F /tmp/errorlist.xml\n";
|
2021-01-05 17:51:32 +01:00
|
|
|
fout << ".PHONY: validateRules\n";
|
|
|
|
fout << "validateRules:\n";
|
2022-06-22 00:03:18 +02:00
|
|
|
fout << "\txmllint --noout rules/*.xml\n";
|
2010-01-23 09:54:51 +01:00
|
|
|
|
|
|
|
fout << "\n###### Build\n\n";
|
|
|
|
|
2011-03-25 07:59:48 +01:00
|
|
|
compilefiles(fout, libfiles, "${INCLUDE_FOR_LIB}");
|
|
|
|
compilefiles(fout, clifiles, "${INCLUDE_FOR_CLI}");
|
|
|
|
compilefiles(fout, testfiles, "${INCLUDE_FOR_TEST}");
|
2022-07-10 10:57:29 +02:00
|
|
|
compilefiles(fout, extfiles, emptyString);
|
2014-05-03 18:54:48 +02:00
|
|
|
compilefiles(fout, toolsfiles, "${INCLUDE_FOR_LIB}");
|
2010-01-23 09:54:51 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|