[buildout]
extends =
  ../coreutils/buildout.cfg
  ../gettext/buildout.cfg
  ../gperf/buildout.cfg
  ../intltool/buildout.cfg
  ../libcap/buildout.cfg
  ../perl-XML-Parser/buildout.cfg
  ../pkgconfig/buildout.cfg
  ../util-linux/buildout.cfg
  ../xz-utils/buildout.cfg
  ../ninja/buildout.cfg
  ../meson/buildout.cfg

[systemd-markupsafe-download]
recipe = slapos.recipe.build:download
shared = true
url = https://files.pythonhosted.org/packages/bf/10/ff66fea6d1788c458663a84d88787bae15d45daa16f6b3ef33322a51fc7e/${:filename}
filename = MarkupSafe-2.0.1.tar.gz
md5sum = 892e0fefa3c488387e5cc0cad2daa523

[systemd-markupsafe-download:sys.version_info < (3,8)]
url = https://files.pythonhosted.org/packages/4d/de/32d741db316d8fdb7680822dd37001ef7a448255de9699ab4bfcbdf4172b/${:filename}
filename = MarkupSafe-1.0.tar.gz
md5sum = 2fcedc9284d50e577b5192e8e3578355

[systemd-jinja2-download]
recipe = slapos.recipe.build:download
shared = true
url = https://files.pythonhosted.org/packages/4f/e7/65300e6b32e69768ded990494809106f87da1d436418d5f1367ed3966fd7/${:filename}
filename = Jinja2-2.11.3.tar.gz
md5sum = 231dc00d34afb2672c497713fa9cdaaa

[systemd-python]
recipe = slapos.recipe.build
shared = true
markupsafe = ${systemd-markupsafe-download:target}
jinja2 = ${systemd-jinja2-download:target}

install =
  import os, sys
  call([sys.executable, '-m', 'venv', '--clear', location])
  pip = os.path.join(location, 'bin', 'pip')
  call([pip, 'install', '--no-index', options['markupsafe'], options['jinja2']])
  call([pip, 'uninstall', '-y', 'pip', 'setuptools'])
  # selftest
  python = os.path.join(location, 'bin', 'python')
  call([python, '-c', 'import jinja2'])

[systemd]
recipe = slapos.recipe.build
shared = true
# XXX This version requires Linux kernel >= 3.7.
url = https://github.com/systemd/systemd-stable/archive/v249.6.tar.gz
md5sum = eb4a1923009abdb4e25c4802f4921a18
install =
  env = self.environ
  extract_dir = self.extract(self.download(options['url'], options['md5sum']))
  workdir = guessworkdir(extract_dir)
  call([
    'meson', 'setup', 'build',
    '-Dprefix=%s' % (location,),
    '-Drootprefix=%s' % (location,),
    '-Dsysconfdir=%s/etc' % (location,),
    '-Dsysvinit-path=%s/etc/init.d' % (location,),
    '-Dsysvrcnd-path=%s/etc/rc.d' % (location,),
    '-Dlocalstatedir=%s/var' % (location,),
    '-Dcreate-log-dirs=False',
    '-Dhwdb=False',
  ], cwd=workdir, env=env)
  call(['meson', 'setup', 'build',], cwd=workdir, env=env)
  call(['meson', 'compile', '-C', 'build/'], cwd=workdir, env=env)
  call(['meson', 'install', '-C', 'build/'], cwd=workdir, env=env)
  import os
  # On some systems multiarch is detected, and then libraries go to
  # x86_64-linux-gnu, and as there was no way to control this behaviour
  # during meson setup build phase, simply link it to lib64, where other
  # parts are looking for libraries
  if os.path.exists(os.path.join(location, 'x86_64-linux-gnu')):
    call(['ln', '-s', 'x86_64-linux-gnu', 'lib64'], cwd=location)

environment =
  PATH=${systemd-python:location}/bin:${meson:location}/bin:${ninja:location}/bin:${coreutils:location}/bin:${gettext:location}/bin:${gperf:location}/bin:${intltool:location}/bin:${perl-XML-Parser:perl-PATH}:${pkgconfig:location}/bin:${xz-utils:location}/bin:%(PATH)s
  CPPFLAGS=-I${libcap:location}/include -I${util-linux:location}/include
  LDFLAGS=-L${libcap:location}/lib -Wl,-rpath=${libcap:location}/lib -L${util-linux:location}/lib -Wl,-rpath=${util-linux:location}/lib
  PKG_CONFIG_PATH=${util-linux:location}/lib/pkgconfig
