-
Notifications
You must be signed in to change notification settings - Fork 74
/
build.py
84 lines (70 loc) · 2.49 KB
/
build.py
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
import itertools
import os
import platform
from cffi import FFI
dir_path = os.path.dirname(os.path.realpath(__file__))
#samver is pulled from this file in the Makefile
samver = "1.14"
htslib_dir = os.path.join(dir_path, 'submodules', 'samtools-{}'.format(samver), 'htslib-{}'.format(samver))
deflatever = "1.10"
deflate_dir = os.path.join(dir_path, 'submodules', 'libdeflate-{}'.format(deflatever))
libraries=['m', 'z', 'lzma', 'bz2', 'pthread', 'curl', 'crypto']
library_dirs=[htslib_dir]
if os.getenv('WITHDEFLATE') == "1":
print("Using deflate")
libraries.append('deflate')
library_dirs.append(deflate_dir)
src_dir='src'
extra_compile_args = ['-std=c99', '-O3']
extra_link_args = []
if platform.machine() in {"aarch64", "arm64"}:
if platform.system() == "Darwin":
pass
else:
extra_compile_args.append("-march=armv8-a+simd")
else:
extra_compile_args.append("-mtune=haswell")
if os.getenv('MEDAKA_COMPILE_ARGS') is not None:
extra_compile_args.append(os.getenv('MEDAKA_COMPILE_ARGS'))
if os.getenv('MEDAKA_LINK_ARGS') is not None:
extra_link_args.append(os.getenv('MEDAKA_LINK_ARGS'))
print("Extra compile args: ", extra_compile_args)
print("Extra link args: ", extra_link_args)
ffibuilder = FFI()
ffibuilder.set_source("libmedaka",
r"""
#include "kvec.h"
#include "medaka_bamiter.h"
#include "medaka_common.h"
#include "medaka_counts.h"
#include "medaka_trimbam.h"
#include "medaka_pytrimbam.h"
#include "medaka_rnn_variants.h"
#include "fastrle.h"
#include "kseq.h"
""",
libraries=libraries,
library_dirs=library_dirs,
include_dirs=[src_dir, htslib_dir],
sources=[
os.path.join(src_dir, x) for x in (
'medaka_bamiter.c', 'medaka_common.c', 'medaka_counts.c',
'fastrle.c', 'medaka_trimbam.c', 'medaka_pytrimbam.c',
'medaka_rnn_variants.c')],
extra_compile_args=extra_compile_args,
extra_objects=['libhts.a'],
extra_link_args=extra_link_args,
)
cdef = [
"typedef struct { ...; } bam_fset;"
"bam_fset* create_bam_fset(char* fname);"
"void destroy_bam_fset(bam_fset* fset);"
]
for header in ('medaka_counts.h','fastrle.h', 'medaka_pytrimbam.h', 'medaka_rnn_variants.h'):
with open(os.path.join(src_dir, header), 'r') as fh:
# remove directives
lines = ''.join(x for x in fh.readlines() if not x.startswith('#'))
cdef.append(lines)
ffibuilder.cdef('\n\n'.join(cdef))
if __name__ == "__main__":
ffibuilder.compile(verbose=True)