summaryrefslogtreecommitdiff
path: root/recipes/gmp.recipe
blob: 067a65a9394cf968d404074dadf1d373d4f5b8ee (plain)
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
# -*- Mode: Python -*- vi:si:et:sw=4:sts=4:ts=4:syntax=python
import shutil

GMP_H_UNVERSAL='''\
#ifdef __i386__
#include "i386/gmp.h"
#elif defined(__ppc__)
#include "ppc/gmp.h"
#elif defined(__x86_64__)
#include "x86_64/gmp.h"
#elif defined(__arm__)
#include "arm/gmp.h"
#elif defined(__arm64__)
#include "arm64/gmp.h"
#else
#error "Unsupported Architecture"
#endif
'''

class Recipe(recipe.Recipe):
    name = 'gmp'
    version = '6.1.2'
    url = 'http://ftp.gnu.org/gnu/gmp/gmp-%(version)s.tar.xz'
    stype = SourceType.TARBALL
    licenses = [License.LGPLv3Plus]
    tarball_dirname = 'gmp-6.1.2'

    files_libs = ['libgmp']
    files_devel = ['include/gmp.h']

    def prepare(self):
        if self.config.target_platform == Platform.WINDOWS:
            self.configure_options = ' --enable-shared --disable-static'
        elif self.config.target_platform == Platform.IOS:
            self.configure_options = ' --disable-assembly'
        elif self.config.target_platform == Platform.ANDROID:
            # gmp use CFLAGS to compile and link some programs during configure
            self.append_env('CFLAGS', os.environ['LDFLAGS'])

        if self.config.target_platform in [Platform.DARWIN, Platform.IOS]:
            self.files_devel.append(os.path.join('include', '*', 'gmp.h'))

    def post_install(self):
        if self.config.target_platform == Platform.WINDOWS:
            dllname = 'libgmp-10.dll'

            src = os.path.join(self.config.prefix, 'lib', dllname)
            dll = os.path.join(self.config.prefix, 'bin', dllname)
            dll_a = os.path.join(self.config.prefix, 'lib', 'libgmp.dll.a')
            defs_file = os.path.join(self.build_dir, '.libs', 'libgmp-3.dll.def')
            dlltool = os.environ.get('DLLTOOL', None)
            if not dlltool:
              raise FatalError('dlltool was not found, check cerbero configuration')

            if os.path.exists(dll_a):
                os.remove(dll_a)
            shell.check_call([dlltool, '-D', dllname, '-d', defs_file, '-l', dll_a])
            shutil.copy(src, dll)
            gmp_la = os.path.join(self.config.prefix, 'lib', 'libgmp.la')
            shell.replace(gmp_la, {'libgmp.lib': 'libgmp.dll.a'})
        elif self.config.target_platform in [Platform.DARWIN, Platform.IOS]:
            # For the universal build we need to ship gmp.h of both
            # architectures in a subfolder and include the correct one depending
            # on the compiler architecture
            arch = self.config.target_arch
            if arch == Architecture.X86:
                arch = 'i386'
            elif arch == Architecture.ARM64:
                arch = 'arm64'
            elif Architecture.is_arm(arch):
                arch = 'arm'

            arch_dir = os.path.join(self.config.prefix, 'include', arch)
            if not os.path.exists(arch_dir):
                os.makedirs(arch_dir)
            shutil.copyfile(os.path.join(self.build_dir, 'gmp.h'),
                        os.path.join(arch_dir, 'gmp.h'))
            with open(os.path.join(self.config.prefix, 'include', 'gmp.h'), 'w+') as f:
                f.write(GMP_H_UNVERSAL)