import sys, os, stat, commands

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

#sys.version_info[0:5]

def scandir(dir, files=[]):
    for file in os.listdir(dir):
        path = os.path.join(dir, file)
        if os.path.isfile(path) and path.endswith('.pyx'):
            files.append(path.replace(os.path.sep, '.')[:-4])
        elif os.path.isdir(path):
            scandir(path, files)
    return files

def getdirs(cdir, dirs=[]):
    dirs.append(cdir.replace(os.path.sep, '.'))
    for dir in os.listdir(cdir):
        path = os.path.join(cdir, dir)
        if os.path.isdir(path):
            getdirs(path, dirs)
    return dirs

def makeExtension(extName):
    extPath = extName.replace('.', os.path.sep) + '.pyx'
    return Extension(
        name = extName,
        sources = [extPath],
        include_dirs = ['../../../include','.'],
        library_dirs = ['../../../build/lib'],
        libraries = ['SIEGE'],
        )

names = scandir('siege')
extensions = [makeExtension(name) for name in names]

dirs = getdirs('siege')

setup(name               = 'SIEGE',
      version           = '0.1.18',
      description       = 'Simple Interplatform Entity Game Engine',
      long_description = 'SIEGE is a simple, event-based modular 2D game engine.',
      url               = 'http://libsiege.org',
      cmdclass = {'build_ext': build_ext},
      packages = dirs,
      ext_modules = extensions
      )
