almost done
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
#include "builder.h"
|
||||
#include "ld.h"
|
||||
#include "c.h"
|
||||
|
||||
class CProjectBuilder : public IProjectBuilder
|
||||
{
|
||||
public:
|
||||
virtual BuildFile_t *BuildProject( const char *szProjectName, const char *szPath ) override;
|
||||
|
||||
BuildFile_t *m_pBuildFiles = NULL;
|
||||
};
|
||||
|
||||
|
||||
static CProjectBuilder s_projectBuilder;
|
||||
|
||||
EXPOSE_INTERFACE_GLOBALVAR(CProjectBuilder, IProjectBuilder, PROJECT_BUILDER_INTERFACE_NAME, s_projectBuilder)
|
||||
|
||||
IProjectBuilder *ProjectBuilder()
|
||||
{
|
||||
return &s_projectBuilder;
|
||||
};
|
||||
|
||||
BuildFile_t *CProjectBuilder::BuildProject( const char *szProjectName, const char *szPath )
|
||||
{
|
||||
CProject_t stCompileProject = {};
|
||||
LinkProject_t stLinkProject = {};
|
||||
CUtlString szBuildLibrary;
|
||||
void *pLibrary;
|
||||
CreateInterfaceFn pBuildFactory;
|
||||
BuildFileInfo_t *pBuildFileInfo;
|
||||
BuildFileInfo_t stBuildFileInfo;
|
||||
BuildFile_t *pBuildFile = NULL;
|
||||
|
||||
CUtlString szWd = CUtlString(szPath).GetDirectory();
|
||||
|
||||
Plat_SetWorkingDir(szWd);
|
||||
|
||||
|
||||
stCompileProject.m_szName = szProjectName;
|
||||
stCompileProject.files = {
|
||||
szPath,
|
||||
};
|
||||
stCompileProject.includeDirectories = {CUtlString("%s/public",filesystem2->OwnDirectory()),CUtlString("%s/public", filesystem2->BuildDirectory()), CUtlString("%s/../public",filesystem2->OwnDirectory()),CUtlString("%s/../public", filesystem2->BuildDirectory())};
|
||||
stCompileProject.bFPIC = true;
|
||||
stCompileProject.m_target = Target_t::HostTarget();
|
||||
|
||||
stLinkProject = ccompiler->Compile(&stCompileProject);
|
||||
stLinkProject.linkType = ELINK_DYNAMIC_LIBRARY;
|
||||
stLinkProject.m_target = Target_t::HostTarget();
|
||||
stLinkProject.objects.AppendHead({CUtlString("%s/libfpcbuild.a",filesystem2->OwnDirectory())});
|
||||
stLinkProject.objects.AppendHead({CUtlString("%s/libtier2.a",filesystem2->OwnDirectory())});
|
||||
stLinkProject.objects.AppendHead({CUtlString("%s/libtier1.a",filesystem2->OwnDirectory())});
|
||||
szBuildLibrary = linker->Link(&stLinkProject);
|
||||
|
||||
pLibrary = Plat_LoadLibrary(szBuildLibrary);
|
||||
if ( !pLibrary )
|
||||
return NULL;
|
||||
|
||||
pBuildFactory = Sys_GetFactory(pLibrary);
|
||||
if (!pBuildFactory)
|
||||
{
|
||||
V_printf("Failed to find CreateInterface\n");
|
||||
Plat_UnloadLibrary(szBuildLibrary);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pBuildFileInfo = (BuildFileInfo_t*)pBuildFactory(BUILD_FILE_INFO_INTERFACE_NAME, NULL);
|
||||
if (!pBuildFileInfo)
|
||||
{
|
||||
V_printf("Failed to find build file info interface\n");
|
||||
Plat_UnloadLibrary(szBuildLibrary);
|
||||
return NULL;
|
||||
}
|
||||
stBuildFileInfo = *pBuildFileInfo;
|
||||
for (auto a: stBuildFileInfo.m_dependantFiles)
|
||||
{
|
||||
BuildProject("something", CUtlString("%s/build.cpp",a));
|
||||
}
|
||||
|
||||
Plat_SetWorkingDir(szWd);
|
||||
|
||||
|
||||
for (auto &build: stBuildFileInfo.m_stages)
|
||||
{
|
||||
build->m_pMainFn();
|
||||
};
|
||||
|
||||
pBuildFile = new BuildFile_t;
|
||||
pBuildFile->m_szOutputFile = szBuildLibrary;
|
||||
pBuildFile->m_pLibrary = pLibrary;
|
||||
pBuildFile->m_pNext = m_pBuildFiles;
|
||||
m_pBuildFiles = pBuildFile;
|
||||
|
||||
|
||||
return pBuildFile;
|
||||
}
|
||||
|
||||
@@ -156,7 +156,7 @@ CUtlString CClangLinker::Link( LinkProject_t *pProject )
|
||||
}
|
||||
if (pProject->m_target.kernel == TARGET_KERNEL_LINUX || pProject->m_target.kernel == TARGET_KERNEL_ANDROID)
|
||||
{
|
||||
args.AppendTail("-rdynamic");
|
||||
//args.AppendTail("-rdynamic");
|
||||
args.AppendTail("-Wl,-rpath,$ORIGIN");
|
||||
}
|
||||
|
||||
|
||||
@@ -133,21 +133,4 @@ bool CPOSIXFileSystem2::ShouldRecompile(const char *szSource, const char *szOutp
|
||||
return outbuf.st_mtime < srcbuf.st_mtime;
|
||||
};
|
||||
|
||||
CUtlVector<CBuildStage*> g_buildStages;
|
||||
|
||||
CBuildStage::CBuildStage( const char *psz, int(*pMainFn)() )
|
||||
{
|
||||
m_psz = psz;
|
||||
m_pMainFn = pMainFn;
|
||||
if (psz == 0 || pMainFn == 0)
|
||||
Plat_FatalErrorFunc("Name and function pointer must be set\n");
|
||||
|
||||
g_buildStages.AppendTail(this);
|
||||
};
|
||||
|
||||
CUtlVector<CBuildStage*>& BuildStages()
|
||||
{
|
||||
return g_buildStages;
|
||||
}
|
||||
|
||||
IINIFile *g_pConfig;
|
||||
|
||||
@@ -1,3 +1,8 @@
|
||||
#include "ld.h"
|
||||
|
||||
ILinker *linker;
|
||||
|
||||
void LinkProject_t::AddObject( Object_t object )
|
||||
{
|
||||
objects.AppendTail(object);
|
||||
};
|
||||
|
||||
@@ -115,7 +115,7 @@ CUtlString CMSVCLinker::Link( LinkProject_t *pProject )
|
||||
"/nologo"
|
||||
};
|
||||
|
||||
const char *szWindowsPath = GetWindowsPath(szOutputFile);
|
||||
const char *szWindowsPath = filesystem2->GetWindowsPath(szOutputFile);
|
||||
args.AppendTail(CUtlString("/out:%s", szWindowsPath));
|
||||
V_free((void*)szWindowsPath);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user