80 lines
1.9 KiB
C++
80 lines
1.9 KiB
C++
#include "ld.h"
|
|
#include "helper.h"
|
|
#include "libgen.h"
|
|
|
|
CUtlString CLDProject::Link( void )
|
|
{
|
|
CUtlString szFileName;
|
|
unsigned int hash = GenerateProjectHash();
|
|
switch(linkType)
|
|
{
|
|
case ELINK_EXECUTABLE:
|
|
szFileName = CUtlString("%s", m_szName.GetString());
|
|
break;
|
|
case ELINK_STATIC_LIBRARY:
|
|
szFileName = CUtlString("lib%s.a", m_szName.GetString());
|
|
break;
|
|
case ELINK_DYNAMIC_LIBRARY:
|
|
szFileName = CUtlString("lib%s.so", m_szName.GetString());
|
|
break;
|
|
}
|
|
CUtlString szOutputFile = CUtlString("%s/ld/%u_%s/%s",FPC_TEMPORAL_DIRNAME, hash, m_szName.GetString(), szFileName.GetString());
|
|
CUtlString szOutputDir = szOutputFile;
|
|
szOutputDir = dirname(szOutputDir);
|
|
IFileSystem2::MakeDirectory(szOutputDir);
|
|
if (linkType == ELINK_STATIC_LIBRARY)
|
|
{
|
|
V_printf(" AR %s\n", m_szName.GetString());
|
|
bool shouldRecompile = false;
|
|
CUtlVector<CUtlString> args;
|
|
for (auto object: objects)
|
|
{
|
|
if (IFileSystem2::ShouldRecompile(object.m_szObjectFile,szOutputFile))
|
|
{
|
|
shouldRecompile = true;
|
|
break;
|
|
}
|
|
}
|
|
if (!shouldRecompile)
|
|
goto compiled;
|
|
args = {
|
|
"rcs",
|
|
szOutputFile
|
|
};
|
|
for (auto object: objects)
|
|
args.AppendTail(object.m_szObjectFile);
|
|
IRunner::Run("ar", args);
|
|
} else {
|
|
V_printf(" LINK %s\n", m_szName.GetString());
|
|
bool shouldRecompile = false;
|
|
CUtlVector<CUtlString> args;
|
|
for (auto object: objects)
|
|
{
|
|
if (IFileSystem2::ShouldRecompile(object.m_szObjectFile,szOutputFile))
|
|
{
|
|
shouldRecompile = true;
|
|
break;
|
|
}
|
|
}
|
|
if (!shouldRecompile)
|
|
goto compiled;
|
|
args = {
|
|
"-rdynamic",
|
|
"-o",
|
|
szOutputFile,
|
|
};
|
|
if (linkType == ELINK_DYNAMIC_LIBRARY)
|
|
args.AppendTail("-shared");
|
|
for (auto object: objects)
|
|
args.AppendTail(object.m_szObjectFile);
|
|
for (auto lib: libraries)
|
|
{
|
|
args.AppendTail("-l");
|
|
args.AppendTail(lib);
|
|
}
|
|
IRunner::Run("clang++", args);
|
|
}
|
|
compiled:
|
|
return szOutputFile;
|
|
};
|