forked from karpierz/jni
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
71 lines (65 loc) · 2.5 KB
/
setup.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
# Copyright (c) 2004 Adam Karpierz
# Licensed under CC BY-NC-ND 4.0
# Licensed under proprietary License
# Please refer to the accompanying LICENSE file.
import sys
from os import path
from io import open
from glob import glob
from setuptools import setup
from setuptools import Extension
top_dir = path.dirname(path.abspath(__file__))
GEN_CFFI = not path.exists("src/jni/cffi/jni.py")
if GEN_CFFI:
def build_ffi(src_dir, emit_jni_i=False):
import sys
from os import path
import cffi
sys.path.insert(0, src_dir)
from jni._util import Preprocessor
sys.path.pop(0)
with open(path.join(src_dir, "jni/cffi/jni.h"),
"r", encoding="utf-8") as f:
source = f.read()
source = Preprocessor().preprocess(source,
define_macros = (
("JNICALL", ""),
("JNIIMPORT", ""),
("JNIEXPORT", ""),
),
undef_macros = (
"_JAVASOFT_JNI_H_",
"__cplusplus",
"JNI_TYPES_ALREADY_DEFINED_IN_JNI_MD_H",
"_JNI_IMPLEMENTATION_",
))
if emit_jni_i:
with open(path.join(src_dir, "jni/cffi/jni.i"),
"w", encoding="utf-8") as f:
f.write(source)
ffi = cffi.FFI()
ffi.set_source("jni", None)
ffi.cdef("// temporary for cffi")
ffi.cdef("typedef void* va_list;")
ffi.cdef(source)
ffi.compile(tmpdir=path.join(src_dir, "jni/cffi"))
build_ffi(path.join(top_dir, "src"))
GEN_CYTHON = (not path.exists("src/jni/cython/jni.c") or
not path.exists("src/jni/cython/jni.h"))
ext = ".pyx" if GEN_CYTHON else ".c"
ext_modules = [Extension(name="jni.cython.jni",
language="c",
sources=["src/jni/cython/jni" + ext])]
if GEN_CYTHON:
from Cython.Build import cythonize
from Cython.Compiler import Options
Options.docstrings = False
Options.emit_code_comments = False
ext_modules = cythonize(ext_modules, language_level=sys.version_info.major,
force=True)#, show_all_warnings=True)
platform = "linux" if sys.platform.startswith("linux") else sys.platform
ext_modules += [Extension(name="jni.capi.jni",
language="c",
include_dirs=["src/jni/capi/java/jdk/include/"+ platform],
sources=["src/jni/capi/jni.c"])]
setup(ext_modules=ext_modules)