Import('env', 'common', 'msgq')

cereal_dir = Dir('.')
gen_dir = Dir('gen')

# Build cereal
schema_files = ['log.capnp', 'car.capnp', 'legacy.capnp', 'custom.capnp']
env.Command([f'gen/cpp/{s}.c++' for s in schema_files] + [f'gen/cpp/{s}.h' for s in schema_files],
            schema_files,
            f"capnpc --src-prefix={cereal_dir.path} $SOURCES -o c++:{gen_dir.path}/cpp/")

cereal = env.Library('cereal', [f'gen/cpp/{s}.c++' for s in schema_files])

# Build messaging
services_h = env.Command(['services.h'], ['services.py'], 'python3 ' + cereal_dir.path + '/services.py > $TARGET')
env.Program('messaging/bridge', ['messaging/bridge.cc', 'messaging/msgq_to_zmq.cc'], LIBS=[msgq, common, 'pthread'])

socketmaster = env.Library('socketmaster', ['messaging/socketmaster.cc'])

Export('cereal', 'socketmaster')
