[buildout]
parts =
  open62541
  compile-coupler
  slapos-cookbook
  instance-profile

extends =
  ../../component/git/buildout.cfg
  ../../component/mbedtls/buildout.cfg
  ../../component/open62541/buildout.cfg
  ../../stack/monitor/buildout.cfg
  ../../stack/slapos.cfg

# we need open62541's sources even after compiling and linking in [open62541]
# section. Reasons is that coupler's C application depends on it.
[open62541-source]
recipe = slapos.recipe.build:download-unpacked
shared = true
url = ${open62541:url}
md5sum = ${open62541:md5sum}

[open62541]
configure-options =
  -DBUILD_SHARED_LIBS=ON
  -DCMAKE_BUILD_TYPE=Release
  -DCMAKE_INSTALL_PREFIX=@@LOCATION@@
  -DUA_ENABLE_PUBSUB=ON
  -DUA_ENABLE_PUBSUB_MONITORING=ON
  -DUA_ENABLE_PUBSUB_ETH_UADP=ON
  -DUA_NAMESPACE_ZERO=REDUCED
  -DUA_ENABLE_ENCRYPTION=MBEDTLS
  -DUA_ENABLE_ENCRYPTION_MBEDTLS=ON
  -DMBEDTLS_INCLUDE_DIRS=${mbedtls:location}/include
  -DMBEDTLS_LIBRARY=${mbedtls:location}/lib/libmbedtls.so
  -DMBEDX509_LIBRARY=${mbedtls:location}/lib/libmbedx509.so
  -DMBEDCRYPTO_LIBRARY=${mbedtls:location}/lib/libmbedcrypto.so
  -DUA_ENABLE_PUBSUB_INFORMATIONMODEL=ON
  -DUA_ENABLE_PUBSUB_MQTT=ON
environment +=
  LDFLAGS=-L${mbedtls:location}/lib -Wl,-rpath=${mbedtls:location}/lib

[osie-repository]
recipe  = slapos.recipe.build:gitclone
git-executable = ${git:location}/bin/git
repository = https://lab.nexedi.com/nexedi/osie.git
revision = dc273b64b594de90080afdef873403f953c989f5

[compile-coupler]
recipe = slapos.recipe.cmmi
path = ${osie-repository:location}/coupler/
bin_dir = ${:path}/bin/
environment =
  OPEN62541_HOME = ${open62541:location}
  OPEN62541_SOURCE_HOME = ${open62541-source:location}
  C_COMPILER_EXTRA_FLAGS = -L ${mbedtls:location}/lib -Wl,-rpath=${mbedtls:location}/lib -l:libopen62541.so -L${open62541:location}/lib -Wl,-rpath=${open62541:location}/lib -I${open62541:location}/include -I${open62541-source:location}/src/pubsub/ -I${open62541-source:location}/deps
configure-command = true

[instance-profile]
recipe = slapos.recipe.template:jinja2
template = ${:_profile_base_location_}/instance.cfg.in
mode = 0644
rendered = ${buildout:directory}/instance.cfg
extensions = jinja2.ext.do
context =
  section buildout buildout
  raw template_monitor ${monitor2-template:output}
  key open62541_location open62541:location
  key mbedtls_location mbedtls:location
  key coupler_location compile-coupler:bin_dir
