improvements on fpc

This commit is contained in:
2026-01-01 02:14:54 +02:00
parent 773a541199
commit 0b8fb15420
31 changed files with 143 additions and 82 deletions

3
.gitignore vendored
View File

@@ -1,5 +1,4 @@
build
.god
.git
.cache
compile_commands.json
@@ -33,3 +32,5 @@ Icon?
# Added by cargo
/target
*.o

View File

@@ -20,7 +20,7 @@ recompile: ../build/tools/fpc
build/fpc build
install: ../build/tools/fpc libfpcbuild.a libfpc.so libtier0.so libtier1.a libtier2.a libfilesystem_std.so install_temp builddir
$(CC) -fPIC main.cpp library/helper.cpp library/target.cpp library/builder.cpp -lc -lstdc++ $(CCFLAGS) -o build/fpc build/libtier0.so build/libtier1.a build/libtier2.a -Wl,--disable-new-dtags -Wl,-rpath,'$$ORIGIN'
$(CC) -fPIC main.cpp library/helper.cpp library/target.cpp library/builder.cpp -lc -lstdc++ $(CCFLAGS) -o build/fpc libtier0.so build/libtier1.a build/libtier2.a -Wl,--disable-new-dtags -Wl,-rpath,'$$ORIGIN'
build/fpc build -fpcdebug
libtier0.so: $(TIER0_FILES) builddir
@@ -51,10 +51,10 @@ builddir:
mkdir -p ../build/tools/fpc
install_fpc: ../build/tools/fpc
mv build/fpc_temp fpc
mv build/libtier0_temp.so libtier0.so
mv build/libfpc_temp.so libfpc.so
mv build/libfilesystem_std_temp.so libfilesystem_std.so
mv build/fpc_temp build/fpc
#mv build/libtier0_temp.so libtier0.so
mv build/libfpc_temp.so build/libfpc.so
#mv build/libfilesystem_std_temp.so libfilesystem_std.so
cp -r build/* ../build/tools/fpc
install_temp: builddir

View File

@@ -82,7 +82,7 @@ DECLARE_BUILD_STAGE(libfpc)
ldProject = ccompiler->Compile(&compileProject);
ldProject.linkType = ELINK_DYNAMIC_LIBRARY;
ldProject.libraryObjects = {
GET_PROJECT_LIBRARY(tier0, "tier0"),
"libtier0.so",
GET_PROJECT_LIBRARY(tier1, "tier1"),
GET_PROJECT_LIBRARY(tier2, "tier2"),
};
@@ -109,10 +109,9 @@ DECLARE_BUILD_STAGE(fpc)
compileProject.includeDirectories = g_IncludeDirectories;
ldProject = ccompiler->Compile(&compileProject);
ldProject.libraryObjects = {
GET_PROJECT_LIBRARY(tier0, "tier0"),
"libtier0.so",
GET_PROJECT_LIBRARY(tier1, "tier1"),
GET_PROJECT_LIBRARY(tier2, "tier2"),
GET_PROJECT_LIBRARY(libfpc, "fpc"),
};
V_printf("WHAT %s\n",GET_PROJECT_LIBRARY(tier0, "tier0").GetString());
@@ -135,12 +134,15 @@ DECLARE_BUILD_STAGE(install)
CUtlString szTier0 = GET_PROJECT_LIBRARY(tier0, "tier0");
CUtlString szTier1 = GET_PROJECT_LIBRARY(tier1, "tier1");
CUtlString szTier2 = GET_PROJECT_LIBRARY(tier2, "tier2");
filesystem2->CopyFile("build/fpc_temp", szExe);
filesystem2->CopyFile("build/libfpc.so", szLibFpc);
filesystem2->CopyFile("build/libtier0_temp.so", szTier0);
filesystem2->CopyFile("build/libfpc_temp.so", szLibFpc);
/*
filesystem2->CopyFile("build/libtier1.a", szTier1);
filesystem2->CopyFile("build/libtier2.a", szTier2);
filesystem2->CopyFile("build/libtier0_temp.so", szTier0);
*/
return 0;
};

Binary file not shown.

BIN
fpc/libfpc.so Normal file

Binary file not shown.

View File

@@ -93,43 +93,45 @@ CUtlString CAPKTool::BuildPackage( AndroidManifest_t manifest, CUtlString szMani
{
V_printf(" APKTOOL %s\n", manifest.m_szPackageID.GetString());
if (CommandLine()->ParamValue("-android_build_tools"))
{
CUtlVector<CUtlString> args = {
"package",
"-f",
"-M",
"AndroidManifest.xml",
"-S",
"res",
"-I",
CUtlString("%s/../../platforms/android-%lu/android.jar", CommandLine()->ParamValue("-android_build_tools"), manifest.m_nTargetVersion),
"-F",
CUtlString("%s.unaligned.apk", manifest.m_szPackageID.GetString()),
};
CUtlString szAndroidSDK = CommandLine()->ParamValue("-android_build_tools");
runner->Run(CUtlString("%s/aapt",szAndroidSDK.GetString()),szManifestDir,args);
runner->Wait();
args = {
"-u",
CUtlString("%s.unaligned.apk", manifest.m_szPackageID.GetString()),
"lib/x86_64/libnative-app.so",
};
runner->Run("zip",szManifestDir, args);
runner->Wait();
args = {
"-f",
"-v",
"4",
CUtlString("%s.unaligned.apk", manifest.m_szPackageID.GetString()),
CUtlString("%s.apk", manifest.m_szPackageID.GetString()),
};
runner->Run(CUtlString("%s/zipalign",szAndroidSDK.GetString()),szManifestDir,args);
} else
Plat_FatalErrorFunc("-android_build_tools was not specified.");
return 0;
IINISection *pSection = NULL;
const char *szBuildTools;
pSection = g_pConfig->GetSection("Android_Build_Tools");
if (!pSection)
Plat_FatalErrorFunc("build_tools are required for this target");
szBuildTools = pSection->GetStringValue("path");
CUtlVector<CUtlString> args = {
"package",
"-f",
"-M",
"AndroidManifest.xml",
"-S",
"res",
"-I",
CUtlString("%s/../../platforms/android-%lu/android.jar", szBuildTools, manifest.m_nTargetVersion),
"-F",
CUtlString("%s.unaligned.apk", manifest.m_szPackageID.GetString()),
};
runner->Run(CUtlString("%s/aapt",szBuildTools),szManifestDir,args);
runner->Wait();
args = {
"-u",
CUtlString("%s.unaligned.apk", manifest.m_szPackageID.GetString()),
"lib/x86_64/libnative-app.so",
};
runner->Run("zip",szManifestDir, args);
runner->Wait();
args = {
"-f",
"-v",
"4",
CUtlString("%s.unaligned.apk", manifest.m_szPackageID.GetString()),
CUtlString("%s.apk", manifest.m_szPackageID.GetString()),
};
runner->Run(CUtlString("%s/zipalign",szBuildTools),szManifestDir,args);
return manifest.m_szPackageID;
}
IAPKTool *APKTool()

View File

@@ -71,7 +71,7 @@ BuildFile_t *CProjectBuilder::BuildProject( const char *szProjectName, const cha
stLinkProject = ccompiler->Compile(&stCompileProject);
stLinkProject.linkType = ELINK_DYNAMIC_LIBRARY;
stLinkProject.m_target = Target_t::HostTarget();
stLinkProject.libraryObjects.AppendHead({CUtlString("%s/libfpcbuild.a",filesystem2->OwnDirectory())});
stLinkProject.objects.AppendHead({CUtlString("%s/libfpcbuild.a",filesystem2->OwnDirectory())});
stLinkProject.libraryObjects.AppendHead({CUtlString("%s/libfpc.so",filesystem2->OwnDirectory())});
stLinkProject.libraryObjects.AppendHead({CUtlString("%s/libtier2.a",filesystem2->OwnDirectory())});
stLinkProject.libraryObjects.AppendHead({CUtlString("%s/libtier1.a",filesystem2->OwnDirectory())});

View File

@@ -31,6 +31,7 @@ CUtlVector<CUtlString> ICCompiler::BuildCommandLine( CProject_t *pProject, const
EnablePIE(cmd);
SetTarget(cmd, pProject);
SetOutputFile(cmd, szOutputFileName);
SetSysroot(cmd, pProject, NULL);
CompileFile(cmd, szFileName);
for (auto &macro: pProject->macros)
Macro(cmd, macro.szName, macro.szValue.GetString());

View File

@@ -46,6 +46,8 @@ protected:
virtual void EnableDebugSymbols( CUtlVector<CUtlString> &cmd ) override;
virtual void EnablePIE( CUtlVector<CUtlString> &cmd ) override;
virtual void EnablePIC( CUtlVector<CUtlString> &cmd ) override;
virtual void SetSysroot( CUtlVector<CUtlString> &cmd, CProject_t *pProject, const char *szSysroot ) override;
};
const char *CClangCompiler::GetOutputObjectFormat()
@@ -117,6 +119,31 @@ void CClangCompiler::EnablePIC( CUtlVector<CUtlString> &cmd )
{
cmd.AppendTail("-fPIC");
}
void CClangCompiler::SetSysroot( CUtlVector<CUtlString> &cmd, CProject_t *pProject, const char *szName )
{
if (szName != NULL)
{
cmd.AppendTail("--sysroot");
cmd.AppendTail(szName);
return;
}
if (!g_pConfig)
return;
IINISection *pSection = g_pConfig->GetSection(pProject->m_target.GetTriplet());
if (!pSection)
return;
const char *szSysroot = pSection->GetStringValue("sysroot");
if (szSysroot)
{
cmd.AppendTail("--sysroot");
cmd.AppendTail(szSysroot);
}
}
EXPOSE_INTERFACE(CClangCompiler, ICCompiler, CLANG_C_COMPILER_INTERFACE_NAME);
@@ -194,12 +221,8 @@ LinkProject_t CClangCompiler::Compile( CProject_t *pProject )
args.AppendTail("-miphoneos-version-min=18.0 ");
args.AppendTail("-fembed-bitcode");
}
if (pProject->m_target.szSysroot)
{
args.AppendTail(CUtlString("--sysroot=%s", pProject->m_target.szSysroot));
}
*/
if (!filesystem2->ShouldRecompile(file, szOutputFile))
goto skipcompile;
else

View File

@@ -139,14 +139,14 @@ CUtlString CClangLinker::Link( LinkProject_t *pProject )
}
else if (pProject->m_target.kernel == TARGET_KERNEL_ANDROID)
{
args.AppendTail(CUtlString("--sysroot=%s/sysroot", pProject->m_target.szSysroot));
// args.AppendTail(CUtlString("--sysroot=%s/sysroot", pProject->m_target.szSysroot));
// Shouldn't be here ?
args.AppendTail("-static-libstdc++");
}
else if (pProject->m_target.szSysroot)
{
args.AppendTail(CUtlString("--sysroot=%s", pProject->m_target.szSysroot));
// args.AppendTail(CUtlString("--sysroot=%s", pProject->m_target.szSysroot));
}
// Magic for the systems
@@ -201,18 +201,34 @@ CUtlString CClangLinker::Link( LinkProject_t *pProject )
args.AppendTail(framework);
}
// Android SDK requires sysroot
if (pProject->m_target.kernel == TARGET_KERNEL_ANDROID)
{
if (!pProject->m_target.szSysroot)
Plat_FatalErrorFunc("szSysroot must be specified for android\n");
runner->Run(CUtlString("%s/bin/clang++",pProject->m_target.szSysroot), args);
IINISection *pSection = NULL;
const char *szLinker;
const char *szSysroot;
if (!g_pConfig)
goto use_default_linker;
}
else
pSection = g_pConfig->GetSection(pProject->m_target.GetTriplet());
if (!pSection)
goto use_default_linker;
szSysroot = pSection->GetStringValue("sysroot");
if (szSysroot)
{
runner->Run("clang++", args);
args.AppendTail("--sysroot");
args.AppendTail(szSysroot);
}
szLinker = pSection->GetStringValue("CLANG_LINKER_INTERFACE_NAME");
if (szLinker)
{
runner->Run(szLinker, args);
}
runner->Wait();
goto compiled;
use_default_linker:
runner->Run("clang++", args);
runner->Wait();
}
compiled:

View File

@@ -97,9 +97,7 @@ void CPOSIXFileSystem2::CopyFile( const char *szDestination, const char *szOrigi
szOrigin,
szDestination,
};
printf("runner: %p\n",runner);
runner->Run(CUtlString("cp"), args);
printf("runner: %p\n",runner);
runner->Wait();
}
void CPOSIXFileSystem2::CopyDirectory( const char *szDestination, const char *szOrigin )
@@ -138,3 +136,4 @@ bool CPOSIXFileSystem2::ShouldRecompile(const char *szSource, const char *szOutp
IINIFile *g_pConfig;
EXPOSE_INTERFACE_GLOBALVAR(IINIFile, IINIFile, LIBFPC_CONFIG_INTERFACE_VERSION, g_pConfig);

View File

@@ -51,9 +51,7 @@ int CPOSIXRunner::Run(CUtlString szName, CUtlVector<CUtlString>& args)
_exit(0);
}
}
printf("%i %p\n",m_processes.GetSize(),m_processes.GetData());
m_processes.AppendTail(pid);
printf("%i %p\n",m_processes.GetSize(),m_processes.GetData());
return 0;
}
@@ -85,9 +83,7 @@ int CPOSIXRunner::Run(CUtlString szName, CUtlString szDirectory, CUtlVector<CUtl
_exit(0);
}
}
printf("%i %p\n",m_processes.GetSize(),m_processes.GetData());
m_processes.AppendTail(pid);
printf("%i %p\n",m_processes.GetSize(),m_processes.GetData());
/* parent */
return 0;
}
@@ -99,14 +95,8 @@ int CPOSIXRunner::Run(CUtlString szName, CUtlString szDirectory, CUtlVector<CUtl
int CPOSIXRunner::Wait( void )
{
printf("%i %p\n",m_processes.GetSize(),m_processes.GetData());
if (m_processes.GetSize())
printf("%i\n",m_processes[0]);
printf("%i %p\n",m_processes.GetSize(),m_processes.GetData());
for (int i = 0; i<m_processes.GetSize(); i++)
{
printf("p %i\n",m_processes[i]);
int status;
pid_t wpid = waitpid(m_processes[i], &status, 0);
}

View File

@@ -149,6 +149,9 @@ findbuild:
g_pConfig = INIManager()->ReadFile(".fpccfg");
IINIFile **ppConfig = (IINIFile**)pLibFPCFactory(LIBFPC_CONFIG_INTERFACE_VERSION, NULL);
*ppConfig = g_pConfig;
CommandLine()->CreateCommandLine(c, v);
if (CommandLine()->CheckParam("build"))
return build();

View File

@@ -129,6 +129,8 @@ protected:
virtual void EnableDebugSymbols( CUtlVector<CUtlString> &cmd ) = 0;
virtual void EnablePIE( CUtlVector<CUtlString> &cmd ) = 0;
virtual void EnablePIC( CUtlVector<CUtlString> &cmd ) = 0;
virtual void SetSysroot( CUtlVector<CUtlString> &cmd, CProject_t *pProject , const char *szSysroot ) = 0;
};
extern ICCompiler *ccompiler;

View File

@@ -149,5 +149,6 @@ typedef CUtlString(*GetProjectObjectFn)( const char *szName, const char *szObjec
extern IINIFile *g_pConfig;
#define LIBFPC_CONFIG_INTERFACE_VERSION "LibFPCConfig001"
#endif

View File

@@ -0,0 +1,6 @@
[x86_64-linux-android]
sysroot = "/home/kotofyt/Android/Sdk/ndk/29.0.13599879/toolchains/llvm/prebuilt/linux-x86_64/sysroot"
CLANG_LINKER_INTERFACE_NAME = "/home/kotofyt/Android/Sdk/ndk/29.0.13599879/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++"
[Android_Build_Tools]
path = "/home/kotofyt/Android/Sdk/build-tools/36.0.0"

View File

@@ -16,8 +16,11 @@ DECLARE_BUILD_STAGE(android_build)
compileProject.m_szName = "android_app";
compileProject.m_androidmanifest = manifest;
compileProject.bFPIC = true;
compileProject.m_target = Target_t::HostTarget();
compileProject.m_target.kernel = TARGET_KERNEL_ANDROID;
compileProject.files = {
"main.c",
"android_native_app_glue.c",
};
LinkProject_t ldProject = ccompiler->Compile(&compileProject);
ldProject.libraries = {

View File

@@ -17,7 +17,6 @@ static void handle_cmd(struct android_app* app, int32_t cmd) {
}
}
// Entry point for native app
void android_main(struct android_app* app) {
app->onAppCmd = handle_cmd;
@@ -26,7 +25,6 @@ void android_main(struct android_app* app) {
int events;
struct android_poll_source* source;
// Main event loop
while (1) {
int ident;
while ((ident = ALooper_pollOnce(0, NULL, &events, (void**)&source)) >= 0) {
@@ -37,6 +35,5 @@ void android_main(struct android_app* app) {
}
}
// Here you can update your game/render loop
}
}

Binary file not shown.

View File

@@ -118,7 +118,17 @@ public:
}
virtual CUtlBuffer<unsigned char> Read( IFileHandle *pFile ) override { return NULL; };
virtual const char *ReadString( IFileHandle *pFile ) override { return NULL; };
virtual const char *ReadString( IFileHandle *pFile ) override {
char *szData = NULL;
size_t uSize = Size(pFile);
szData = (char*)V_malloc(uSize+1);
Read(pFile, szData,uSize);
szData[uSize] = 0;
return szData;
};
};
EXPOSE_INTERFACE(CLIBCFileSystem, IFileSystem, FILESYSTEM_INTERFACE_VERSION)

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -58,7 +58,12 @@ const char *CINISection::GetStringValue( const char *szKeyName )
CUtlString CINISection::GetUTLStringValue( const char *szKeyName )
{
for (auto &value: m_values)
{
if (value->m_szKey == szKeyName)
return value->m_szData;
}
return 0;
}
class CINIFile: public IINIFile

Binary file not shown.

Binary file not shown.