# WindowSystem GLUT

import os

Import('*')

sources = []
headers = []
generated = []
GVBetaDirs = []

if _po.getOption('gv_beta'):
    # add the gv beta stuff
    GVBetaDirs = [Dir('../../Experimental/Gerrit/VRMLLoader')]
    headers, sources, tests, generated = ProcessDirs(GVBetaDirs)
    # we need this for the flex/bison generated files.
    headers2, sources2, tests2, generated = ProcessDirs([Dir('../../System/FileIO/ScanParseSkel')])

sources += Split("""
    OSGGLUTWindow.cpp
    OSGGLUTWindowBase.cpp
""")

headers += Split("""
    OSGGLUTWindow.h
    OSGGLUTWindow.inl
    OSGGLUTWindowBase.h
    OSGGLUTWindowBase.inl
    OSGGLUTWindowFields.h
    OSGWindowGLUTDef.h
""")

InstallHeaders(env, headers)

def custom(env):
    env.Append(LIBS=env.get('OSG_WINDOW_GLUT_LIBS', []))

def custom2(env):
    env.Append(LIBS=env.get('OSG_WINDOW_GLUT_LIBS'))
    env.Append(LIBS=env.get('OSG_SYSTEM_LIBS'))
    env['OSG_PROGDIR'] = os.path.join('..', 'WindowGLUTTest')

BuildLibrary(tc, 'OSGWindowGLUT', sources,
             updates=[custom, OpenSGLibrary(['OSGSystem', 'OSGBase'])],
             CPPPATH=ExpandCPPPath([Dir('.')] + BaseDirs + SystemDirs + GVBetaDirs, generated),
             CPPDEFINES=['OSG_BUILD_DLL', 'OSG_COMPILEWINDOWGLUTLIB',
                         'OSG_WITH_GLUT'])

if _po.getOption('tests'):
    # create test programs
    testsources = Glob('test*.cpp')
    for testsource in testsources:
        target = testsource.name[:-4] # get leafname and remove .cpp
        BuildProgram(tc, target, [testsource], tools=[],
                     updates=[custom2, OpenSGLibrary(['OSGWindowGLUT', 'OSGSystem', 'OSGBase'])],
                     CPPPATH=['.', env['PREFIX'].Dir('include'), env['PREFIX'].Dir('include/OpenSG')],
                     CPPDEFINES = ['OSG_BUILD_DLL', 'OSG_WITH_GLUT'])

