#!/usr/bin/make -f

DEB_UPSTREAM_VERSION := $(shell dpkg-parsechangelog|grep "^Version:"|cut -d" " -f2|rev|cut -d- -f2-|rev|cut -d':' -f2)
DEB_HOST_MULTIARCH   := $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)

%:
	dh $@ --with python2 --with autotools-dev

override_dh_install:
	strip --remove-section=.comment --remove-section=.note --strip-unneeded \
		debian/tmp/usr/lib/*/glusterfs/*/xlator/debug/trace.so
	strip --remove-section=.comment --remove-section=.note --strip-unneeded \
		debian/tmp/usr/lib/*/glusterfs/*/xlator/debug/error-gen.so
	strip --remove-section=.comment --remove-section=.note --strip-unneeded \
		debian/tmp/usr/lib/*/glusterfs/*/xlator/debug/io-stats.so
	find debian/tmp/usr/lib -type f -name \*.la -exec sed 's/^dependency_libs/#dependency_libs/g' -i {} \;
	dh_install --list-missing
	mv $(CURDIR)/debian/glusterfs-common/usr/share/glusterfs/scripts/gsync-sync-gfid \
		$(CURDIR)/debian/glusterfs-common/usr/lib/glusterfs/gsync-sync-gfid
	mv $(CURDIR)/debian/glusterfs-server/usr/sbin/gcron.py \
		$(CURDIR)/debian/glusterfs-server/usr/sbin/gcron
	mv $(CURDIR)/debian/glusterfs-server/usr/sbin/snap_scheduler.py \
		$(CURDIR)/debian/glusterfs-server/usr/sbin/snap_scheduler
	chmod +x $(CURDIR)/debian/glusterfs-common/usr/share/glusterfs/scripts/*.sh

override_dh_python2:
	dh_python2 usr/lib/$(DEB_HOST_MULTIARCH)/glusterfs/$(DEB_UPSTREAM_VERSION)/xlator/features/glupy/
	dh_python2 usr/lib/$(DEB_HOST_MULTIARCH)/glusterfs/python/syncdaemon/
	dh_python2 usr/lib/$(DEB_HOST_MULTIARCH)/glusterfs/glusterfind/
	dh_python2 usr/lib/python2.7/dist-packages/gluster/

override_dh_installinit:
	dh_installinit -pglusterfs-client --no-start --name mounting-glusterfs
	dh_installinit

override_dh_strip:
	dh_strip --dbg-package=glusterfs-dbg
