# Copyright (C) 2008 Kristian B. Oelgaard and Garth N. Wells.
# Licensed under the GNU LGPL Version 3.
#
# First added:  2009-07-10
# Last changed: 2009-07-10
#

import commands
import os
from glob import glob

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

# Create a SCons Environment based on the main os environment
env = Environment(ENV=os.environ, CXX=compiler)

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

# Get header files (don't inclue the NewApp.h interface file)
files = commands.getoutput('ls *.h').split("\n")
includes = [glob(os.path.join('', f)) for f in files if not f == 'NewApp.h']

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

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

# Install header files and libary in local directories
libDir  = os.path.join('#local', 'lib')
incDir  = os.path.join('#local', 'include', 'new-app')
appDir = os.path.join('#local', 'include')

libInstall = env.Install(libDir, lib)
incInstall = env.Install(incDir, includes)
apInstall = env.Install(appDir, 'NewApp.h')

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


