"""
Setup script for building the {{ soc_name }} C++ extension
Generated by PeakRDL-pybind11
"""

from setuptools import setup, Extension
from setuptools.command.build_ext import build_ext
import sys
import setuptools
import pybind11

class get_pybind_include:
    """Helper class to determine the pybind11 include path"""
    def __str__(self):
        return pybind11.get_include()

ext_modules = [
    Extension(
        '_{{ soc_name }}_native',
        ['{{ soc_name }}_bindings.cpp'],
        include_dirs=[
            get_pybind_include(),
            '.',
        ],
        language='c++',
        extra_compile_args=['-std=c++11'],
    ),
]

class BuildExt(build_ext):
    """Custom build extension to set C++ standard"""
    
    def build_extensions(self):
        # Set C++ standard
        ct = self.compiler.compiler_type
        opts = []
        link_opts = []
        
        if ct == 'unix':
            opts.append('-std=c++11')
            opts.append('-O3')
            opts.append('-Wall')
        elif ct == 'msvc':
            opts.append('/std:c++11')
            opts.append('/O2')
            opts.append('/W3')
        
        for ext in self.extensions:
            ext.extra_compile_args = opts
            ext.extra_link_args = link_opts
        
        build_ext.build_extensions(self)

setup(
    name='{{ soc_name }}',
    version='0.1.0',
    description='{{ soc_name }} register map bindings',
    ext_modules=ext_modules,
    cmdclass={'build_ext': BuildExt},
    zip_safe=False,
    python_requires='>=3.7',
    install_requires=['pybind11>=2.6.0'],
)
