"""Build DAOS utilities"""


def scons():
    """Execute build"""

    Import('env', 'prereqs')

    if not prereqs.client_requested():
        return

    env.d_add_build_rpath()

    # Build self test
    SConscript('self_test/SConscript')
    Default('self_test')

    if prereqs.test_requested():
        # Build wrapper libraries
        SConscript('wrap/SConscript')

        # Build crt_launch
        SConscript('crt_launch/SConscript')

        # Build daos_metrics
        SConscript('daos_metrics/SConscript')

    # Build cart_ctl
    SConscript('ctl/SConscript')

    denv = env.Clone()
    denv.AppendUnique(LIBPATH=[Dir('../client/dfs')])
    denv.AppendUnique(CPPPATH=[Dir('../client/dfs').srcnode()])
    libs = ['daos', 'daos_common', 'uuid', 'dfs', 'duns', 'gurt', 'cart', 'dl']

    daos_hdlrs_src = ['daos_hdlr.c', 'daos_autotest.c', 'daos_dfs_hdlr.c']
    daos_hdlrs_lib = denv.d_library('daos_cmd_hdlrs', daos_hdlrs_src, LIBS=libs)
    env.Install('$PREFIX/lib64/', daos_hdlrs_lib)


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