#!/usr/bin/make -f
# Sample debian/rules that uses debhelper.
# GNU copyright 1997 to 1999 by Joey Hess.

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

# This is the debhelper compatability version to use.
export DH_COMPAT=3

# shared library versions, option 1
VERSION = $(shell dpkg-parsechangelog | grep '^Version' | sed -e 's/Version: //g' -e 's/-[A-Za-z0-9\.]*$$//g')

SCRIPT_DIR = /usr/share/dbs

# the dbs rules
TAR_DIR := gnome-vfs-$(VERSION)
include $(SCRIPT_DIR)/dbs-build.mk

# dpkg-arch rules
ifeq (,$(DEB_BUILD_GNU_TYPE))
	include $(SCRIPT_DIR)/dpkg-arch.mk
endif

SONAME  = 0

TMP_DIR = debian/libgnomevfs2-common

debian/control:
	sed -e "s/@SONAME@/${SONAME}/g" $@.in > $@

	@echo
	@echo "*** VERSION=$(VERSION) ***"
	@echo

pre-configure: $(STAMP_DIR)/pre-configure
$(STAMP_DIR)/pre-configure:
	dh_testdir

	mkdir -p build-tree $(STAMP_DIR)
	cd build-tree && ln -sf gnome-vfs-$(VERSION) gnome-vfs

	touch $@

configure: $(STAMP_DIR)/configure
$(STAMP_DIR)/configure: $(STAMP_DIR)/pre-configure $(patched)
	dh_testdir

	cd $(BUILD_TREE) && ./autogen.sh --prefix=/usr \
                --mandir=\$${prefix}/share/man \
                --infodir=\$${prefix}/share/info --sysconfdir=/etc \
		--disable-gtk-doc \
		--disable-openssl \
		--enable-gnutls

	touch $@

build: debian/control configure $(STAMP_DIR)/build
$(STAMP_DIR)/build:
	dh_testdir

	cd $(BUILD_TREE) && $(MAKE)

	touch $@

clean:	debian/control
	dh_testdir

	rm -rf $(STAMP_DIR) build-tree
	perl $(SCRIPT_DIR)/dbs_split clean

	dh_clean

install: $(STAMP_DIR)/build
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs

	rm $(BUILD_TREE)/modules/*.la
	rm $(BUILD_TREE)/modules/vfolder/*.la
	cd $(BUILD_TREE) && $(MAKE) install DESTDIR=$(CURDIR)/$(TMP_DIR) LDFLAGS="-L$(CURDIR)/$(TMP_DIR)/usr/lib"

	dh_movefiles --sourcedir=$(TMP_DIR)
	rm -rf $(TMP_DIR)/usr/lib/gnome-vfs-2.0/modules/*.a \
	$(TMP_DIR)/usr/lib/gnome-vfs-2.0/modules/*.la \
	$(TMP_DIR)/usr/lib/vfs/extfs

	-rm debian/libgnomevfs2-common/etc/gnome-vfs-2.0/vfolders/applications.vfolder-info

	-find debian/ -type d -empty | sort -r | xargs rmdir -p > /dev/null 2>&1 

# Build architecture-independent files here.
binary-indep: build install
# We have nothing to do by default.

# Build architecture-dependent files here.
binary-arch: build install
#	dh_testversion
	dh_testdir
	dh_testroot
	dh_installdocs $(BUILD_TREE)/NEWS $(BUILD_TREE)/README $(BUILD_TREE)/TODO
	dh_installexamples
	dh_installmenu
	dh_installinfo
	dh_undocumented 
	dh_installchangelogs $(BUILD_TREE)/ChangeLog
	-rm -rf debian/libgnomevfs2-${SONAME}/usr/share/doc/*
	-rm -rf debian/libgnomevfs2-dev/usr/share/doc/*

	dh_link -plibgnomevfs2-dev /usr/share/doc/libgnomevfs2-common /usr/share/doc/libgnomevfs2-dev
	dh_link -plibgnomevfs2-${SONAME} /usr/share/doc/libgnomevfs2-common /usr/share/doc/libgnomevfs2-${SONAME}
	install -d debian/libgnomevfs2-dev/usr/share/doc/libgnomevfs2-common/
	mv $(TMP_DIR)/usr/share/gtk-doc/html/gnome-vfs-2.0 \
		debian/libgnomevfs2-dev/usr/share/doc/libgnomevfs2-common/html
	dh_link -plibgnomevfs2-dev /usr/share/doc/libgnomevfs2-common/html /usr/share/gtk-doc/html/gnome-vfs-2.0
	dh_strip
	dh_compress
	dh_fixperms
	dh_makeshlibs -plibgnomevfs2-${SONAME} -V"libgnomevfs2-${SONAME} (>= ${VERSION}), libgnomevfs2-common (>= ${VERSION})"
	dh_installdeb
	dh_shlibdeps -ldebian/libgnomevfs2-${SONAME}/usr/lib
	dh_gencontrol
	dh_md5sums
	dh_builddeb

binary: binary-indep binary-arch
.PHONY: build clean binary-indep binary-arch binary install debian/control
