# emacs, this is -*-Python-*- mode
import sys, os

debug = ARGUMENTS.get('debug', 0)

env = Environment()#ENV = os.environ)

if int(debug):
    if sys.platform.startswith('win'):
        raise NotImplementedError('')
    else:
        env.Append(CCFLAGS = '-g')

def add_osg_opts(kws):
    if sys.platform.startswith('darwin'):
        if os.path.exists('/opt/local/include/osg'):
            print "Using Macports's OSG version in /opt/local"
            env.Append(CPPPATH=['/opt/local/include/'],
                       LIBPATH=['/opt/local/lib/'], 
                       LIBS=['osg', 'OpenThreads', 'osgText', 'osgDB', 'osgUtil', 'osgGA', 'osgViewer'])
        else:
            kws.setdefault('LINKFLAGS',[]).extend('-framework osg -framework OpenThreads -framework osgText -framework osgDB -framework osgUtil -framework osgGA -framework osgViewer'.split())
            kws.setdefault('CPPDEFINES',{}).update({'__USE_OSX_CGL_IMPLEMENTATION__':None})
        #kws.setdefault('CPPDEFINES',{}).update({'__USE_OSX_AGL_IMPLEMENTATION__':None})
    else:
        if sys.platform.startswith('win'):
            osg_root = os.environ['OSG_ROOT']
            kws.setdefault('CPPPATH',[]).append( os.path.join(osg_root,'include'))
            kws.setdefault('CPPDEFINES',{}).update({'WIN32':None})
            kws.setdefault('LIBPATH',[]).append( os.path.join(osg_root,'lib'))
        kws.setdefault('LIBS',[]).extend(['osgDB', 'osgUtil', 'osg', 'osgViewer','osgGA'])
    return kws

if 1:

    if 1:
        sodict = {}
        add_osg_opts(sodict)

        shlib_target = 'fsoi_ng'
        sodict['target'] = shlib_target
        sodict['source'] = ['fsoi_ng.cpp','EyeMap.cpp']

        if sys.platform.startswith('win'):
            sodict.setdefault('CPPDEFINES',{}).update({'FSOI_NG_DLL':None,
                                                       'FSOI_NG_EXPORTS':None,
                                                       })
            sodict.setdefault('CXXFLAGS',[]).append('/EHsc')

        USE_SKYBOX = True

        if USE_SKYBOX:
            sodict.setdefault('CPPDEFINES',{}).update({'USE_SKYBOX':None})
            sodict['source'].append('skybox.cpp')

        lib_fsoi_ng = env.SharedLibrary(**sodict)

        if 1:
            kws = {}
            if sys.platform.startswith('win'):
                kws.setdefault('CPPDEFINES',{}).update({'FSOI_NG_DLL':None,
                                                       })

            
            env.Program(target='fsoi_ng_test',
                        source=['fsoi_ng_test.c'],
                        LIBS=[lib_fsoi_ng], 
#                        LIBPATH=[shlib_target],
                        **kws)
    else:
        prog_kws = {}
        add_osg_opts(prog_kws)
        env.Program(target='fsoi_ng_test',
                    source=['fsoi_ng_test.c'],#,'skybox.cpp'],
                    **prog_kws
                    )
