diff options
-rwxr-xr-x | configure | 46 | ||||
-rw-r--r-- | script/mconfig.py | 15 |
2 files changed, 49 insertions, 12 deletions
@@ -13,6 +13,9 @@ c.dsymutil.required() settings.add_setting_option('imaon2', '--with-imaon2', 'path to imaon2 (optional)', '') settings.add_setting_option('gen_dia', '--enable-recompile-dia', 'generate darwin-inject-asm.S', False, bool=True) settings.add_setting_option('enable_tests', '--enable-tests', 'tests!', False, bool=True) +settings.add_setting_option('enable_ios_bootstrap', '--enable-ios-bootstrap', 'default: true if you pass --xcode-sdk=iphoneos', + lambda: 'iphoneos' in str(settings.host_machine().toolchains()[0].sdk_opt.value), + bool=True) asm_archs = [ ('x86_64', []), @@ -42,6 +45,9 @@ mconfig.parse_args() #################################### mconfig.mark_safe_to_clean('(src)/generated/darwin-inject-asm.S', settings) +if settings.enable_ios_bootstrap: + mconfig.log('Will build iOS bootstrap.\n') + settings.host.debug_info = True settings.c_includes = ['(src)/lib', '(src)/substrate'] @@ -107,8 +113,6 @@ if settings.gen_dia: args.extend([name, bin]) emitter.add_command(settings, ['(src)/generated/darwin-inject-asm.S'], ['(src)/script/gen-inject-asm.sh'] + args[1::2], [['(src)/script/gen-inject-asm.sh', '(outs[0])'] + args]) -all_deps = ['(out)/libsubstitute.dylib'] - if settings.enable_tests: # just for quick testing for ofile, sfile, cflags, mach in [ @@ -121,7 +125,7 @@ if settings.enable_tests: ('transform-dis-cases-x86_64.o', 'transform-dis-cases-x86_64.S', [], machs[0]), ]: mconfig.build_c_objs(emitter, mach, settings.specialize(override_obj_fn='(out)/'+ofile), ['(src)/test/'+sfile]) - all_deps.append(o_to_bin('(out)/'+ofile)) + o_to_bin('(out)/'+ofile) tests = [ ('find-syms', ['-std=c89']), @@ -164,13 +168,41 @@ if settings.enable_tests: cfile = glob.glob(settings.src+'/test/test-'+ibase+'.*')[0] mconfig.build_and_link_c_objs(emitter, settings.host_machine(), settings.specialize( override_cflags=cflags+settings.host.cflags, - override_ldflags=ldflags+['-L(out)', '-lsubstitute']+settings.host.ldflags, + override_ldflags=ldflags+settings.host.ldflags, override_obj_fn=o+'.o', override_is_cxx=options.get('cxx', False), - ), 'exec', o, [cfile], objs=options.get('extra_objs', [])) - all_deps.append(o) + ), 'exec', o, [cfile], objs=options.get('extra_objs', [])+['(out)/libsubstitute.dylib']) + + mconfig.build_and_link_c_objs(emitter, settings.host_machine(), settings, 'dylib', '(out)/injected-test-dylib.dylib', ['(src)/test/injected-test-dylib.c']) + +if settings.enable_ios_bootstrap: + mconfig.build_and_link_c_objs(emitter, settings.host_machine(), + settings.specialize( + override_cflags=['-fobjc-arc', '-Wno-unused-parameter']+settings.host.cflags, + override_ldflags=['-framework', 'UIKit', '-framework', 'Foundation', '-dead_strip']+settings.host.ldflags, + ), + 'exec', + '(out)/safety-dance/SafetyDance.app/SafetyDance', + [ + '(src)/darwin-bootstrap/safety-dance/AutoGrid.m', + '(src)/darwin-bootstrap/safety-dance/main.m', + ] + ) + emitter.add_command(settings, ['(out)/safety-dance/SafetyDance.app/Info.plist'], ['(src)/darwin-bootstrap/safety-dance/Info.plist'], ['plutil -convert binary1 -o (outs[0]) (ins[0])']) + for out in ['Default.png', 'Default@2x.png']: + emitter.add_command(settings, ['(out)/safety-dance/SafetyDance.app/'+out], ['(src)/darwin-bootstrap/safety-dance/white.png'], ['cp (ins[0]) (outs[0])']) + + ls = ['(out)/libsubstitute.dylib'] + for ty, out, ins, objs, ldf, cf in [ + ('dylib', '(out)/posixspawn-hook.dylib', ['(src)/darwin-bootstrap/posixspawn-hook.c'], ls, [], []), + ('dylib', '(out)/bundle-loader.dylib', ['(src)/darwin-bootstrap/bundle-loader.c'], [], [], []), + ('exec', '(out)/unrestrict', ['(src)/darwin-bootstrap/unrestrict.c'], ls, [], []), + ('exec', '(out)/inject-into-launchd', ['(src)/darwin-bootstrap/inject-into-launchd.c'], ls, ['-framework', 'IOKit', '-framework', 'CoreFoundation'], []), + ('exec', '(out)/substituted', ['(src)/darwin-bootstrap/substituted.c', '(src)/darwin-bootstrap/substituted-plist-loader.m'], [], ['-lbsm', '-framework', 'Foundation', '-framework', 'CoreFoundation'], ['-fobjc-arc']), + ]: + mconfig.build_and_link_c_objs(emitter, settings.host_machine(), settings.specialize(override_ldflags=ldf+settings.host.ldflags, override_cflags=cf+settings.host.cflags), ty, out, ins, objs=objs) -emitter.add_command(settings, ['all'], all_deps, [], phony=True) +emitter.add_command(settings, ['all'], list(emitter.all_outs), [], phony=True) emitter.set_default_rule('all') mconfig.finish_and_emit() diff --git a/script/mconfig.py b/script/mconfig.py index e009675..aa84df8 100644 --- a/script/mconfig.py +++ b/script/mconfig.py @@ -257,7 +257,7 @@ class Option(object): if not self.show: # If you didn't mention the option in help, you don't get no stinking value. This is for ignored options only. return - if value is None: + if value is (False if self.bool else None): value = self.default if callable(value): # Pending value = value() @@ -507,9 +507,15 @@ class CLITool(object): def optional(self): self.argv_opt.need() + def f(): + try: + self.argv() + except DependencyNotFoundException: + pass + post_parse_args_will_need.append(f) def required(self): - self.optional() + self.argv_opt.need() post_parse_args_will_need.append(lambda: self.argv()) def argv(self): # mem @@ -673,7 +679,7 @@ class XcodeToolchain(object): def find_tool(self, tool, failure_notes): if not self.ok: return None - argv = ['/usr/bin/xcrun', '--sdk', self.sdk, tool.name] + self.arch_flags() + argv = ['/usr/bin/xcrun', '--sdk', self.sdk, tool.name] + ([] if tool.name == 'dsymutil' else self.arch_flags()) sod, sed, code = run_command(argv + ['--asdf']) if code != 0: if sed.startswith('xcrun: error: unable to find utility'): @@ -1052,8 +1058,6 @@ def default_is_cxx(filename): # force_cli: don't use IDEs' native C/C++ compilation mechanism # expand: call expand on filenames def build_c_objs(emitter, machine, settings, sources, headers=[], settings_cb=None, force_cli=False, expand=True): - if expand: - headers = [expand(header, settings) for header in headers] tools = machine.c_tools() any_was_cxx = False obj_fns = [] @@ -1063,6 +1067,7 @@ def build_c_objs(emitter, machine, settings, sources, headers=[], settings_cb=No _expand_argv = lambda x: expand_argv(x, settings) else: _expand = _expand_argv = lambda x: x + headers = list(map(_expand, headers)) for fn in map(_expand, sources): my_settings = settings if settings_cb is not None: |