2010-01-23 09:54:51 +01:00
|
|
|
/*
|
|
|
|
* Cppcheck - A tool for static C/C++ code analysis
|
2015-01-03 12:14:58 +01:00
|
|
|
* Copyright (C) 2007-2015 Daniel Marjamäki and 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>
|
|
|
|
#include <fstream>
|
|
|
|
#include <iostream>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
2011-02-09 00:06:51 +01:00
|
|
|
#include <sstream>
|
2010-03-11 21:30:06 +01:00
|
|
|
|
2011-03-20 14:25:11 +01:00
|
|
|
#include "../cli/filelister.h"
|
2015-07-23 14:52:44 +02:00
|
|
|
#include "../cli/pathmatch.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)
|
2012-12-10 09:43:07 +01:00
|
|
|
filename = "$(SRCDIR)" + 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
|
|
|
{
|
|
|
|
cppfile.erase(cppfile.rfind("."));
|
2012-12-02 12:36:55 +01:00
|
|
|
return builddir(cppfile + ".o");
|
2010-01-23 09:54:51 +01:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
|
|
|
// Is the dependency already included?
|
2010-04-02 07:30:58 +02:00
|
|
|
if (std::find(depfiles.begin(), depfiles.end(), filename) != depfiles.end())
|
2010-01-23 09:54:51 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
std::ifstream f(filename.c_str());
|
2011-10-13 20:53:06 +02:00
|
|
|
if (! f.is_open()) {
|
2010-04-02 07:30:58 +02:00
|
|
|
if (filename.compare(0, 4, "cli/") == 0 || filename.compare(0, 5, "test/") == 0)
|
2010-01-23 09:54:51 +01:00
|
|
|
getDeps("lib" + filename.substr(filename.find("/")), depfiles);
|
|
|
|
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);
|
2010-04-02 07:30:58 +02:00
|
|
|
if (path.find("/") != std::string::npos)
|
2010-01-23 09:54:51 +01:00
|
|
|
path.erase(1 + path.rfind("/"));
|
|
|
|
|
|
|
|
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 \"");
|
2010-04-02 07:30:58 +02:00
|
|
|
if (pos1 == std::string::npos)
|
2010-01-23 09:54:51 +01:00
|
|
|
continue;
|
|
|
|
pos1 += 10;
|
|
|
|
|
|
|
|
std::string::size_type pos2 = line.find("\"", pos1);
|
|
|
|
std::string hfile(path + line.substr(pos1, pos2 - pos1));
|
2012-09-29 17:28:14 +02:00
|
|
|
if (hfile.find("/../") != std::string::npos) // TODO: Ugly fix
|
2010-01-23 09:54:51 +01:00
|
|
|
hfile.erase(0, 4 + hfile.find("/../"));
|
|
|
|
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
|
|
|
{
|
2011-10-13 20:53:06 +02:00
|
|
|
for (unsigned int i = 0; i < files.size(); ++i) {
|
2010-01-23 09:54:51 +01:00
|
|
|
fout << objfile(files[i]) << ": " << files[i];
|
|
|
|
std::vector<std::string> depfiles;
|
2014-02-15 07:52:17 +01:00
|
|
|
depfiles.push_back("lib/cxx11emu.h");
|
2010-01-23 09:54:51 +01:00
|
|
|
getDeps(files[i], depfiles);
|
2010-04-02 07:30:58 +02:00
|
|
|
for (unsigned int dep = 0; dep < depfiles.size(); ++dep)
|
2010-01-23 09:54:51 +01:00
|
|
|
fout << " " << depfiles[dep];
|
2015-11-08 12:52:56 +01:00
|
|
|
fout << "\n\t$(CXX) " << args << " $(CPPFLAGS) $(CFG) $(CXXFLAGS) $(UNDEF_STRICT_ANSI) -c -o " << objfile(files[i]) << " " << builddir(files[i]) << "\n\n";
|
2010-01-23 09:54:51 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-05 06:48:44 +01:00
|
|
|
static void 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);
|
|
|
|
FileLister::addFiles(filemap, path, extra, recursive, matcher);
|
2012-02-26 10:18:21 +01:00
|
|
|
|
|
|
|
// add *.cpp files to the "files" vector..
|
|
|
|
for (std::map<std::string,size_t>::const_iterator it = filemap.begin(); it != filemap.end(); ++it) {
|
|
|
|
if (it->first.find(".cpp") != std::string::npos)
|
|
|
|
files.push_back(it->first);
|
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";
|
|
|
|
}
|
|
|
|
|
2011-02-09 00:06:51 +01:00
|
|
|
static std::string getLibName(const std::string &path)
|
|
|
|
{
|
|
|
|
// path can be e.g. "externals/foo/foo.cpp" then returned
|
|
|
|
// library name is "FOO".
|
|
|
|
std::string libName = path.substr(path.find('/')+1);
|
|
|
|
libName = libName.substr(0, libName.find('/'));
|
|
|
|
std::transform(libName.begin(), libName.end(),libName.begin(), ::toupper);
|
|
|
|
return libName;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void makeExtObj(std::ostream &fout, const std::vector<std::string> &externalfiles)
|
|
|
|
{
|
|
|
|
bool start = true;
|
|
|
|
std::ostringstream libNames;
|
|
|
|
std::string libName;
|
2015-11-08 12:52:56 +01:00
|
|
|
for (std::size_t i = 0; i < externalfiles.size(); ++i) {
|
2011-10-13 20:53:06 +02:00
|
|
|
if (start) {
|
2011-02-09 00:06:51 +01:00
|
|
|
libName = getLibName(externalfiles[i]);
|
2013-02-24 12:30:58 +01:00
|
|
|
fout << "ifndef " << libName << "\n";
|
2011-02-09 00:06:51 +01:00
|
|
|
fout << " " << libName << " = " << objfile(externalfiles[i]);
|
2013-02-24 12:30:58 +01:00
|
|
|
libNames << "EXTOBJ += $(" << libName << ")\n";
|
2011-02-09 00:06:51 +01:00
|
|
|
start = false;
|
2011-10-13 20:53:06 +02:00
|
|
|
} else {
|
2011-02-09 00:06:51 +01:00
|
|
|
fout << std::string(14, ' ') << objfile(externalfiles[i]);
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
if (i+1 >= externalfiles.size() || libName != getLibName(externalfiles[i+1])) {
|
2011-02-09 00:06:51 +01:00
|
|
|
// This was the last file for this library
|
2013-02-24 12:30:58 +01:00
|
|
|
fout << "\nendif\n\n\n";
|
2011-02-09 00:06:51 +01:00
|
|
|
start = true;
|
2011-10-13 20:53:06 +02:00
|
|
|
} else {
|
2011-02-09 00:06:51 +01:00
|
|
|
// There are more files for this library
|
2013-02-24 12:30:58 +01:00
|
|
|
fout << " \\\n";
|
2011-02-09 00:06:51 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fout << libNames.str();
|
|
|
|
}
|
2010-09-19 13:05:46 +02:00
|
|
|
|
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;
|
2015-03-05 06:48:44 +01:00
|
|
|
getCppFiles(libfiles, "lib/", false);
|
2010-01-23 09:54:51 +01:00
|
|
|
|
|
|
|
std::vector<std::string> clifiles;
|
2015-03-05 06:48:44 +01:00
|
|
|
getCppFiles(clifiles, "cli/", false);
|
2010-01-23 09:54:51 +01:00
|
|
|
|
|
|
|
std::vector<std::string> testfiles;
|
2015-03-05 06:48:44 +01:00
|
|
|
getCppFiles(testfiles, "test/", false);
|
2014-05-04 12:02:55 +02:00
|
|
|
|
2014-05-03 18:54:48 +02:00
|
|
|
std::vector<std::string> toolsfiles;
|
2015-03-05 06:48:44 +01:00
|
|
|
getCppFiles(toolsfiles, "tools/", false);
|
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;
|
|
|
|
}
|
|
|
|
|
2010-12-12 11:56:22 +01:00
|
|
|
std::vector<std::string> externalfiles;
|
2015-03-05 06:48:44 +01:00
|
|
|
getCppFiles(externalfiles, "externals/", true);
|
2010-12-12 11:56:22 +01:00
|
|
|
|
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";
|
2013-07-08 21:56:09 +02:00
|
|
|
fout1 << "BASEPATH = ../externals/tinyxml/\n";
|
|
|
|
fout1 << "include($$PWD/../externals/tinyxml/tinyxml.pri)\n";
|
|
|
|
fout1 << "BASEPATH = ../lib/\n";
|
2011-08-18 19:13:21 +02:00
|
|
|
fout1 << "INCLUDEPATH += ../externals/tinyxml\n";
|
2010-12-18 16:11:19 +01:00
|
|
|
fout1 << "HEADERS += $${BASEPATH}check.h \\\n";
|
2011-10-13 20:53:06 +02:00
|
|
|
for (unsigned int i = 0; i < libfiles.size(); ++i) {
|
2010-02-23 21:27:01 +01:00
|
|
|
std::string fname(libfiles[i].substr(4));
|
2010-04-02 07:30:58 +02:00
|
|
|
if (fname.find(".cpp") == std::string::npos)
|
2010-02-23 21:27:01 +01:00
|
|
|
continue; // shouldn't happen
|
|
|
|
fname.erase(fname.find(".cpp"));
|
2010-12-18 16:11:19 +01:00
|
|
|
fout1 << std::string(11, ' ') << "$${BASEPATH}" << fname << ".h";
|
2012-06-11 21:09:09 +02:00
|
|
|
if (i + 1 < testfiles.size())
|
2010-02-23 21:27:01 +01:00
|
|
|
fout1 << " \\\n";
|
|
|
|
}
|
|
|
|
fout1 << "\n\nSOURCES += ";
|
2011-10-13 20:53:06 +02:00
|
|
|
for (unsigned int i = 0; i < libfiles.size(); ++i) {
|
2010-12-18 16:11:19 +01:00
|
|
|
fout1 << "$${BASEPATH}" << libfiles[i].substr(4);
|
2010-04-02 07:30:58 +02:00
|
|
|
if (i < libfiles.size() - 1)
|
2010-02-23 21:27:01 +01:00
|
|
|
fout1 << " \\\n" << std::string(11, ' ');
|
|
|
|
}
|
|
|
|
fout1 << "\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-11 14:59:33 +02:00
|
|
|
// QMAKE - test/testfiles.pri
|
|
|
|
{
|
2012-06-18 06:41:04 +02:00
|
|
|
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));
|
|
|
|
// Include only files containing tests in this listing.
|
|
|
|
// I.e. filenames beginning with "test".
|
2012-06-11 14:59:33 +02:00
|
|
|
if (filename.compare(0, 4, "test") == 0) {
|
2012-06-18 06:41:04 +02:00
|
|
|
fout1 << "$${BASEPATH}/" << filename;
|
2012-06-11 14:59:33 +02:00
|
|
|
if (i + 1 < testfiles.size())
|
2012-06-18 06:41:04 +02:00
|
|
|
fout1 << " \\\n" << std::string(11, ' ');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fout1 << "\n";
|
|
|
|
}
|
2012-06-11 14:59:33 +02:00
|
|
|
}
|
2010-02-23 21:27:01 +01:00
|
|
|
|
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";
|
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
|
|
|
|
2012-12-02 12:36:55 +01:00
|
|
|
// compiled patterns..
|
|
|
|
fout << "# folder where lib/*.cpp files are located\n";
|
2012-12-10 09:43:07 +01:00
|
|
|
makeConditionalVariable(fout, "SRCDIR", "lib");
|
|
|
|
fout << "ifeq ($(SRCDIR),build)\n"
|
2013-05-15 13:04:19 +02:00
|
|
|
<< " ifdef VERIFY\n"
|
|
|
|
<< " matchcompiler_S := $(shell python tools/matchcompiler.py --verify)\n"
|
|
|
|
<< " else\n"
|
|
|
|
<< " matchcompiler_S := $(shell python tools/matchcompiler.py)\n"
|
|
|
|
<< " endif\n"
|
2012-12-02 12:36:55 +01:00
|
|
|
<< "endif\n\n";
|
|
|
|
|
2013-12-28 12:15:08 +01:00
|
|
|
// explicit cfg dir..
|
|
|
|
fout << "ifdef CFGDIR\n"
|
|
|
|
<< " CFG=-DCFGDIR=\\\"$(CFGDIR)\\\"\n"
|
|
|
|
<< "else\n"
|
|
|
|
<< " CFG=\n"
|
|
|
|
<< "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"
|
|
|
|
<< " ifdef ComSpec\n"
|
|
|
|
<< " #### ComSpec is defined on some WIN32's.\n"
|
|
|
|
<< " COMSPEC=$(ComSpec)\n"
|
|
|
|
<< " endif # ComSpec\n"
|
|
|
|
<< "endif # COMSPEC\n"
|
|
|
|
<< "\n"
|
|
|
|
<< "ifdef COMSPEC\n"
|
|
|
|
<< " #### 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"
|
|
|
|
<< " ifeq ($(MSYSTEM),MINGW32)\n"
|
|
|
|
<< " LDFLAGS=-lshlwapi\n"
|
2014-03-30 20:50:03 +02:00
|
|
|
<< " else\n"
|
|
|
|
<< " RDYNAMIC=-lshlwapi\n"
|
2013-02-08 12:10:07 +01:00
|
|
|
<< " endif\n"
|
2012-02-12 03:30:58 +01:00
|
|
|
<< "else # !COMSPEC\n"
|
|
|
|
<< " uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not')\n"
|
|
|
|
<< "\n"
|
|
|
|
<< " 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"
|
|
|
|
<< "endif # COMSPEC\n"
|
|
|
|
<< "\n";
|
|
|
|
|
2014-04-24 22:22:43 +02:00
|
|
|
// tinymxl2 requires __STRICT_ANSI__ to be undefined to compile under CYGWIN.
|
|
|
|
fout << "# Set the UNDEF_STRICT_ANSI flag to address compile time warnings\n"
|
|
|
|
<< "# with tinyxml2 and Cygwin.\n"
|
|
|
|
<< "ifdef COMSPEC\n"
|
|
|
|
<< " uname_S := $(shell uname -s)\n"
|
|
|
|
<< "\n"
|
|
|
|
<< " ifneq (,$(findstring CYGWIN,$(uname_S)))\n"
|
|
|
|
<< " UNDEF_STRICT_ANSI=-U__STRICT_ANSI__\n"
|
|
|
|
<< " endif # CYGWIN\n"
|
|
|
|
<< "endif # COMSPEC\n"
|
|
|
|
<< "\n";
|
|
|
|
|
2015-10-05 04:51:06 +02:00
|
|
|
// skip "-D_GLIBCXX_DEBUG" if clang, since it breaks the build
|
|
|
|
makeConditionalVariable(fout, "CXX", "g++");
|
|
|
|
fout << "ifeq ($(CXX), clang++)\n"
|
|
|
|
<< " 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) {
|
2015-11-08 12:52:56 +01:00
|
|
|
makeConditionalVariable(fout, "CXXFLAGS", "-std=c++0x -O2 -include lib/cxx11emu.h -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",
|
2014-02-15 07:52:17 +01:00
|
|
|
"-include lib/cxx11emu.h "
|
2011-10-24 02:52:55 +02:00
|
|
|
"-pedantic "
|
2010-09-19 13:05:46 +02:00
|
|
|
"-Wall "
|
|
|
|
"-Wextra "
|
2011-10-22 15:00:44 +02:00
|
|
|
"-Wabi "
|
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 *);
|
2011-10-24 02:52:55 +02:00
|
|
|
"-Wfloat-equal "
|
2011-10-22 15:00:44 +02:00
|
|
|
"-Winline "
|
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 "
|
|
|
|
"-Wshadow "
|
2012-01-03 15:10:32 +01:00
|
|
|
// "-Wsign-conversion "
|
2011-10-24 02:52:55 +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 "
|
2014-01-18 09:51:48 +01:00
|
|
|
"-Wno-sign-compare " // danmar: I don't like this warning, it's very rarelly a bug
|
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
|
|
|
|
2015-11-10 21:07:06 +01:00
|
|
|
fout << "ifeq ($(CXX), g++)\n"
|
|
|
|
<< " override CXXFLAGS += -std=c++0x\n"
|
|
|
|
<< "else ifeq ($(CXX), clang++)\n"
|
|
|
|
<< " 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"
|
2015-11-13 11:38:06 +01:00
|
|
|
<< " override CXXFLAGS += -DHAVE_RULES -DTIXML_USE_STL $(shell pcre-config --cflags)\n"
|
2011-06-19 19:56:12 +02:00
|
|
|
<< " ifdef LIBS\n"
|
2011-10-28 21:20:19 +02:00
|
|
|
<< " LIBS += $(shell pcre-config --libs)\n"
|
2011-04-22 14:20:38 +02:00
|
|
|
<< " else\n"
|
2011-10-28 21:20:19 +02: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");
|
2014-03-03 12:09:21 +01:00
|
|
|
makeConditionalVariable(fout, "INCLUDE_FOR_LIB", "-Ilib -Iexternals/tinyxml");
|
|
|
|
makeConditionalVariable(fout, "INCLUDE_FOR_CLI", "-Ilib -Iexternals/tinyxml");
|
|
|
|
makeConditionalVariable(fout, "INCLUDE_FOR_TEST", "-Ilib -Icli -Iexternals/tinyxml");
|
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";
|
2011-01-31 08:18:35 +01:00
|
|
|
fout << "LIBOBJ = " << objfile(libfiles[0]);
|
2014-05-03 18:54:48 +02:00
|
|
|
for (size_t i = 1; i < libfiles.size(); ++i)
|
2013-02-24 12:30:58 +01:00
|
|
|
fout << " \\\n" << std::string(14, ' ') << objfile(libfiles[i]);
|
2010-01-23 09:54:51 +01:00
|
|
|
fout << "\n\n";
|
2011-01-31 08:18:35 +01:00
|
|
|
fout << "CLIOBJ = " << objfile(clifiles[0]);
|
2014-05-03 18:54:48 +02:00
|
|
|
for (size_t i = 1; i < clifiles.size(); ++i)
|
2013-02-24 12:30:58 +01:00
|
|
|
fout << " \\\n" << std::string(14, ' ') << objfile(clifiles[i]);
|
2010-01-23 09:54:51 +01:00
|
|
|
fout << "\n\n";
|
|
|
|
fout << "TESTOBJ = " << objfile(testfiles[0]);
|
2014-05-03 18:54:48 +02:00
|
|
|
for (size_t i = 1; i < testfiles.size(); ++i)
|
2013-02-24 12:30:58 +01:00
|
|
|
fout << " \\\n" << std::string(14, ' ') << objfile(testfiles[i]);
|
2010-01-23 09:54:51 +01:00
|
|
|
fout << "\n\n";
|
|
|
|
|
2011-02-09 00:06:51 +01:00
|
|
|
makeExtObj(fout, externalfiles);
|
2010-01-23 09:54:51 +01:00
|
|
|
|
2015-09-05 17:12:15 +02:00
|
|
|
fout << ".PHONY: run-dmake\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";
|
2015-11-08 12:52:56 +01:00
|
|
|
fout << "\t$(CXX) $(CPPFLAGS) $(CXXFLAGS) -o cppcheck $(CLIOBJ) $(LIBOBJ) $(EXTOBJ) $(LIBS) $(LDFLAGS) $(RDYNAMIC)\n\n";
|
2011-01-31 08:18:35 +01:00
|
|
|
fout << "all:\tcppcheck testrunner\n\n";
|
2011-03-20 14:25:11 +01:00
|
|
|
fout << "testrunner: $(TESTOBJ) $(LIBOBJ) $(EXTOBJ) cli/threadexecutor.o cli/cmdlineparser.o cli/cppcheckexecutor.o cli/filelister.o cli/pathmatch.o\n";
|
2015-11-08 12:52:56 +01:00
|
|
|
fout << "\t$(CXX) $(CPPFLAGS) $(CXXFLAGS) -o testrunner $(TESTOBJ) $(LIBOBJ) cli/threadexecutor.o cli/cppcheckexecutor.o cli/cmdlineparser.o cli/filelister.o cli/pathmatch.o $(EXTOBJ) $(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";
|
|
|
|
fout << "\t./testrunner -g -q\n\n";
|
2015-01-27 19:31:41 +01:00
|
|
|
fout << "checkcfg:\tcppcheck\n";
|
|
|
|
fout << "\t./test/cfg/runtests.sh\n\n";
|
2015-07-23 15:02:32 +02:00
|
|
|
fout << "dmake:\ttools/dmake.o cli/filelister.o cli/pathmatch.o lib/path.o\n";
|
2015-11-08 12:52:56 +01:00
|
|
|
fout << "\t$(CXX) $(CXXFLAGS) -o dmake tools/dmake.o cli/filelister.o cli/pathmatch.o lib/path.o -Ilib $(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";
|
2014-05-03 18:54:48 +02:00
|
|
|
fout << "reduce:\ttools/reduce.o externals/tinyxml/tinyxml2.o $(LIBOBJ)\n";
|
2015-11-08 12:52:56 +01:00
|
|
|
fout << "\t$(CXX) $(CPPFLAGS) $(CXXFLAGS) -g -o reduce tools/reduce.o -Ilib -Iexternals/tinyxml $(LIBOBJ) $(LIBS) externals/tinyxml/tinyxml2.o $(LDFLAGS) $(RDYNAMIC)\n\n";
|
2010-01-23 09:54:51 +01:00
|
|
|
fout << "clean:\n";
|
2014-05-14 13:20:24 +02:00
|
|
|
fout << "\trm -f build/*.o lib/*.o cli/*.o test/*.o tools/*.o externals/tinyxml/*.o testrunner reduce dmake cppcheck 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";
|
|
|
|
fout << "\tctags -R --exclude=doxyoutput .\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";
|
|
|
|
fout << "ifdef CFGDIR \n";
|
2014-09-25 18:50:48 +02:00
|
|
|
fout << "\tinstall -d ${DESTDIR}${CFGDIR}\n";
|
|
|
|
fout << "\tinstall -m 644 cfg/* ${DESTDIR}${CFGDIR}\n";
|
2014-05-17 11:05:42 +02:00
|
|
|
fout << "endif\n\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}");
|
2014-01-17 22:52:05 +01:00
|
|
|
compilefiles(fout, externalfiles, "${INCLUDE_FOR_LIB}");
|
2014-05-03 18:54:48 +02:00
|
|
|
compilefiles(fout, toolsfiles, "${INCLUDE_FOR_LIB}");
|
2010-01-23 09:54:51 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|