Fix absolute path in Makefile
This commit is contained in:
@@ -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 $@ $<
|
||||
|
||||
+15
-1
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#define BIT(x) (1<<x)
|
||||
|
||||
@@ -12,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 1
|
||||
#define MAKEGEN_VERSION_MINOR 2
|
||||
#define MAKEGEN_VERSION ("v" STR(MAKEGEN_VERSION_MAJOR) "." STR(MAKEGEN_VERSION_RELEASE) "." STR(MAKEGEN_VERSION_MINOR))
|
||||
|
||||
const static unsigned int FLAG_HELP = BIT(0);
|
||||
@@ -37,3 +38,16 @@ void Log(const T& var, const Ts& ...vars)
|
||||
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);
|
||||
}
|
||||
|
||||
+1
-1
@@ -119,8 +119,8 @@ ConfigFile ConfigFile::Load(const std::string& filepath)
|
||||
// Create dependency config files.
|
||||
for(size_t i = 0; i < conf.dependencies.size();++i)
|
||||
{
|
||||
conf.dependencyConfigs.push_back(ConfigFile::Load(conf.configPath + conf.dependencies[i]));
|
||||
conf.dependencies[i] = FileUtils::GetRealPath(conf.dependencies[i]);
|
||||
conf.dependencyConfigs.push_back(ConfigFile::Load(conf.dependencies[i]));
|
||||
}
|
||||
|
||||
return conf;
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include "Common.h"
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include <stdlib.h>
|
||||
|
||||
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<n;i++)
|
||||
{
|
||||
result+="..";
|
||||
if(i != n-1)
|
||||
result+="/";
|
||||
}
|
||||
return result;
|
||||
}
|
||||
// Otherwise it's a path in another directory
|
||||
else
|
||||
{
|
||||
// Find the most common directory
|
||||
std::string commonPath = CommonPrefix(from,to);
|
||||
while(commonPath.back() != '/')
|
||||
commonPath.pop_back();
|
||||
commonPath.pop_back();
|
||||
|
||||
// Go back to the common directory
|
||||
std::string sub = from.substr(commonPath.size());
|
||||
size_t n = std::count(sub.begin(), sub.end(), '/');
|
||||
for(int i = 0;i<n;i++)
|
||||
{
|
||||
result+="..";
|
||||
if(i != n-1)
|
||||
result+="/";
|
||||
}
|
||||
// Add the path which diverges
|
||||
result += to.substr(commonPath.size());
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
static void GetAllFiles(const std::string& folder, std::vector<std::string>& files)
|
||||
{
|
||||
DIR* dp;
|
||||
|
||||
+10
-6
@@ -6,6 +6,8 @@
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
#include <exception>
|
||||
#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){}
|
||||
|
||||
|
||||
+3
-1
@@ -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;
|
||||
|
||||
+3
-1
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user