# -*- python -*-

Import('env')
# can we import path in one place?
import sys
sys.path.append(env['base_dir']+'SconsTests')
import utils
import platform

name = "Plugin_VideoOGL"

files = [
	'BPFunctions.cpp',
	'Config.cpp',
	'rasterfont.cpp',
	'Render.cpp',
	'TextureMngr.cpp',
	'NativeVertexFormat.cpp',
	'PixelShaderCache.cpp',
	'VertexShaderCache.cpp',
	'TextureConverter.cpp',
	'VertexManager.cpp',
	'VertexLoaderManager.cpp',
	'XFB.cpp',
	'TextureConversionShader.cpp',
	'OnScreenDisplay.cpp',
	'PostProcessing.cpp',
	'FramebufferManager.cpp',
	]
compileFlags = [
	'-fPIC',
	]
linkFlags = [
	]
libs = [
	'videocommon', 'soil', 'common',
	]

gfxenv = env.Clone()

if gfxenv['GLTEST']:
	files += [
		'nmain.cpp',
		'nGLUtil.cpp',
		]
	libs += [ 'inputcommon' ]
else:
	files += [
		'main.cpp',
		'GLUtil.cpp',
		]
if gfxenv['HAVE_WX']:
	files += [
                'GUI/ConfigDlg.cpp',
		'Debugger/Debugger.cpp',
                ]

if gfxenv['HAVE_COCOA']:
        files += [ 'cocoaGL.m' ]
        compileFlags +=	[
                '-x',
                'objective-c++',
                ]
if sys.platform == 'win32':
        files += [ 'OS/Win32.cpp' ]

tests = {'CheckPKG' : utils.CheckPKG}
conf = gfxenv.Configure(custom_tests = tests,
                        config_h=env['base_dir']+"Source/Core/Common/Src/Config.h")

if sys.platform == 'darwin':
	
	conf.CheckPKG('OpenGL')
	if not conf.CheckPKG('Cg'):
		print name + " must have Cg framework from nvidia to be build"
		Return()

elif sys.platform == 'win32':
        print name + " is assuming that you have opengl, glu, cg, and cggl"
else:
        if not (conf.CheckPKG('GL') and conf.CheckPKG('GLU')):
                print name + " must have opengl and glu to be build"
                Return()
	
	if not conf.CheckPKG('Cg') or not conf.CheckPKG('CgGL'):
                print name + " must have cg and cggl to be build"
                Return()
if sys.platform == 'win32':
	print name + " is assuming that you have glew"
else:
	if not conf.CheckPKG('GLEW'):
		print name + " must have glew to be build"
		Return()


if sys.platform == 'win32':
	files += [
		'OS/Win32.cpp'
		]
	libs += [
		env['base_dir'] + '/Externals/Cg/'
		]	
	gfxenv['CPPPATH'] += libs
	

# check for xxf86vm

gfxenv['HAVE_XXF86VM'] = gfxenv['HAVE_X11'] and conf.CheckPKG('xxf86vm')
        
conf.Define('HAVE_XXF86VM', gfxenv['HAVE_XXF86VM'])

conf.Finish()

if gfxenv['GLTEST']:
	if gfxenv['HAVE_XXF86VM']:
		files += [
			'X11Window.cpp',
			]
		
	if gfxenv['HAVE_SDL']:
		files += [
			'SDLWindow.cpp',
			]
	if gfxenv['USE_WX']:
		files += [
			'WXGLWindow.cpp',
			]

# Sanity check
if gfxenv['USE_WX'] and not gfxenv['HAVE_WX']:
    print "Must have wx to use wxgl"
    Return()

if gfxenv['USE_SDL'] and not gfxenv['HAVE_SDL']:
    print "Must have sdl to use SDL gl"
    Return()

gfxenv.Append(
	CXXFLAGS = compileFlags,
	LINKFLAGS = linkFlags,
	)

gfxenv.SharedLibrary(
	env['plugin_dir']+name,
	files,
	LIBS =  libs + gfxenv['LIBS']
	)
