from distutils.core import setup
from distutils.extension import Extension
from distutils.sysconfig import get_config_var

if float(get_config_var('VERSION')) < 3:

    setup(name='fontforge',
        version='1.0',
        description='font manipulation module',
        author='George Williams',
        url='http://fontforge.sf.net/',
        ext_modules=[Extension('fontforge',['fontforgepyhook.c'],
                include_dirs=[@PYINCLUDE@],
                define_macros=[@PYDEFINES@],
                libraries=[@PYLIBS@]),
            Extension('psMat',['psMatpyhook.c'],
                include_dirs=[@PYINCLUDE@],
                define_macros=[@PYDEFINES@],
                libraries=[@PYLIBS@])]
        )

else:
    from distutils.sysconfig import get_python_lib
    from distutils.file_util import copy_file
    from os.path import join
    import os

    so_ext = get_config_var('SO')
    py_libdir = get_python_lib(prefix = '@PYPREFIX@')
    libfontforge_so = join('@libdir@', 'libfontforge' + so_ext)
    fontforge_so = join(py_libdir, 'fontforge' + so_ext)
    psMat_so = join(py_libdir, 'psMat' + so_ext)

    if hasattr(os, 'symlink'):
        link = 'sym'
    else:
        link = None
    try: os.remove(fontforge_so)
    except: pass
    try: os.remove(psMat_so)
    except: pass
    copy_file(libfontforge_so, fontforge_so, link = link)
    copy_file(libfontforge_so, psMat_so, link = link)
    setup(name='fontforge',
          version='1.0',
          description='font manipulation module',
          author='George Williams',
          url='http://fontforge.sf.net/')
