
##############################################################################
#
# Copyright (c) 2003-2026 by the esys.escript Group
# https://github.com/LutzGross/esys-escript.github.io
#
# Primary Business: Queensland, Australia
# Licensed under the Apache License, version 2.0
# http://www.apache.org/licenses/LICENSE-2.0
#
# See CREDITS file for contributors and development history
# Development from 2019 by School of Earth and Environmental Sciences
#
##############################################################################

Import('*')


sources = """
    ScriptMPI.cpp
""".split()

headers = """
	esys_python.h
""".split()

# sources = ['ScriptMPI.cpp']
sources_redirect = ['ScriptMPIredirect.cpp']
sources_verbose = ['ScriptMPIverbose.cpp']

local_env = env.Clone()
local_env.PrependUnique(LIBS = ['escript'])

progs = local_env.Program('pythonMPI', sources)
progs += local_env.Program('pythonMPIredirect', sources_redirect)
progs += local_env.Program('pythonMPIverbose', sources_verbose)

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

lib_inst = local_env.Install(local_env['libinstall'], progs)

# Only build the Python module when mpi4py is enabled. Without
# ESYS_HAVE_MPI4PY the source file contains no BOOST_PYTHON_MODULE
# block, so MSVC produces a .pyd with no exports and the install step
# fails trying to copy a .exp file the linker never emits.
mod_inst = []
if env['mpi4py']:
    py_env = local_env.Clone()
    # py_env.Prepend(LIBS = ['pythonMPI'])
    py_lib = py_env.PythonModule('pythonMPIcpp', 'pythonMPIcpp.cpp')
    mod_path = Dir('pythonMPI', local_env['pyinstall'])
    mod_inst = py_env.Install(mod_path, py_lib)

env.Alias('build_pythonMPI', progs)
env.Alias('install_pythonMPI', [lib_inst, mod_inst])



