[buildout]
parts =
  gcc-10.2
  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
  ../../component/gcc/buildout.cfg

# disable warning for time_t type structure after 2038
# https://www.gnu.org/software/gnulib/manual/html_node/Avoiding-the-year-2038-problem.html
[coreutils]
configure-options =
  --disable-libcap
  --without-selinux
  --prefix=@@LOCATION@@
  --disable-year2038

# 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 = 5d193e57b50a7ebb3df147e403917201eb9cb6c6

[compile-coupler]
recipe = slapos.recipe.cmmi
path = ${osie-repository:location}/coupler
bin_dir = ${:path}/bin/
environment =
  PATH=${gcc-10.2:location}/bin:/usr/bin
  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