10 class Platform(object):
14 class simulator_platform(Platform
):
16 triple
= 'i386-apple-darwin11'
18 prefix
= "#ifdef __i386__\n\n"
21 src_files
= ['sysv.S', 'ffi.c', 'internal.h']
24 class simulator64_platform(Platform
):
26 triple
= 'x86_64-apple-darwin13'
28 prefix
= "#ifdef __x86_64__\n\n"
31 src_files
= ['unix64.S', 'ffi64.c', 'ffiw64.c', 'win64.S', 'internal64.h', 'asmnames.h']
34 class device_platform(Platform
):
36 triple
= 'arm-apple-darwin11'
38 prefix
= "#ifdef __arm__\n\n"
41 src_files
= ['sysv.S', 'ffi.c', 'internal.h']
44 class device64_platform(Platform
):
46 triple
= 'aarch64-apple-darwin13'
48 prefix
= "#ifdef __arm64__\n\n"
51 src_files
= ['sysv.S', 'ffi.c', 'internal.h']
54 class ios_simulator_platform(simulator_platform
):
55 directory
= 'darwin_ios'
56 sdk
= 'iphonesimulator'
57 version_min
= '-miphoneos-version-min=7.0'
60 class ios_simulator64_platform(simulator64_platform
):
61 directory
= 'darwin_ios'
62 sdk
= 'iphonesimulator'
63 version_min
= '-miphoneos-version-min=7.0'
66 class ios_device_platform(device_platform
):
67 directory
= 'darwin_ios'
69 version_min
= '-miphoneos-version-min=7.0'
72 class ios_device64_platform(device64_platform
):
73 directory
= 'darwin_ios'
75 version_min
= '-miphoneos-version-min=7.0'
78 class desktop32_platform(Platform
):
79 directory
= 'darwin_osx'
82 triple
= 'i386-apple-darwin10'
83 version_min
= '-mmacosx-version-min=10.6'
85 src_files
= ['sysv.S', 'ffi.c', 'internal.h']
87 prefix
= "#ifdef __i386__\n\n"
91 class desktop64_platform(Platform
):
92 directory
= 'darwin_osx'
95 triple
= 'x86_64-apple-darwin10'
96 version_min
= '-mmacosx-version-min=10.6'
98 prefix
= "#ifdef __x86_64__\n\n"
101 src_files
= ['unix64.S', 'ffi64.c', 'ffiw64.c', 'win64.S', 'internal64.h', 'asmnames.h']
104 class tvos_simulator64_platform(simulator64_platform
):
105 directory
= 'darwin_tvos'
106 sdk
= 'appletvsimulator'
107 version_min
= '-mtvos-version-min=9.0'
110 class tvos_device64_platform(device64_platform
):
111 directory
= 'darwin_tvos'
113 version_min
= '-mtvos-version-min=9.0'
116 class watchos_simulator_platform(simulator_platform
):
117 directory
= 'darwin_watchos'
118 sdk
= 'watchsimulator'
119 version_min
= '-mwatchos-version-min=4.0'
122 class watchos_device_platform(device_platform
):
123 directory
= 'darwin_watchos'
126 version_min
= '-mwatchos-version-min=4.0'
132 except OSError as exc
: # Python >2.5
133 if exc
.errno
!= errno
.EEXIST
:
137 def move_file(src_dir
, dst_dir
, filename
, file_suffix
=None, prefix
='', suffix
=''):
139 out_filename
= filename
142 if filename
in ['internal64.h', 'asmnames.h', 'internal.h']:
143 out_filename
= filename
145 split_name
= os
.path
.splitext(filename
)
146 out_filename
= "%s_%s%s" % (split_name
[0], file_suffix
, split_name
[1])
148 with
open(os
.path
.join(src_dir
, filename
)) as in_file
:
149 with
open(os
.path
.join(dst_dir
, out_filename
), 'w') as out_file
:
151 out_file
.write(prefix
)
153 out_file
.write(in_file
.read())
156 out_file
.write(suffix
)
159 def list_files(src_dir
, pattern
=None, filelist
=None):
160 if pattern
: filelist
= glob
.iglob(os
.path
.join(src_dir
, pattern
))
161 for file in filelist
:
162 yield os
.path
.basename(file)
165 def copy_files(src_dir
, dst_dir
, pattern
=None, filelist
=None, file_suffix
=None, prefix
=None, suffix
=None):
166 for filename
in list_files(src_dir
, pattern
=pattern
, filelist
=filelist
):
167 move_file(src_dir
, dst_dir
, filename
, file_suffix
=file_suffix
, prefix
=prefix
, suffix
=suffix
)
170 def copy_src_platform_files(platform
):
171 src_dir
= os
.path
.join('src', platform
.src_dir
)
172 dst_dir
= os
.path
.join(platform
.directory
, 'src', platform
.src_dir
)
173 copy_files(src_dir
, dst_dir
, filelist
=platform
.src_files
, file_suffix
=platform
.arch
, prefix
=platform
.prefix
, suffix
=platform
.suffix
)
176 def build_target(platform
, platform_headers
):
178 return 'xcrun -sdk %s %s -arch %s' % (platform
.sdk
, cmd
, platform
.arch
)
180 tag
='%s-%s' % (platform
.sdk
, platform
.arch
)
181 build_dir
= 'build_%s' % tag
183 env
= dict(CC
=xcrun_cmd('clang'),
185 CFLAGS
='%s -fembed-bitcode' % (platform
.version_min
))
186 working_dir
= os
.getcwd()
189 subprocess
.check_call(['../configure', '-host', platform
.triple
], env
=env
)
191 os
.chdir(working_dir
)
193 for src_dir
in [build_dir
, os
.path
.join(build_dir
, 'include')]:
195 os
.path
.join(platform
.directory
, 'include'),
197 file_suffix
=platform
.arch
,
198 prefix
=platform
.prefix
,
199 suffix
=platform
.suffix
)
201 for filename
in list_files(src_dir
, pattern
='*.h'):
202 platform_headers
[filename
].add((platform
.prefix
, platform
.arch
, platform
.suffix
))
205 def generate_source_and_headers(
209 generate_watchos
=True,
211 copy_files('src', 'darwin_common/src', pattern
='*.c')
212 copy_files('include', 'darwin_common/include', pattern
='*.h')
215 copy_src_platform_files(ios_simulator_platform
)
216 copy_src_platform_files(ios_simulator64_platform
)
217 copy_src_platform_files(ios_device_platform
)
218 copy_src_platform_files(ios_device64_platform
)
220 copy_src_platform_files(desktop64_platform
)
222 copy_src_platform_files(tvos_simulator64_platform
)
223 copy_src_platform_files(tvos_device64_platform
)
225 copy_src_platform_files(watchos_simulator_platform
)
226 copy_src_platform_files(watchos_device_platform
)
228 platform_headers
= collections
.defaultdict(set)
231 build_target(ios_simulator_platform
, platform_headers
)
232 build_target(ios_simulator64_platform
, platform_headers
)
233 build_target(ios_device_platform
, platform_headers
)
234 build_target(ios_device64_platform
, platform_headers
)
236 build_target(desktop64_platform
, platform_headers
)
238 build_target(tvos_simulator64_platform
, platform_headers
)
239 build_target(tvos_device64_platform
, platform_headers
)
241 build_target(watchos_simulator_platform
, platform_headers
)
242 build_target(watchos_device_platform
, platform_headers
)
244 mkdir_p('darwin_common/include')
245 for header_name
, tag_tuples
in platform_headers
.items():
246 basename
, suffix
= os
.path
.splitext(header_name
)
247 with
open(os
.path
.join('darwin_common/include', header_name
), 'w') as header
:
248 for tag_tuple
in tag_tuples
:
249 header
.write('%s#include <%s_%s%s>\n%s\n' % (tag_tuple
[0], basename
, tag_tuple
[1], suffix
, tag_tuple
[2]))
251 if __name__
== '__main__':
252 parser
= argparse
.ArgumentParser()
253 parser
.add_argument('--only-ios', action
='store_true', default
=False)
254 parser
.add_argument('--only-osx', action
='store_true', default
=False)
255 parser
.add_argument('--only-tvos', action
='store_true', default
=False)
256 parser
.add_argument('--only-watchos', action
='store_true', default
=False)
257 args
= parser
.parse_args()
259 generate_source_and_headers(
260 generate_osx
=not args
.only_ios
and not args
.only_tvos
and not args
.only_watchos
,
261 generate_ios
=not args
.only_osx
and not args
.only_tvos
and not args
.only_watchos
,
262 generate_tvos
=not args
.only_ios
and not args
.only_osx
and not args
.only_watchos
,
263 generate_watchos
=not args
.only_ios
and not args
.only_osx
and not args
.only_tvos
,