# 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
#
# This SContruct file builds and installs the NewApp library

import os

# Build library
SConscript(os.path.join('src', 'SConstruct'))

env = Environment(ENV=os.environ)
cwd = os.getcwd()

# Generate pkg-config file
pkgDir = os.path.join('local', 'lib', 'pkgconfig')
pkgFile = os.path.join('src', 'new-app.pc')

f = open(pkgFile, 'w')
f.write('prefix=%s\n' % os.path.join(cwd, 'local'))
f.write('includedir=${prefix}/include\n')
f.write('libdir=${prefix}/lib\n')
f.write('\nName: NewApp\n')
f.write('Description: Description of NewApp for the FEniCS project.\n')
f.write('Version: 0.1\n')
f.write('Requires: dolfin\n')
f.write('Conflicts:\n')
f.write('Libs: -L${libdir} -lnew-app\n')
f.write('Cflags: -I${includedir}\n')
f.close()

pkgInstall = env.Install(pkgDir, pkgFile)
env.Alias('install', [pkgInstall])

# Generate new-app.conf file
f = open('new-app.conf', 'w')
f.write('export LD_LIBRARY_PATH="%s:$LD_LIBRARY_PATH"\n' % os.path.join(cwd, 'local', 'lib'))
f.write('export PKG_CONFIG_PATH="%s:$PKG_CONFIG_PATH"' % os.path.join(cwd, pkgDir))
f.close()

msg = """---------------------------------------------------------

To compile a program against the NewApp library,
you need to update your environment variables. A simple way
to do this if you are using Bash-like shell is to source the
file new-app.conf:

    source new-app.conf

This will update the values for the environment variables
LD_LIBRARY_PATH and PKG_CONFIG_PATH
---------------------------------------------------------"""

print msg

