mirror of
https://github.com/YGGverse/xash3d-fwgs.git
synced 2025-01-17 18:40:02 +00:00
waf: strip installed binaries to reduce size
This commit is contained in:
parent
5986874be2
commit
67c6cfce71
38
scripts/waifulib/strip_on_install.py
Normal file
38
scripts/waifulib/strip_on_install.py
Normal file
@ -0,0 +1,38 @@
|
||||
#! /usr/bin/env python
|
||||
# Modified: Alibek Omarov <a1ba.omarov@gmail.com>
|
||||
# Originally taken from Thomas Nagy's blogpost
|
||||
|
||||
"""
|
||||
Strip executables upon installation
|
||||
"""
|
||||
|
||||
import shutil, os
|
||||
from waflib import Build, Utils, Context, Errors, Logs
|
||||
|
||||
def configure(conf):
|
||||
if conf.env.DEST_BINFMT in ['elf', 'mac-o']:
|
||||
conf.find_program('strip')
|
||||
if not conf.env.STRIPFLAGS:
|
||||
conf.env.STRIPFLAGS = os.environ['STRIPFLAGS'] if 'STRIPFLAGS' in os.environ else []
|
||||
|
||||
def copy_fun(self, src, tgt):
|
||||
inst_copy_fun(self, src, tgt)
|
||||
|
||||
if self.env.KEEP_DEBUG_INFO:
|
||||
return # don't strip debug information in debug mode
|
||||
|
||||
if getattr(self.generator, 'link_task', None) and self.generator.link_task.outputs[0] in self.inputs:
|
||||
cmd = self.env.STRIP + self.env.STRIPFLAGS + [tgt]
|
||||
try:
|
||||
if not self.generator.bld.progress_bar:
|
||||
c1 = Logs.colors.NORMAL
|
||||
c2 = Logs.colors.CYAN
|
||||
|
||||
Logs.info('%s+ strip %s%s%s', c1, c2, tgt, c2)
|
||||
self.generator.bld.cmd_and_log(cmd, output=Context.BOTH, quiet=Context.BOTH)
|
||||
except Errors.WafError as e:
|
||||
print(e.stdout, e.stderr)
|
||||
|
||||
inst_copy_fun = Build.inst.copy_fun
|
||||
Build.inst.copy_fun = copy_fun
|
||||
|
@ -187,6 +187,9 @@ class Android:
|
||||
triplet = self.ndk_triplet() + '-'
|
||||
return os.path.join(self.gen_gcc_toolchain_path(), 'bin', triplet)
|
||||
|
||||
def gen_binutils_path(self):
|
||||
return os.path.join(self.gen_gcc_toolchain_path(), self.ndk_triplet(), 'bin')
|
||||
|
||||
def cc(self):
|
||||
if self.is_host():
|
||||
return 'clang'
|
||||
@ -197,6 +200,11 @@ class Android:
|
||||
return 'clang++'
|
||||
return self.toolchain_path + ('clang++' if self.is_clang() else 'g++')
|
||||
|
||||
def strip(self):
|
||||
if self.is_host():
|
||||
return 'strip'
|
||||
return os.path.join(self.gen_binutils_path(), 'strip')
|
||||
|
||||
def system_stl(self):
|
||||
# TODO: proper STL support
|
||||
return os.path.abspath(os.path.join(self.ndk_home, 'sources', 'cxx-stl', 'system', 'include'))
|
||||
@ -305,6 +313,7 @@ def configure(conf):
|
||||
setattr(conf, 'android', android)
|
||||
conf.environ['CC'] = android.cc()
|
||||
conf.environ['CXX'] = android.cxx()
|
||||
conf.environ['STRIP'] = android.strip()
|
||||
conf.env.CFLAGS += android.cflags()
|
||||
conf.env.CXXFLAGS += android.cflags()
|
||||
conf.env.LINKFLAGS += android.linkflags()
|
||||
|
2
wscript
2
wscript
@ -90,7 +90,7 @@ def configure(conf):
|
||||
conf.env.MSVC_TARGETS = ['x86'] # explicitly request x86 target for MSVC
|
||||
if sys.platform == 'win32':
|
||||
conf.load('msvc msvcfix msdev msvs')
|
||||
conf.load('xcompile compiler_c compiler_cxx gitversion clang_compilation_database')
|
||||
conf.load('xcompile compiler_c compiler_cxx gitversion clang_compilation_database strip_on_install')
|
||||
|
||||
# Every static library must have fPIC
|
||||
if conf.env.DEST_OS != 'win32' and '-fPIC' in conf.env.CFLAGS_cshlib:
|
||||
|
Loading…
x
Reference in New Issue
Block a user