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:
parent
4ca795056f
commit
4934cfa622
|
@ -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)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
const bool release(argc >= 2 && std::string(argv[1]) == "--release");
|
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;
|
std::vector<std::string> testfiles;
|
||||||
getCppFiles(testfiles, "test/");
|
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
|
// 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..
|
// Makefile settings..
|
||||||
if (release)
|
if (release)
|
||||||
{
|
{
|
||||||
fout << "CXXFLAGS=-O2 -DNDEBUG -Wall\n";
|
makeConditionalVariable(fout, "CXXFLAGS", "-O2 -DNDEBUG -Wall");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
fout << "# This file is generated by tools/dmake, do not edit.\n\n";
|
||||||
|
|
||||||
// TODO: add more compiler warnings.
|
// TODO: add more compiler warnings.
|
||||||
// -Wconversion : generates too many compiler warnings currently
|
// -Wconversion : generates too many compiler warnings currently
|
||||||
// -Wlogical-op : doesn't work on older GCC
|
// -Wlogical-op : doesn't work on older GCC
|
||||||
|
|
||||||
// The _GLIBCXX_DEBUG doesn't work in cygwin
|
// The _GLIBCXX_DEBUG doesn't work in cygwin
|
||||||
fout << "CXXFLAGS="
|
makeConditionalVariable(fout, "CXXFLAGS",
|
||||||
<< "-Wall "
|
"-Wall "
|
||||||
<< "-Wextra "
|
"-Wextra "
|
||||||
<< "-Wshadow "
|
"-Wshadow "
|
||||||
<< "-pedantic "
|
"-pedantic "
|
||||||
<< "-Wno-long-long "
|
"-Wno-long-long "
|
||||||
<< "-Wfloat-equal "
|
"-Wfloat-equal "
|
||||||
<< "-Wcast-qual "
|
"-Wcast-qual "
|
||||||
<< "-Wsign-conversion "
|
"-Wsign-conversion "
|
||||||
// << "-Wconversion "
|
// "-Wconversion "
|
||||||
<< "-g\n";
|
"-g");
|
||||||
}
|
}
|
||||||
fout << "CXX=g++\n";
|
makeConditionalVariable(fout, "CXX", "g++");
|
||||||
fout << "BIN=${DESTDIR}/usr/bin\n\n";
|
makeConditionalVariable(fout, "PREFIX", "/usr");
|
||||||
fout << "# For 'make man': sudo apt-get install xsltproc docbook-xsl docbook-xml\n";
|
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 << "DB2MAN=/usr/share/sgml/docbook/stylesheet/xsl/nwalsh/manpages/docbook.xsl\n";
|
||||||
fout << "XP=xsltproc -''-nonet -''-param man.charmap.use.subset \"0\"\n";
|
fout << "XP=xsltproc -''-nonet -''-param man.charmap.use.subset \"0\"\n";
|
||||||
fout << "MAN_SOURCE=man/cppcheck.1.xml\n\n";
|
fout << "MAN_SOURCE=man/cppcheck.1.xml\n\n";
|
||||||
|
@ -221,4 +248,3 @@ int main(int argc, char **argv)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue