Fix so that project builds dependencies

Currently there is a problem where the h files in the makefile are in
absolute path. This makes it so that the Makefile cannot be shared
between different computers.
This commit is contained in:
Thraix
2019-06-16 11:48:08 +02:00
parent 3425daa792
commit 313ec9b770
10 changed files with 193 additions and 96 deletions
+45 -44
View File
@@ -1,57 +1,58 @@
#include "IncludeDeps.h"
#include "Common.h"
std::set<std::string> IncludeDeps::printSet;
int IncludeDeps::printCounter = 0;
IncludeDeps::IncludeDeps(const std::string& filename, const std::string& dir, const std::set<std::string>& files, std::map<std::string, IncludeDeps*>& allDeps)
: filepath(dir+filename)
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)
{
if(filename[filename.length() - 1] =='h')
{
allDeps.emplace(filepath, this);
}
std::ifstream file(filepath);
std::string line;
while(std::getline(file,line))
{
size_t pos = line.find("#include");
if(pos != std::string::npos)
{
if(filename[filename.length() - 1] =='h')
std::string include = GetIncludeFile(line, pos, filename);
auto it = files.find(include);
if(it != files.end())
{
allDeps.emplace(filepath, this);
}
std::ifstream file(filepath);
std::string line;
while(std::getline(file,line))
{
size_t pos = line.find("#include");
if(pos != std::string::npos)
auto itD = allDeps.find(it->second + it->first);
if(itD == allDeps.end())
{
std::string include = GetIncludeFile(line, pos, filename);
auto it = files.find(include);
if(it != files.end())
{
auto itD = allDeps.find(dir + *it);
if(itD == allDeps.end())
{
IncludeDeps* inc = new IncludeDeps(*it, dir,files,allDeps);
dependencies.emplace(dir + *it, inc);
}else{
dependencies.emplace(itD->first, itD->second);
}
}
IncludeDeps* inc = new IncludeDeps(it->first, it->second,files,allDeps);
dependencies.emplace(it->second + it->first, inc);
}else{
dependencies.emplace(itD->first, itD->second);
}
}
}
}
}
std::string IncludeDeps::GetIncludeFile(const std::string& line, size_t pos, const std::string& filename)
std::string IncludeDeps::GetIncludeFile(const std::string& line, size_t pos, const std::string& filename)
{
size_t bracket = line.find('<',pos);
if(bracket == std::string::npos)
{
bracket = line.find('\"',pos);
if(bracket == std::string::npos)
{
size_t bracket = line.find('<',pos);
if(bracket == std::string::npos)
{
bracket = line.find('\"',pos);
if(bracket == std::string::npos)
{
return "";
}
size_t slash = filename.find_last_of("/");
std::string include = line.substr(bracket+1, line.find('\"',bracket+1)-bracket-1);
if(slash == std::string::npos)
slash = -1;
return filename.substr(0,slash+1)+include;
}
else
{
return line.substr(bracket+1, line.find('>',bracket+1)-bracket-1);
}
return "";
}
size_t slash = filename.find_last_of("/");
std::string include = line.substr(bracket+1, line.find('\"',bracket+1)-bracket-1);
if(slash == std::string::npos)
slash = -1;
return filename.substr(0,slash+1)+include;
}
else
{
return line.substr(bracket+1, line.find('>',bracket+1)-bracket-1);
}
}