#!/usr/bin/make -f
# -*- mode: makefile; coding: utf-8 -*-
# Copyright © 2016 IOhannes m zmölnig <zmoelnig@iem.at>
# Description: Main Debian packaging script for faust
#
# 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/debhelper.mk
include /usr/share/cdbs/1/class/makefile-vars.mk
include /usr/share/cdbs/1/rules/utils.mk

DEB_COPYRIGHT_CHECK_IGNORE_REGEX = \
        ^(.*\.(png|pdf|doctree|jar|xcuserstate|swc|ots)|debian/(changelog|copyright(|_hints|_newhints)))$

DEB_COMPRESS_EXCLUDE_ALL=.dsp .lib Makefile
MANPAGEDIR=debian/man

build/faust::
	CPPFLAGS="$(CPPFLAGS)" CFLAGS="$(CFLAGS)" CXXFLAGS="$(CXXFLAGS)" LDFLAGS="$(LDFLAGS)" $(MAKE) PREFIX=/usr
	mkdir -p $(MANPAGEDIR)
	help2man -N -n "functional programming language for realtime audio applications" \
		debian/faust-help2man > $(MANPAGEDIR)/faust.1
	help2man -N -n "Compile faust DSP code into SuperCollider module" \
		tools/faust2sc-1.0.0/faust2sc > $(MANPAGEDIR)/faust2sc.1
	debian/faust2man $(MANPAGEDIR) debian/faust2api.1

install/faust::
	CPPFLAGS="$(CPPFLAGS)" CFLAGS="$(CFLAGS)" CXXFLAGS="$(CXXFLAGS)" LDFLAGS="$(LDFLAGS)" $(MAKE) DESTDIR=$(DEB_DESTDIR) PREFIX=/usr install
	mkdir -p $(DEB_DESTDIR)/usr/share/faust
	mv $(DEB_DESTDIR)/usr/lib/faust $(DEB_DESTDIR)/usr/share/faust/code
#	 remove source faustpath and faustoptflags from libexecdir
	-rm $(DEB_DESTDIR)/usr/bin/faustoptflags
	-rm $(DEB_DESTDIR)/usr/bin/faustpath
	sed -e 's|^\( *\. \)faust|\1/usr/share/faust/utils/faust|' -i $(DEB_DESTDIR)/usr/bin/faust2*

clean::
	$(MAKE) clean
	-rm -rf $(MANPAGEDIR)

#override_dh_auto_install:
#	$(MAKE) prefix=`pwd`/debian/faust/usr install

#override_dh_compress:
#	dh_compress -X.lib -X.dsp -XMakefile
