Migrated
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
#include "c.h"
|
||||
#include "ld.h"
|
||||
#include "tier1/utlstring.h"
|
||||
#include "tier1/commandline.h"
|
||||
|
||||
CUtlVector<CUtlString> engine_CompiledFiles = {
|
||||
"engine/console.cpp",
|
||||
@@ -29,6 +30,12 @@ CUtlVector<CUtlString> engine_CompiledFiles = {
|
||||
"engine/vk_videosdl.cpp",
|
||||
};
|
||||
|
||||
CUtlVector<CUtlString> engine_Libraries = {
|
||||
"c",
|
||||
"SDL3",
|
||||
"vulkan",
|
||||
};
|
||||
|
||||
int engine_build()
|
||||
{
|
||||
CCProject compileProject = {};
|
||||
@@ -40,9 +47,19 @@ int engine_build()
|
||||
compileProject.bFPIC = true;
|
||||
ldProject = compileProject.Compile();
|
||||
ldProject.linkType = ELINK_DYNAMIC_LIBRARY;
|
||||
ldProject.libraries = engine_Libraries;
|
||||
ldProject.objects.AppendTail((CObject){tier1_lib});
|
||||
ldProject.objects.AppendTail((CObject){rapier_lib});
|
||||
|
||||
CUtlString outputProject = ldProject.Link();
|
||||
|
||||
|
||||
const char *szGameName = ICommandLine::ParamValue("-game");
|
||||
if (szGameName == NULL)
|
||||
szGameName = "funnygame";
|
||||
IFileSystem2::CopyFile(CUtlString("build/%s/game/bin",szGameName), outputProject);
|
||||
|
||||
|
||||
return 0;
|
||||
};
|
||||
DECLARE_BUILD_STAGE(engine, engine_build);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
TIER_FILES := ../tier0/lib.cpp ../tier0/mem.cpp ../tier0/platform.cpp ../tier1/utlbuffer.cpp ../tier1/utlstring.cpp ../tier1/utlvector.cpp ../tier1/utlmap.cpp ../tier1/commandline.cpp
|
||||
FPC_FILES := main.cpp library/runner.cpp library/helper.cpp library/c.cpp library/ld.cpp
|
||||
FPC_FILES := main.cpp library/runner.cpp library/helper.cpp library/c.cpp library/ld.cpp library/target.cpp
|
||||
CC = clang
|
||||
OUTPUT_DIR = fpc
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ CUtlVector<CUtlString> g_CompiledFiles = {
|
||||
"library/helper.cpp",
|
||||
"library/c.cpp",
|
||||
"library/ld.cpp",
|
||||
"library/target.cpp",
|
||||
"../tier0/lib.cpp",
|
||||
"../tier0/mem.cpp",
|
||||
"../tier0/platform.cpp",
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
#include "helper.h"
|
||||
#include "tier1/utlvector.h"
|
||||
#include "libgen.h"
|
||||
#include <cstdio>
|
||||
|
||||
struct ClangFile_t
|
||||
{
|
||||
@@ -21,11 +20,10 @@ CLDProject CCProject::Compile()
|
||||
for (auto &file: files)
|
||||
{
|
||||
CUtlString szOutputFile = CUtlString("%s/cc/%u_%s/%s/%s.o",FPC_TEMPORAL_DIRNAME, hash, m_szName.GetString(), IFileSystem2::OwnDirectory(), file.GetString());
|
||||
CUtlString szOutputDir = szOutputFile;
|
||||
szOutputDir = dirname(szOutputDir);
|
||||
IFileSystem2::MakeDirectory(szOutputDir);
|
||||
CUtlString szOutputDir;
|
||||
CUtlVector<CUtlString> args;
|
||||
|
||||
CUtlVector<CUtlString> args = {
|
||||
args = {
|
||||
"-g",
|
||||
"-c",
|
||||
"-o",
|
||||
@@ -51,7 +49,14 @@ CLDProject CCProject::Compile()
|
||||
args.AppendTail("-include");
|
||||
args.AppendTail(include);
|
||||
}
|
||||
if (!IFileSystem2::ShouldRecompile(file, szOutputFile))
|
||||
goto skipcompile;
|
||||
szOutputDir = szOutputFile;
|
||||
szOutputDir = dirname(szOutputDir);
|
||||
IFileSystem2::MakeDirectory(szOutputDir);
|
||||
IRunner::Run("clang", args);
|
||||
|
||||
skipcompile:
|
||||
proj.objects.AppendTail((CObject){szOutputFile});
|
||||
|
||||
ClangFile_t cfile = {};
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "tier1/utlstring.h"
|
||||
#include "unistd.h"
|
||||
#include "libgen.h"
|
||||
#include "sys/stat.h"
|
||||
|
||||
unsigned int g_hashState = 102851263;
|
||||
unsigned int CProject::GenerateProjectHash( void )
|
||||
@@ -52,6 +53,19 @@ void IFileSystem2::MakeDirectory( const char *psz )
|
||||
IRunner::Run("mkdir", args);
|
||||
};
|
||||
|
||||
bool IFileSystem2::ShouldRecompile(const char *szSource, const char *szOutput)
|
||||
{
|
||||
struct stat srcbuf;
|
||||
struct stat outbuf;
|
||||
if (stat(szSource, &srcbuf) != 0) {
|
||||
return true;
|
||||
}
|
||||
if (stat(szOutput, &outbuf) != 0) {
|
||||
return true;
|
||||
}
|
||||
return outbuf.st_mtime < srcbuf.st_mtime;
|
||||
};
|
||||
|
||||
CUtlVector<CBuildStage*> g_buildStages;
|
||||
|
||||
CBuildStage::CBuildStage( CUtlString sz, int(*pMainFn)() )
|
||||
|
||||
@@ -40,6 +40,11 @@ CUtlString CLDProject::Link( void )
|
||||
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);
|
||||
}
|
||||
return szOutputFile;
|
||||
|
||||
@@ -16,6 +16,7 @@ int IRunner::Run(CUtlString szName, CUtlVector<CUtlString>& args)
|
||||
execargs.AppendTail(szName);
|
||||
for (auto &arg: args)
|
||||
{
|
||||
V_printf("%s\n",arg.GetString());
|
||||
execargs.AppendTail(arg);
|
||||
}
|
||||
execargs.AppendTail(0);
|
||||
|
||||
16
fpc/library/target.cpp
Normal file
16
fpc/library/target.cpp
Normal file
@@ -0,0 +1,16 @@
|
||||
#include "target.h"
|
||||
#include <god/build.h>
|
||||
|
||||
Target_t Target_t::DefaultTarget()
|
||||
{
|
||||
return {
|
||||
.kernel = TARGET_KERNEL_LINUX,
|
||||
#ifdef __x86_64__
|
||||
.cpu = TARGET_CPU_AMD64,
|
||||
#endif
|
||||
#ifdef __x86__
|
||||
.cpu = TARGET_CPU_I386,
|
||||
#endif
|
||||
.optimization = TARGET_DEBUG,
|
||||
};
|
||||
}
|
||||
@@ -23,6 +23,7 @@ public:
|
||||
CUtlVector<CUtlString> includeFiles;
|
||||
bool bFPIE;
|
||||
bool bFPIC;
|
||||
bool bDebug = m_target.optimization == TARGET_DEBUG;
|
||||
CLDProject Compile();
|
||||
static void GenerateCompileCommands();
|
||||
};
|
||||
|
||||
@@ -2,12 +2,14 @@
|
||||
#define HELPER_H
|
||||
|
||||
#include "tier1/utlstring.h"
|
||||
#include "target.h"
|
||||
|
||||
#define FPC_TEMPORAL_DIRNAME ".fpc"
|
||||
|
||||
class CProject
|
||||
{
|
||||
public:
|
||||
Target_t m_target = Target_t::DefaultTarget();
|
||||
CUtlString m_szName;
|
||||
unsigned int GenerateProjectHash( void );
|
||||
};
|
||||
@@ -20,6 +22,7 @@ public:
|
||||
static void MakeDirectory( const char *psz );
|
||||
static void CopyFile( const char *szDestination, const char *szOrigin );
|
||||
static void CopyDirectory( const char *szDestination, const char *szOrigin );
|
||||
static bool ShouldRecompile( const char *szSource, const char *szOutput );
|
||||
};
|
||||
|
||||
class CBuildStage
|
||||
|
||||
@@ -13,10 +13,18 @@ enum ETargetCPU
|
||||
TARGET_CPU_I386,
|
||||
};
|
||||
|
||||
enum ETargetOptimization
|
||||
{
|
||||
TARGET_DEBUG,
|
||||
TARGET_RELEASE_SPEED,
|
||||
TARGET_RELEASE_SIZE
|
||||
};
|
||||
|
||||
struct Target_t
|
||||
{
|
||||
ETargetKernel kernel;
|
||||
ETargetCPU cpu;
|
||||
ETargetOptimization optimization;
|
||||
static Target_t DefaultTarget();
|
||||
};
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include "c.h"
|
||||
#include "ld.h"
|
||||
#include "tier1/utlstring.h"
|
||||
#include "tier1/commandline.h"
|
||||
|
||||
CUtlVector<CUtlString> client_CompiledFiles = {
|
||||
"game/client/baseplayer.cpp",
|
||||
@@ -20,6 +21,11 @@ int client_build()
|
||||
ldProject.linkType = ELINK_DYNAMIC_LIBRARY;
|
||||
|
||||
CUtlString outputProject = ldProject.Link();
|
||||
|
||||
const char *szGameName = ICommandLine::ParamValue("-game");
|
||||
if (szGameName == NULL)
|
||||
szGameName = "funnygame";
|
||||
IFileSystem2::CopyFile(CUtlString("build/%s/game/%s/bin",szGameName,szGameName), outputProject);
|
||||
|
||||
return 0;
|
||||
};
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include "c.h"
|
||||
#include "ld.h"
|
||||
#include "tier1/utlstring.h"
|
||||
#include "tier1/commandline.h"
|
||||
|
||||
CUtlVector<CUtlString> server_CompiledFiles = {
|
||||
"game/server/game.cpp",
|
||||
@@ -21,6 +22,11 @@ int server_build()
|
||||
ldProject.linkType = ELINK_DYNAMIC_LIBRARY;
|
||||
|
||||
CUtlString outputProject = ldProject.Link();
|
||||
|
||||
const char *szGameName = ICommandLine::ParamValue("-game");
|
||||
if (szGameName == NULL)
|
||||
szGameName = "funnygame";
|
||||
IFileSystem2::CopyFile(CUtlString("build/%s/game/%s/bin",szGameName,szGameName), outputProject);
|
||||
|
||||
return 0;
|
||||
};
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
#ifndef TIER1_COMMANDLINE_H
|
||||
#define TIER1_COMMANDLINE_H
|
||||
|
||||
|
||||
#include "tier0/platform.h"
|
||||
|
||||
interface ICommandLine
|
||||
@@ -14,4 +18,6 @@ public:
|
||||
static int ParamCount();
|
||||
static int FindParam( const char *psz );
|
||||
static const char *GetParam(int nIndex);
|
||||
};
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
#include "ld.h"
|
||||
#include "tier1/utlstring.h"
|
||||
|
||||
|
||||
CUtlString rapier_lib;
|
||||
int rapier_build()
|
||||
{
|
||||
CUtlVector<CUtlString> cargo_args = {
|
||||
@@ -22,6 +24,7 @@ int rapier_build()
|
||||
"../public/physics_gen.h",
|
||||
};
|
||||
IRunner::Run("cbindgen", "rapier", cbindgen_args);
|
||||
rapier_lib = "rapier/target/x86_64-unknown-linux-gnu/release/librapier_rtt.a";
|
||||
|
||||
return 0;
|
||||
};
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include "c.h"
|
||||
#include "ld.h"
|
||||
#include "tier1/utlstring.h"
|
||||
#include "tier1/commandline.h"
|
||||
|
||||
CUtlVector<CUtlString> tier0_CompiledFiles = {
|
||||
"tier0/lib.cpp",
|
||||
@@ -22,6 +23,11 @@ int tier0_build()
|
||||
ldProject.linkType = ELINK_DYNAMIC_LIBRARY;
|
||||
|
||||
CUtlString outputProject = ldProject.Link();
|
||||
|
||||
const char *szGameName = ICommandLine::ParamValue("-game");
|
||||
if (szGameName == NULL)
|
||||
szGameName = "funnygame";
|
||||
IFileSystem2::CopyFile(CUtlString("build/%s/game/bin",szGameName), outputProject);
|
||||
|
||||
return 0;
|
||||
};
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include "c.h"
|
||||
#include "ld.h"
|
||||
#include "tier1/utlstring.h"
|
||||
#include "tier1/commandline.h"
|
||||
|
||||
CUtlVector<CUtlString> tier1_CompiledFiles = {
|
||||
"tier1/commandline.cpp",
|
||||
@@ -10,6 +11,7 @@ CUtlVector<CUtlString> tier1_CompiledFiles = {
|
||||
"tier1/utlstring.cpp",
|
||||
"tier1/utlvector.cpp",
|
||||
};
|
||||
CUtlString tier1_lib;
|
||||
|
||||
int tier1_build()
|
||||
{
|
||||
@@ -24,6 +26,7 @@ int tier1_build()
|
||||
ldProject.linkType = ELINK_STATIC_LIBRARY;
|
||||
|
||||
CUtlString outputProject = ldProject.Link();
|
||||
tier1_lib = outputProject;
|
||||
|
||||
return 0;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user