import thirdparty
import os
import SCons

def buildOgre(context, sourceDir):
    os.chdir(sourceDir)
    if context.sconf.env['PLATFORM'] == 'posix':
	make = context.sconf.env['MAKE']
	os.spawnl(os.P_WAIT, 'configure', 'configure', 
		  '--prefix=' + context.sconf.env['THIRDPARTY_STAGEDIR'], 
		  'LDFLAGS=-L'+os.path.join(context.sconf.env['THIRDPARTY_STAGEDIR'], 'lib'),
		  'CFLAGS=-I'+os.path.join(context.sconf.env['THIRDPARTY_STAGEDIR'], 'include'))
	os.spawnl(os.P_WAIT, make, make, 'all')
	os.spawnl(os.P_WAIT, make, make, 'install')
    elif context.sconf.env['PLATFORM'] == 'darwin':
	pass

def ogreConfig(context):
    return thirdparty.TryCompileAndLink(context, 'Ogre', 'OGRE_', '.cc',
                                        headers=['OGRE/Ogre.h'],
                                        pkgConfigName='OGRE')
    
def checkOgre(context):
    return thirdparty.configureDependency(context,
                                          ogreConfig,
                                          downloadSource=('http://interreality.org/~tetron/',
                                                          'ogre-linux_osx-v1-4-3.tar.bz2',
                                                          'ogrenew',
							  28642728,
							  'd184bfbc1dd7cbc56aef419171699da6'),
                                          buildFunc=buildOgre)

import scripts
scripts.AddCustomTest('CheckOgre', checkOgre)
