#!/usr/bin/make -f

### CDBS INCLUDES
include /usr/share/cdbs/1/rules/debhelper.mk
include debian/cdbs/debian-qt-kde.mk
include /usr/share/cdbs/1/rules/patchsys-quilt.mk

DEB_CONFIGURE_INCLUDEDIR := /opt/kde3/include/kde
DEB_CONFIGURE_MANDIR := /opt/kde3/share/man
DEB_CONFIGURE_PREFIX := /opt/kde3
DEB_CONFIGURE_INFODIR := /opt/kde3/share/info

cdbs_configure_flags := --with-qt-dir=/usr/share/qt3 --with-xinerama $(cdbs_kde_enable_final) $(cdbs_kde_enable_debug)

### VARIABLES
# Exempt amarok engines from being handled as proper public libraries
# by dh_makeshlibs
DEB_DH_MAKESHLIBS_ARGS_ALL = -Xlibamarok_\\w*-engine-kde3

export KUBUNTU_DESKTOP_POT=extragear-multimedia_amarok-kde3

DEB_CONFIGURE_EXTRA_FLAGS  :=	--without-included-sqlite \
				--disable-final \
				--without-akode \
				--without-gstreamer10 \
				--without-libkarma \
				--with-ifp      \
				--with-libgpod  \
				--with-libnjb   \
				--with-libmtp   \
				--enable-mysql  \
				--enable-postgresql \
				--with-yauap \
				--prefix=/opt/kde3 \
				--with-extra-libs=/usr/lib/mesa

# Ship upstream README in amarok docs
DEB_INSTALL_DOCS_ALL =
DEB_INSTALL_DOCS_amarok-kde3 = $(DEB_SRCDIR)/README

# Amarok engines should not auto-depend on amarok. 
# Appropriate relationships are set manually in the control file.
DEB_DH_SHLIBDEPS_ARGS_amarok-engine-xine-kde3 = -- -xamarok-kde3
DEB_DH_SHLIBDEPS_ARGS_amarok-engine-yauap-kde3 = -- -xamarok-kde3

### Libtool and Automake updates
# Autoguess automake /usr/share subdirectory. Insure from failures
DEB_AUTOMAKE_SHARE_DIR = /usr/share/automake-$(shell automake --version | head -n 1 | sed 's/^automake (GNU automake) \([0-9]\+\.[0-9]\+\).*/\1/')
ifneq ($(words $(DEB_AUTOMAKE_SHARE_DIR)),1)
DEB_AUTOMAKE_SHARE_DIR =
endif

post-patches:: debian/stamp-automake
debian/stamp-automake:
	touch debian/stamp-automake-started
	if test -n "$(DEB_AUTOMAKE_SHARE_DIR)"; then \
		for f in $(DEB_AUTOMAKE_SHARE_DIR)/*; do \
			if  test -f $$f && \
			test -f $(DEB_SRCDIR)/admin/`basename $$f`; then \
			cp -f $$f $(DEB_SRCDIR)/admin; \
			fi; \
		done; \
	fi
	$(MAKE) -C $(DEB_SRCDIR) -f admin/Makefile.common
	touch $@

# Install ${curpkg}.install as lintian overrides
$(patsubst %,binary-install/%,$(DEB_PACKAGES))::
	if test -e debian/$(cdbs_curpkg).lintian; then \
		install -p -D -m644 debian/$(cdbs_curpkg).lintian \
		    debian/$(cdbs_curpkg)/opt/kde3/share/lintian/overrides/$(cdbs_curpkg); \
	fi

clean::
	if test -d $(DEB_SRCDIR) && test -f debian/stamp-automake-started; then \
		cd $(DEB_SRCDIR); \
		find . -name Makefile.in -print | \
				xargs --no-run-if-empty rm -f; \
		rm -f Makefile.am acinclude.m4 aclocal.m4 config.h.in \
				configure configure.files configure.in stamp-h.in \
				subdirs; \
	fi
	rm -f debian/stamp-automake*

binary-fixup/amarok-common-kde3::
	# Fix permissions of some amarok scripts
	chmod a+x  \
	    debian/$(cdbs_curpkg)/opt/kde3/share/apps/amarok/scripts/lyrics_astraweb/lyrics_astraweb.rb \
	    debian/$(cdbs_curpkg)/opt/kde3/share/apps/amarok/scripts/playlist2html/Playlist.py \
	    debian/$(cdbs_curpkg)/opt/kde3/share/apps/amarok/scripts/ruby_debug/debug.rb \
	    debian/$(cdbs_curpkg)/opt/kde3/share/apps/amarok/scripts/templates/python_qt_template.py \
	    debian/$(cdbs_curpkg)/opt/kde3/share/apps/amarok/scripts/templates/ruby_qt_template.rb \
	    debian/$(cdbs_curpkg)/opt/kde3/share/apps/amarok/scripts/webcontrol/Playlist.py \
	    debian/$(cdbs_curpkg)/opt/kde3/share/apps/amarok/scripts/webcontrol/RequestHandler.py

binary-post-install/amarok-common-kde3::
	# Remove excess COPYING files from script directories
	rm -f \
	    debian/$(cdbs_curpkg)/opt/kde3/share/apps/amarok/scripts/lyrics_astraweb/COPYING \
	    debian/$(cdbs_curpkg)/opt/kde3/share/apps/amarok/scripts/lyrics_lyrc/COPYING \
	    debian/$(cdbs_curpkg)/opt/kde3/share/apps/amarok/scripts/score_default/COPYING \
	    debian/$(cdbs_curpkg)/opt/kde3/share/apps/amarok/scripts/score_impulsive/COPYING
	# Remove Mac OSX resource fork file
	rm -f debian/$(cdbs_curpkg)/opt/kde3/share/apps/amarok/ruby_lib/rubygems/._gem_commands.rb

### POST-INSTALL HACKING
common-binary-post-install-arch::
	# Check for not installed files
	dh_install --no-act --list-missing

	chmod a+x debian/amarok-kde3/opt/kde3/lib/amarok/install-mp3
	chmod +x debian/amarok-kde3/opt/kde3/bin/kubuntu-media-amarok
	ln -s /opt/kde3/bin/amarokapp debian/amarok-kde3/opt/kde3/lib/amarok/amarokapp
