Started work on build system
This commit is contained in:
61
fpc/library/c.cpp
Normal file
61
fpc/library/c.cpp
Normal file
@@ -0,0 +1,61 @@
|
||||
#include "c.h"
|
||||
#include "filesystem.h"
|
||||
#include "helper.h"
|
||||
#include "tier1/utlvector.h"
|
||||
#include "libgen.h"
|
||||
|
||||
struct ClangFile_t
|
||||
{
|
||||
CUtlString m_szName;
|
||||
CUtlVector<CUtlString> m_szArguments;
|
||||
};
|
||||
|
||||
CUtlVector<ClangFile_t> g_clangFiles;
|
||||
|
||||
CLDProject CCProject::Compile()
|
||||
{
|
||||
CLDProject proj = {};
|
||||
proj.m_szName = m_szName;
|
||||
unsigned int hash = GenerateProjectHash();
|
||||
for (auto &file: files)
|
||||
{
|
||||
CUtlString szOutputFile = CUtlString("%s/cc/%u/%s.o",FPC_TEMPORAL_DIRNAME, hash, file.GetString());
|
||||
CUtlString szOutputDir = szOutputFile;
|
||||
szOutputDir = dirname(szOutputDir);
|
||||
IFileSystem2::MakeDirectory(szOutputDir);
|
||||
|
||||
CUtlVector<CUtlString> args = {
|
||||
"-c",
|
||||
"-o",
|
||||
szOutputFile,
|
||||
file,
|
||||
};
|
||||
if (bFPIC)
|
||||
args.AppendTail("-fPIC");
|
||||
if (bFPIE)
|
||||
args.AppendTail("-fPIE");
|
||||
for (auto ¯o: macros)
|
||||
{
|
||||
args.AppendTail("-D");
|
||||
args.AppendTail(CUtlString("%s=%s", (char*)macro.szName, (char*)macro.szValue));
|
||||
}
|
||||
for (auto &include: includeDirectories)
|
||||
{
|
||||
args.AppendTail("-I");
|
||||
args.AppendTail(include);
|
||||
}
|
||||
for (auto &include: includeFiles)
|
||||
{
|
||||
args.AppendTail("-include");
|
||||
args.AppendTail(include);
|
||||
}
|
||||
IRunner::Run("clang", args);
|
||||
proj.objects.AppendTail((CObject){szOutputFile});
|
||||
|
||||
ClangFile_t file = {};
|
||||
file.m_szName = m_szName;
|
||||
file.m_szArguments = args;
|
||||
g_clangFiles.AppendTail(file);
|
||||
}
|
||||
return proj;
|
||||
}
|
||||
Reference in New Issue
Block a user