#!/usr/bin/make -f
# -*- mode: makefile; coding: utf-8 -*-
# Copyright © 2008, 2009, 2010, 2011, 2012 Jonas Smedegaard
# <dr@jones.dk>
# Description: Main Debian packaging script for unicap
#
# 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, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
# 02111-1307 USA.

DEB_AUTO_UPDATE_AUTOCONF = 2.67
DEB_AUTO_UPDATE_AUTOHEADER = 2.67
DEB_AUTO_UPDATE_ACLOCAL = 1.11
DEB_AUTO_UPDATE_AUTOMAKE = 1.11
DEB_AUTO_UPDATE_LIBTOOL = pre
-include /usr/share/cdbs/1/rules/upstream-tarball.mk
include /usr/share/cdbs/1/rules/utils.mk
include /usr/share/cdbs/1/class/autotools.mk
include /usr/share/cdbs/1/rules/debhelper.mk

# suppress optional build-dependencies
CDBS_BUILD_DEPENDS_rules_upstream-tarball =
CDBS_BUILD_DEPENDS_rules_utils_copyright-check =
CDBS_BUILD_DEPENDS_rules_utils_buildinfo =

pkgbasename = unicap
pkgname = libunicap2
libname = libunicap

DEB_UPSTREAM_URL = http://unicap-imaging.org/downloads
DEB_UPSTREAM_PACKAGE = libunicap
DEB_UPSTREAM_TARBALL_MD5 = 353657b4da519251d4cc6dee5a232391

# Ignore logo and tarball-in-tarball, in addition to default stuff
DEB_COPYRIGHT_CHECK_IGNORE_REGEX = ^(doc/api/html/images/logo_unicap\.gif|examples/c/xv_display/xv_display-0\.0\.7\.tar\.gz|debian/(changelog|copyright(|_hints|_newhints)))$

DEB_CONFIGURE_USER_FLAGS = \
	--disable-rpath \
	--enable-gtk-doc \
	--enable-vid21394-visca \
	--enable-libv4l

DEB_MAKE_CHECK_TARGET = check

LDFLAGS += -pthread -Wl,-z,defs -Wl,--as-needed -Wl,--no-undefined

DEB_SHLIBDEPS_LIBRARY_libunicap2 = $(libname)
DEB_SHLIBDEPS_INCLUDE_libunicap2 = /usr/lib/unicap2 /usr/lib/unicap2/cpi

DEB_DH_INSTALL_ARGS := --sourcedir=debian/tmp

# Let d-shlibs calculate development package dependencies
#  and handle shared library install
install/libunicap2-dev:: debian/install-unicap-stamp
debian/install-unicap-stamp:
	d-shlibmove --commit \
		--exclude-la \
		--override s/libraw1394-8-dev/libraw1394-dev/ \
		--movedev "debian/tmp/usr/include/unicap/*.h" usr/include/unicap/ \
		--movedev "debian/tmp/usr/lib/pkgconfig/*.pc" usr/lib/pkgconfig/ \
		--movedev "debian/tmp/usr/lib/unicap2/cpi/*.a" usr/lib/unicap2/cpi/ \
		--moveshl "debian/tmp/usr/lib/unicap2/cpi/*.so" usr/lib/unicap2/cpi/ \
		debian/tmp/usr/lib/$(libname).so
	touch $@
clean::
	rm -f debian/install-unicap-stamp

# put aside autogenerated files during build
# TODO: use DEB_UPSTREAM_CRUFT_MOVE when cdbs 0.4.106 is in stable
upstreamtmpstuff = include/unicap_version.h
upstreamtmpstuff += doc/libunicap/html doc/libunicap/tmpl doc/libunicap/xml
makefiledirs = . common cpi cpi/dcam cpi/euvccam cpi/include cpi/thing
makefiledirs += cpi/v4l cpi/v4l2cpi cpi/vid21394 data doc doc/libunicap
makefiledirs += include src
upstreamtmpstuff += $(addsuffix /Makefile.in,$(makefiledirs))
upstreamtmpstuff += aclocal.m4 configure config.h.in
upstreamtmpstuff += config.guess config.sub depcomp install-sh missing
upstreamtmpstuff += compile ltmain.sh
pre-build:: debian/upstream-stuff
debian/upstream-stuff: debian/stamp-copyright-check
	mkdir -p debian/upstream-stuff
	@for orig in $(upstreamtmpstuff); do \
		backup="debian/upstream-stuff/$$orig"; \
		[ ! -e "$$orig" ] || [ -e "$$backup" ] || { \
			mkdir -p "$$(dirname "$$backup")"; \
			echo mv "$$orig" "$$backup"; \
			mv "$$orig" "$$backup"; \
		}; \
	done
clean::
	@for orig in $(upstreamtmpstuff); do \
		backup="debian/upstream-stuff/$$orig"; \
		if [ -e "$$backup" ]; then \
			if [ -e "$$orig" ]; then \
				echo "rm -rf" "$$orig"; \
				rm -rf "$$orig"; \
			fi; \
			echo mv "$$backup" "$$orig"; \
			mv "$$backup" "$$orig"; \
		fi; \
	done
	rm -rf debian/upstream-stuff

# Needed by upstream build process
CDBS_BUILD_DEPENDS += , intltool, gtk-doc-tools (>= 1.4)
CDBS_BUILD_DEPENDS += , libraw1394-dev (>= 1.1.0), libv4l-dev
CDBS_BUILD_DEPENDS += , libgtk2.0-dev, libglib2.0-dev

# Needed for our packaging
CDBS_BUILD_DEPENDS += , pkg-config, d-shlibs (>= 0.45~)

# (re)generate most possible autotools files
DEB_ACLOCAL_ARGS = -Im4 --install --force
DEB_AUTOMAKE_ARGS = --add-missing --copy --foreign --force
DEB_MAKE_CLEAN_TARGET = distclean
makebuilddir::
	mkdir -p m4
clean::
	rm -rf m4
