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

conf = Configure(env)
# 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)
pg = ARGUMENTS.get('postgresql',1)
if int(pg):
	print 'Using postgresql backend.'
	if not conf.CheckLib('pq'):
		print 'libpq was not found.'
		Exit(1)
env = conf.Finish()

# add support for GLib etc
env.ParseConfig('pkg-config --cflags --libs glib-2.0 gmodule-2.0') 

# 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','pg')
SConscript(['bondcommon/SConstruct',
	'bondsql/SConstruct',
	'src/SConstruct'])

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

Help(opts.GenerateHelpText(env))

env.Install('/usr/lib/pkgconfig','bonddb.pc')
env.Install('/usr/lib/pkgconfig','bondcommon.pc')
env.Alias('install', '/usr/lib/pkgconfig')
