27 void scanDir(
const string& folder, vector<string>& sourceFiles, vector<string>& mainSourceFiles) {
30 virtual ~SourceFilesFilter() {}
32 bool accept(
const string& pathName,
const string& fileName)
override {
33 if (fileName ==
".")
return false;
34 if (fileName ==
"..")
return false;
35 if (FileSystem::getInstance()->isPath(pathName +
"/" + fileName) ==
true)
return true;
37 if (StringTools::endsWith(StringTools::toLowerCase(fileName),
".incl.cpp") ==
true)
return false;
38 if (StringTools::endsWith(StringTools::toLowerCase(fileName),
".include.cpp") ==
true)
return false;
40 if (StringTools::endsWith(StringTools::toLowerCase(fileName),
".cpp") ==
true)
return true;
45 SourceFilesFilter sourceFilesFilter;
48 FileSystem::getInstance()->list(folder, files, &sourceFilesFilter);
50 for (
const auto& fileName: files) {
51 if (StringTools::endsWith(fileName,
"-main.cpp") ==
true) {
52 mainSourceFiles.push_back(folder +
"/" + fileName);
54 if (StringTools::endsWith(fileName,
".cpp") ==
true) {
55 sourceFiles.push_back(folder +
"/" + fileName);
57 scanDir(folder +
"/" + fileName, sourceFiles, mainSourceFiles);
62 int main(
int argc,
char** argv)
64 Console::println(
string(
"makefilegenerator ") + Version::getVersion());
65 Console::println(Version::getCopyright());
70 Console::println(
"Usage: makefilegenerator path_to_source");
71 Application::exit(Application::EXITCODE_FAILURE);
75 auto pathToSource = string(argv[1]);
79 Console::println(
"Scanning source files");
80 vector<string> sourceFiles;
81 vector<string> mainSourceFiles;
82 scanDir(pathToSource, sourceFiles, mainSourceFiles);
84 string sourceFilesVariable =
"\\\n";
85 for (
const auto& file: sourceFiles) sourceFilesVariable+=
"\t" + file +
"\\\n";
86 sourceFilesVariable+=
"\n";
88 string mainSourceFilesVariable =
"\\\n";
89 for (
const auto& file: mainSourceFiles) mainSourceFilesVariable+=
"\t" + file +
"\\\n";
90 mainSourceFilesVariable+=
"\n";
92 Console::println(
"Generating Makefile");
94 auto executableFolder = StringTools::replace(argv[0],
"\\",
"/");
95 auto tdme2Folder = StringTools::substring(executableFolder, 0, StringTools::toLowerCase(executableFolder).rfind(
"/tdme2/") +
string(
"/tdme2/").length());
97 auto makefileSource = FileSystem::getInstance()->getContentAsString(tdme2Folder +
"/resources/engine/templates/makefiles",
"Makefile");
98 makefileSource = StringTools::replace(makefileSource,
"{$source-files}", sourceFilesVariable);
99 makefileSource = StringTools::replace(makefileSource,
"{$main-source-files}", mainSourceFilesVariable);
100 FileSystem::getInstance()->setContentFromString(
".",
"Makefile", makefileSource);
102 Console::println(
"An error occurred: " +
string(exception.what()));
106 Application::exit(Application::EXITCODE_SUCCESS);
Application base class, please make sure to allocate application on heap to have correct application ...
File system singleton class.
int main(int argc, char **argv)
void scanDir(const string &folder, vector< string > &sourceFiles, vector< string > &mainSourceFiles)
std::exception Exception
Exception base class.
File system file name filter interface.
virtual bool accept(const string &path, const string &file)=0
Accept a file.