Change so that project h files are not listed as include dependency
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
# This Makefile was generated using MakeGen v1.1.4 made by Tim Håkansson
|
||||
# This Makefile was generated using MakeGen v1.1.5 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++
|
||||
@@ -7,7 +7,7 @@ MKDIR_P=mkdir -p
|
||||
BIN=bin/
|
||||
OBJPATH=$(BIN)intermediates
|
||||
INCLUDES=
|
||||
OBJECTS=$(OBJPATH)/ConfigFile.o $(OBJPATH)/HFileGen.o $(OBJPATH)/IncludeDeps.o $(OBJPATH)/Makefile.o $(OBJPATH)/main.o
|
||||
OBJECTS=$(OBJPATH)/ConfigFile.o $(OBJPATH)/HFileGen.o $(OBJPATH)/IncludeDeps.o $(OBJPATH)/Makefile.o $(OBJPATH)/Utils.o $(OBJPATH)/main.o
|
||||
CFLAGS=$(INCLUDES) -std=c++17 -c -w -g3 -D_DEBUG
|
||||
LIBDIR=
|
||||
LDFLAGS=
|
||||
@@ -33,18 +33,21 @@ $(OUTPUT): $(OBJECTS)
|
||||
install: all
|
||||
$(info Installing MakeGen to /usr/bin/)
|
||||
@cp $(OUTPUT) /usr/bin/makegen
|
||||
$(OBJPATH)/ConfigFile.o : src/ConfigFile.cpp src/Common.h src/ConfigFile.h src/FileUtils.h
|
||||
$(info -[20%]- $<)
|
||||
$(OBJPATH)/ConfigFile.o : src/ConfigFile.cpp src/Common.h src/ConfigFile.h src/FileUtils.h src/Utils.h
|
||||
$(info -[16%]- $<)
|
||||
$(CC) $(CFLAGS) -o $@ $<
|
||||
$(OBJPATH)/HFileGen.o : src/HFileGen.cpp src/FileUtils.h src/Common.h src/HFileGen.h src/ConfigFile.h
|
||||
$(info -[40%]- $<)
|
||||
$(OBJPATH)/HFileGen.o : src/HFileGen.cpp src/FileUtils.h src/Common.h src/Utils.h src/ConfigFile.h src/HFileGen.h
|
||||
$(info -[33%]- $<)
|
||||
$(CC) $(CFLAGS) -o $@ $<
|
||||
$(OBJPATH)/IncludeDeps.o : src/IncludeDeps.cpp src/Common.h src/IncludeDeps.h src/ConfigFile.h src/FileUtils.h
|
||||
$(info -[60%]- $<)
|
||||
$(OBJPATH)/IncludeDeps.o : src/IncludeDeps.cpp src/Common.h src/IncludeDeps.h src/ConfigFile.h src/FileUtils.h src/Utils.h
|
||||
$(info -[50%]- $<)
|
||||
$(CC) $(CFLAGS) -o $@ $<
|
||||
$(OBJPATH)/Makefile.o : src/Makefile.cpp src/Common.h src/FileUtils.h src/IncludeDeps.h src/ConfigFile.h src/Makefile.h
|
||||
$(info -[80%]- $<)
|
||||
$(OBJPATH)/Makefile.o : src/Makefile.cpp src/Common.h src/FileUtils.h src/Utils.h src/ConfigFile.h src/IncludeDeps.h src/Makefile.h
|
||||
$(info -[66%]- $<)
|
||||
$(CC) $(CFLAGS) -o $@ $<
|
||||
$(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
|
||||
$(OBJPATH)/Utils.o : src/Utils.cpp src/FileUtils.h src/Common.h src/Utils.h src/ConfigFile.h
|
||||
$(info -[83%]- $<)
|
||||
$(CC) $(CFLAGS) -o $@ $<
|
||||
$(OBJPATH)/main.o : src/main.cpp src/Common.h src/ConfigFile.h src/FileUtils.h src/Utils.h src/HFileGen.h src/IncludeDeps.h src/Makefile.h src/Timer.h
|
||||
$(info -[100%]- $<)
|
||||
$(CC) $(CFLAGS) -o $@ $<
|
||||
|
||||
+1
-15
@@ -13,7 +13,7 @@
|
||||
// Release , should be backwards compatible with any minor version
|
||||
#define MAKEGEN_VERSION_RELEASE 1
|
||||
// Minor changes, should be compatible with any other minor version with same major and release.
|
||||
#define MAKEGEN_VERSION_MINOR 4
|
||||
#define MAKEGEN_VERSION_MINOR 5
|
||||
#define MAKEGEN_VERSION ("v" STR(MAKEGEN_VERSION_MAJOR) "." STR(MAKEGEN_VERSION_RELEASE) "." STR(MAKEGEN_VERSION_MINOR))
|
||||
|
||||
const static unsigned int FLAG_HELP = BIT(0);
|
||||
@@ -44,17 +44,3 @@ void Log(const T& var, const Ts& ...vars)
|
||||
Log(var);
|
||||
Log(vars...);
|
||||
}
|
||||
|
||||
inline std::string CommonPrefix(const std::string& s1, const std::string& s2)
|
||||
{
|
||||
size_t n = 0;
|
||||
for(size_t i = 0; i<s1.size() && i<s2.size();++i)
|
||||
{
|
||||
if(s1[i] != s2[i])
|
||||
{
|
||||
n = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return s1.substr(0, n);
|
||||
}
|
||||
|
||||
+2
-1
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "Common.h"
|
||||
#include "Utils.h"
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
#include <dirent.h>
|
||||
@@ -74,7 +75,7 @@ struct FileUtils
|
||||
else
|
||||
{
|
||||
// Find the most common directory
|
||||
std::string commonPath = CommonPrefix(from,to);
|
||||
std::string commonPath = Utils::CommonPrefix(from,to);
|
||||
while(commonPath.back() != '/')
|
||||
commonPath.pop_back();
|
||||
commonPath.pop_back();
|
||||
|
||||
+11
-6
@@ -3,8 +3,13 @@
|
||||
|
||||
std::set<std::string> IncludeDeps::printSet;
|
||||
int IncludeDeps::printCounter = 0;
|
||||
IncludeDeps::IncludeDeps(const std::string& filename, const std::string& dir, const std::map<std::string, std::string>& files, std::map<std::string, IncludeDeps*>& allDeps)
|
||||
: filepath(dir+filename)
|
||||
|
||||
IncludeDeps::IncludeDeps(const std::string& filename, const std::string& dir, const std::set<HFile>& files, std::map<std::string, IncludeDeps*>& allDeps)
|
||||
: IncludeDeps{filename, dir, false, files, allDeps}
|
||||
{}
|
||||
|
||||
IncludeDeps::IncludeDeps(const std::string& filename, const std::string& dir, bool projectHFile, const std::set<HFile>& files, std::map<std::string, IncludeDeps*>& allDeps)
|
||||
: filepath(dir+filename), projectHFile{projectHFile}
|
||||
{
|
||||
if(filename[filename.length() - 1] =='h')
|
||||
{
|
||||
@@ -18,14 +23,14 @@ IncludeDeps::IncludeDeps(const std::string& filename, const std::string& dir, co
|
||||
if(pos != std::string::npos)
|
||||
{
|
||||
std::string include = GetIncludeFile(line, pos, filename);
|
||||
auto it = files.find(include);
|
||||
auto it = files.find({include, "", false});
|
||||
if(it != files.end())
|
||||
{
|
||||
auto itD = allDeps.find(it->second + it->first);
|
||||
auto itD = allDeps.find(it->filepath);
|
||||
if(itD == allDeps.end())
|
||||
{
|
||||
IncludeDeps* inc = new IncludeDeps(it->first, it->second,files,allDeps);
|
||||
dependencies.emplace(it->second + it->first, inc);
|
||||
IncludeDeps* inc = new IncludeDeps(it->filename,it->directory, it->isProjectHFile, files,allDeps);
|
||||
dependencies.emplace(it->filepath, inc);
|
||||
}else{
|
||||
dependencies.emplace(itD->first, itD->second);
|
||||
}
|
||||
|
||||
+14
-12
@@ -1,13 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <set>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
#include <exception>
|
||||
#include "ConfigFile.h"
|
||||
#include "FileUtils.h"
|
||||
#include "Utils.h"
|
||||
|
||||
#include <exception>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <string>
|
||||
|
||||
struct CompareIncludeDeps;
|
||||
|
||||
@@ -16,10 +18,13 @@ class IncludeDeps
|
||||
public:
|
||||
std::map<std::string, IncludeDeps*> dependencies;
|
||||
std::string filepath;
|
||||
bool projectHFile;
|
||||
static std::set<std::string> printSet;
|
||||
static int printCounter;
|
||||
|
||||
IncludeDeps(const std::string& filename, const std::string& dir, const std::map<std::string, std::string>& files, std::map<std::string, IncludeDeps*>& allDeps);
|
||||
IncludeDeps(const std::string& filename, const std::string& dir, const std::set<HFile>& files, std::map<std::string, IncludeDeps*>& allDeps);
|
||||
|
||||
IncludeDeps(const std::string& filename, const std::string& dir, bool projectHFile, const std::set<HFile>& files, std::map<std::string, IncludeDeps*>& allDeps);
|
||||
|
||||
std::string GetIncludeFile(const std::string& line, size_t pos, const std::string& filename);
|
||||
|
||||
@@ -29,7 +34,8 @@ class IncludeDeps
|
||||
return stream;
|
||||
printCounter++;
|
||||
printSet.emplace(filepath);
|
||||
stream << FileUtils::GetRelativePath(conf.configPath, filepath);
|
||||
if(!projectHFile)
|
||||
stream << FileUtils::GetRelativePath(conf.configPath, filepath);
|
||||
for(auto it = dependencies.begin();it!=dependencies.end();++it)
|
||||
{
|
||||
stream << " ";
|
||||
@@ -40,10 +46,6 @@ class IncludeDeps
|
||||
printSet.clear();
|
||||
return stream;
|
||||
}
|
||||
|
||||
IncludeDeps(const std::string& filename, const std::string& dir)
|
||||
: filepath(dir+filename){}
|
||||
|
||||
};
|
||||
|
||||
struct CompareIncludeDeps
|
||||
|
||||
+11
-53
@@ -1,18 +1,20 @@
|
||||
#include "Makefile.h"
|
||||
#include <map>
|
||||
#include <errno.h>
|
||||
#include <dirent.h>
|
||||
#include <cstring>
|
||||
#include <fstream>
|
||||
#include "IncludeDeps.h"
|
||||
|
||||
#include "Common.h"
|
||||
#include "FileUtils.h"
|
||||
#include "IncludeDeps.h"
|
||||
#include "Utils.h"
|
||||
|
||||
#include <cstring>
|
||||
#include <dirent.h>
|
||||
#include <fstream>
|
||||
#include <map>
|
||||
|
||||
void Makefile::Save(const ConfigFile& conf)
|
||||
{
|
||||
std::map<std::string, std::string> hFiles; // hFile, directory
|
||||
std::set<HFile> hFiles; // hFile, directory
|
||||
std::set<std::string> cppFiles;
|
||||
GetCppAndHFiles(conf,hFiles,cppFiles);
|
||||
Utils::GetCppAndHFiles(conf, hFiles, cppFiles);
|
||||
|
||||
std::ofstream outputFile(conf.configPath + "Makefile");
|
||||
outputFile << "# This Makefile was generated using MakeGen "<< MAKEGEN_VERSION<< " made by Tim Håkansson" << std::endl;
|
||||
@@ -141,7 +143,7 @@ void Makefile::Save(const ConfigFile& conf)
|
||||
|
||||
std::map<std::string, IncludeDeps*> dependencies;
|
||||
size_t i = 0;
|
||||
for(auto it = cppFiles.begin(); it!=cppFiles.end();++it)
|
||||
for(auto it = cppFiles.begin(); it!= cppFiles.end();++it)
|
||||
{
|
||||
i++;
|
||||
auto itD = dependencies.find(conf.srcdir + *it);
|
||||
@@ -161,47 +163,3 @@ void Makefile::Save(const ConfigFile& conf)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Makefile::GetCppAndHFiles(const ConfigFile& conf, std::map<std::string, std::string>& hFiles, std::set<std::string>& cppFiles)
|
||||
{
|
||||
std::vector<std::string> files;
|
||||
std::string path = conf.configPath + conf.srcdir;
|
||||
FileUtils::GetAllFiles(path,files);
|
||||
// include paramenter with the path of the file
|
||||
// For example src/graphics/Window.h -> graphics/Window.h if src is a src folder
|
||||
for(auto it = files.begin(); it!=files.end();++it)
|
||||
{
|
||||
size_t extensionPos = it->find_last_of(".");
|
||||
if(extensionPos != std::string::npos)
|
||||
{
|
||||
std::string extension = it->substr(extensionPos+1);
|
||||
std::string filename = it->substr(path.length());
|
||||
if(extension == "cpp" || extension == "c")
|
||||
{
|
||||
cppFiles.emplace(filename);
|
||||
}
|
||||
else if(extension == "hpp" || extension == "h")
|
||||
{
|
||||
hFiles.emplace(filename,path);
|
||||
}
|
||||
}
|
||||
}
|
||||
for(size_t i = 0; i < conf.dependencies.size(); ++i)
|
||||
{
|
||||
std::vector<std::string> files;
|
||||
std::string depSrcDir = conf.dependencies[i] + conf.dependencyConfigs[i].srcdir;
|
||||
FileUtils::GetAllFiles(depSrcDir, files);
|
||||
for(auto it = files.begin(); it!=files.end();++it)
|
||||
{
|
||||
size_t extensionPos = it->find_last_of(".");
|
||||
if(extensionPos != std::string::npos)
|
||||
{
|
||||
std::string extension = it->substr(extensionPos+1);
|
||||
if(extension == "hpp" || extension == "h")
|
||||
{
|
||||
hFiles.emplace(it->substr(depSrcDir.length()),depSrcDir);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-2
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "ConfigFile.h"
|
||||
|
||||
#include <set>
|
||||
#include <map>
|
||||
|
||||
@@ -8,6 +9,4 @@ class Makefile
|
||||
{
|
||||
public:
|
||||
static void Save(const ConfigFile& conf);
|
||||
private:
|
||||
static void GetCppAndHFiles(const ConfigFile& conf, std::map<std::string, std::string>& hFiles, std::set<std::string>& cppFiles);
|
||||
};
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
#include "Utils.h"
|
||||
|
||||
#include "FileUtils.h"
|
||||
|
||||
std::string Utils::CommonPrefix(const std::string& s1, const std::string& s2)
|
||||
{
|
||||
size_t n = 0;
|
||||
for(size_t i = 0; i<s1.size() && i<s2.size();++i)
|
||||
{
|
||||
if(s1[i] != s2[i])
|
||||
{
|
||||
n = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return s1.substr(0, n);
|
||||
}
|
||||
|
||||
void Utils::GetCppAndHFiles(const ConfigFile& conf, std::set<HFile>& hFiles, std::set<std::string>& cppFiles)
|
||||
{
|
||||
std::vector<std::string> files;
|
||||
std::string path = conf.configPath + conf.srcdir;
|
||||
FileUtils::GetAllFiles(path,files);
|
||||
// include paramenter with the path of the file
|
||||
// For example src/graphics/Window.h -> graphics/Window.h if src is a src folder
|
||||
for(auto it = files.begin(); it!=files.end();++it)
|
||||
{
|
||||
size_t extensionPos = it->find_last_of(".");
|
||||
if(extensionPos != std::string::npos)
|
||||
{
|
||||
std::string extension = it->substr(extensionPos+1);
|
||||
std::string filename = it->substr(path.length());
|
||||
if(extension == "cpp" || extension == "c")
|
||||
{
|
||||
cppFiles.emplace(filename);
|
||||
}
|
||||
else if(extension == "hpp" || extension == "h")
|
||||
{
|
||||
hFiles.emplace(HFile{filename,path,false});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(size_t i = 0; i < conf.dependencies.size(); ++i)
|
||||
{
|
||||
GetHFiles(conf.dependencies[i], conf.dependencyConfigs[i], hFiles);
|
||||
}
|
||||
}
|
||||
|
||||
void Utils::GetHFiles(const std::string& dependencyDir, const ConfigFile& conf, std::set<HFile>& hFiles)
|
||||
{
|
||||
// TODO: Fix so that cyclic dependencies doesn't crash the tool.
|
||||
// Cyclic dependencies probably shouldn't exist.
|
||||
// so just warn the user that it does and terminate.
|
||||
for(size_t i = 0; i < conf.dependencies.size(); ++i)
|
||||
{
|
||||
GetHFiles(conf.dependencies[i], conf.dependencyConfigs[i], hFiles);
|
||||
}
|
||||
|
||||
std::vector<std::string> files;
|
||||
std::string depSrcDir = dependencyDir + conf.srcdir;
|
||||
FileUtils::GetAllFiles(depSrcDir, files);
|
||||
for(auto it = files.begin(); it!=files.end();++it)
|
||||
{
|
||||
size_t extensionPos = it->find_last_of(".");
|
||||
if(extensionPos != std::string::npos)
|
||||
{
|
||||
std::string extension = it->substr(extensionPos+1);
|
||||
if(extension == "hpp" || extension == "h")
|
||||
{
|
||||
std::string filename = it->substr(depSrcDir.length());
|
||||
hFiles.emplace(HFile{filename, depSrcDir, conf.generateHFile && filename == conf.hFile});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
#pragma once
|
||||
|
||||
#include "ConfigFile.h"
|
||||
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <string>
|
||||
|
||||
|
||||
struct HFile
|
||||
{
|
||||
std::string filename;
|
||||
std::string directory;
|
||||
bool isProjectHFile;
|
||||
|
||||
std::string filepath;
|
||||
|
||||
HFile(const std::string& filename, const std::string& directory, bool isProjectHFile)
|
||||
: filename{filename}, directory{directory}, isProjectHFile{isProjectHFile}, filepath{directory+filename}
|
||||
{}
|
||||
|
||||
friend bool operator<(const HFile& h1, const HFile& h2)
|
||||
{
|
||||
return h1.filename < h2.filename;
|
||||
}
|
||||
};
|
||||
|
||||
struct Utils
|
||||
{
|
||||
static std::string CommonPrefix(const std::string& s1, const std::string& s2);
|
||||
static void GetCppAndHFiles(const ConfigFile& conf, std::set<HFile>& hFiles, std::set<std::string>& cppFiles);
|
||||
static void GetHFiles(const std::string& dependencyDir, const ConfigFile& conf, std::set<HFile>& hFiles);
|
||||
};
|
||||
Reference in New Issue
Block a user