| 1 |
"""Support for OS X.""" |
| 2 |
from __future__ import print_function |
| 3 |
|
| 4 |
from rpython.translator.platform import posix |
| 5 |
import os |
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
DARWIN_VERSION_MIN = '-mmacosx-version-min=10.13' |
| 22 |
|
| 23 |
class Darwin(posix.BasePosix): |
| 24 |
name = "darwin" |
| 25 |
|
| 26 |
standalone_only = ('-mdynamic-no-pic',) |
| 27 |
shared_only = () |
| 28 |
|
| 29 |
link_flags = (DARWIN_VERSION_MIN,) |
| 30 |
cflags = ('-O3', |
| 31 |
'-fomit-frame-pointer', |
| 32 |
|
| 33 |
'-Wno-duplicate-decl-specifier', |
| 34 |
DARWIN_VERSION_MIN,) |
| 35 |
|
| 36 |
so_ext = 'dylib' |
| 37 |
DEFAULT_CC = 'clang' |
| 38 |
rpath_flags = ['-Wl,-rpath', '-Wl,@executable_path/'] |
| 39 |
|
| 40 |
def get_multiarch(self): |
| 41 |
return 'darwin' |
| 42 |
|
| 43 |
def get_rpath_flags(self, rel_libdirs): |
| 44 |
|
| 45 |
if len(rel_libdirs) > 0: |
| 46 |
print('in get_rpath_flags, rel_libdirs is not fixed up',rel_libdirs) |
| 47 |
return self.rpath_flags |
| 48 |
|
| 49 |
def _args_for_shared(self, args, **kwds): |
| 50 |
if 'exe_name' in kwds: |
| 51 |
target_basename = kwds['exe_name'].basename |
| 52 |
else: |
| 53 |
target_basename = '$(TARGET)' |
| 54 |
|
| 55 |
|
| 56 |
return (list(self.shared_only) |
| 57 |
+ ['-dynamiclib', '-install_name', '@rpath/' + target_basename, |
| 58 |
'-undefined', 'dynamic_lookup', '-flat_namespace', |
| 59 |
'-headerpad_max_install_names', |
| 60 |
] |
| 61 |
+ args) |
| 62 |
|
| 63 |
def _include_dirs_for_libffi(self): |
| 64 |
return self._pkg_config("libffi", "--cflags-only-I", |
| 65 |
['/usr/include/ffi'], |
| 66 |
check_result_dir=True) |
| 67 |
|
| 68 |
def _library_dirs_for_libffi(self): |
| 69 |
return self._pkg_config("libffi", "--libs-only-L", |
| 70 |
['/usr/lib'], |
| 71 |
check_result_dir=True) |
| 72 |
|
| 73 |
def _include_dirs_for_openssl(self): |
| 74 |
return self._pkg_config("openssl", "--cflags-only-I", |
| 75 |
['/usr/include', '/usr/local/opt/openssl/include'], |
| 76 |
check_result_dir=True) |
| 77 |
|
| 78 |
def _library_dirs_for_openssl(self): |
| 79 |
return self._pkg_config("openssl", "--libs-only-L", |
| 80 |
['/usr/lib', '/usr/local/opt/openssl/lib'], |
| 81 |
check_result_dir=True) |
| 82 |
|
| 83 |
def _frameworks(self, frameworks): |
| 84 |
args = [] |
| 85 |
for f in frameworks: |
| 86 |
args.append('-framework') |
| 87 |
args.append(f) |
| 88 |
return args |
| 89 |
|
| 90 |
def _link_args_from_eci(self, eci, standalone): |
| 91 |
args = super(Darwin, self)._link_args_from_eci(eci, standalone) |
| 92 |
frameworks = self._frameworks(eci.frameworks) |
| 93 |
include_dirs = self._includedirs(eci.include_dirs) |
| 94 |
return (args + frameworks + include_dirs) |
| 95 |
|
| 96 |
def _exportsymbols_link_flags(self): |
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
return [] |
| 102 |
|
| 103 |
def gen_makefile(self, cfiles, eci, exe_name=None, path=None, |
| 104 |
shared=False, headers_to_precompile=[], |
| 105 |
no_precompile_cfiles = [], profopt=False, config=None): |
| 106 |
|
| 107 |
fs = self._frameworks(eci.frameworks) |
| 108 |
extra_libs = self.extra_libs |
| 109 |
if len(fs) > 0: |
| 110 |
|
| 111 |
self.extra_libs += tuple(map(" ".join, zip(fs[::2], fs[1::2]))) |
| 112 |
mk = super(Darwin, self).gen_makefile(cfiles, eci, exe_name, path, |
| 113 |
shared=shared, |
| 114 |
headers_to_precompile=headers_to_precompile, |
| 115 |
no_precompile_cfiles = no_precompile_cfiles, |
| 116 |
profopt=profopt, config=config) |
| 117 |
self.extra_libs = extra_libs |
| 118 |
return mk |
| 119 |
|
| 120 |
class Darwin_PowerPC(Darwin): |
| 121 |
name = "darwin_powerpc" |
| 122 |
link_flags = Darwin.link_flags + ('-arch', 'ppc') |
| 123 |
cflags = Darwin.cflags + ('-arch', 'ppc') |
| 124 |
|
| 125 |
class Darwin_i386(Darwin): |
| 126 |
name = "darwin_i386" |
| 127 |
link_flags = Darwin.link_flags + ('-arch', 'i386') |
| 128 |
cflags = Darwin.cflags + ('-arch', 'i386') |
| 129 |
|
| 130 |
class Darwin_x86_64(Darwin): |
| 131 |
name = "darwin_x86_64" |
| 132 |
link_flags = Darwin.link_flags + ('-arch', 'x86_64') |
| 133 |
cflags = Darwin.cflags + ('-arch', 'x86_64') |
| 134 |
|
| 135 |
class Darwin_arm64(Darwin): |
| 136 |
name = 'darwin_arm64' |
| 137 |
link_flags = Darwin.link_flags + ('-arch', 'arm64') |
| 138 |
cflags = Darwin.cflags + ('-arch', 'arm64') |