#!/usr/bin/make -f
# -*- mode: makefile; coding: utf-8 -*-
# Copyright 2010, 2011, 2013 Jonas Smedegaard <dr@jones.dk>
# Copyright 2012 Andrew Harvey <andrew.harvey4@gmail.com>
# Description: Main Debian packaging script for Leaflet.markercluster
#
# 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/rules/upstream-tarball.mk
include /usr/share/cdbs/1/rules/utils.mk
include /usr/share/cdbs/1/rules/debhelper.mk

# package variables
libname = leaflet-markercluster
pkg = libjs-leaflet-markercluster

CDBS_BUILD_DEPENDS += , node-uglify , node-jake
CDBS_RECOMMENDS_$(pkg) = javascript-common, libjs-leaflet

#
# Upstream tarball settings
#

DEB_UPSTREAM_URL = https://github.com/Leaflet/Leaflet.markercluster/archive
DEB_UPSTREAM_TARBALL_BASENAME = $(DEB_UPSTREAM_TARBALL_VERSION)
DEB_UPSTREAM_TARBALL_SRCDIR = Leaflet.markercluster-$(DEB_UPSTREAM_TARBALL_VERSION)
DEB_UPSTREAM_TARBALL_MD5 = 1d6184f7757454d8c8bc4ef7d14df34d

# Remove upstream shipped autogenerated files
DEB_UPSTREAM_REPACKAGE_EXCLUDES = dist/*.js

# Remove upstream shipped example data which have unclear licensing
DEB_UPSTREAM_REPACKAGE_EXCLUDES += example/realworld.*.js


#
# Installation
#

js-destdir = /usr/share/javascript/$(libname)

# install files to the js-dest-dir as defined by javascript-common
DEB_DH_INSTALL_ARGS_$(pkg) = dist/* $(js-destdir)

# install documentation
DEB_INSTALL_DOCS_$(pkg) = README.md example/

# install upstream changelog
DEB_INSTALL_CHANGELOGS_$(pkg) = CHANGELOG.md


#
# Build
#

# rule for building project from source
build/$(pkg)::
	jake

# Fix paths in example files
html-examples = $(cdbs_curdestdir)usr/share/doc/$(cdbs_curpkg)/examples/*.html
binary-fixup/$(pkg)::
	perl -i -pe 's,(href|src)="\Khttp://cdn.leafletjs.com/leaflet-0.4.4,/javascript/leaflet,g' $(html-examples)
	perl -i -pe 's,(href|src)="\K../dist,/javascript/leaflet-markercluster,g' $(html-examples)
