#!/usr/bin/make -f

include /usr/share/dpkg/pkg-info.mk

export DEB_BUILD_MAINT_OPTIONS = hardening=+all

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

override_dh_install:
	cp extras/run-gluster.tmpfiles $(CURDIR)/debian/glusterfs-server.tmpfile
	cp extras/systemd/glusterd.service $(CURDIR)/debian/glusterfs-server.glusterd.service
	cp extras/systemd/glustereventsd.service $(CURDIR)/debian/glusterfs-server.glustereventsd.service
	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
	strip --remove-section=.comment --remove-section=.note --strip-unneeded \
		debian/tmp/usr/lib/*/glusterfs/*/xlator/debug/sink.so
	strip --remove-section=.comment --remove-section=.note --strip-unneeded \
		debian/tmp/usr/lib/*/glusterfs/*/xlator/debug/delay-gen.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/$(DEB_HOST_MULTIARCH)/glusterfs/gsync-sync-gfid
	rm -f $(CURDIR)/debian/glusterfs-common/usr/lib/$(DEB_HOST_MULTIARCH)/glusterfs/python/syncdaemon/README.md

override_dh_systemd_enable:
	dh_systemd_enable --no-enable --name=glusterd
	dh_systemd_enable --no-enable --name=glustereventsd

override_dh_link:
	dh_link
	dh_link -pglusterfs-common \
		"usr/lib/$(DEB_HOST_MULTIARCH)/glusterfs/gsync-sync-gfid" \
		"usr/share/glusterfs/scripts/gsync-sync-gfid"

override_dh_python2:
	dh_python2 usr/lib/$(DEB_HOST_MULTIARCH)/glusterfs/$(DEB_VERSION_UPSTREAM)/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/$(DEB_HOST_MULTIARCH)/glusterfs/events/
	dh_python2 usr/lib/python2.7/dist-packages/gluster/

override_dh_makeshlibs:
	dh_makeshlibs --no-scripts
