From 817ed344b4432111b3c4897f54fe7d7f97e42e4c Mon Sep 17 00:00:00 2001 From: kotofyt Date: Thu, 31 Jul 2025 18:07:25 +0300 Subject: [PATCH] documented fpc --- fpc/library/generator/makefile.cpp | 0 fpc/library/target.cpp | 17 +++++---- fpc/public/apktool.h | 4 +++ fpc/public/c.h | 47 +++++++++++++++++++++++-- fpc/public/helper.h | 37 +++++++++++++++++--- fpc/public/ld.h | 55 +++++++++++++++++++++++++----- fpc/public/obj.h | 4 +++ fpc/public/runner.h | 5 +++ fpc/public/signtool.h | 5 +++ fpc/public/target.h | 4 +++ tier1/commandline.cpp | 1 + 11 files changed, 154 insertions(+), 25 deletions(-) delete mode 100644 fpc/library/generator/makefile.cpp diff --git a/fpc/library/generator/makefile.cpp b/fpc/library/generator/makefile.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/fpc/library/target.cpp b/fpc/library/target.cpp index d51792e..dd69b8b 100644 --- a/fpc/library/target.cpp +++ b/fpc/library/target.cpp @@ -36,6 +36,10 @@ CUtlString Target_t::GetTriplet() return triplet; } + +//---------------------------------------------------------------------------- +// Returns target on which fpc is being run +//---------------------------------------------------------------------------- Target_t Target_t::HostTarget() { ETargetKernel kernel = @@ -54,7 +58,7 @@ Target_t Target_t::HostTarget() }; //----------------------------------------------------------------------------- -// Returns default target for build +// Returns default target for build, by default it will be host target //----------------------------------------------------------------------------- Target_t Target_t::DefaultTarget() { @@ -62,14 +66,9 @@ Target_t Target_t::DefaultTarget() CUtlString szOS = CommandLine()->ParamValue("-os"); CUtlString szArch = CommandLine()->ParamValue("-arch"); - ETargetKernel kernel = -#if defined(__linux__) - TARGET_KERNEL_LINUX -#elif defined(__APPLE__) - TARGET_KERNEL_DARWIN -#endif - ; - ETargetCPU cpu = TARGET_CPU_AMD64; + ETargetKernel kernel = HostTarget().kernel; + ETargetCPU cpu = HostTarget().cpu; + if ( szArch == "x86_64" ) cpu = TARGET_CPU_AMD64; else if ( szArch == "aarch64" ) diff --git a/fpc/public/apktool.h b/fpc/public/apktool.h index 3032519..12a1f29 100644 --- a/fpc/public/apktool.h +++ b/fpc/public/apktool.h @@ -1,3 +1,7 @@ +//================= Copyright kotofyt, All rights reserved ==================// +// Purpose: Set Android metadata aboth the package. +//===========================================================================// + #ifndef APK_TOOL_H #define APK_TOOL_H diff --git a/fpc/public/c.h b/fpc/public/c.h index 0431147..6fcce32 100644 --- a/fpc/public/c.h +++ b/fpc/public/c.h @@ -1,3 +1,7 @@ +//================= Copyright kotofyt, All rights reserved ==================// +// Purpose: C, C++, Objective-C and Objective-C++ compiler interface. +//===========================================================================// + #ifndef C_H #define C_H @@ -15,6 +19,8 @@ struct C_Macro_t CUtlString szValue; }; + +// Target C version enum ECVersion { CVERSION_89, @@ -25,6 +31,7 @@ enum ECVersion CVERSION_2Y, }; +// Target C++ version enum ECPPVersion { CPPVERSION_98 = 1, @@ -36,32 +43,66 @@ enum ECPPVersion CPPVERSION_2C = 6, }; +//---------------------------------------------------------------------------- +// C project settings used in compilation +// Example usage: +// CProject_t compileProject = {}; +// LinkProject_t ldProject = {}; +// +// compileProject.m_szName = "your project name"; +// compileProject.files = g_CompiledFiles; +// compileProject.includeDirectories = g_IncludeDirectories; +// ldProject = ccompiler->Compile(&compileProject); +//---------------------------------------------------------------------------- struct CProject_t : public CPUProject_t { public: + // Compiled files CUtlVector files = {}; + + // Included directories CUtlVector includeDirectories = {}; + + // Included files + // They are included on top of the file CUtlVector includeFiles = {}; + + // Defined macros CUtlVector macros = {}; + // Is compiled as position independent executable bool bFPIE = false; + + // Is compiled as position independent code + // Use for shared libraries bool bFPIC = false; + // Target C version ECVersion cVersion; + + // Target C++ version ECPPVersion cppVersion; + // Android manifest AndroidManifest_t m_androidmanifest; }; +// Basic interface name #define C_COMPILER_INTERFACE_NAME "CCompiler001" -#define CLANG_C_COMPILER_INTERFACE_NAME "ClangCCompiler001" -#define GCC_C_COMPILER_INTERFACE_NAME "GCCCCompiler001" -#define MSVC_C_COMPILER_INTERFACE_NAME "MSVCCCompiler001" +#define CLANG_C_COMPILER_INTERFACE_NAME "Clang" C_COMPILER_INTERFACE_NAME +#define GNU_C_COMPILER_INTERFACE_NAME "GNU" C_COMPILER_INTERFACE_NAME +#define MSVC_C_COMPILER_INTERFACE_NAME "MSVC" C_COMPILER_INTERFACE_NAME abstract_class ICCompiler { public: + + // Compiles all files into objects, returns linker project, + // which can be linked into executable or library. virtual LinkProject_t Compile( CProject_t *pProject ) = 0; + + // Generates linter data + // Handled by the fpc automatically virtual void GenerateLinterData( void ) = 0; }; diff --git a/fpc/public/helper.h b/fpc/public/helper.h index f832263..e8b2dc2 100644 --- a/fpc/public/helper.h +++ b/fpc/public/helper.h @@ -1,3 +1,7 @@ +//================= Copyright kotofyt, All rights reserved ==================// +// Purpose: Helper functions for compilers, filesystem2 and build stages. +//===========================================================================// + #ifndef HELPER_H #define HELPER_H @@ -7,15 +11,20 @@ #define FPC_TEMPORAL_DIRNAME ".fpc" - +//----------------------------------------------------------------------------- +// A base for all projects +//----------------------------------------------------------------------------- struct BaseProject_t { public: CUtlString m_szName; + // Creates a hash for the project unsigned int GenerateProjectHash( void ); }; - +//----------------------------------------------------------------------------- +// A base for cpu projects +//----------------------------------------------------------------------------- struct CPUProject_t : public BaseProject_t { public: @@ -23,7 +32,9 @@ public: }; - +//----------------------------------------------------------------------------- +// A base for shader projects +//----------------------------------------------------------------------------- struct ShaderProject_t : public BaseProject_t { public: @@ -31,9 +42,8 @@ public: }; //----------------------------------------------------------------------------- -// File system. +// File system manager. //----------------------------------------------------------------------------- - #define FILE_SYSTEM_2_INTERFACE_NAME "FileSystem2_001" abstract_class IFileSystem2 @@ -45,9 +55,16 @@ public: // Returns directory of build.cpp virtual char *BuildDirectory() = 0; + // Creates new directory at path virtual void MakeDirectory( const char *psz ) = 0; + + // UNIX-style file copy virtual void CopyFile( const char *szDestination, const char *szOrigin ) = 0; + + // UNIX-style recursive directory copy virtual void CopyDirectory( const char *szDestination, const char *szOrigin ) = 0; + + // Compares timestamps of 2 files virtual bool ShouldRecompile( const char *szSource, const char *szOutput ) = 0; }; @@ -65,11 +82,21 @@ public: int(*m_pMainFn)(); }; +//----------------------------------------------------------------------------- +// Declares new build stage. +// example: +// DECLARE_BUILD_STAGE(your_build_stage_name) +// { +// return 0; +// } +//----------------------------------------------------------------------------- #define DECLARE_BUILD_STAGE(sz) \ int __build_stage_##sz(); \ CBuildStage __##sz##_build_stage(#sz, __build_stage_##sz); \ int __build_stage_##sz() +// Returns all available build stages +// Used internally CUtlVector& BuildStages(); #endif diff --git a/fpc/public/ld.h b/fpc/public/ld.h index e621808..35d637c 100644 --- a/fpc/public/ld.h +++ b/fpc/public/ld.h @@ -1,3 +1,7 @@ +//================= Copyright kotofyt, All rights reserved ==================// +// Purpose: Linker interface. +//===========================================================================// + #ifndef LD_H #define LD_H @@ -15,29 +19,64 @@ enum ELinkType ELINK_STATIC_LIBRARY, }; +//---------------------------------------------------------------------------- +// C project settings used in compilation +// Example usage: +// CProject_t compileProject = {}; +// LinkProject_t ldProject = {}; +// CUtlString szOutputFile; +// +// compileProject.m_szName = "your_project_name"; +// compileProject.files = g_CompiledFiles; +// compileProject.includeDirectories = g_IncludeDirectories; +// +// ldProject = ccompiler->Compile(&compileProject); +// ldProject.linkType = ELINK_EXECUTABLE +// szOutputFile = linker->Link(&ldProject); +// +//---------------------------------------------------------------------------- struct LinkProject_t: public CPUProject_t { public: void AddObject( Object_t& object ); + // output file ELinkType linkType; - CUtlVector objects = {}; - CUtlVector libraries ={}; - CUtlVector libraryDirectories = {}; - CUtlVector libraryObjects = {}; - CUtlVector frameworkDirectories = {}; - CUtlVector frameworks = {}; - AndroidManifest_t m_androidmanifest; + // objects, they could be libraries and compiled files + CUtlVector objects = {}; + + // system libraries + CUtlVector libraries ={}; + + // directories for libraries + CUtlVector libraryDirectories = {}; + + // not used + CUtlVector libraryObjects = {}; + + // Apple framework directories + CUtlVector frameworkDirectories = {}; + + // Disables C standart library bool bNoStdLib; + + // Apple frameworks + CUtlVector frameworks = {}; + + // Android manifest + AndroidManifest_t m_androidmanifest; }; +// Basic interface name #define LINKER_INTERFACE_NAME "Linker001" -#define CLANG_LINKER_INTERFACE_NAME "ClangLinker001" +#define CLANG_LINKER_INTERFACE_NAME "Clang" LINKER_INTERFACE_NAME abstract_class ILinker { public: + + // Links project virtual CUtlString Link( LinkProject_t *pProject ) = 0; }; diff --git a/fpc/public/obj.h b/fpc/public/obj.h index 3da86b8..b4b32b3 100644 --- a/fpc/public/obj.h +++ b/fpc/public/obj.h @@ -1,3 +1,7 @@ +//================= Copyright kotofyt, All rights reserved ==================// +// Purpose: Object handler. +//===========================================================================// + #ifndef OBJ_H #define OBJ_H diff --git a/fpc/public/runner.h b/fpc/public/runner.h index 023f056..b9508e9 100644 --- a/fpc/public/runner.h +++ b/fpc/public/runner.h @@ -1,3 +1,8 @@ +//================= Copyright kotofyt, All rights reserved ==================// +// Purpose: Executable runner. It is mainly used to run compilers and linkers, +// but can be used to run anything with given executable name +//===========================================================================// + #ifndef RUNNER_H #define RUNNER_H diff --git a/fpc/public/signtool.h b/fpc/public/signtool.h index 7a42f26..d6004ea 100644 --- a/fpc/public/signtool.h +++ b/fpc/public/signtool.h @@ -1,3 +1,8 @@ +//================= Copyright kotofyt, All rights reserved ==================// +// Purpose: Automatic signature generator for iOS, Android and other devices, +// which require signed executables, files etc. +//===========================================================================// + #ifndef SIGN_TOOL_H #define SIGN_TOOL_H diff --git a/fpc/public/target.h b/fpc/public/target.h index 641235c..8d2b3dd 100644 --- a/fpc/public/target.h +++ b/fpc/public/target.h @@ -1,3 +1,7 @@ +//================= Copyright kotofyt, All rights reserved ==================// +// Purpose: Target manager for compilers. +//===========================================================================// + #ifndef TARGET_T #define TARGET_T diff --git a/tier1/commandline.cpp b/tier1/commandline.cpp index b973c25..5a3d99e 100644 --- a/tier1/commandline.cpp +++ b/tier1/commandline.cpp @@ -20,6 +20,7 @@ private: CUtlVector m_params; }; + void CCommandLine::CreateCommandLine( int argc, char **argv ) { m_params.AppendTail(argv,argc);