
##############################################################################
#
# Copyright (c) 2003-2020 by The University of Queensland
# http://www.uq.edu.au
#
# Primary Business: Queensland, Australia
# Licensed under the Apache License, version 2.0
# http://www.apache.org/licenses/LICENSE-2.0
#
# Development until 2012 by Earth Systems Science Computational Center (ESSCC)
# Development 2012-2013 by School of Earth Sciences
# Development from 2014 by Centre for Geoscience Computing (GeoComp)
# Development from 2019 by School of Earth and Environmental Sciences
#
##############################################################################

Import('*')

module_name = 'ripley'

sources = """
    blocktools.cpp
    blocktools2.cpp
    Brick.cpp
    DefaultAssembler2D.cpp
    DefaultAssembler3D.cpp
    domainhelpers.cpp
    LameAssembler2D.cpp
    LameAssembler3D.cpp
    MultiBrick.cpp
    MultiRectangle.cpp
    Rectangle.cpp
    RipleyDomain.cpp
    WaveAssembler2D.cpp
    WaveAssembler3D.cpp
""".split()

headers = """
    AbstractAssembler.h
    blocktools.h
    Brick.h
    DefaultAssembler2D.h
    DefaultAssembler3D.h
    domainhelpers.h
    LameAssembler2D.h
    LameAssembler3D.h
    MultiBrick.h
    MultiRectangle.h
    Rectangle.h
    Ripley.h
    RipleyDomain.h
    RipleyException.h
    RipleySystemMatrix.h
    system_dep.h
    WaveAssembler2D.h
    WaveAssembler3D.h
""".split()

local_env = env.Clone()

if IS_WINDOWS:
    local_env.Append(CPPDEFINES = ['RIPLEY_EXPORTS'])

# collect dependencies for other modules
ripleylibs = []
ripleylibs += env['escript_libs']
if env['paso']:
    ripleylibs += env['paso_libs']
if env['trilinos']:
    ripleylibs += env['trilinoswrap_libs']
if env['silo']:
    ripleylibs += env['silo_libs']
if env['compressed_files']:
    ripleylibs += env['compression_libs']

local_env.PrependUnique(LIBS = ripleylibs)

env['ripley_libs'] = [module_name] + ripleylibs

include_path = Dir(module_name, local_env['incinstall'])
hdr_inst = local_env.Install(include_path, headers)

lib = local_env.SharedLibrary(module_name, sources)
lib_inst = local_env.Install(local_env['libinstall'], lib)

### Python wrapper ###
py_env = local_env.Clone()
py_env.PrependUnique(LIBS = [module_name])
py_lib_name = module_name + 'cpp'
py_lib = py_env.PythonModule(py_lib_name, 'ripleycpp.cpp')

mod_path = Dir(module_name, local_env['pyinstall'])
mod_inst = py_env.Install(mod_path, py_lib)

build = env.Alias('build_ripley', [hdr_inst, lib, py_lib])
env.Alias('install_ripley', ['build_ripley', lib_inst, mod_inst])

