Browse Source

Don't use objcopy for macOS build (#143)

* Don't use objcopy for macOS build

* Add -x option to strip on macOS
Without -x strip results in error for dylib
pull/144/head
exstrim401 2 years ago committed by GitHub
parent
commit
a1c4e27718
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 14
      scripts/waifulib/strip_on_install_v2.py
  2. 4
      wscript

14
scripts/waifulib/strip_on_install.py → scripts/waifulib/strip_on_install_v2.py

@ -23,6 +23,10 @@ def configure(conf):
if not conf.env.STRIPFLAGS: if not conf.env.STRIPFLAGS:
conf.env.STRIPFLAGS = os.environ['STRIPFLAGS'] if 'STRIPFLAGS' in os.environ else [] conf.env.STRIPFLAGS = os.environ['STRIPFLAGS'] if 'STRIPFLAGS' in os.environ else []
if conf.env.DEST_BINFMT == 'mac-o':
conf.env.STRIPFLAGS += ['-x']
return # macOS don't have objcopy
# a1ba: I am lazy to add `export OBJCOPY=` everywhere in my scripts # a1ba: I am lazy to add `export OBJCOPY=` everywhere in my scripts
# so just try to deduce which objcopy we have # so just try to deduce which objcopy we have
try: try:
@ -47,26 +51,26 @@ def copy_fun(self, src, tgt):
if getattr(self.generator, 'link_task', None) and self.generator.link_task.outputs[0] in self.inputs: if getattr(self.generator, 'link_task', None) and self.generator.link_task.outputs[0] in self.inputs:
tgt_debug = tgt + '.debug' tgt_debug = tgt + '.debug'
strip_cmd = self.env.STRIP + self.env.STRIPFLAGS + [tgt]
ocopy_cmd = self.env.OBJCOPY + ['--only-keep-debug', tgt, tgt_debug]
ocopy_debuglink_cmd = self.env.OBJCOPY + ['--add-gnu-debuglink=%s' % tgt_debug, tgt]
c1 = Logs.colors.NORMAL c1 = Logs.colors.NORMAL
c2 = Logs.colors.CYAN c2 = Logs.colors.CYAN
c3 = Logs.colors.YELLOW c3 = Logs.colors.YELLOW
c4 = Logs.colors.BLUE c4 = Logs.colors.BLUE
try: try:
if self.generator.bld.options.strip_to_file: if self.generator.bld.options.strip_to_file and self.env.DEST_BINFMT == 'elf':
ocopy_cmd = self.env.OBJCOPY + ['--only-keep-debug', tgt, tgt_debug]
self.generator.bld.cmd_and_log(ocopy_cmd, output=Context.BOTH, quiet=Context.BOTH) self.generator.bld.cmd_and_log(ocopy_cmd, output=Context.BOTH, quiet=Context.BOTH)
if not self.generator.bld.progress_bar: if not self.generator.bld.progress_bar:
Logs.info('%s+ objcopy --only-keep-debug %s%s%s %s%s%s', c1, c4, tgt, c1, c3, tgt_debug, c1) Logs.info('%s+ objcopy --only-keep-debug %s%s%s %s%s%s', c1, c4, tgt, c1, c3, tgt_debug, c1)
strip_cmd = self.env.STRIP + self.env.STRIPFLAGS + [tgt]
self.generator.bld.cmd_and_log(strip_cmd, output=Context.BOTH, quiet=Context.BOTH) self.generator.bld.cmd_and_log(strip_cmd, output=Context.BOTH, quiet=Context.BOTH)
if not self.generator.bld.progress_bar: if not self.generator.bld.progress_bar:
f1 = os.path.getsize(src) f1 = os.path.getsize(src)
f2 = os.path.getsize(tgt) f2 = os.path.getsize(tgt)
Logs.info('%s+ strip %s%s%s (%d bytes change)', c1, c2, tgt, c1, f2 - f1) Logs.info('%s+ strip %s%s%s (%d bytes change)', c1, c2, tgt, c1, f2 - f1)
if self.generator.bld.options.strip_to_file: if self.generator.bld.options.strip_to_file and self.env.DEST_BINFMT == 'elf':
ocopy_debuglink_cmd = self.env.OBJCOPY + ['--add-gnu-debuglink=%s' % tgt_debug, tgt]
self.generator.bld.cmd_and_log(ocopy_debuglink_cmd, output=Context.BOTH, quiet=Context.BOTH) self.generator.bld.cmd_and_log(ocopy_debuglink_cmd, output=Context.BOTH, quiet=Context.BOTH)
if not self.generator.bld.progress_bar: if not self.generator.bld.progress_bar:
Logs.info('%s+ objcopy --add-gnu-debuglink=%s%s%s %s%s%s', c1, c3, tgt_debug, c1, c2, tgt, c1) Logs.info('%s+ objcopy --add-gnu-debuglink=%s%s%s %s%s%s', c1, c3, tgt_debug, c1, c2, tgt, c1)

4
wscript

@ -272,7 +272,7 @@ def options(opt):
opt.load('compiler_optimizations subproject') opt.load('compiler_optimizations subproject')
opt.load('xcompile compiler_cxx compiler_c sdl2 clang_compilation_database strip_on_install waf_unit_test subproject') opt.load('xcompile compiler_cxx compiler_c sdl2 clang_compilation_database strip_on_install_v2 waf_unit_test subproject')
if sys.platform == 'win32': if sys.platform == 'win32':
opt.load('msvc msdev msvs') opt.load('msvc msdev msvs')
opt.load('reconfigure') opt.load('reconfigure')
@ -289,7 +289,7 @@ def configure(conf):
conf.env.MSVC_TARGETS = ['x64'] conf.env.MSVC_TARGETS = ['x64']
if sys.platform == 'win32': if sys.platform == 'win32':
conf.load('msvc_pdb_ext msdev msvs') conf.load('msvc_pdb_ext msdev msvs')
conf.load('subproject xcompile compiler_c compiler_cxx gitversion clang_compilation_database strip_on_install waf_unit_test enforce_pic') conf.load('subproject xcompile compiler_c compiler_cxx gitversion clang_compilation_database strip_on_install_v2 waf_unit_test enforce_pic')
if conf.env.DEST_OS == 'win32' and conf.env.DEST_CPU == 'amd64': if conf.env.DEST_OS == 'win32' and conf.env.DEST_CPU == 'amd64':
conf.load('masm') conf.load('masm')
elif conf.env.DEST_OS == 'darwin': elif conf.env.DEST_OS == 'darwin':

Loading…
Cancel
Save