28void scanDir(
const string& folder, vector<string>& sourceFiles, vector<string>& mainSourceFiles) {
31 virtual ~SourceFilesFilter() {}
33 bool accept(
const string& pathName,
const string& fileName)
override {
34 if (fileName ==
".")
return false;
35 if (fileName ==
"..")
return false;
36 if (FileSystem::getInstance()->isPath(pathName +
"/" + fileName) ==
true)
return true;
37 if (StringTools::endsWith(StringTools::toLowerCase(fileName),
".cpp") ==
true)
return true;
42 SourceFilesFilter sourceFilesFilter;
45 FileSystem::getInstance()->list(folder, files, &sourceFilesFilter);
47 for (
auto fileName: files) {
48 if (StringTools::endsWith(fileName,
"-main.cpp") ==
true) {
49 mainSourceFiles.push_back(folder +
"/" + fileName);
51 if (StringTools::endsWith(fileName,
".cpp") ==
true) {
52 sourceFiles.push_back(folder +
"/" + fileName);
54 scanDir(folder +
"/" + fileName, sourceFiles, mainSourceFiles);
59int main(
int argc,
char** argv)
61 Console::println(
string(
"makefilegenerator ") + Version::getVersion());
62 Console::println(Version::getCopyright());
66 Console::println(
"Usage: makefilegenerator path_to_source");
70 auto pathToSource = string(argv[1]);
73 Console::println(
"Scanning source files");
74 vector<string> sourceFiles;
75 vector<string> mainSourceFiles;
76 scanDir(pathToSource, sourceFiles, mainSourceFiles);
78 string sourceFilesVariable =
"\\\n";
79 for (
auto& file: sourceFiles) sourceFilesVariable+=
"\t" + file +
"\\\n";
80 sourceFilesVariable+=
"\n";
82 string mainSourceFilesVariable =
"\\\n";
83 for (
auto& file: mainSourceFiles) mainSourceFilesVariable+=
"\t" + file +
"\\\n";
84 mainSourceFilesVariable+=
"\n";
86 Console::println(
"Generating Makefile");
88 auto executableFolder = StringTools::replace(argv[0],
"\\",
"/");
89 auto tdme2Folder = StringTools::substring(executableFolder, 0, executableFolder.rfind(
"/tdme2/") +
string(
"/tdme2/").length());
91 auto makefileSource = FileSystem::getInstance()->getContentAsString(tdme2Folder +
"/resources/engine/templates/makefiles",
"Makefile");
92 makefileSource = StringTools::replace(makefileSource,
"{$source-files}", sourceFilesVariable);
93 makefileSource = StringTools::replace(makefileSource,
"{$main-source-files}", mainSourceFilesVariable);
94 FileSystem::getInstance()->setContentFromString(
".",
"Makefile", makefileSource);
96 Console::println(
"An error occurred: " +
string(exception.what()));
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.