driver cross-compilation
This commit is contained in:
@@ -0,0 +1,178 @@
|
||||
#include "tier0/mem.h"
|
||||
#include "winerunner.h"
|
||||
#include "c.h"
|
||||
#include "helper.h"
|
||||
#include "obj.h"
|
||||
#include "target.h"
|
||||
#include "tier0/lib.h"
|
||||
#include "tier0/mem.h"
|
||||
#include "tier0/platform.h"
|
||||
#include "tier1/commandline.h"
|
||||
#include "tier1/interface.h"
|
||||
#include "tier1/utlstring.h"
|
||||
#include "tier1/utlvector.h"
|
||||
#include "libgen.h"
|
||||
#include "ctype.h"
|
||||
|
||||
struct ClangFile_t
|
||||
{
|
||||
CUtlString m_szName;
|
||||
CUtlVector<CUtlString> m_szArguments;
|
||||
};
|
||||
|
||||
class CMSVCCompiler : public ICCompiler
|
||||
{
|
||||
public:
|
||||
virtual LinkProject_t Compile( CProject_t *pProject ) override;
|
||||
virtual void GenerateLinterData( void ) override;
|
||||
};
|
||||
|
||||
EXPOSE_INTERFACE(CMSVCCompiler, ICCompiler, MSVC_C_COMPILER_INTERFACE_NAME);
|
||||
/*
|
||||
CUtlVector<ClangFile_t> g_msvcFiles;
|
||||
*/
|
||||
LinkProject_t CMSVCCompiler::Compile( CProject_t *pProject )
|
||||
{
|
||||
if (pProject->m_szName == 0)
|
||||
{
|
||||
Plat_FatalErrorFunc("m_szName must be present\n");
|
||||
}
|
||||
|
||||
if (pProject->m_target.kernel != TARGET_KERNEL_WINDOWS_MSVC)
|
||||
{
|
||||
Plat_FatalErrorFunc("target must be TARGET_KERNEL_WINDOWS_MSVC\n");
|
||||
}
|
||||
|
||||
LinkProject_t proj = {};
|
||||
proj.m_szName = pProject->m_szName;
|
||||
proj.m_target = pProject->m_target;
|
||||
proj.m_androidmanifest = pProject->m_androidmanifest;
|
||||
unsigned int hash = pProject->GenerateProjectHash();
|
||||
|
||||
if (!g_pConfig)
|
||||
Plat_FatalErrorFunc(".fpccfg was not found\n");
|
||||
IINISection *pSection = g_pConfig->GetSection("MSVC_C_COMPILER_INTERFACE_NAME");
|
||||
if (!pSection)
|
||||
Plat_FatalErrorFunc("MSVC_C_COMPILER_INTERFACE_NAME was not found in .fpccfg\n");
|
||||
CUtlString szExePath = pSection->GetStringValue("exe");
|
||||
if (!pSection)
|
||||
Plat_FatalErrorFunc("exe was not found in MSVC_C_COMPILER_INTERFACE_NAME\n");
|
||||
|
||||
|
||||
|
||||
// Get output directories
|
||||
for (auto &file: pProject->files)
|
||||
{
|
||||
CUtlString szTarget = pProject->m_target.GetTriplet();
|
||||
CUtlString szOutputFile = CUtlString("%s/%s/cc/%u_%s/%s/%s.obj",FPC_TEMPORAL_DIRNAME, szTarget.GetString(), hash, pProject->m_szName.GetString(), filesystem2->BuildDirectory(), file.GetString());
|
||||
CUtlString szOutputDir = szOutputFile;
|
||||
szOutputDir = dirname(szOutputDir);
|
||||
filesystem2->MakeDirectory(szOutputDir);
|
||||
}
|
||||
|
||||
// Run CC
|
||||
for (auto &file: pProject->files)
|
||||
{
|
||||
V_printf(" CC %s\n", file.GetString());
|
||||
|
||||
CUtlVector<CUtlString> args;
|
||||
CUtlString szTarget = pProject->m_target.GetTriplet();
|
||||
CUtlString szCompiledTarget = szTarget;
|
||||
bool bAreDependenciesUpdated = false;
|
||||
if (pProject->m_target.kernel == TARGET_KERNEL_ANDROID)
|
||||
{
|
||||
szCompiledTarget = CUtlString("%s%u", szTarget.GetString(), pProject->m_androidmanifest.m_nTargetVersion);
|
||||
}
|
||||
CUtlString szOutputFile = CUtlString("%s/%s/cc/%u_%s/%s/%s.obj",FPC_TEMPORAL_DIRNAME, szTarget.GetString(), hash, pProject->m_szName.GetString(), filesystem2->BuildDirectory(), file.GetString());
|
||||
|
||||
args = {
|
||||
"/nologo",
|
||||
};
|
||||
/*
|
||||
if (!strcmp(Plat_GetExtension(file),"cpp"))
|
||||
args.AppendTail("-std=c++17");
|
||||
else if (!strcmp(Plat_GetExtension(file),"mm"))
|
||||
;
|
||||
else
|
||||
args.AppendTail("-std=c99");
|
||||
|
||||
if (pProject->bFPIC)
|
||||
args.AppendTail("-fPIC");
|
||||
if (pProject->bFPIE)
|
||||
args.AppendTail("-fPIE");
|
||||
*/
|
||||
for (auto ¯o: pProject->macros)
|
||||
{
|
||||
args.AppendTail(CUtlString("/D%s=%s", (char*)macro.szName, (char*)macro.szValue));
|
||||
}
|
||||
for (auto &include: pProject->includeDirectories)
|
||||
{
|
||||
const char *szWindowsPath = GetWindowsPath(include.GetString());
|
||||
args.AppendTail(CUtlString("/I%s", szWindowsPath));
|
||||
V_free((void*)szWindowsPath);
|
||||
}
|
||||
/*
|
||||
for (auto &include: pProject->includeFiles)
|
||||
{
|
||||
args.AppendTail("-include");
|
||||
args.AppendTail(include);
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
if (!filesystem2->ShouldRecompile(file, szOutputFile) && !bAreDependenciesUpdated)
|
||||
goto skipcompile;
|
||||
|
||||
args.AppendTail("/c");
|
||||
args.AppendTail(CUtlString("/Fo%s", szOutputFile.GetString()));
|
||||
args.AppendTail(file);
|
||||
|
||||
winerunner->Run(szExePath, args);
|
||||
skipcompile:
|
||||
proj.objects.AppendTail((Object_t){szOutputFile});
|
||||
|
||||
ClangFile_t cfile = {};
|
||||
cfile.m_szName = file;
|
||||
cfile.m_szArguments = args;
|
||||
if (pProject->m_target.kernel == TARGET_KERNEL_ANDROID)
|
||||
{
|
||||
if (!pProject->m_target.szSysroot)
|
||||
Plat_FatalErrorFunc("sysroot must be specified for android\n");
|
||||
cfile.m_szArguments.AppendHead(CUtlString("%s/bin/clang", pProject->m_target.szSysroot));
|
||||
}
|
||||
else
|
||||
cfile.m_szArguments.AppendHead("clang");
|
||||
|
||||
/*
|
||||
g_clangFiles.AppendTail(cfile);
|
||||
*/
|
||||
}
|
||||
winerunner->Wait();
|
||||
return proj;
|
||||
}
|
||||
|
||||
void CMSVCCompiler::GenerateLinterData()
|
||||
{
|
||||
/*
|
||||
FILE* f = V_fopen("compile_commands.json", "wb");
|
||||
V_fprintf(f, "[\n");
|
||||
uint32_t i = 0;
|
||||
for (auto &file: g_clangFiles)
|
||||
{
|
||||
V_fprintf(f, "\t{\n");
|
||||
V_fprintf(f, "\t\t\"arguments\": [\n");
|
||||
for (auto &arg: file.m_szArguments)
|
||||
V_fprintf(f, "\t\t\t\"%s\",\n",arg.GetString());
|
||||
|
||||
V_fseek(f, -2, SEEK_CUR);
|
||||
V_fprintf(f, "\n\t\t],\n");
|
||||
V_fprintf(f, "\t\t\"file\": \"%s\",\n", file.m_szName.GetString());
|
||||
V_fprintf(f, "\t\t\"directory\": \"%s\"\n", filesystem2->BuildDirectory());
|
||||
V_fprintf(f, "\t},\n");
|
||||
};
|
||||
V_fseek(f, -2, SEEK_CUR);
|
||||
V_fprintf(f, "\n]\n");
|
||||
V_fclose(f);
|
||||
*/
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user