From 73e746cfd803785c23fb97041569cc89e0be0374 Mon Sep 17 00:00:00 2001 From: Reijo Tomperi Date: Wed, 9 Feb 2011 01:06:51 +0200 Subject: [PATCH] Change Makefile to allow another external library to be used instead of bundled one. E.g. make TINYXML="-ltinyxml" can be used to compile with libtinyxml-dev instead of externals/tinyxml (but won't compile yet, because of #include "tinyxml/tinyxml.h" in the code). --- Makefile | 6 +++++- tools/dmake.cpp | 52 +++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 53 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 794e7c5d1..ea8a3a46e 100644 --- a/Makefile +++ b/Makefile @@ -92,12 +92,16 @@ TESTOBJ = test/options.o \ test/testunusedprivfunc.o \ test/testunusedvar.o -EXTOBJ = externals/tinyxml/tinystr.o \ +#ifndef TINYXML + TINYXML = externals/tinyxml/tinystr.o \ externals/tinyxml/tinyxml.o \ externals/tinyxml/tinyxmlerror.o \ externals/tinyxml/tinyxmlparser.o +#endif +EXTOBJ += $(TINYXML) + ###### Targets cppcheck: $(LIBOBJ) $(CLIOBJ) $(EXTOBJ) diff --git a/tools/dmake.cpp b/tools/dmake.cpp index 7e688f33c..572e389eb 100644 --- a/tools/dmake.cpp +++ b/tools/dmake.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #if defined(_WIN32) #include "../cli/fileLister_win32.h" @@ -107,6 +108,52 @@ static void makeConditionalVariable(std::ostream &os, const std::string &variabl << "\n"; } +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 &externalfiles) +{ + bool start = true; + std::ostringstream libNames; + std::string libName; + for (unsigned int i = 0; i < externalfiles.size(); ++i) + { + if (start) + { + libName = getLibName(externalfiles[i]); + fout << "#ifndef " << libName << std::endl; + fout << " " << libName << " = " << objfile(externalfiles[i]); + libNames << "EXTOBJ += $(" << libName << ")" << std::endl; + start = false; + } + else + { + fout << std::string(14, ' ') << objfile(externalfiles[i]); + } + + if (i+1 >= externalfiles.size() || libName != getLibName(externalfiles[i+1])) + { + // This was the last file for this library + fout << std::endl << "#endif" << std::endl; + fout << "\n\n"; + start = true; + } + else + { + // There are more files for this library + fout << " \\" << std::endl; + } + } + + fout << libNames.str(); +} int main(int argc, char **argv) { @@ -220,11 +267,8 @@ int main(int argc, char **argv) for (unsigned int i = 1; i < testfiles.size(); ++i) fout << " \\" << std::endl << std::string(14, ' ') << objfile(testfiles[i]); fout << "\n\n"; - fout << "EXTOBJ = " << objfile(externalfiles[0]); - for (unsigned int i = 1; i < externalfiles.size(); ++i) - fout << " \\" << std::endl << std::string(14, ' ') << objfile(externalfiles[i]); - fout << "\n\n"; + makeExtObj(fout, externalfiles); fout << "\n###### Targets\n\n"; fout << "cppcheck: $(LIBOBJ) $(CLIOBJ) $(EXTOBJ)\n";