# Copyright (C) 2008 Kristian B. Oelgaard and Garth N. Wells.
# Licensed under the GNU LGPL Version 3.
#
# First added:  2008-01-30
# Last changed: 2008-09-12
#

import commands
import os
from glob import glob

# Get compiler from pkg-config
compiler = commands.getoutput('pkg-config --variable=compiler dolfin')

# Get the library and include directory from the DOLFIN installation
libDir = commands.getoutput('pkg-config --variable=libdir dolfin')
incDir = commands.getoutput('pkg-config --variable=includedir dolfin')

# Add dolfin to the include directory
incDir = os.path.join(incDir, 'dolfin')

# Import system PATH (if mpicxx is not in default path)
env = Environment(ENV = {'PATH' : os.environ['PATH']})

# Update CXX compiler
env.Replace(CXX = compiler)

# Get source files
sources = []
sources += glob(os.path.join('', '*.cpp'))

# Get header files
includes = []
includes += glob(os.path.join('', '*.h'))

# Get cflags and libs from DOLFIN package
env.ParseConfig('pkg-config --cflags --libs dolfin')

# Build shared library
lib = env.SharedLibrary('plasticity', sources,
                         CPPPATH=env['CPPPATH']+['.'])

# Install header files and libary in the DOLFIN directories
libInstall = env.Install(libDir, lib)
incInstall = env.Install(incDir, includes)

env.Alias('install', [libInstall, incInstall])


