From 951b655febb8d9037df495e4295e02fe0880850d Mon Sep 17 00:00:00 2001 From: Kenzzer Date: Fri, 4 Oct 2024 12:40:43 +0200 Subject: [PATCH] Statically link libz, libgcc & libstdc++ --- .gitmodules | 3 +++ AMBuildScript | 11 ++++++++++- third_party/AMBuilder | 30 +++++++++++++++++++++++++++++- third_party/zlib | 1 + 4 files changed, 43 insertions(+), 2 deletions(-) create mode 160000 third_party/zlib diff --git a/.gitmodules b/.gitmodules index cac1574..f7af9d4 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "breakpad"] path = third_party/breakpad url = https://github.com/google/breakpad.git +[submodule ".\\third_party\\zlib"] + path = .\\third_party\\zlib + url = https://github.com/madler/zlib.git diff --git a/AMBuildScript b/AMBuildScript index 9d76887..47c1367 100644 --- a/AMBuildScript +++ b/AMBuildScript @@ -28,6 +28,7 @@ class AcceleratorConfig(object): self.mms_root = None self.sm_root = None self.extension = None + self.libz = None self.libbreakpad_client = None self.libbreakpad = None self.libdisasm = None @@ -118,7 +119,7 @@ class AcceleratorConfig(object): '-Wno-implicit-exception-spec-mismatch' ] - cxx.postlink += ['-pthread', '-lz'] + cxx.postlink += ['-pthread', '-static-libstdc++', '-static-libgcc'] if builder.options.opt == '1': cxx.cflags += ['-O3'] @@ -161,6 +162,14 @@ class AcceleratorConfig(object): os.path.join(self.sm_root, 'sourcepawn', 'include') ] + def link_libz(self, compiler, context): + for task in self.libz: + if task.target.arch == compiler.target.arch: + compiler.postlink += [os.path.join(context.buildPath, task.binary.path)] + compiler.linkdeps += [task.binary] + return + raise Exception('No suitable build of libz was found.') + def link_libbreakpad_client(self, compiler, context): for task in self.libbreakpad_client: if task.target.arch == compiler.target.arch: diff --git a/third_party/AMBuilder b/third_party/AMBuilder index f6502e7..a7b3e5f 100644 --- a/third_party/AMBuilder +++ b/third_party/AMBuilder @@ -7,7 +7,33 @@ def AddSourceFilesFromDir(path, files): list.append(os.path.join(path, file)) return list -builder.SetBuildFolder('./third_party/breakpad') +builder.SetBuildFolder('./third_party') + +libz = builder.StaticLibraryProject('libz') +libz.sources = AddSourceFilesFromDir(os.path.join(builder.currentSourcePath, 'zlib'),[ + 'adler32.c', + 'compress.c', + 'crc32.c', + 'deflate.c', + 'gzclose.c', + 'gzlib.c', + 'gzread.c', + 'gzwrite.c', + 'infback.c', + 'inffast.c', + 'inflate.c', + 'inftrees.c', + 'trees.c', + 'uncompr.c', + 'zutil.c' +]) + +for cxx in Accelerator.targets: + if cxx.target.platform == 'linux': + binary = Accelerator.ConfigureLibrary(libz, cxx, builder) + binary.compiler.cflags += ['-Wno-implicit-function-declaration'] + +Accelerator.libz = builder.Add(libz) libbreakpad_client = builder.StaticLibraryProject('libbreakpad_client') libbreakpad_client.sources = AddSourceFilesFromDir(os.path.join(builder.currentSourcePath, 'breakpad', 'src'),[ @@ -130,6 +156,8 @@ for cxx in Accelerator.targets: compiler.sourcedeps += Accelerator.breakpad_patch if compiler.target.platform == 'linux': + # Link against our zlib if linux + Accelerator.link_libz(cxx, builder) binary.sources += linux_src if compiler.target.platform == 'windows': binary.sources += windows_src diff --git a/third_party/zlib b/third_party/zlib new file mode 160000 index 0000000..d476828 --- /dev/null +++ b/third_party/zlib @@ -0,0 +1 @@ +Subproject commit d476828316d05d54c6fd6a068b121b30c147b5cd