"""Build versioned object store"""
import os
import daos_build

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

    build_dir = Dir('.')
    lib = os.path.basename(build_dir.abspath)
    env.AppendUnique(LIBPATH=[build_dir])

    prereqs.require(env, 'pmdk')
    denv = env.Clone()

    # Compiler options
    denv.Append(CPPPATH=[Dir('../vos').srcnode()])

    if lib == "vos":
        # generate standalone library
        denv.Append(CPPDEFINES={'VOS_STANDALONE' : '1'})
        install = 'lib'
    else:
        # generate DAOS server module
        install = 'lib/daos_srv'

    Export('install')

    # VEA
    SConscript('vea/SConscript')
    denv.AppendUnique(LIBPATH=['vea'])

    vos = daos_build.library(denv, lib, Glob('*.c'), LIBS=['vea'])
    denv.Install('$PREFIX/' + install, vos)

    # Tests
    if lib == "vos":
        SConscript('tests/SConscript', exports='denv')

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