#!/usr/bin/make -f
# rules
#
# Robert Jordens <rjo@gmx.de>
#
# This software may be used and distributed according to the terms
# of the GNU General Public License, incorporated herein by reference.
#
# $Id: rules 342 2004-03-25 14:00:53Z rj $
#

# DEB_AUTO_UPDATE_DEBIAN_CONTROL := yes
include /usr/share/cdbs/1/class/makefile.mk
DEB_UPSTREAM_VERSION := $(shell echo $(DEB_VERSION) | sed 's/-[^-]*//')
# strip of a optionally added cvs patch (format: upstream+cvs-debian)
DEB_UPSTREAM_TARBALL_VERSION := $(shell echo $(DEB_UPSTREAM_VERSION) | sed 's/+[^+]*//')
DEB_TAR_SRCDIR := $(DEB_SOURCE_PACKAGE)-$(DEB_UPSTREAM_TARBALL_VERSION)
# tarball has to be first because of #205396
include /usr/share/cdbs/1/rules/tarball.mk
include /usr/share/cdbs/1/class/autotools.mk
include /usr/share/cdbs/1/rules/debhelper.mk
include /usr/share/cdbs/1/rules/simple-patchsys.mk

#unused, TODO get this soname from configure.in
#DEB_SONAME_VERSION := 0.91.1-0
DEB_CONFIGURE_EXTRA_FLAGS := --enable-resize \
	--enable-timestamps --disable-iec61883 --with-oldtrans \
	--disable-ensure-mlock
	# --enable-posix-shm
# to avoid stripping when nostrip is set in DEB_BUILD_OPTIONS
ifeq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS)))
  DEB_CONFIGURE_EXTRA_FLAGS += --enable-stripped-jackd
endif

ifeq ($(DEB_HOST_GNU_SYSTEM),linux-gnu)
  DEB_CONFIGURE_EXTRA_FLAGS += --enable-capabilities --with-default-tmpdir=/dev/shm 
endif

ifeq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
# do optimization for the different architectures
# ifneq (,$(findstring i386,$(DEB_HOST_GNU_CPU)))
# 		DEB_CONFIGURE_EXTRA_FLAGS += --enable-optimize
# 		OPTI_FLAGS := -D_REENTRANT -O3 -fomit-frame-pointer -ffast-math -fstrength-reduce -funroll-loops -fmove-all-movables
# 		CXXFLAGS += $(OPTI_FLAGS)
# 		CFLAGS += $(OPTI_FLAGS)
# endif
endif

DEB_DH_MAKESHLIBS_ARGS := -V -Xintime -Xinprocess -Xjack_alsa -Xjack_oss\
	-Xjack_dummy -Xjack_iec61883
# unused, don't use. generates duplicate depends
# DEB_SHLIBDEPS_INCLUDE := debian/libjack$(DEB_SONAME_VERSION)/usr/lib

# ensure jackstart can be root.audio 4754
DEB_FIXPERMS_EXCLUDE := jackstart

post-patches:: debian/stamp-autotools-maintregen-arch
debian/stamp-autotools-maintregen-arch:
	cd $(DEB_BUILDDIR) && chmod +x autogen.sh && ./autogen.sh --no-conf
	touch debian/stamp-autotools-maintregen-arch

# after the directories are created but before dh_compress is run.
common-binary-post-install-arch::
	dh_buildinfo

binary-predeb/jackd::
ifeq ($(DEB_HOST_GNU_SYSTEM),linux)
	chown root.audio debian/jackd/usr/bin/jackstart
	chmod u=rwxs,g=rx,o=r debian/jackd/usr/bin/jackstart
endif

ifeq ($(DEB_HOST_GNU_SYSTEM),linux)
DEB_DH_GENCONTROL_ARGS := -u'-Vasound:Depends=libasound2-dev'
else
DEB_DH_GENCONTROL_ARGS := -u'-Vasound:Depends='
endif

clean::
	-rm -f debian/stamp-autotools-maintregen-arch

.PHONY: faq
# this target fetches the FAQ from the JACK homepage
faq:
	dh_testdir
	w3m -dump http://jackit.sourceforge.net/docs/faq.php > debian/FAQ.dltmp
	mv debian/FAQ.dltmp debian/FAQ
	dch -a "debian/FAQ: updated from webpage"

.PHONY: user-howto
# this target fetches the user howto from the web
user-howto:
	dh_testdir
	w3m -dump http://www.djcj.org/LAU/jack/ > debian/user-howto.dltmp
	mv debian/user-howto.dltmp debian/user-howto
	dch -a "debian/user-howto: updated from webpage"

.PHONY: devel-readme
# this target fetches README.developers from the web
devel-readme:
	dh_testdir
	w3m -dump \
	'http://cvs.sourceforge.net/viewcvs.py/*checkout*/jackit/jack/README.developers?content-type=text%2Fplain&rev=HEAD' \
	> debian/README.developers.dltmp
	mv debian/README.developers.dltmp debian/README.developers
	dch -a "debian/README.developers: updated from webpage"

.PHONY: update-create-orig-tarball
update-create-orig-tarball:
	mkdir -p tmp-orig-tree/$(DEB_SOURCE_PACKAGE)-$(DEB_UPSTREAM_VERSION).orig
	cp *.tar.* tmp-orig-tree/$(DEB_SOURCE_PACKAGE)-$(DEB_UPSTREAM_VERSION).orig
	tar -C tmp-orig-tree -czvf \
                ../$(DEB_SOURCE_PACKAGE)_$(DEB_UPSTREAM_VERSION).orig.tar.gz \
                $(DEB_SOURCE_PACKAGE)-$(DEB_UPSTREAM_VERSION).orig

.PHONY: update-clean
update-clean:
	rm -rf tmp-orig-tree

clean:: update-clean

.PHONY: update-cvs-snapshot
update-cvs-snapshot:
	# TODO: sanitize/cvsize DEB_UPSTREAM_TARBALL_VERSION; change version
	# number
	cvs -d :pserver:anonymous@cvs.sourceforge.net:/cvsroot/jackit \
		rdiff -u -r RELEASE_$(DEB_UPSTREAM_TARBALL_VERSION) \
		-D today jack \
		> debian/patches/01_$(DEB_UPSTREAM_TARBALL_VERSION)-cvs`date +%y%m%d`.patch

