Import('env')

sources = Split("""
  mucipher.i
  wraphelp.c
  perlwrap.cc
""")

def file_copy(target, source, env):
    open(str(target[0]), "w").write(open(str(source[0])).read())

import sys
import os

pl_inc = os.popen("perl -e 'use Config; print $Config{archlib};'").read()
if pl_inc:
    pl_inc = os.path.join(pl_inc, "CORE")

if pl_inc:
    env_swigpl = Environment(tools = ['default', 'swig'])
    env_swigpl.SConsignFile()

    env_swigpl.Append(CPPPATH = env['CPPPATH'] + [pl_inc])
    env_swigpl.Append(LIBPATH = env['LIBPATH_MUCIPHER'])
    env_swigpl.Append(LIBS = ['ucipher'])
    env_swigpl.Replace(SHLIBPREFIX='')

#    env_swigpl.Command("mucipher.i", "../mucipher.i", file_copy)
    env_swigpl.Command("wraphelp.c", "../wraphelp.c", file_copy)

    mucipherc = env_swigpl.SharedLibrary('mucipherc', sources, SWIGFLAGS='-perl -c++')
