diff --git a/engine/__build.cpp b/engine/__build.cpp index 21353ed..0551d80 100644 --- a/engine/__build.cpp +++ b/engine/__build.cpp @@ -2,6 +2,7 @@ #include "c.h" #include "ld.h" #include "tier1/utlstring.h" +#include "tier1/commandline.h" CUtlVector engine_CompiledFiles = { "engine/console.cpp", @@ -29,6 +30,12 @@ CUtlVector engine_CompiledFiles = { "engine/vk_videosdl.cpp", }; +CUtlVector 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); diff --git a/fpc/Makefile b/fpc/Makefile index fbeaaec..d136b0f 100644 --- a/fpc/Makefile +++ b/fpc/Makefile @@ -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 diff --git a/fpc/build.cpp b/fpc/build.cpp index a958aa1..c0fcb81 100644 --- a/fpc/build.cpp +++ b/fpc/build.cpp @@ -10,6 +10,7 @@ CUtlVector g_CompiledFiles = { "library/helper.cpp", "library/c.cpp", "library/ld.cpp", + "library/target.cpp", "../tier0/lib.cpp", "../tier0/mem.cpp", "../tier0/platform.cpp", diff --git a/fpc/library/c.cpp b/fpc/library/c.cpp index 09f9f50..08858e1 100644 --- a/fpc/library/c.cpp +++ b/fpc/library/c.cpp @@ -3,7 +3,6 @@ #include "helper.h" #include "tier1/utlvector.h" #include "libgen.h" -#include 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 args; - CUtlVector 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 = {}; diff --git a/fpc/library/helper.cpp b/fpc/library/helper.cpp index 38cecf3..2441914 100644 --- a/fpc/library/helper.cpp +++ b/fpc/library/helper.cpp @@ -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 g_buildStages; CBuildStage::CBuildStage( CUtlString sz, int(*pMainFn)() ) diff --git a/fpc/library/ld.cpp b/fpc/library/ld.cpp index af1f76e..9bdfe19 100644 --- a/fpc/library/ld.cpp +++ b/fpc/library/ld.cpp @@ -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; diff --git a/fpc/library/runner.cpp b/fpc/library/runner.cpp index f1a082b..4c07bca 100644 --- a/fpc/library/runner.cpp +++ b/fpc/library/runner.cpp @@ -16,6 +16,7 @@ int IRunner::Run(CUtlString szName, CUtlVector& args) execargs.AppendTail(szName); for (auto &arg: args) { + V_printf("%s\n",arg.GetString()); execargs.AppendTail(arg); } execargs.AppendTail(0); diff --git a/fpc/library/target.cpp b/fpc/library/target.cpp new file mode 100644 index 0000000..3d42cb9 --- /dev/null +++ b/fpc/library/target.cpp @@ -0,0 +1,16 @@ +#include "target.h" +#include + +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, + }; +} diff --git a/fpc/public/c.h b/fpc/public/c.h index d1d7734..77415f7 100644 --- a/fpc/public/c.h +++ b/fpc/public/c.h @@ -23,6 +23,7 @@ public: CUtlVector includeFiles; bool bFPIE; bool bFPIC; + bool bDebug = m_target.optimization == TARGET_DEBUG; CLDProject Compile(); static void GenerateCompileCommands(); }; diff --git a/fpc/public/helper.h b/fpc/public/helper.h index 04dbcd7..a98a4f4 100644 --- a/fpc/public/helper.h +++ b/fpc/public/helper.h @@ -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 diff --git a/fpc/public/target.h b/fpc/public/target.h index 94fc26e..1fda99d 100644 --- a/fpc/public/target.h +++ b/fpc/public/target.h @@ -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(); }; diff --git a/game/client/__build.cpp b/game/client/__build.cpp index 32044a2..eed8bb7 100644 --- a/game/client/__build.cpp +++ b/game/client/__build.cpp @@ -2,6 +2,7 @@ #include "c.h" #include "ld.h" #include "tier1/utlstring.h" +#include "tier1/commandline.h" CUtlVector 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; }; diff --git a/game/server/__build.cpp b/game/server/__build.cpp index d912f6d..ea8de6a 100644 --- a/game/server/__build.cpp +++ b/game/server/__build.cpp @@ -2,6 +2,7 @@ #include "c.h" #include "ld.h" #include "tier1/utlstring.h" +#include "tier1/commandline.h" CUtlVector 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; }; diff --git a/public/tier1/commandline.h b/public/tier1/commandline.h index 4e3773e..c6dd892 100644 --- a/public/tier1/commandline.h +++ b/public/tier1/commandline.h @@ -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); -}; \ No newline at end of file +}; + +#endif diff --git a/rapier/__build.cpp b/rapier/__build.cpp index ded9d8b..56f8029 100644 --- a/rapier/__build.cpp +++ b/rapier/__build.cpp @@ -3,6 +3,8 @@ #include "ld.h" #include "tier1/utlstring.h" + +CUtlString rapier_lib; int rapier_build() { CUtlVector 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; }; diff --git a/tier0/__build.cpp b/tier0/__build.cpp index 1c9e8c9..cd92a00 100644 --- a/tier0/__build.cpp +++ b/tier0/__build.cpp @@ -2,6 +2,7 @@ #include "c.h" #include "ld.h" #include "tier1/utlstring.h" +#include "tier1/commandline.h" CUtlVector 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; }; diff --git a/tier1/__build.cpp b/tier1/__build.cpp index 15b4f17..82978fc 100644 --- a/tier1/__build.cpp +++ b/tier1/__build.cpp @@ -2,6 +2,7 @@ #include "c.h" #include "ld.h" #include "tier1/utlstring.h" +#include "tier1/commandline.h" CUtlVector tier1_CompiledFiles = { "tier1/commandline.cpp", @@ -10,6 +11,7 @@ CUtlVector 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; };