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