opts = Options()
opts.Add(BoolOption('RELEASE', 'Set to true to do a release build.', 0))
env = Environment(options = opts, 
	CPPDEFINES = {'RELEASE_BUILD' : '${RELEASE}'} )

def CheckPKG(context, name, version): 
	context.Message( 'Checking for %s >= %s... ' % (name, version) ) 
	ret = context.TryAction('pkg-config %s --atleast-version=%s' % (name,version))[0] 
	context.Result( ret ) 
	return ret 

conf = Configure(env, custom_tests = { 'CheckPKG' : CheckPKG })
# Checks for libraries, header files, etc. go here!

if not conf.CheckCHeader('string.h'):
	print 'string.h must be installed.'
	Exit(1)
if not conf.CheckFunc('strcasecmp'):
	print 'strcasecmp() can not be found.'
	Exit(1)
if not conf.CheckPKG('libxml-2.0','2.6.0'): 
    	print 'libxml-2.0 >= 2.6.0 failed. Install latest version of libxml' 
     	Exit(1) 
if not conf.CheckPKG('gtk+-2.0','2.4.9'): 
   	print 'GTK+-2.0 >= 2.4.9 was not found. Make certain you have latest version of gtk' 
     	Exit(1) 
if not conf.CheckPKG('bonddb','0.8.0'): 
    	print 'bonddb >= 0.8.0 failed. Install latest version of bonddb' 
     	Exit(1) 
env = conf.Finish()

# add support for GTK etc
env.ParseConfig('pkg-config --cflags --libs gtk+-2.0 glib-2.0 gmodule-2.0 libxml-2.0') 
# add support for bonddb
env.ParseConfig('pkg-config --cflags --libs bonddb')

# Optomised version for speed
if env['RELEASE']==1:
	env.Prepend(CCFLAGS = '-O2 -DUNIX')
	print 'Building optimized release.'
if env['RELEASE']==0:
	env.Prepend(CCFLAGS = '-g -ansi -Wall -DUNIX -DMEM_TEST')

Export('env')
SConscript(['uigtk/SConstruct',
	'src/SConstruct'])
#	'src/SConstruct'])

Help("""
	Type: 'scons' to build bond.
	      'scons RELEASE=1' to build the non-debugging optimised
	      version. This needs to have RELEASE=1 for all bond
	      apps else compiling wont complete.
	      'scons install' to install bond.
	""")

env.Command('bond.dtd','bond-2.0.dtd',"ln -s $SOURCE $TARGET")
env.Install('/usr/lib/pkgconfig','bond.pc')
env.Alias('install', '/usr/lib/pkgconfig')
env.Install('/usr/share/bond','bond-2.0.dtd')
env.Alias('install', '/usr/share/bond')
env.Install('/usr/share/bond','bond.dtd')
env.Alias('install', '/usr/share/bond')
