| 1 |
|
| 2 |
import os |
| 3 |
import sys |
| 4 |
|
| 5 |
from setuptools import Extension, setup |
| 6 |
from setuptools.command.build_ext import build_ext |
| 7 |
from setuptools.command.egg_info import egg_info |
| 8 |
|
| 9 |
|
| 10 |
sources = [ |
| 11 |
"src/lib/deflate.c", |
| 12 |
"src/lib/deflate_tree.c", |
| 13 |
"src/lib/inflate.c", |
| 14 |
"src/lib/inflate_tree.c", |
| 15 |
"src/lib/util.c", |
| 16 |
"src/lib/static_tables.c" |
| 17 |
] |
| 18 |
packages = ["inflate64"] |
| 19 |
kwargs = {"include_dirs": ["src/lib", "src/ext"], "library_dirs": [], "libraries": [], "sources": sources, "define_macros": []} |
| 20 |
|
| 21 |
kwargs["name"] = "inflate64._inflate64" |
| 22 |
kwargs["sources"].append("src/ext/_inflate64module.c") |
| 23 |
binary_extension = Extension(**kwargs) |
| 24 |
_deflate64_extension = Extension("inflate64._inflate64", sources) |
| 25 |
|
| 26 |
|
| 27 |
def has_option(option): |
| 28 |
if option in sys.argv: |
| 29 |
sys.argv = [s for s in sys.argv if s != option] |
| 30 |
return True |
| 31 |
else: |
| 32 |
return False |
| 33 |
|
| 34 |
|
| 35 |
WARNING_AS_ERROR = has_option("--warning-as-error") |
| 36 |
|
| 37 |
|
| 38 |
class build_ext_compiler_check(build_ext): |
| 39 |
def build_extensions(self): |
| 40 |
for extension in self.extensions: |
| 41 |
if self.compiler.compiler_type.lower() in ("unix", "mingw32"): |
| 42 |
if WARNING_AS_ERROR: |
| 43 |
extension.extra_compile_args.append("-Werror") |
| 44 |
elif self.compiler.compiler_type.lower() == "msvc": |
| 45 |
|
| 46 |
|
| 47 |
more_options = ["/GF", "/Gy", "/wd4996"] |
| 48 |
if WARNING_AS_ERROR: |
| 49 |
more_options.append("/WX") |
| 50 |
extension.extra_compile_args.extend(more_options) |
| 51 |
super().build_extensions() |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
class my_egg_info(egg_info): |
| 56 |
def run(self): |
| 57 |
try: |
| 58 |
os.remove(os.path.join(self.egg_info, "SOURCES.txt")) |
| 59 |
except FileNotFoundError: |
| 60 |
pass |
| 61 |
super().run() |
| 62 |
|
| 63 |
|
| 64 |
setup( |
| 65 |
ext_modules=[binary_extension], |
| 66 |
package_dir={"": "src"}, |
| 67 |
packages=packages, |
| 68 |
cmdclass={"build_ext": build_ext_compiler_check, "egg_info": my_egg_info}, |
| 69 |
) |