Dmake cleanups (#2077)

* dmake: Refactor object files to separate function

No functional change.

* dmake: Use range for loops

No functional change.

* Add all external cpp files instead of open coding

No functional change.

* Remove duplicate check.h in lib.pri HEADERS

* Add missing newline

No functional change, but the readability of the generated Makefile is
slightly improved.
This commit is contained in:
Rikard Falkeborn 2019-08-14 20:53:51 +02:00 committed by Daniel Marjamäki
parent 4f76588f98
commit f139558d90
3 changed files with 43 additions and 43 deletions

View File

@ -357,6 +357,7 @@ validateXML: createXMLExamples
checkCWEEntries: /tmp/errorlist.xml checkCWEEntries: /tmp/errorlist.xml
./tools/listErrorsWithoutCWE.py -F /tmp/errorlist.xml ./tools/listErrorsWithoutCWE.py -F /tmp/errorlist.xml
###### Build ###### Build
$(libcppdir)/analyzerinfo.o: lib/analyzerinfo.cpp lib/analyzerinfo.h lib/config.h lib/errorlogger.h lib/suppressions.h lib/importproject.h lib/platform.h lib/utils.h lib/path.h $(libcppdir)/analyzerinfo.o: lib/analyzerinfo.cpp lib/analyzerinfo.h lib/config.h lib/errorlogger.h lib/suppressions.h lib/importproject.h lib/platform.h lib/utils.h lib/path.h

View File

@ -3,8 +3,7 @@
include($$PWD/pcrerules.pri) include($$PWD/pcrerules.pri)
include($$PWD/../externals/externals.pri) include($$PWD/../externals/externals.pri)
INCLUDEPATH += $$PWD INCLUDEPATH += $$PWD
HEADERS += $${PWD}/check.h \ HEADERS += $${PWD}/analyzerinfo.h \
$${PWD}/analyzerinfo.h \
$${PWD}/astutils.h \ $${PWD}/astutils.h \
$${PWD}/check.h \ $${PWD}/check.h \
$${PWD}/check64bit.h \ $${PWD}/check64bit.h \

View File

@ -41,6 +41,19 @@ static std::string objfile(std::string cppfile)
return builddir(cppfile + ".o"); return builddir(cppfile + ".o");
} }
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;
}
static void getDeps(const std::string &filename, std::vector<std::string> &depfiles) static void getDeps(const std::string &filename, std::vector<std::string> &depfiles)
{ {
// Is the dependency already included? // Is the dependency already included?
@ -77,14 +90,14 @@ static void getDeps(const std::string &filename, std::vector<std::string> &depfi
static void compilefiles(std::ostream &fout, const std::vector<std::string> &files, const std::string &args) static void compilefiles(std::ostream &fout, const std::vector<std::string> &files, const std::string &args)
{ {
for (unsigned int i = 0; i < files.size(); ++i) { for (const std::string &file : files) {
bool external(files[i].compare(0,10,"externals/") == 0); bool external(file.compare(0,10,"externals/") == 0);
fout << objfile(files[i]) << ": " << files[i]; fout << objfile(file) << ": " << file;
std::vector<std::string> depfiles; std::vector<std::string> depfiles;
getDeps(files[i], depfiles); getDeps(file, depfiles);
for (unsigned int dep = 0; dep < depfiles.size(); ++dep) for (const std::string &depfile : depfiles)
fout << " " << depfiles[dep]; fout << " " << depfile;
fout << "\n\t$(CXX) " << args << " $(CPPFLAGS) $(CFG) $(CXXFLAGS)" << (external?" -w":"") << " $(UNDEF_STRICT_ANSI) -c -o " << objfile(files[i]) << " " << builddir(files[i]) << "\n\n"; fout << "\n\t$(CXX) " << args << " $(CPPFLAGS) $(CFG) $(CXXFLAGS)" << (external?" -w":"") << " $(UNDEF_STRICT_ANSI) -c -o " << objfile(file) << " " << builddir(file) << "\n\n";
} }
} }
@ -97,9 +110,9 @@ static void getCppFiles(std::vector<std::string> &files, const std::string &path
FileLister::addFiles(filemap, path, extra, recursive, matcher); FileLister::addFiles(filemap, path, extra, recursive, matcher);
// add *.cpp files to the "files" vector.. // add *.cpp files to the "files" vector..
for (std::map<std::string,size_t>::const_iterator it = filemap.begin(); it != filemap.end(); ++it) { for (const std::pair<const std::string&, size_t> file : filemap) {
if (it->first.find(".cpp") != std::string::npos) if (file.first.find(".cpp") != std::string::npos)
files.push_back(it->first); files.push_back(file.first);
} }
} }
@ -121,8 +134,7 @@ int main(int argc, char **argv)
getCppFiles(libfiles, "lib/", false); getCppFiles(libfiles, "lib/", false);
std::vector<std::string> extfiles; std::vector<std::string> extfiles;
extfiles.push_back("externals/simplecpp/simplecpp.cpp"); getCppFiles(extfiles, "externals/", true);
extfiles.push_back("externals/tinyxml/tinyxml2.cpp");
std::vector<std::string> clifiles; std::vector<std::string> clifiles;
getCppFiles(clifiles, "cli/", false); getCppFiles(clifiles, "cli/", false);
@ -146,20 +158,20 @@ int main(int argc, char **argv)
fout1 << "include($$PWD/pcrerules.pri)\n"; fout1 << "include($$PWD/pcrerules.pri)\n";
fout1 << "include($$PWD/../externals/externals.pri)\n"; fout1 << "include($$PWD/../externals/externals.pri)\n";
fout1 << "INCLUDEPATH += $$PWD\n"; fout1 << "INCLUDEPATH += $$PWD\n";
fout1 << "HEADERS += $${PWD}/check.h \\\n"; fout1 << "HEADERS += ";
for (unsigned int i = 0; i < libfiles.size(); ++i) { for (const std::string &libfile : libfiles) {
std::string fname(libfiles[i].substr(4)); std::string fname(libfile.substr(4));
if (fname.find(".cpp") == std::string::npos) if (fname.find(".cpp") == std::string::npos)
continue; // shouldn't happen continue; // shouldn't happen
fname.erase(fname.find(".cpp")); fname.erase(fname.find(".cpp"));
fout1 << std::string(11, ' ') << "$${PWD}/" << fname << ".h"; fout1 << "$${PWD}/" << fname << ".h";
if (i + 1 < libfiles.size()) if (libfile != libfiles.back())
fout1 << " \\\n"; fout1 << " \\\n" << std::string(11, ' ');
} }
fout1 << "\n\nSOURCES += "; fout1 << "\n\nSOURCES += ";
for (unsigned int i = 0; i < libfiles.size(); ++i) { for (const std::string &libfile : libfiles) {
fout1 << "$${PWD}/" << libfiles[i].substr(4); fout1 << "$${PWD}/" << libfile.substr(4);
if (i < libfiles.size() - 1) if (libfile != libfiles.back())
fout1 << " \\\n" << std::string(11, ' '); fout1 << " \\\n" << std::string(11, ' ');
} }
fout1 << "\n"; fout1 << "\n";
@ -173,13 +185,13 @@ int main(int argc, char **argv)
fout1 << "# no manual edits - this file is autogenerated by dmake\n\n"; fout1 << "# no manual edits - this file is autogenerated by dmake\n\n";
fout1 << "INCLUDEPATH += ../externals/tinyxml\n"; fout1 << "INCLUDEPATH += ../externals/tinyxml\n";
fout1 << "\n\nSOURCES += "; fout1 << "\n\nSOURCES += ";
for (unsigned int i = 0; i < testfiles.size(); ++i) { for (const std::string &testfile : testfiles) {
const std::string filename(testfiles[i].substr(5)); const std::string filename(testfile.substr(5));
// Include only files containing tests in this listing. // Include only files containing tests in this listing.
// I.e. filenames beginning with "test". // I.e. filenames beginning with "test".
if (filename.compare(0, 4, "test") == 0) { if (filename.compare(0, 4, "test") == 0) {
fout1 << "$${BASEPATH}/" << filename; fout1 << "$${BASEPATH}/" << filename;
if (i + 1 < testfiles.size()) if (testfile != testfiles.back())
fout1 << " \\\n" << std::string(11, ' '); fout1 << " \\\n" << std::string(11, ' ');
} }
} }
@ -362,22 +374,10 @@ int main(int argc, char **argv)
fout << "MAN_SOURCE=man/cppcheck.1.xml\n\n"; fout << "MAN_SOURCE=man/cppcheck.1.xml\n\n";
fout << "\n###### Object Files\n\n"; fout << "\n###### Object Files\n\n";
fout << "LIBOBJ = " << objfile(libfiles[0]); fout << "LIBOBJ = " << objfiles(libfiles) << "\n\n";
for (size_t i = 1; i < libfiles.size(); ++i) fout << "EXTOBJ = " << objfiles(extfiles) << "\n\n";
fout << " \\\n" << std::string(14, ' ') << objfile(libfiles[i]); fout << "CLIOBJ = " << objfiles(clifiles) << "\n\n";
fout << "\n\n"; fout << "TESTOBJ = " << objfiles(testfiles) << "\n\n";
fout << "EXTOBJ = " << objfile(extfiles[0]);
for (size_t i = 1; i < extfiles.size(); ++i)
fout << " \\\n" << std::string(14, ' ') << objfile(extfiles[i]);
fout << "\n\n";
fout << "CLIOBJ = " << objfile(clifiles[0]);
for (size_t i = 1; i < clifiles.size(); ++i)
fout << " \\\n" << std::string(14, ' ') << objfile(clifiles[i]);
fout << "\n\n";
fout << "TESTOBJ = " << objfile(testfiles[0]);
for (size_t i = 1; i < testfiles.size(); ++i)
fout << " \\\n" << std::string(14, ' ') << objfile(testfiles[i]);
fout << "\n\n";
fout << ".PHONY: run-dmake tags\n\n"; fout << ".PHONY: run-dmake tags\n\n";
fout << "\n###### Targets\n\n"; fout << "\n###### Targets\n\n";
@ -456,7 +456,7 @@ int main(int argc, char **argv)
fout << "\txmllint --noout --relaxng cppcheck-errors.rng /tmp/errorlist.xml\n"; fout << "\txmllint --noout --relaxng cppcheck-errors.rng /tmp/errorlist.xml\n";
fout << "\txmllint --noout --relaxng cppcheck-errors.rng /tmp/example.xml\n"; fout << "\txmllint --noout --relaxng cppcheck-errors.rng /tmp/example.xml\n";
fout << "\ncheckCWEEntries: /tmp/errorlist.xml\n"; fout << "\ncheckCWEEntries: /tmp/errorlist.xml\n";
fout << "\t./tools/listErrorsWithoutCWE.py -F /tmp/errorlist.xml"; fout << "\t./tools/listErrorsWithoutCWE.py -F /tmp/errorlist.xml\n";
fout << "\n###### Build\n\n"; fout << "\n###### Build\n\n";