#!/usr/bin/make -f
# -*- mode: makefile; coding: utf-8 -*-
# Copyright © 2007-2008 Felipe Sateler <fsateler@debian.org>
# Copyright © 2008-2010 Jonas Smedegaard <dr@jones.dk>
# Description: Main Debian packaging script for CSound Reference Manual
#
# 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/makefile.mk
include /usr/share/cdbs/1/rules/debhelper.mk

DEB_UPSTREAM_URL = http://downloads.sourceforge.net/csound
DEB_UPSTREAM_TARBALL_BASENAME = Csound$(DEB_UPSTREAM_TARBALL_VERSION)-manual-src
DEB_UPSTREAM_TARBALL_MD5 = f14986002b04aabed2d01b098b7d1122

DEB_UPSTREAM_TARBALL_SRCDIR = manual

# Possibly non free soundfonts
DEB_UPSTREAM_REPACKAGE_EXCLUDES = ./examples/22Bassoon.sf2 ./examples/01hpschd.sf2

# Licensing status is not clear upstream
DEB_UPSTREAM_REPACKAGE_EXCLUDES += ./opcodes/py*.xml

# DEB_INSTALL_DOCS_ALL += authors.txt

pre-build clean:: fail-source-not-repackaged

build/csound-manpages:: manpages-stamp
manpages-stamp:
	$(MAKE) manpages
# Correct some flaws in the manpage
	sed -i -e '/\\\.csoundrc/d' manpages/csound.1
	sed -i -e 's/(e\\\.g\\\. in /(e\\\.g\\\. in \\\.csoundrc)\./' manpages/csound.1
	sed -i -e '/^[[:space:]]*5\.[0-9]\{2\}[[:space:]]*$$/d' manpages/csound.1
	touch $@

# Do not duplicate copyright information
common-post-build-indep::
	rm -f html/copying.txt
# generate authors.txt
# Disable it for now while automation is correctly handled
#	lynx -dump html/PrefaceHistory.html | \
#		iconv --from-code=ISO-8859-1 --to-code=UTF8  | \
#		sed -n -e '/^History/,/   from the/p' | \
#		sed -e 's/\[[0-9]\+\]//g' > authors.txt

clean::
	rm -f manpages-stamp
#	rm -f authors.txt

# Needed by upstream build process
CDBS_BUILD_DEPENDS += , xsltproc

# Do not use shipped docbook
CDBS_BUILD_DEPENDS += , docbook-xsl, docbook-xml

# Use lynx to dump the contents of the html history
#CDBS_BUILD_DEPENDS += , lynx

# Needed (sometimes) at runtime
CDBS_SUGGESTS_ALL = csound
CDBS_SUGGESTS_csound-manpages = csound-utils
