#!/usr/bin/make -f
# -*- mode: makefile; coding: utf-8 -*-
# Copyright © 2013 Jonas Smedegaard <dr@jones.dk>
# Description: Main Debian packaging script for node_raptor
#
# 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 2, 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/class/langcore.mk
include /usr/share/cdbs/1/rules/debhelper.mk

pkg = node-raptor

CDBS_BUILD_DEPENDS += , nodejs-dev, libraptor2-dev
CDBS_DEPENDS_$(pkg) = nodejs

DEB_UPSTREAM_URL = https://github.com/0xfeedface/node_raptor/archive
#DEB_UPSTREAM_TARBALL_BASENAME = v$(DEB_UPSTREAM_TARBALL_VERSION)
DEB_UPSTREAM_TARBALL_BASENAME = 91abde
DEB_UPSTREAM_TARBALL_MD5 = 7215c1b992cca1a4cb7c381224297273

DEB_SRCDIR = src

DEB_INSTALL_DOCS_$(pkg) += README.mdown

# node-waf build routines
NODE-PATH = $(cdbs_curdestdir)usr/lib/nodejs/raptor/native
NODE-WAF-BUILDFLAGS = CFLAGS="$(CFLAGS)" CXXFLAGS="$(CXXFLAGS)" CPPFLAGS="$(CPPFLAGS)" LINKFLAGS="$(LDFLAGS)"
NODE-WAF = NOCOLOR=1 NODE_PATH="$(NODE-PATH)" RAPTOR_PREFIX=/usr node-waf -v
configure/$(pkg):: debian/stamp-node-waf-configure
debian/stamp-node-waf-configure:
	cd $(DEB_SRCDIR) && $(NODE-WAF-BUILDFLAGS) $(NODE-WAF) configure
	touch $@
build/$(pkg):: debian/stamp-node-waf-build
debian/stamp-node-waf-build:
	cd $(DEB_SRCDIR) && $(NODE-WAF) build
	$(if $(filter nocheck,$(DEB_BUILD_OPTIONS)),,make test)
	touch $@
install/$(pkg)::
	cd $(DEB_SRCDIR) && $(NODE-WAF) install
clean::
	rm -rf build
	rm -f $(DEB_SRCDIR)/.lock-wscript
	rm -f debian/stamp-node-waf-configure debian/stamp-node-waf-build

# Node modules have an uncommon extension preventing autodetection by
# dh_shlibdeps, so we do it manually
binary-strip-IMPL/$(pkg)::
	$(if $(is_debug_package)$(filter nostrip,$(DEB_BUILD_OPTIONS)),,find "$(cdbs_curdestdir)" -name "*.node" -exec strip --remove-section=.comment --remove-section=.note --strip-unneeded {} +)
binary-predeb-IMPL/$(pkg)::
	find "$(cdbs_curdestdir)" -name "*.node" -exec dpkg-shlibdeps -Tdebian/$(cdbs_curpkg).substvars {} +
