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
79
80
81
82
83
84
85
86
87
|
# -*- Mode: Python -*- vi:si:et:sw=4:sts=4:ts=4:syntax=python
import shutil
import glob
FFI_H_UNVERSAL='''\
#ifdef __i386__
#include "i386/ffi.h"
#elif defined(__ppc__)
#include "ppc/ffi.h"
#elif defined(__x86_64__)
#include "x86_64/ffi.h"
#elif defined(__arm__)
#include "arm/ffi.h"
#elif defined(__arm64__)
#include "arm64/ffi.h"
#else
#error "Unsupported Architecture"
#endif
'''
class Recipe(recipe.Recipe):
name = 'libffi'
version = '3.2.1'
autoreconf = True
remotes = {'origin': 'https://github.com/atgreen/libffi.git'}
commit = '20562ac0427c3578250d04c6e34fb0127d4551cf'
licenses = [License.BSD_like]
files_libs = ['libffi']
files_devel = ['lib/libffi-3.2.1/include/ffi.h', 'lib/pkgconfig/libffi.pc']
patches = ['libffi/0001-libffi-Don-t-be-smart-about-toolexeclibdir.patch']
def prepare(self):
self.libffidir = os.path.join('lib', 'libffi-%s' % self.version)
if self.config.target_platform in [Platform.DARWIN, Platform.IOS]:
arch = self.config.target_arch
if self.config.target_arch == Architecture.X86_64:
dir = 'x86_64-apple-darwin*'
elif self.config.target_arch == Architecture.X86:
dir = 'i386-apple-darwin*'
arch = 'i386'
elif self.config.target_arch == Architecture.ARM64:
dir = 'aarch64-apple-darwin*'
arch = 'arm64'
elif Architecture.is_arm(self.config.target_arch):
dir = 'arm-apple-darwin*'
arch = 'arm'
self.files_devel.append(os.path.join(self.libffidir, 'include', '*', 'ffi.h'))
self.files_devel.append(os.path.join(self.libffidir, 'include', '*', 'ffitarget.h'))
self.make = 'make -C %s' % dir
self.make_install = 'make -C %s install' % dir
else:
self.files_devel.append(os.path.join(self.libffidir, 'include', 'ffitarget.h'))
def post_install(self):
if self.config.target_platform in [Platform.DARWIN, Platform.IOS]:
# For the universal build we need to ship ffi.h of both
# architectures in a subfolder and include the correct one depending
# on the compiler architecture
arch = self.config.target_arch
if self.config.target_arch == Architecture.X86_64:
dir = 'x86_64-apple-darwin*'
elif self.config.target_arch == Architecture.X86:
dir = 'i386-apple-darwin*'
arch = 'i386'
elif self.config.target_arch == Architecture.ARM64:
dir = 'aarch64-apple-darwin*'
elif Architecture.is_arm(self.config.target_arch):
dir = 'arm-apple-darwin*'
arch = 'arm'
arch_dir = os.path.join(self.config.prefix, self.libffidir, 'include', arch)
if not os.path.exists(arch_dir):
os.makedirs(arch_dir)
replacements = {'#include <ffitarget.h>': '#include "ffitarget.h"'}
shell.replace(glob.glob(os.path.join(self.build_dir, dir, 'include', 'ffi.h'))[0], replacements)
shutil.copyfile(glob.glob(os.path.join(self.build_dir, dir, 'include', 'ffi.h'))[0],
os.path.join(arch_dir, 'ffi.h'))
shutil.copyfile(glob.glob(os.path.join(self.build_dir, dir, 'include', 'ffitarget.h'))[0],
os.path.join(arch_dir, 'ffitarget.h'))
with open(os.path.join(self.config.prefix, self.libffidir, 'include', 'ffi.h'), 'w+') as f:
f.write(FFI_H_UNVERSAL)
|