summaryrefslogtreecommitdiffstats
path: root/setup_crypto.py
blob: 313bedbc7b270f32e0ba8f72e841c9165426852f (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
# Support code for building a C extension with crypto code

import os
import sys

is_win32 = sys.platform.startswith('win32')


def multi_join(paths, *path_segments):
    """apply os.path.join on a list of paths"""
    return [os.path.join(*(path_segments + (path,))) for path in paths]


def crypto_ext_kwargs(pc, system_prefix):
    if system_prefix:
        print('Detected OpenSSL [via BORG_OPENSSL_PREFIX]')
        if is_win32:
            lib_dir = system_prefix
            lib_name = 'libcrypto'
        else:
            lib_dir = os.path.join(system_prefix, 'lib')
            lib_name = 'crypto'

        return dict(include_dirs=[os.path.join(system_prefix, 'include')],
                    library_dirs=[lib_dir],
                    libraries=[lib_name])

    if pc and pc.exists('libcrypto'):
        print('Detected OpenSSL [via pkg-config]')
        return pc.parse('libcrypto')

    raise Exception('Could not find OpenSSL lib/headers, please set BORG_OPENSSL_PREFIX')