Skip to content

Commit a1c4e27

Browse files
authored
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
1 parent ad5790e commit a1c4e27

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

scripts/waifulib/strip_on_install.py renamed to scripts/waifulib/strip_on_install_v2.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ def configure(conf):
2222
conf.find_program('strip', var='STRIP')
2323
if not conf.env.STRIPFLAGS:
2424
conf.env.STRIPFLAGS = os.environ['STRIPFLAGS'] if 'STRIPFLAGS' in os.environ else []
25+
26+
if conf.env.DEST_BINFMT == 'mac-o':
27+
conf.env.STRIPFLAGS += ['-x']
28+
return # macOS don't have objcopy
2529

2630
# a1ba: I am lazy to add `export OBJCOPY=` everywhere in my scripts
2731
# so just try to deduce which objcopy we have
@@ -47,26 +51,26 @@ def copy_fun(self, src, tgt):
4751

4852
if getattr(self.generator, 'link_task', None) and self.generator.link_task.outputs[0] in self.inputs:
4953
tgt_debug = tgt + '.debug'
50-
strip_cmd = self.env.STRIP + self.env.STRIPFLAGS + [tgt]
51-
ocopy_cmd = self.env.OBJCOPY + ['--only-keep-debug', tgt, tgt_debug]
52-
ocopy_debuglink_cmd = self.env.OBJCOPY + ['--add-gnu-debuglink=%s' % tgt_debug, tgt]
5354
c1 = Logs.colors.NORMAL
5455
c2 = Logs.colors.CYAN
5556
c3 = Logs.colors.YELLOW
5657
c4 = Logs.colors.BLUE
5758
try:
58-
if self.generator.bld.options.strip_to_file:
59+
if self.generator.bld.options.strip_to_file and self.env.DEST_BINFMT == 'elf':
60+
ocopy_cmd = self.env.OBJCOPY + ['--only-keep-debug', tgt, tgt_debug]
5961
self.generator.bld.cmd_and_log(ocopy_cmd, output=Context.BOTH, quiet=Context.BOTH)
6062
if not self.generator.bld.progress_bar:
6163
Logs.info('%s+ objcopy --only-keep-debug %s%s%s %s%s%s', c1, c4, tgt, c1, c3, tgt_debug, c1)
6264

65+
strip_cmd = self.env.STRIP + self.env.STRIPFLAGS + [tgt]
6366
self.generator.bld.cmd_and_log(strip_cmd, output=Context.BOTH, quiet=Context.BOTH)
6467
if not self.generator.bld.progress_bar:
6568
f1 = os.path.getsize(src)
6669
f2 = os.path.getsize(tgt)
6770
Logs.info('%s+ strip %s%s%s (%d bytes change)', c1, c2, tgt, c1, f2 - f1)
6871

69-
if self.generator.bld.options.strip_to_file:
72+
if self.generator.bld.options.strip_to_file and self.env.DEST_BINFMT == 'elf':
73+
ocopy_debuglink_cmd = self.env.OBJCOPY + ['--add-gnu-debuglink=%s' % tgt_debug, tgt]
7074
self.generator.bld.cmd_and_log(ocopy_debuglink_cmd, output=Context.BOTH, quiet=Context.BOTH)
7175
if not self.generator.bld.progress_bar:
7276
Logs.info('%s+ objcopy --add-gnu-debuglink=%s%s%s %s%s%s', c1, c3, tgt_debug, c1, c2, tgt, c1)

wscript

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ def options(opt):
272272

273273
opt.load('compiler_optimizations subproject')
274274

275-
opt.load('xcompile compiler_cxx compiler_c sdl2 clang_compilation_database strip_on_install waf_unit_test subproject')
275+
opt.load('xcompile compiler_cxx compiler_c sdl2 clang_compilation_database strip_on_install_v2 waf_unit_test subproject')
276276
if sys.platform == 'win32':
277277
opt.load('msvc msdev msvs')
278278
opt.load('reconfigure')
@@ -289,7 +289,7 @@ def configure(conf):
289289
conf.env.MSVC_TARGETS = ['x64']
290290
if sys.platform == 'win32':
291291
conf.load('msvc_pdb_ext msdev msvs')
292-
conf.load('subproject xcompile compiler_c compiler_cxx gitversion clang_compilation_database strip_on_install waf_unit_test enforce_pic')
292+
conf.load('subproject xcompile compiler_c compiler_cxx gitversion clang_compilation_database strip_on_install_v2 waf_unit_test enforce_pic')
293293
if conf.env.DEST_OS == 'win32' and conf.env.DEST_CPU == 'amd64':
294294
conf.load('masm')
295295
elif conf.env.DEST_OS == 'darwin':

0 commit comments

Comments
 (0)