5 os
.chdir(os
.path
.dirname(os
.path
.abspath(argv
[0])))
7 sys
.argv
+= ["--quiet", "build_ext", "--inplace"]
9 from setuptools
.command
.build_ext
import build_ext
10 from setuptools
import setup
, Extension
12 from distutils
.command
.build_ext
import build_ext
13 from distutils
.extension
import Extension
14 from distutils
.core
import setup
15 LIBA_OPENMP
= os
.environ
.get("LIBA_OPENMP")
17 LIBA_OPENMP
= int(LIBA_OPENMP
)
18 LIBA_FLOAT
= os
.environ
.get("LIBA_FLOAT")
20 LIBA_FLOAT
= int(LIBA_FLOAT
)
25 from sys
import version_info
26 from Cython
.Build
import cythonize
29 from argparse
import ArgumentParser
30 from sys
import byteorder
31 from re
import findall
36 def check_math(text
=""):
37 if sys
.platform
== "win32":
38 path_libm
= ctypes
.util
.find_library("ucrtbase")
40 path_libm
= ctypes
.util
.find_msvcrt()
42 path_libm
= ctypes
.util
.find_library("m")
44 libm
= ctypes
.CDLL(path_libm
)
69 name
= "A_HAVE_" + func
.upper()
70 if LIBA_FLOAT
== 0x10:
72 if LIBA_FLOAT
== 0x04:
78 text
+= "#define %s 1\n" % (name
)
82 def configure(config
):
83 with
open("setup.cfg", "r") as f
:
84 version
= findall(r
"version = (.+)", f
.read())[0]
85 major
, minor
, patch
= findall(r
"(\d+).(\d+).(\d+)", version
)[0]
86 order
= {"little": 1234, "big": 4321}.get(byteorder
)
87 vsize
= ctypes
.sizeof(ctypes
.c_void_p(0))
88 text
= """/* autogenerated by setup.py */
89 #define A_VERSION "{}"
90 #define A_VERSION_MAJOR {}
91 #define A_VERSION_MINOR {}
92 #define A_VERSION_PATCH {}
93 #if !defined A_SIZE_POINTER
94 #define A_SIZE_POINTER {}
95 #endif /* A_SIZE_POINTER */
96 #if !defined A_BYTE_ORDER
97 #define A_BYTE_ORDER {}
98 #endif /* A_BYTE_ORDER */
100 version
, major
, minor
, patch
, vsize
, order
, check_math()
102 with
open(config
, "wb") as f
:
103 f
.write(text
.encode("UTF-8"))
106 parser
= ArgumentParser(add_help
=False)
107 parser
.add_argument("-b", "--build-base", default
="build")
108 parser
.add_argument("-O", "--link-objects")
109 args
= parser
.parse_known_args(argv
[1:])
110 base
= args
[0].build_base
112 sources
, objects
= [], []
113 config_h
= os
.path
.join(base
, "a.setup.h")
114 a_have_h
= os
.path
.relpath(config_h
, "include/a")
115 define_macros
= [("A_HAVE_H", '"' + a_have_h
+ '"'), ("A_EXPORTS", None)]
117 define_macros
+= [("A_SIZE_FLOAT", LIBA_FLOAT
)]
118 if USE_CYTHON
and os
.path
.exists("python/src/a.pyx"):
119 sources
+= ["python/src/a.pyx"]
120 elif os
.path
.exists("python/src/a.c"):
121 sources
+= ["python/src/a.c"]
122 if not os
.path
.exists(base
):
126 for dirpath
, dirnames
, filenames
in os
.walk("src"):
127 if args
[0].link_objects
:
129 for filename
in filenames
:
130 source
= os
.path
.join(dirpath
, filename
)
131 if os
.path
.splitext(source
)[-1] == ".c":
132 sources
.append(source
)
139 include_dirs
=["include"],
140 define_macros
=define_macros
,
144 ext_modules
= cythonize( # type: ignore
146 language_level
=version_info
[0], # type: ignore
151 class Build(build_ext
): # type: ignore
152 def build_extensions(self
):
153 if self
.compiler
.compiler_type
== "msvc":
154 for e
in self
.extensions
:
156 e
.extra_compile_args
+= ["/openmp"]
157 if not self
.compiler
.compiler_type
== "msvc":
158 for e
in self
.extensions
:
160 e
.extra_compile_args
+= ["-fopenmp"]
161 e
.extra_link_args
+= ["-fopenmp"]
162 if self
.compiler
.compiler_type
== "mingw32":
163 self
.compiler
.define_macro("__USE_MINGW_ANSI_STDIO", 1)
164 for e
in self
.extensions
:
165 if e
.language
== "c++":
166 e
.extra_link_args
+= ["-static-libstdc++"]
167 e
.extra_link_args
+= ["-static-libgcc"]
168 e
.extra_link_args
+= [
169 "-Wl,-Bstatic,--whole-archive",
171 "-Wl,--no-whole-archive",
173 build_ext
.build_extensions(self
)
177 ext_modules
=ext_modules
, # type: ignore
178 cmdclass
={"build_ext": Build
},