diff --git a/Makefile b/Makefile index 1904c7a..641ac87 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -# This Makefile was generated using MakeGen v1.1.1 made by Tim HÃ¥kansson +# This Makefile was generated using MakeGen v1.1.2 made by Tim HÃ¥kansson # and is licensed under MIT. Full source of the project can be found at # https://github.com/Thraix/MakeGen CC=@g++ @@ -32,18 +32,18 @@ $(OUTPUT): $(OBJECTS) install: all $(info Installing MakeGen to /usr/bin/) @cp $(OUTPUT) /usr/bin/makegen -$(OBJPATH)/ConfigFile.o : /home/thraix/Documents/MakeGen/src/ConfigFile.cpp /home/thraix/Documents/MakeGen/src/Common.h /home/thraix/Documents/MakeGen/src/ConfigFile.h /home/thraix/Documents/MakeGen/src/FileUtils.h +$(OBJPATH)/ConfigFile.o : src/ConfigFile.cpp src/Common.h src/ConfigFile.h src/FileUtils.h $(info -[20%]- $<) $(CC) $(CFLAGS) -o $@ $< -$(OBJPATH)/HFileGen.o : /home/thraix/Documents/MakeGen/src/HFileGen.cpp /home/thraix/Documents/MakeGen/src/FileUtils.h /home/thraix/Documents/MakeGen/src/Common.h /home/thraix/Documents/MakeGen/src/HFileGen.h /home/thraix/Documents/MakeGen/src/ConfigFile.h +$(OBJPATH)/HFileGen.o : src/HFileGen.cpp src/FileUtils.h src/Common.h src/HFileGen.h src/ConfigFile.h $(info -[40%]- $<) $(CC) $(CFLAGS) -o $@ $< -$(OBJPATH)/IncludeDeps.o : /home/thraix/Documents/MakeGen/src/IncludeDeps.cpp /home/thraix/Documents/MakeGen/src/Common.h /home/thraix/Documents/MakeGen/src/IncludeDeps.h +$(OBJPATH)/IncludeDeps.o : src/IncludeDeps.cpp src/Common.h src/IncludeDeps.h src/ConfigFile.h src/FileUtils.h $(info -[60%]- $<) $(CC) $(CFLAGS) -o $@ $< -$(OBJPATH)/Makefile.o : /home/thraix/Documents/MakeGen/src/Makefile.cpp /home/thraix/Documents/MakeGen/src/Common.h /home/thraix/Documents/MakeGen/src/FileUtils.h /home/thraix/Documents/MakeGen/src/IncludeDeps.h /home/thraix/Documents/MakeGen/src/Makefile.h /home/thraix/Documents/MakeGen/src/ConfigFile.h +$(OBJPATH)/Makefile.o : src/Makefile.cpp src/Common.h src/FileUtils.h src/IncludeDeps.h src/ConfigFile.h src/Makefile.h $(info -[80%]- $<) $(CC) $(CFLAGS) -o $@ $< -$(OBJPATH)/main.o : /home/thraix/Documents/MakeGen/src/main.cpp /home/thraix/Documents/MakeGen/src/Common.h /home/thraix/Documents/MakeGen/src/ConfigFile.h /home/thraix/Documents/MakeGen/src/HFileGen.h /home/thraix/Documents/MakeGen/src/IncludeDeps.h /home/thraix/Documents/MakeGen/src/Makefile.h /home/thraix/Documents/MakeGen/src/Timer.h +$(OBJPATH)/main.o : src/main.cpp src/Common.h src/ConfigFile.h src/FileUtils.h src/HFileGen.h src/IncludeDeps.h src/Makefile.h src/Timer.h $(info -[100%]- $<) $(CC) $(CFLAGS) -o $@ $< diff --git a/src/Common.h b/src/Common.h index ac81250..8f28e27 100755 --- a/src/Common.h +++ b/src/Common.h @@ -1,6 +1,7 @@ #pragma once #include +#include #define BIT(x) (1< #include +#include #include struct FileUtils @@ -23,6 +24,60 @@ struct FileUtils return filename; } + static std::string GetRelativePath(std::string from, std::string to) + { + std::string result; + if(to[to.size()-1] == '/') + to.pop_back(); + if(from[from.size()-1] == '/') + from.pop_back(); + + // Check if the directory is inside 'from' + if(strncmp(to.c_str(), from.c_str(), from.size()) == 0) + { + // Same directory + if(to.size() == from.size()) + return ""; + // Remove the 'from' path + return to.substr(from.size()+1); + } + // Check if the directory is a child of from + else if(strncmp(from.c_str(), to.c_str(), to.size()) == 0) + { + std::string sub = from.substr(to.size()); + size_t n = std::count(sub.begin(), sub.end(), '/'); + for(int i = 0;i& files) { DIR* dp; diff --git a/src/IncludeDeps.h b/src/IncludeDeps.h index 9e11c4b..9d8d039 100755 --- a/src/IncludeDeps.h +++ b/src/IncludeDeps.h @@ -6,6 +6,8 @@ #include #include #include +#include "ConfigFile.h" +#include "FileUtils.h" struct CompareIncludeDeps; @@ -21,22 +23,24 @@ class IncludeDeps std::string GetIncludeFile(const std::string& line, size_t pos, const std::string& filename); - friend std::ostream& operator<<(std::ostream& stream, const IncludeDeps& deps) + std::ostream& Output(std::ostream& stream, const ConfigFile& conf) { - if(printSet.find(deps.filepath) != printSet.end()) + if(printSet.find(filepath) != printSet.end()) return stream; printCounter++; - printSet.emplace(deps.filepath); - stream << deps.filepath; - for(auto it = deps.dependencies.begin();it!=deps.dependencies.end();++it) + printSet.emplace(filepath); + stream << FileUtils::GetRelativePath(conf.configPath, filepath); + for(auto it = dependencies.begin();it!=dependencies.end();++it) { - stream << " " << *(it->second); + stream << " "; + (it->second)->Output(stream, conf); } printCounter--; if(printCounter == 0) printSet.clear(); return stream; } + IncludeDeps(const std::string& filename, const std::string& dir) : filepath(dir+filename){} diff --git a/src/Makefile.cpp b/src/Makefile.cpp index 11acadd..1b5d8ba 100755 --- a/src/Makefile.cpp +++ b/src/Makefile.cpp @@ -139,7 +139,9 @@ void Makefile::Save(const ConfigFile& conf) size_t extensionPos = it->find_last_of("."); size_t slash = it->find_last_of("/")+1; std::string oFile = it->substr(slash, extensionPos - slash)+".o "; - outputFile << "$(OBJPATH)/" << oFile << ": " << *deps << std::endl; + outputFile << "$(OBJPATH)/" << oFile << ": "; + deps->Output(outputFile, conf); + outputFile << std::endl; outputFile << "\t$(info -[" << (int)(i / (float)cppFiles.size() * 100) << "%]- $<)" << std::endl; outputFile << "\t$(CC) $(CFLAGS) -o $@ $<" << std::endl; //std::cout << *deps << std::endl; diff --git a/src/main.cpp b/src/main.cpp index e007557..24ff04f 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -80,7 +80,7 @@ bool MakeGen(const std::string& filepath, const std::string& args, const ConfigF if(!success) return success; } - LOG_INFO("---------------------------"); + LOG_INFO("-----------------------------------"); LOG_INFO("Building ", conf.projectname); LOG_INFO("Generating Makefile..."); Timer timer; @@ -91,6 +91,8 @@ bool MakeGen(const std::string& filepath, const std::string& args, const ConfigF return system(std::string("make --no-print-directory -C " + filepath + " " + args).c_str()) == 0; } +#include "FileUtils.h" + int main(int argc, char** argv) { unsigned int flags = ReadFlags(argc,argv);