#
# Copyright (c) 2012-2014 by Pawel Tomulik
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE


Import('env')

from SConsGnu import AcDirVars
from SConsGnu.AcDirVars import default_var_key_transform
from SConsGnu.AcDirVars import default_opt_key_transform

options = [ '--prefix', '--exec-prefix' ]

kw = { 'var_key_transform' : lambda x : \
          default_var_key_transform(x) if x not in options else None,
       'opt_key_transform' : lambda x : \
          default_opt_key_transform(x) if x in options else None  }
gdecls = AcDirVars.DeclareGVars(**kw)

cli_vars = Variables()
gvars = gdecls.Commit(env, cli_vars, True)
gvars.UpdateEnvironment(env, cli_vars, True, ARGUMENTS)
vproxy = gvars.VarEnvProxy(env)

if not GetOption('help'):
    print ''
    print 'There are two options added to control GNU dir variables:'
    print '============================================================'
    print '  --prefix'
    print '  --exec-prefix'
    print '============================================================'
    print "run 'scons ex3 --help' to see them under Local Options"
    print ''
    print 'There are also several command line variables. Some of them:'
    print '============================================================'
    for key in ['bindir', 'sbindir', 'sysconfdir', 'pkglibdir', 'man2dir',
               'man2ext']:
        var_key = gvars.var_key(key)
        print '  %s=%s' % (var_key, vproxy[var_key])
    print '============================================================'
    print 'The options and construction variables are supplementary'
    print ''
    print 'The construction variables involved:'
    print '============================================================'
    for key in ['prefix', 'exec_prefix', 'bindir', 'sbindir', 'sysconfdir',
               'pkglibdir', 'man2dir', 'man2ext']:
        env_key = gvars.env_key(key)
        print '  env["%s"]=%r' % (env_key, env[env_key])
    print '============================================================'

# Local Variables:
# # tab-width:4
# # indent-tabs-mode:nil
# # End:
# vim: set syntax=python expandtab tabstop=4 shiftwidth=4:
