
##############################################################################
#
# 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 = 'dudley'

sources = """
    Assemble_AverageElementData.cpp
    Assemble_CopyElementData.cpp
    Assemble_CopyNodalData.cpp
    Assemble_LumpedSystem.cpp
    Assemble_NodeCoordinates.cpp
    Assemble_PDE.cpp
    Assemble_PDE_Points.cpp
    Assemble_PDE_Single_2D.cpp
    Assemble_PDE_Single_3D.cpp
    Assemble_PDE_System_2D.cpp
    Assemble_PDE_System_3D.cpp
    Assemble_addToSystemMatrix.cpp
    Assemble_getAssembleParameters.cpp
    Assemble_getNormal.cpp
    Assemble_getSize.cpp
    Assemble_integrate.cpp
    Assemble_interpolate.cpp
    DomainFactory.cpp
    DudleyDomain.cpp
    ElementFile.cpp
    ElementFile_createColoring.cpp
    ElementFile_distributeByRankOfDOF.cpp
    ElementFile_jacobians.cpp
    IndexList.cpp
    Mesh_distributeByRankOfDOF.cpp
    Mesh_getPattern.cpp
    Mesh_optimizeDOFDistribution.cpp
    Mesh_optimizeDOFLabeling.cpp
    Mesh_read.cpp
    Mesh_readGmsh.cpp
    Mesh_resolveNodeIds.cpp
    Mesh_tet4.cpp
    Mesh_tri3.cpp
    Mesh_write.cpp
    NodeFile.cpp
    NodeFile_createDenseLabelings.cpp
    NodeFile_createMappings.cpp
    NodeFile_createTrilinosGraph.cpp
    NodeFile_gather.cpp
    ShapeTable.cpp
    Util.cpp
""".split()
unroll_sources= """
    Assemble_gradient.cpp
    Assemble_jacobians.cpp
""".split()

headers = """
    Assemble.h
    DomainFactory.h
    Dudley.h
    DudleyDomain.h
    DudleyException.h
    DudleyVersion.h
    ElementFile.h
    ElementType.h
    IndexList.h
    NodeFile.h
    NodeMapping.h
    ShapeTable.h
    Util.h
    system_dep.h
""".split()

local_env = env.Clone()

unroll_env = env.Clone()
unroll_env.Append(CCFLAGS = env['dudley_assemble_flags'])
un = [ unroll_env.SharedObject(x) for x in unroll_sources]

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

# collect dependencies for other modules
dudleylibs = []
dudleylibs += env['escript_libs']
if env['parmetis']:
    dudleylibs += env['parmetis_libs']
if env['paso']:
    dudleylibs += env['paso_libs']
if env['trilinos']:
    dudleylibs += env['trilinoswrap_libs']

local_env.PrependUnique(LIBS = dudleylibs)

env['dudley_libs'] = [module_name] + dudleylibs

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

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

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

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

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

