General improvements
This commit is contained in:
141
fpc/library/windows/ld.cpp
Normal file
141
fpc/library/windows/ld.cpp
Normal file
@@ -0,0 +1,141 @@
|
||||
#include "ld.h"
|
||||
#include "helper.h"
|
||||
#include "libgen.h"
|
||||
#include "target.h"
|
||||
#include "tier0/platform.h"
|
||||
#include "tier1/interface.h"
|
||||
#include "tier1/utlstring.h"
|
||||
#include "tier2/fileformats/ini.h"
|
||||
|
||||
class CMSVCLinker : public ILinker
|
||||
{
|
||||
public:
|
||||
virtual CUtlString Link( LinkProject_t *pProject ) override;
|
||||
virtual bool IsLibraryExists( CUtlString szName ) override;
|
||||
};
|
||||
|
||||
EXPOSE_INTERFACE(CMSVCLinker, ILinker, MSVC_LINKER_INTERFACE_NAME);
|
||||
|
||||
CUtlString CMSVCLinker::Link( LinkProject_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");
|
||||
}
|
||||
|
||||
// Find a name for the file
|
||||
CUtlString szFileName;
|
||||
unsigned int hash = pProject->GenerateProjectHash();
|
||||
switch(pProject->linkType)
|
||||
{
|
||||
case ELINK_EXECUTABLE:
|
||||
szFileName = CUtlString("%s.exe", pProject->m_szName.GetString());
|
||||
case ELINK_STATIC_LIBRARY:
|
||||
szFileName = CUtlString("lib%s.a", pProject->m_szName.GetString());
|
||||
break;
|
||||
case ELINK_DYNAMIC_LIBRARY:
|
||||
szFileName = CUtlString("%s.dll", pProject->m_szName.GetString());
|
||||
break;
|
||||
}
|
||||
|
||||
CUtlString szTarget = pProject->m_target.GetTriplet();
|
||||
CUtlString szOutputFile = CUtlString("%s/%s/ld/%u_%s/%s",FPC_TEMPORAL_DIRNAME, szTarget.GetString(), hash, pProject->m_szName.GetString(), szFileName.GetString());
|
||||
CUtlString szOutputDir = szOutputFile;
|
||||
szOutputDir = dirname(szOutputDir);
|
||||
filesystem2->MakeDirectory(szOutputDir);
|
||||
|
||||
IINISection *pSection = g_pConfig->GetSection("MSVC_LINKER_INTERFACE_NAME");
|
||||
CUtlString szExePath = pSection->GetStringValue("exe");
|
||||
|
||||
if (pProject->linkType == ELINK_STATIC_LIBRARY)
|
||||
{
|
||||
V_printf(" AR %s\n", pProject->m_szName.GetString());
|
||||
bool shouldRecompile = false;
|
||||
CUtlVector<CUtlString> args;
|
||||
for (auto object: pProject->objects)
|
||||
{
|
||||
if (filesystem2->ShouldRecompile(object.m_szObjectFile,szOutputFile))
|
||||
{
|
||||
shouldRecompile = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!shouldRecompile)
|
||||
goto compiled;
|
||||
args = {
|
||||
"rcs",
|
||||
szOutputFile
|
||||
};
|
||||
for (auto object: pProject->objects)
|
||||
args.AppendTail(object.m_szObjectFile);
|
||||
runner->Run("ar", args);
|
||||
runner->Wait();
|
||||
|
||||
} else {
|
||||
V_printf(" LINK %s\n", pProject->m_szName.GetString());
|
||||
bool shouldRecompile = false;
|
||||
CUtlVector<CUtlString> args;
|
||||
|
||||
// Check if any of the files have changed
|
||||
for (auto object: pProject->objects)
|
||||
{
|
||||
if (filesystem2->ShouldRecompile(object.m_szObjectFile,szOutputFile))
|
||||
{
|
||||
shouldRecompile = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!shouldRecompile)
|
||||
goto compiled;
|
||||
|
||||
|
||||
CUtlString szTarget = pProject->m_target.GetTriplet();
|
||||
CUtlString szCompiledTarget = szTarget;
|
||||
if (pProject->m_target.kernel == TARGET_KERNEL_ANDROID)
|
||||
{
|
||||
szCompiledTarget = CUtlString("%s%u", szTarget.GetString(), pProject->m_androidmanifest.m_nTargetVersion);
|
||||
}
|
||||
args = {
|
||||
"-o",
|
||||
szOutputFile,
|
||||
"-target",
|
||||
szCompiledTarget,
|
||||
};
|
||||
|
||||
// Disable stdlib
|
||||
if (pProject->bNoStdLib)
|
||||
{
|
||||
args.AppendTail("-nostdlib");
|
||||
}
|
||||
|
||||
for (auto object: pProject->objects)
|
||||
args.AppendTail(object.m_szObjectFile);
|
||||
|
||||
for (auto lib: pProject->libraries)
|
||||
{
|
||||
args.AppendTail("-l");
|
||||
args.AppendTail(lib);
|
||||
}
|
||||
|
||||
// Apple frameworks
|
||||
for (auto &directory: pProject->frameworkDirectories)
|
||||
{
|
||||
args.AppendTail("-F");
|
||||
args.AppendTail(directory);
|
||||
}
|
||||
for (auto &framework: pProject->frameworks)
|
||||
{
|
||||
args.AppendTail("-framework");
|
||||
args.AppendTail(framework);
|
||||
}
|
||||
runner->Run(szExePath, args);
|
||||
runner->Wait();
|
||||
}
|
||||
compiled:
|
||||
return szOutputFile;
|
||||
};
|
||||
Reference in New Issue
Block a user