#!/usr/bin/make -f
# -*- mode: makefile; coding: utf-8 -*-
# Copyright © 2015-2016 Jonas Smedegaard <dr@jones.dk>
# Description: Main Debian packaging script for sass-spec
#
# 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/debhelper.mk

pkg = $(DEB_SOURCE_PACKAGE)
pkg-data = $(pkg)-data

DEB_UPSTREAM_URL = https://github.com/sass/sass-spec/archive
#DEB_UPSTREAM_TARBALL_BASENAME = $(DEB_UPSTREAM_TARBALL_VERSION)
DEB_UPSTREAM_TARBALL_BASENAME = 1f9e016

# * TODO: recommend (not suggest) ruby-minitap when in Debian
CDBS_BUILD_DEPENDS +=, ruby | ruby-interpreter
CDBS_DEPENDS_$(pkg) = ruby | ruby-interpreter, ruby-sass | sass
CDBS_RECOMMENDS_$(pkg) = $(pkg-data), ruby-sass
CDBS_SUGGESTS_$(pkg) = ruby-minitap
CDBS_ENHANCES_$(pkg-data) = $(pkg)

DEB_DH_INSTALL_ARGS_$(pkg) = sass-spec /usr/bin
DEB_DH_INSTALL_ARGS_$(pkg-data) = spec /usr/share/sass
DEB_INSTALL_DOCS_all += README.md

# install using gem2deb
CDBS_BUILD_DEPENDS +=, gem2deb
$(patsubst %,%/$(pkg),configure build install):: %/$(pkg): debian/stamp-ruby-gem-%
$(patsubst %,debian/stamp-ruby-gem-%,configure build install):: debian/stamp-ruby-gem-%:
	dh_ruby --$*
	touch $@
cleanbuilddir/$(pkg)::
	dh_ruby --clean
	rm -f $(patsubst %,debian/stamp-ruby-gem-%,configure build install)

# generate manpages based on --help of script itself
manpages = debian/sass-spec.1
CDBS_BUILD_DEPENDS +=, help2man
DEB_INSTALL_MANPAGES_$(pkg) = $(manpages)
build/$(pkg):: $(manpages)
$(manpages): debian/%.1:
	cp -f $*.rb $*
	chmod +x $*
	RUBYLIB=lib help2man \
		--name "sass-spec testsuite for Sass implementions" \
		--no-info --no-discard-stderr --output=$@ ./$* \
		|| { RUBYLIB=lib ./$* --help; false; }
clean::
	rm -f sass-spec $(manpages)
