"""Build management server module"""


def scons():
    """Execute build"""
    Import('env', 'prereqs', 'libdaos_tgts')

    env.AppendUnique(LIBPATH=[Dir('.')])

    denv = env.Clone()

    denv.AppendUnique(CPPPATH=[Dir('.').srcnode()])

    denv.require('protobufc')

    pb_objs = denv.SharedObject(['acl.pb-c.c', 'pool.pb-c.c', 'svc.pb-c.c',
                                 'smd.pb-c.c', 'cont.pb-c.c', 'server.pb-c.c'])
    common = denv.SharedObject(['rpc.c']) + pb_objs

    # Management client library
    libdaos_tgts.extend(common + denv.SharedObject(['cli_mgmt.c', 'cli_query.c', 'cli_debug.c']))

    if not prereqs.server_requested():
        return

    senv = denv.Clone()
    senv.require('argobots', 'pmdk', headers_only=True)
    # Management server module
    senv.Append(CPPDEFINES=['-DDAOS_PMEM_BUILD'])
    mgmt_srv = senv.d_library('mgmt',
                              [common, 'srv.c', 'srv_layout.c',
                               'srv_pool.c', 'srv_system.c',
                               'srv_target.c', 'srv_query.c',
                               'srv_drpc.c', 'srv_util.c',
                               'srv_container.c'],
                              install_off='../..')
    senv.Install('$PREFIX/lib64/daos_srv', mgmt_srv)

    denv = senv
    if prereqs.test_requested():
        SConscript('tests/SConscript', exports=['denv', 'pb_objs'])


if __name__ == "SCons.Script":
    scons()
