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

[perl]
recipe = slapos.recipe.cmmi
shared = true
version = 5.28.1
url = http://www.cpan.org/src/5.0/perl-${:version}.tar.xz
md5sum = fbb590c305f2f88578f448581b8cf9c4
siteprefix =@@LOCATION@@/site_${:_buildout_section_name_}
patch-options = -p1
patches =
  ${:_profile_base_location_}/perl-keep-linker-flags-in-ldflags.patch#4e8e0c59d7176eafb0c7402dea17bef1
  ${:_profile_base_location_}/0001-Fix-missing-build-dependency-for-pods.patch#85aff81f3bea34fcd6ce9a611ee1cdb2
  ${:_profile_base_location_}/0002-prereq1.patch#c9bf3b521a39134d044eaa2c2312174f
  ${:_profile_base_location_}/0003-prereq2.patch#5268ff6dd06718cff34e6fb758045996
  ${:_profile_base_location_}/0004-disable-probing.patch#e68446ccd155c2282639e495a5be612b
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=${patch:location}/bin:${xz-utils:location}/bin:%(PATH)s
post-make-hook = ${:_profile_base_location_}/perl-create-libs-symlink.py#943453b7d3ff8d49ed12d44a7f7076ee: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:jinja2
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 %}  "$@"
rendered = ${buildout:bin-directory}/${:_buildout_section_name_}
perl-bin = ${:rendered}
