# Julien Antille, Thomas Nagy, 2005
# BSD license (see COPYING)

BOLD   ="\033[1m"
RED    ="\033[91m"
GREEN  ="\033[92m"
YELLOW ="\033[93m"
CYAN   ="\033[96m"
NORMAL ="\033[0m"

def exists(env):
	return true

def generate(env):
	""" Detect the clucene library"""

        from SCons.Options import Options
	cachefile = env['CACHEDIR']+'/lucene.cache.py'
        opts = Options(cachefile)
        opts.AddOptions(
                ( 'HASLUCENE', 'has the lucene library' ),
        )
        opts.Update(env)

	if env['_CONFIGURE'] or not env.has_key('HASLUCENE'):
		print "Checking for clucene              : ",
		
		#import SCons.SConf
		#conf = SCons.SConf.SConf( env )
		#if not conf.CheckCHeader( 'Cg/cg.h' ):
		import os
		lst=['/usr', '/opt', '/usr/local']
		found=0
		for dir in lst:
			if os.path.isfile( dir+'/include/CLucene.h' ):
				found=2
# 			        if os.path.isfile( dir+'/include/CLucene/debug/condition.h' ):	
# 					found=2
		
		if found==0:
			print RED+'We really need the clucene library !'+NORMAL
			print RED+'Install clucene-0.8.13'+NORMAL
			env.Exit(1)
# 		elif found==1:
# 			print RED+'The clucene library has been found'
# 			print RED+'but it is missing the following header file:'
# 			print BOLD+dir+'/include/CLucene/debug/condition.h'+NORMAL
# 			print RED+'Sorry for the inconvenience, you must reinstall'
# 			print RED+'clucene-0.8.13 but '+BOLD+'run autoconf/automake/aclocal '+RED+' before running configure'
# 			print RED+'(see http://kioclucene.objectis.net/documentation/howtos/download_and_install)'
# 			env.Exit(1)

		else:
			print RED+'looks good, but cannot check it is clucene-0.9.10 or higer'+NORMAL
		env['HASLUCENE']=1
		#env = conf.Finish()
		opts.Save(cachefile, env)
