# -*- mode: python; -*-

default = DefaultEnvironment()
env = default.Clone()

third_party_path = '#/third_party'
# This is latest hiredis master code which will be 0.15.0 eventually.
# hiredis-0.15.0 release is tracked by CEM-5832
hiredis_path = '#/third_party/hiredis-master'
hiredis_asio_adapter_path = '#/third_party/hiredis-boostasio-adapter'

include = [ third_party_path, hiredis_path, hiredis_path + '/adapters',
        '#/build/include', '#/third_party/tbb-2018_U5/include' ]

env.Append(CPPPATH = include)
env.Append(CCFLAGS = ['-g', '-DHIREDIS_SSL'])
env.Append(LDFLAGS = ['-lssl', '-lcrypto'])

env.VariantDir('#/' + Dir('.').path + '/src', hiredis_path)
hiredis_buildpath = Dir('.').abspath + '/src'

env.VariantDir('#/' + Dir('.').path + '/hiredis-boostasio-adapter', hiredis_asio_adapter_path)
hiredis_asio_adapter_buildpath = Dir('.').abspath + '/hiredis-boostasio-adapter'

boostasio_obj = env.Object(hiredis_asio_adapter_buildpath + '/boostasio.cpp')

lib = env.Library('hiredis',
                  [hiredis_buildpath + '/net.c',
                   hiredis_buildpath + '/hiredis.c',
                   hiredis_buildpath + '/sds.c',
                   hiredis_buildpath + '/async.c',
                   hiredis_buildpath + '/dict.c',
                   hiredis_buildpath + '/sslio.c',
                   hiredis_buildpath + '/read.c',
                   boostasio_obj,
                   'base64.cpp']
                  )

if not env.UseSystemBoost():
    env.Depends(lib, '#/build/include/boost')

env.Install('#/build/lib/', 'libhiredis.a')
env.Install('#/build/include/hiredis', hiredis_path + '/hiredis.h')
env.Install('#/build/include/hiredis', hiredis_path + '/async.h')
env.Install('#/build/include/hiredis', hiredis_path + '/sslio.h')
env.Install('#/build/include/hiredis', hiredis_path + '/read.h')
env.Install('#/build/include/hiredis', hiredis_path + '/sds.h')
env.Install('#/build/include/hiredis', 'base64.h')
env.Install('#/build/include/hiredis', hiredis_asio_adapter_path + '/boostasio.hpp')
