Skip to content

Commit

Permalink
Wrapped variables in conditions
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
johnsyweb committed Sep 20, 2010
1 parent 4ca7950 commit 4934cfa
Showing 1 changed file with 43 additions and 17 deletions.
60 changes: 43 additions & 17 deletions tools/dmake.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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
{
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -221,4 +248,3 @@ int main(int argc, char **argv)
return 0;
}


0 comments on commit 4934cfa

Please sign in to comment.