Import('sys', 'env', 'hasCollada', 'stubs', 'winstubs')

# Create an environment with Xerces and OpenGL
mainEnv = env.Clone()
if 'XERCESINCLUDE' in mainEnv:
        mainEnv.Prepend(CPPPATH=mainEnv['XERCESINCLUDE'])
if 'XERCESLIBDIR' in mainEnv:
        mainEnv.Prepend(LIBPATH=mainEnv['XERCESLIBDIR'])
if 'XERCESLIB' in mainEnv:
        mainEnv.Prepend(LIBS=mainEnv['XERCESLIB'])
if 'GLLIB' in mainEnv:
        mainEnv.Prepend(LIBS=mainEnv['GLLIB'])
if 'GLLIBDIR' in mainEnv:
        mainEnv.Prepend(LIBPATH=mainEnv['GLLIBDIR'])
if 'GLFLAGS' in mainEnv:
        mainEnv.Prepend(CXXFLAGS=mainEnv['GLFLAGS'])
if 'GLINCLUDE' in mainEnv:
        mainEnv.Prepend(CPPPATH=mainEnv['GLINCLUDE'])

if sys.platform == 'darwin':
        # On OSX, we need this stub to access OpenGL from the command line
        mainEnv_osx = mainEnv.Clone()
        mainEnv_osx.ConfigureForObjectiveCPP()
        stubs += [mainEnv_osx.StaticObject('darwin_stub.mm')]
        mainEnv.Append(LINKFLAGS=['-Xlinker', '-rpath', '-Xlinker', '@executable_path/../Frameworks'])

mainEnv.Program('mtsutil', stubs + winstubs + ['mtsutil.cpp'])

# Build the command-line+GUI interface
mainEnv.Program('mtssrv',  winstubs + ['mtssrv.cpp'])
mainEnv.Program('mitsuba', winstubs + ['mitsuba.cpp'])

Return('mainEnv')
