aboutsummaryrefslogtreecommitdiff
path: root/configure
blob: 5e1ad3d87a2e035e744683f74829ead9400dc2a3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env python2.7
import mconfig
settings = mconfig.settings_root
settings.package_unix_name.value = 'substitute'

c = settings.host_machine().c_tools()

c.cc.required()
c.dsymutil.required()

asm_archs = [
    ('x86_64', []),
    ('i386', []),
    ('arm', ['-marm']),
    ('arm64', []), # XXX
]

machs = []
for name, cflags in asm_archs:
    mach = mconfig.Machine('asm-' + name, settings, 'for cross-compiling the inject baton', name + '-apple-darwin10')
    machs.append(mach)
    mach.c_tools().cc.required()


mconfig.parse_args()
settings.cflags = ['-I%s/lib' % (settings.src,)] + settings.cflags
settings.debug_info = True

emitter = settings.emitter

balco = lambda *args, **kwargs: mconfig.build_and_link_c_objs(emitter, settings.host_machine(), settings, *args, **kwargs)

def cb(fn):
    if fn.endswith('/objc.c'):
        return settings.specialize(obj_ldflag_sets=[('-lobjc',)])
    return settings

# Note: the order of darwin-inject-asm.o is significant.  Per man page, ld is
# guaranteed to link objects in order, which is necessary because
# darwin-inject-asm.S does not itself ensure there is at least 0x4000 bytes of
# executable stuff after inject_page_start (so that arm can remap into arm64).
# By putting it at the beginning, we can just reuse the space for the rest of
# the library rather than having to pad with zeroes.
# (This only matters on 32-bit ARM, and the text segment is currently 0xa000
# bytes there, more than enough.)

balco(
    'dylib',
    '(out)/libsubstitute.dylib',
    [
        '(src)/generated/darwin-inject-asm.S',
        '(src)/lib/darwin/find-syms.c',
        '(src)/lib/darwin/inject.c',
        '(src)/lib/darwin/interpose.c',
        '(src)/lib/darwin/objc-asm.S',
        '(src)/lib/darwin/objc.c',
        '(src)/lib/darwin/read.c',
        '(src)/lib/darwin/substrate-compat.c',
        '(src)/lib/darwin/execmem.c',
        '(src)/lib/cbit/vec.c',
        '(src)/lib/jump-dis.c',
        '(src)/lib/transform-dis.c',
        '(src)/lib/hook-functions.c',
        '(src)/lib/strerror.c',
    ],
    settings_cb=cb
)

#for name, arch_flag, opts in [
#]:
#compile_c_objs(emitter, settings.host_machine(), 
    

#settings.test = 'foo baz'
emitter.add_command(settings, ['all'], ['(out)/libsubstitute.dylib'], [], phony=True)
emitter.set_default_rule('all')

mconfig.finish_and_emit()