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;
|
||||
}
|
||||
46
fpc/library/helper.cpp
Normal file
46
fpc/library/helper.cpp
Normal file
@@ -0,0 +1,46 @@
|
||||
#include "helper.h"
|
||||
#include "runner.h"
|
||||
#include "tier0/platform.h"
|
||||
#include "tier1/utlvector.h"
|
||||
#include "tier1/utlstring.h"
|
||||
|
||||
unsigned int g_hashState = 102851263;
|
||||
unsigned int CProject::GenerateProjectHash( void )
|
||||
{
|
||||
unsigned int hash = 5381+g_hashState;
|
||||
int c;
|
||||
char *szName = m_szName;
|
||||
|
||||
while( (c = *szName++) )
|
||||
hash = (hash * 33) + c;
|
||||
|
||||
g_hashState = g_hashState * 1664525 + 1013904223;
|
||||
|
||||
return hash;
|
||||
};
|
||||
|
||||
void IFileSystem2::MakeDirectory( const char *psz )
|
||||
{
|
||||
CUtlVector<CUtlString> args = {
|
||||
"-p",
|
||||
psz,
|
||||
};
|
||||
IRunner::Run("mkdir", args);
|
||||
};
|
||||
|
||||
CUtlVector<CBuildStage*> g_buildStages;
|
||||
|
||||
CBuildStage::CBuildStage( CUtlString sz, int(*pMainFn)() )
|
||||
{
|
||||
m_sz = sz;
|
||||
m_pMainFn = pMainFn;
|
||||
if (sz == 0 || pMainFn == 0)
|
||||
Plat_FatalErrorFunc("Name and function pointer must be set\n");
|
||||
|
||||
g_buildStages.AppendTail(this);
|
||||
};
|
||||
|
||||
CUtlVector<CBuildStage*>& BuildStages()
|
||||
{
|
||||
return g_buildStages;
|
||||
}
|
||||
42
fpc/library/ld.cpp
Normal file
42
fpc/library/ld.cpp
Normal file
@@ -0,0 +1,42 @@
|
||||
#include "ld.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",FPC_TEMPORAL_DIRNAME, hash, szFileName.GetString());
|
||||
CUtlString szOutputDir = szOutputFile;
|
||||
szOutputDir = dirname(szOutputDir);
|
||||
IFileSystem2::MakeDirectory(szOutputDir);
|
||||
if (linkType == ELINK_STATIC_LIBRARY)
|
||||
{
|
||||
CUtlVector<CUtlString> args = {
|
||||
"rcs",
|
||||
};
|
||||
IRunner::Run("ar", args);
|
||||
} else {
|
||||
CUtlVector<CUtlString> args = {
|
||||
"-o",
|
||||
szOutputFile,
|
||||
};
|
||||
if (linkType == ELINK_DYNAMIC_LIBRARY)
|
||||
args.AppendTail("-shared");
|
||||
for (auto object: objects)
|
||||
args.AppendTail(object.m_szObjectFile);
|
||||
IRunner::Run("clang++", args);
|
||||
}
|
||||
return szOutputFile;
|
||||
};
|
||||
37
fpc/library/runner.cpp
Normal file
37
fpc/library/runner.cpp
Normal file
@@ -0,0 +1,37 @@
|
||||
#include "runner.h"
|
||||
#include "tier0/platform.h"
|
||||
#include "tier1/utlstring.h"
|
||||
#include "tier1/utlvector.h"
|
||||
#include "unistd.h"
|
||||
#include "sys/wait.h"
|
||||
int IRunner::Run(CUtlString szName, CUtlVector<CUtlString>& args)
|
||||
{
|
||||
pid_t pid = fork();
|
||||
if (pid < 0)
|
||||
Plat_FatalErrorFunc("Failed to fork");
|
||||
/* child */
|
||||
if (pid == 0)
|
||||
{
|
||||
CUtlVector<const char*> execargs;
|
||||
execargs.AppendTail(szName);
|
||||
for (auto &arg: args)
|
||||
{
|
||||
execargs.AppendTail(arg);
|
||||
}
|
||||
execargs.AppendTail(0);
|
||||
execvp(szName, (char *const*)execargs.GetData());
|
||||
}
|
||||
/* parent */
|
||||
wait(NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int IRunner::Run(CUtlString szName, CUtlString szDirectory, CUtlVector<CUtlString>& args)
|
||||
{
|
||||
}
|
||||
|
||||
int IRunner::Run(CUtlString szName, CUtlString szDirectory, CUtlVector<CUtlString>& args, CUtlVector<CUtlString>& environment)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user