from setuptools import setup, find_packages, Extension
import os
import sys
import numpy as np

def find_all_c_files(directory):
    c_files = []
    for root, _, files in os.walk(directory):
        for file in files:
            if file.endswith('.c'):
                dir = os.path.normpath(os.path.join(root, file))
                c_files.append(dir.replace(os.sep, '/'))  # Convert to forward slashes

    print("C source files:", c_files)
    return c_files

include_dirs=[
    os.path.abspath("testy_mnm/core/src"),  # Ensure headers are found
    np.get_include()
]

extra_compile_args = ['-std=c99', '-fPIC']
if sys.platform == "win32":
    extra_compile_args = ['/std:c99']

testy_c_module = Extension(
    'testy_mnm.core.testy_c_module',
    sources=find_all_c_files('testy_mnm/core'),
    include_dirs=include_dirs,
    extra_compile_args=extra_compile_args
)

setup(
    name='testy_mnm',
    version='1.2.10',
    packages=find_packages(),
    ext_modules=[testy_c_module],
    package_data={"": ["*.h"]},
    zip_safe=False,
)
