Wrapped variables in conditions

This allows CXX and CXXFLAGS to be overridden without patching. Added PREFIX for MacPorts compatibility, allowing staging to $(DESTDIR)$(PREFIX)/bin, leaving original behaviour unchanged.

Exit early if run in incorrect directory or if Makefile cannot be written.
This commit is contained in:
Pete Johns 2010-09-19 21:05:46 +10:00
parent 4ca795056f
commit 4934cfa622
1 changed files with 43 additions and 17 deletions

View File

@ -98,6 +98,16 @@ static void getCppFiles(std::vector<std::string> &files, const std::string &path
}
}
static void makeConditionalVariable(std::ostream &os, const std::string &variable, const std::string &value)
{
os << "ifndef " << variable << '\n'
<< " " << variable << '=' << value << '\n'
<< "endif\n"
<< "\n";
}
int main(int argc, char **argv)
{
const bool release(argc >= 2 && std::string(argv[1]) == "--release");
@ -112,6 +122,12 @@ int main(int argc, char **argv)
std::vector<std::string> testfiles;
getCppFiles(testfiles, "test/");
if (libfiles.empty() && clifiles.empty() && testfiles.empty())
{
std::cerr << "No files found. Are you in the correct directory?" << std::endl;
return EXIT_FAILURE;
}
// QMAKE - lib/lib.pri
{
@ -142,35 +158,46 @@ int main(int argc, char **argv)
}
std::ofstream fout("Makefile");
static const char makefile[] = "Makefile";
std::ofstream fout(makefile, std::ios_base::trunc);
if (!fout.is_open())
{
std::cerr << "An error occurred while trying to open "
<< makefile
<< ".\n";
return EXIT_FAILURE;
}
// Makefile settings..
if (release)
{
fout << "CXXFLAGS=-O2 -DNDEBUG -Wall\n";
makeConditionalVariable(fout, "CXXFLAGS", "-O2 -DNDEBUG -Wall");
}
else
{
fout << "# This file is generated by tools/dmake, do not edit.\n\n";
// TODO: add more compiler warnings.
// -Wconversion : generates too many compiler warnings currently
// -Wlogical-op : doesn't work on older GCC
// The _GLIBCXX_DEBUG doesn't work in cygwin
fout << "CXXFLAGS="
<< "-Wall "
<< "-Wextra "
<< "-Wshadow "
<< "-pedantic "
<< "-Wno-long-long "
<< "-Wfloat-equal "
<< "-Wcast-qual "
<< "-Wsign-conversion "
// << "-Wconversion "
<< "-g\n";
makeConditionalVariable(fout, "CXXFLAGS",
"-Wall "
"-Wextra "
"-Wshadow "
"-pedantic "
"-Wno-long-long "
"-Wfloat-equal "
"-Wcast-qual "
"-Wsign-conversion "
// "-Wconversion "
"-g");
}
fout << "CXX=g++\n";
fout << "BIN=${DESTDIR}/usr/bin\n\n";
fout << "# For 'make man': sudo apt-get install xsltproc docbook-xsl docbook-xml\n";
makeConditionalVariable(fout, "CXX", "g++");
makeConditionalVariable(fout, "PREFIX", "/usr");
fout << "BIN=$(DESTDIR)$(PREFIX)/bin\n\n";
fout << "# For 'make man': sudo apt-get install xsltproc docbook-xsl docbook-xml on Linux\n";
fout << "DB2MAN=/usr/share/sgml/docbook/stylesheet/xsl/nwalsh/manpages/docbook.xsl\n";
fout << "XP=xsltproc -''-nonet -''-param man.charmap.use.subset \"0\"\n";
fout << "MAN_SOURCE=man/cppcheck.1.xml\n\n";
@ -221,4 +248,3 @@ int main(int argc, char **argv)
return 0;
}