python-cnorxz/setup.py

84 lines
2.2 KiB
Python
Raw Normal View History

2023-02-21 19:31:14 +01:00
#!/usr/bin/env python
2024-02-24 18:51:53 +01:00
# imports:
2024-02-06 01:41:49 +01:00
import setuptools
from distutils.core import setup, Extension
2024-02-24 18:51:53 +01:00
import os
2023-02-21 19:31:14 +01:00
import sysconfig
2023-02-22 01:04:45 +01:00
import subprocess
2023-02-21 19:31:14 +01:00
2024-02-24 18:51:53 +01:00
# basic variables:
2023-02-21 19:31:14 +01:00
libname = "cnorxz"
author = "Christian Zimmermann"
author_email = "chizeta@f3l.de"
2024-02-24 18:51:53 +01:00
path_to_cnorxz = ""
if 'CNORXZ' in os.environ:
path_to_cnorxz = os.environ['CNORXZ']
version = "0.0.0"
have_numpy = True
# flags:
2023-02-22 01:04:45 +01:00
2024-02-24 18:51:53 +01:00
extra_compile_args = sysconfig.get_config_var('CFLAGS').split()
2023-02-22 02:37:51 +01:00
cnorxz_version = subprocess.run([path_to_cnorxz+"/bin/cnorxz-config",'--version'],stdout=subprocess.PIPE).stdout.decode('ascii')[:-1]
2024-02-24 18:51:53 +01:00
cnorxz_flags = subprocess.run([path_to_cnorxz+"/bin/cnorxz-config",'--flags'],stdout=subprocess.PIPE).stdout.decode('ascii').split()
cnorxz_definitions = subprocess.run([path_to_cnorxz+"/bin/cnorxz-config",'--definitions'],stdout=subprocess.PIPE).stdout.decode('ascii').split()
cnorxz_flags.remove("-Werror")
cnorxz_flags.append("-Wno-write-strings")
extra_compile_args += cnorxz_flags
# includes:
2023-02-22 01:04:45 +01:00
2023-02-21 19:31:14 +01:00
inc_dirs = list()
2023-02-22 01:04:45 +01:00
if path_to_cnorxz != "":
inc_dirs.append( path_to_cnorxz + "/include/cnorxz" )
inc_dirs.append( "cnorxz/core/include" )
2024-02-24 18:51:53 +01:00
# library dirs:
2023-02-21 19:31:14 +01:00
lib_dirs = list()
lib_dirs.append( "/usr/lib" )
lib_dirs.append( "/usr/local/lib" )
2023-02-22 01:04:45 +01:00
if path_to_cnorxz != "":
2024-02-24 18:51:53 +01:00
lib_dirs.append( path_to_cnorxz + "/lib" )
2023-02-21 19:31:14 +01:00
2024-02-24 18:51:53 +01:00
# optional dependencies:
if have_numpy:
import numpy
inc_dirs.append( numpy.get_include() )
# main
2023-02-21 19:31:14 +01:00
default_extension_args = dict(
language = "c++",
include_dirs = inc_dirs,
libraries = [libname],
library_dirs = lib_dirs,
extra_compile_args = extra_compile_args,
2024-02-24 18:51:53 +01:00
define_macros = [(mac,None) for mac in cnorxz_definitions]
2023-02-21 19:31:14 +01:00
)
if __name__ == "__main__":
print("Include directories:")
for d in inc_dirs:
print("\t",d)
print("Library directories:")
for d in lib_dirs:
print("\t",d)
setup(
2023-02-21 19:31:14 +01:00
name = libname,
packages = setuptools.find_packages(),
2023-02-22 01:04:45 +01:00
version = version,
2023-02-21 19:31:14 +01:00
include_dirs = inc_dirs,
ext_modules = [Extension(
2024-02-08 01:01:47 +01:00
'cnorxz', ['cnorxz/core/core.cpp','cnorxz/core/lib/array_wrapper.cpp','cnorxz/core/lib/range_wrapper.cpp'],
**default_extension_args
)],
2023-02-21 19:31:14 +01:00
author = author,
author_email = author_email,
)