#  Copyright (C) 2008 The University of British Columbia
#  
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#  
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#  
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

from slabcore import *
from os.path import join
from glob import glob

env = Environment( )

LoadConfigFile( env )


#===============================================================================
# Variables
#===============================================================================
vars = Variables( )

rsfvar = PackageVariable('RSF', 'path to your RSF installation directory', env.get('RSF',True) )

vars.Add( rsfvar )
vars.Update( env )

#===============================================================================
# HELP
#===============================================================================
Help( "\n" )
Help( "\n" )
Help( "Options for 'rsf' external tool:" )
Help( vars.GenerateHelpText(env) )

#===============================================================================
# Configuration
#===============================================================================
toolname = 'rsf'
tc = ToolCreator( toolname )

if DoConfig( env ):
    conf  = Configure(env,conf_dir="#/config-etc/tests",log_file="#/config-etc/config.log")
    
    if env.get('RSF'):
        RSF        = env.get('RSF')
        rsfpath    = None
        rsflibpath = None
        if isinstance( RSF , str):
            # Header path
            rsfpath = join( RSF, 'include' )
            conf.env['CPPPATH'] = rsfpath
            # Library path
            rsflibpath = join( RSF, 'lib' )
            conf.env['LIBPATH'] = rsflibpath
    
        if conf.CheckLibWithHeader( 'rsf','rsf.h', 'c', autoadd=False):
            tc.Prepend( LIBS=['rsf'] )
            if rsfpath:
                tc.Prepend( CPPPATH=rsfpath )
            if rsflibpath:
                tc.Prepend( LIBPATH=rsflibpath )
            tc.Exists(True)
        else:
            tc.Exists(False)
        
    env = conf.Finish( )
    
#===============================================================================
# Write file
#===============================================================================
tc.CreateTool(env)

#===============================================================================
# Clean
#===============================================================================
Clean('.', '#/config-etc' )
Clean( '.', glob('*.pyc') )
Clean( '.', join( Dir('#').abspath,toolname+'.py') )
Clean( '.', '#/.sconsign.dblite' )
