[buildout]
extends =
  ../gdbm/buildout.cfg
  ../xz-utils/buildout.cfg
parts =
  perl

[perl]
recipe = slapos.recipe.cmmi
shared = true
version = 5.38.0
url = https://www.cpan.org/src/5.0/perl-${:version}.tar.xz
md5sum = e1c8aaec897dd386c741f97eef9f2e87
siteprefix =@@LOCATION@@/site_${:_buildout_section_name_}
configure-command =
  sh Configure -des \
    -Dprefix=@@LOCATION@@ \
    -Dsiteprefix=${:siteprefix} \
    -Dcflags=-I${gdbm:location}/include \
    -Dldflags="-L${gdbm:location}/lib -Wl,-rpath=${gdbm:location}/lib" \
    -Ui_db \
    -Dnoextensions=ODBM_File \
    -Dusethreads
environment =
  PATH=${xz-utils:location}/bin:%(PATH)s
post-make-hook = ${:_profile_base_location_}/perl-create-libs-symlink.py#8a2cae20c74f93c2bab2c82564aeeaca:post_make_hook


[perl-CPAN-package]
# Macro to install a perl package from CPAN
# This macro will generate a perl wrapper as {:perl-bin} and rewrite all
# scripts installed by the package to use this perl. Executable scripts are
# installed in ${:perl-PATH}

# Inputs:
#  - module name, ie. Category/Category-Name
module = (required)
#  - module version
version = (required)
#  - checksum of module
md5sum = (required)

#  - colon (:) separated site perl of runtime dependencies, for example
#  ${perl-X-Y:site_perl}:${perl-X-Z:site_perl} these paths will be included in
#  the generated wrappers
inc =
#  - colon (:) separated site perl of install dependencies, for example
#  ${perl-X-Y:site_perl}:${perl-X-Z:site_perl} these paths will be used only
#  for installation. A typical use case is to add current directory (.) for
#  packages using a local version of Module::Install.
install-inc =
#  - extra arguments passed to perl Makefile.PL
extra-configure-args =

# - extra environ varialbles for configure and make
extra-env =

# Outputs:
#  - site_perl, to use in inc in dependent packages
site_perl=${:location}/lib/site_perl/${perl:version}:${:location}:${:inc}

#  - a $PATH that contain the perl wrapper
perl-PATH = ${:location}/bin/
#  - the path for a perl wrapper with @INC set to this CPAN package and all the
#  dependencies
perl-bin = ${:perl-PATH}/perl

perl-PERL5LIB =

# Implementation
recipe = slapos.recipe.cmmi
shared = true
url = https://www.cpan.org/modules/by-module/${:module}-${:version}.tar.gz
configure-command =
  ${:extra-env}
  PERL5LIB="${:inc}:${:install-inc}:${:perl-PERL5LIB}" \
  ${perl:location}/bin/perl \
  Makefile.PL \
  PREFIX=${:location} \
  ${:extra-configure-args}
location = @@LOCATION@@
# Install scripts in "perl-bin", but create wrappers in ./bin/
make-options =
  INSTALLSITESCRIPT=${:location}/perl-bin/

make-binary=
  ${:extra-env} PERL5LIB="${:inc}:${:install-inc}:${:perl-PERL5LIB}" make

# this post-make-hook is same for all users of the macro.
post-make-hook = ${:_profile_base_location_}/../../component/perl/perl-CPAN-package-create-wrapper.py#f28c45a0f473ae050ca3ebaed5c39a4e:post_make_hook

perl_location = ${perl:location}


[perl-wrapper]
# Macro to generate a perl wrapper with @INC set as ${:inc}
# The wrapper will be named as the section name, in buildout's bin directory.
#
# Note that this is usually not needed, because each part installed with
# perl-CPAN-package generates its own wrapper with the package and all
# dependencies available.
# This macro is useful to build a wrapper with several independent package
# available.
# It also takes care of executing perl with -I argument and not with $PERL5LIB
# environment variable, because the later is ignored when perl runs in tainted
# mode ( with -T argument )
#
# Inputs:
#  - inc : colon (:) separated site perl of modules to include in @INC
# Outputs:
#  - perl-bin : an executable perl
recipe = slapos.recipe.template
inline =
  #!/bin/sh
  {% set inc = "${:inc}".split(':') %} {# XXX we could remove duplicates from inc #}
  exec ${perl:location}/bin/perl \
  {% for item in inc -%}{% if item %}  -I "{{ item }}" \
  {% endif %}{% endfor %}  "$@"
output = ${buildout:bin-directory}/${:_buildout_section_name_}
perl-bin = ${:output}