10 class Platform(object):
13 sdk_re
= re
.compile(r
'.*-sdk ([a-zA-Z0-9.]*)')
17 for line
in subprocess
.Popen(['xcodebuild', '-sdk', sdkname
, '-version'], stdout
=subprocess
.PIPE
).stdout
:
18 kv
= line
.strip().split(': ', 1)
24 sim_sdk_info
= sdkinfo('iphonesimulator')
25 device_sdk_info
= sdkinfo('iphoneos')
30 for line
in subprocess
.Popen(['xcodebuild', '-showsdks'], stdout
=subprocess
.PIPE
).stdout
:
31 match
= sdk_re
.match(line
)
33 if 'Simulator' in line
:
34 latest_sim
= match
.group(1)
36 latest_device
= match
.group(1)
38 return latest_sim
, latest_device
40 sim_sdk
, device_sdk
= latest_sdks()
42 class simulator_platform(Platform
):
46 triple
= 'i386-apple-darwin10'
47 sdkroot
= sim_sdk_info
['Path']
49 prefix
= "#if !defined(__arm__) && defined(__i386__)\n\n"
52 class device_platform(Platform
):
56 triple
= 'arm-apple-darwin10'
57 sdkroot
= device_sdk_info
['Path']
59 prefix
= "#ifdef __arm__\n\n"
63 def move_file(src_dir
, dst_dir
, filename
, file_suffix
=None, prefix
='', suffix
=''):
64 if not os
.path
.exists(dst_dir
):
67 out_filename
= filename
70 split_name
= os
.path
.splitext(filename
)
71 out_filename
= "%s_%s%s" % (split_name
[0], file_suffix
, split_name
[1])
73 with
open(os
.path
.join(src_dir
, filename
)) as in_file
:
74 with
open(os
.path
.join(dst_dir
, out_filename
), 'w') as out_file
:
76 out_file
.write(prefix
)
78 out_file
.write(in_file
.read())
81 out_file
.write(suffix
)
83 headers_seen
= collections
.defaultdict(set)
85 def move_source_tree(src_dir
, dest_dir
, dest_include_dir
, arch
=None, prefix
=None, suffix
=None):
86 for root
, dirs
, files
in os
.walk(src_dir
, followlinks
=True):
87 relroot
= os
.path
.relpath(root
,src_dir
)
89 def move_dir(arch
, prefix
='', suffix
='', files
=[]):
92 if file.endswith('.h'):
96 headers_seen
[file].add(arch
)
97 move_file(root
, dest_include_dir
, file, arch
, prefix
=prefix
, suffix
=suffix
)
100 outroot
= os
.path
.join(dest_dir
, relroot
)
101 move_file(root
, outroot
, file, prefix
=prefix
, suffix
=suffix
)
108 elif relroot
== 'arm':
110 prefix
="#ifdef __arm__\n\n",
113 elif relroot
== 'x86':
114 move_dir(arch
='i386',
115 prefix
="#if !defined(__arm__) && defined(__i386__)\n\n",
119 def build_target(platform
):
121 return subprocess
.check_output(['xcrun', '-sdk', platform
.sdkroot
, '-find', cmd
]).strip()
123 build_dir
= 'build_' + platform
.name
124 if not os
.path
.exists(build_dir
):
125 os
.makedirs(build_dir
)
126 env
= dict(CC
=xcrun_cmd('clang'),
128 CFLAGS
='-arch %s -isysroot %s -miphoneos-version-min=4.0' % (platform
.arch
, platform
.sdkroot
))
129 working_dir
=os
.getcwd()
132 subprocess
.check_call(['../configure', '-host', platform
.triple
], env
=env
)
133 move_source_tree('.', None, '../ios/include',
135 prefix
=platform
.prefix
,
136 suffix
=platform
.suffix
)
137 move_source_tree('./include', None, '../ios/include',
139 prefix
=platform
.prefix
,
140 suffix
=platform
.suffix
)
142 os
.chdir(working_dir
)
144 for header_name
, archs
in headers_seen
.iteritems():
145 basename
, suffix
= os
.path
.splitext(header_name
)
148 move_source_tree('src', 'ios/src', 'ios/include')
149 move_source_tree('include', None, 'ios/include')
150 build_target(simulator_platform
)
151 build_target(device_platform
)
153 for header_name
, archs
in headers_seen
.iteritems():
154 basename
, suffix
= os
.path
.splitext(header_name
)
155 with
open(os
.path
.join('ios/include', header_name
), 'w') as header
:
157 header
.write('#include <%s_%s%s>\n' % (basename
, arch
, suffix
))
159 if __name__
== '__main__':