from setuptools import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext

import os


include_dirs = [
{% for d in include_dirs %}
    '{{d}}'{% if not loop.last %},{% endif %}
{% endfor %}
]

include_dirs += [os.path.join(x, 'include') for x in include_dirs]


def find_lib(lib):
    candidates = []
    candidates += [os.path.join(x, lib) for x in include_dirs]
    candidates += [os.path.join(x, 'lib', lib) for x in include_dirs]
    candidates += [os.path.join(x, 'lib64', lib) for x in include_dirs]

    return [x for x in candidates if os.path.isfile(x)][0]


ext_modules = [Extension("{{ name }}",
                     ["{{name}}.pyx"],
                     language='c++',
                     define_macros=[('register', '')],
                     include_dirs=include_dirs,
                     extra_objects = [
                        find_lib('librockspring.a'),
                        find_lib('libzmq.a')
                     ],
                     extra_compile_args=['--std=c++17']
                     )]

setup(
  name = '{{ name }}',
  version = '{{ version }}',
  cmdclass = {'build_ext': build_ext},
  ext_modules = ext_modules
)