#!/usr/bin/make -f

PACKAGE = $(shell dh_listpackages)
INSTALL     = $(CURDIR)/debian/rakudo

# if the Debian package version is needed:
NQP_VERSION = $(shell dpkg -s nqp | sed -rne 's,^Version: (.+).*,\1,p')
#MOARVM_VERSION = $(shell dpkg -s moarvm | sed -rne 's,^Version: (.+).*,\1,p')

# get only upstream version
#NQP_VERSION = $(shell nqp --version | perl -n -E 'm/([\d.]+)/; say $$1;')
MOARVM_VERSION = $(shell moar --version | perl -n -E 'm/([\d.]+)/; say $$1;')

#NQP_NEXT = $(shell nqp --version | perl -n -E 'my ($$y,$$m) = m/(2\d+)\.(\d+)/; if ($$m < 12) { $$m++} else {$$m=1;$$y++}; printf("%d.%02d\n",$$y,$$m);')
MOARVM_NEXT = $(shell moar --version | perl -n -E 'my ($$y,$$m) = m/(2\d+)\.(\d+)/; if ($$m < 12) { $$m++} else {$$m=1;$$y++}; printf("%d.%02d\n",$$y,$$m);')

%:
	dh $@

override_dh_auto_configure:
	perl Configure.pl --prefix=/usr --libdir=/usr/lib --backends=moar

# rakudo needs a strict dependency version of nqp. See README.source
# for details.
# WARNING: rakudo must be compiled with the exact nqp that is shipped to
# Debian. Otherwise timestamp will differ and rakudo will break on user
# systems.
override_dh_gencontrol:
	dh_gencontrol -- -Vnqp:Depends="nqp (= $(NQP_VERSION))" \
	                 -Vmoarvm:Depends="moarvm (>= $(MOARVM_VERSION)), moarvm(<< $(MOARVM_NEXT))"

override_dh_auto_build:
	dh_auto_build
	pod2man --name=perl6 docs/running.pod debian/perl6.1

override_dh_auto_install:
	dh_auto_install
	find $(INSTALL) -type d -empty -delete

