Fix relative paths being put in the wrong intermediate directory

This commit is contained in:
Thraix
2026-01-20 23:24:27 +01:00
parent 1edcfb570b
commit b112ab4501
6 changed files with 27 additions and 6 deletions
+1 -1
View File
@@ -1,4 +1,4 @@
# This Makefile was generated using MakeGen v1.3.7 made by Tim Håkansson
# This Makefile was generated using MakeGen v1.3.8 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++
+1 -1
View File
@@ -19,5 +19,5 @@
<srcdir>src/</srcdir>
</configuration>
<target>Release</target>
<version>v1.3.7</version>
<version>v1.3.8</version>
</makegen>
+1 -1
View File
@@ -14,7 +14,7 @@
// Release, should be backwards compatible with any minor version
#define MAKEGEN_VERSION_RELEASE 3
// Minor changes, generally bug fixes
#define MAKEGEN_VERSION_MINOR 7
#define MAKEGEN_VERSION_MINOR 8
#define MAKEGEN_VERSION ("v" STR(MAKEGEN_VERSION_MAJOR) "." STR(MAKEGEN_VERSION_RELEASE) "." STR(MAKEGEN_VERSION_MINOR))
+9 -3
View File
@@ -54,7 +54,9 @@ void Makefile::Save(ConfigFile& conf, unsigned int flags)
{
std::filesystem::path cppFile(*it);
std::filesystem::path oFile = cppFile.replace_extension("o");
outputFile << "$(OBJPATH)/" << oFile.string() << " ";
std::string oFileStr = oFile.string();
Utils::Replace(oFileStr, "..", "dotdot");
outputFile << "$(OBJPATH)/" << oFileStr << " ";
}
outputFile << std::endl;
if (outputtype == "executable" || outputtype != "sharedlibrary")
@@ -182,7 +184,9 @@ void Makefile::Save(ConfigFile& conf, unsigned int flags)
{
std::filesystem::path cppFile(*it);
std::filesystem::path oFile = cppFile.replace_extension("o");
outputFile << "$(OBJPATH)/" << oFile.string() << ":";
std::string oFileStr = oFile.string();
Utils::Replace(oFileStr, "..", "dotdot");
outputFile << "$(OBJPATH)/" << oFileStr << ":";
if (flags & FLAG_SIMPLE)
{
outputFile << " " << *it;
@@ -206,7 +210,9 @@ std::set<std::string> Makefile::GetIntermediateDirectories(const std::set<std::s
{
std::filesystem::path cppPath{cppFile};
std::filesystem::path oFile = cppPath.replace_extension("o");
intermediateDirectories.emplace("$(OBJPATH)/" + oFile.parent_path().string());
std::string parentPathStr = oFile.parent_path().string();
Utils::Replace(parentPathStr, "..", "dotdot");
intermediateDirectories.emplace("$(OBJPATH)/" + parentPathStr);
}
return intermediateDirectories;
}
+13
View File
@@ -40,6 +40,19 @@ bool Utils::StartsWith(const std::string& str, const std::string& prefix)
return str.compare(0, prefix.size(), prefix) == 0;
}
void Utils::Replace(std::string& str, const std::string& from, const std::string& to)
{
if (from.empty())
return;
size_t pos = str.find(from, 0);
while (pos != std::string::npos)
{
str.replace(pos, from.length(), to);
pos = str.find(from, pos + to.length());
}
}
std::string Utils::CommonPrefix(const std::string& s1, const std::string& s2)
{
size_t n = 0;
+2
View File
@@ -38,7 +38,9 @@ struct Utils
static bool IsHeaderFile(const std::string& filepath);
static std::string CommonPrefix(const std::string& s1, const std::string& s2);
static bool StartsWith(const std::string& str, const std::string& prefix);
static void Replace(std::string& str, const std::string& from, const std::string& to);
static void GetCppFiles(ConfigFile& conf, std::set<std::string>& cppFiles);
static void GetCppAndHFiles(ConfigFile& conf, std::set<HFile>& hFiles, std::set<std::string>& cppFiles);
static void GetHFiles(const std::string& dependencyDir, ConfigFile& conf, std::set<HFile>& hFiles);