#!/usr/bin/make -f
# -*- mode: makefile; coding: utf-8 -*-
# Copyright 2016-2017 Jonas Smedegaard <dr@jones.dk>
# Description: Main Debian packaging script for AtteanX::Endpoint
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

include /usr/share/cdbs/1/class/perl-makemaker.mk
include /usr/share/cdbs/1/rules/debhelper.mk

pkg = $(DEB_SOURCE_PACKAGE)

# Needed by upstream build and (always/often) at runtime
perl-deps = file-sharedir html-html5-writer http-negotiate
perl-deps += json xml-libxml list-moreutils moo moox-log-any plack
perl-deps += trycatch type-tiny namespace-clean
deps = $(patsubst %,$(comma) lib%-perl,$(perl-deps))
deps +=, libattean-perl (>= 0.013)

# Needed by upstream testsuite
perl-deps-test = exception lwp-useragent modern www-mechanize-psgi
deps-test = $(patsubst %,$(comma) libtest-%-perl,$(perl-deps-test))
deps-test +=, libmoose-perl

CDBS_BUILD_DEPENDS +=, $(deps), $(deps-test)
CDBS_DEPENDS_$(pkg) = $(deps)

clean::
	rm -f Makefile.old

DEB_DH_INSTALL_$(pkg) = scripts/endpoint.psgi $(DEB_DESTDIR)/usr/share/$(pkg)
DEB_INSTALL_EXAMPLES_$(pkg) = debian/uwsgi

# use separately packaged Javascript
CDBS_BUILD_DEPENDS +=, libjs-codemirror
CDBS_DEPENDS_$(pkg) +=, libjs-codemirror
binary-post-install/$(pkg)::
	find $(cdbs_curdestdir)usr/share/perl5/auto \
		-type f -not -name codemirror-config.js \
		-delete
	find $(cdbs_curdestdir)usr/share/perl5/auto \
		-type f -name sparqlcolors.css \
		-delete
	ln -fsT ../../../../../../../../javascript/codemirror \
		$(DEB_DESTDIR)usr/share/perl5/auto/share/dist/AtteanX-Endpoint/endpoint/www/js/codemirror
