#!/usr/bin/make -f
# -*- makefile -*-
#
# Expected debian/rules file that is used by the dpkg build procedure
#
#   $ git clone <nfs-ganesha>
#   $ cd nfs-ganesha/src
#   $ dpkg-buildpackage -uc -us
#
export PREFIX=/usr
export DESTDIR=$(CURDIR)/debian/tmp

export DEB_BUILD_MAINT_OPTIONS = hardening=+all

DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)

%:
	 dh $@ --sourcedirectory=src --builddirectory=build --parallel

override_dh_auto_configure:
	 mkdir build && cd build && cmake ../src \
		-DFSAL_DESTINATION=/usr/lib/${DEB_HOST_MULTIARCH}/ganesha \
		-DCMAKE_BUILD_TYPE=RelWithDebInfo \
		-DUSE_FSAL_NULL=OFF \
		-DUSE_FSAL_MEM=OFF \
		-DUSE_FSAL_ZFS=OFF \
		-DUSE_FSAL_XFS=OFF \
		-DUSE_FSAL_CEPH=ON \
		-DUSE_FSAL_RGW=ON \
		-DUSE_FSAL_GPFS=OFF \
		-DUSE_FSAL_PANFS=OFF \
		-DUSE_FSAL_GLUSTER=OFF \
		-DUSE_SYSTEM_NTIRPC=ON \
		-DUSE_9P_RDMA=OFF \
		-DUSE_LTTNG=OFF \
		-DUSE_ADMIN_TOOLS=OFF \
		-DUSE_GUI_ADMIN_TOOLS=OFF \
		-DUSE_DBUS=ON \
		-DUSE_FSAL_VFS=ON \
		-DUSE_FSAL_PROXY=OFF \
		-DUSE_9P=OFF \
		-DDISTNAME_HAS_GIT_DATA=OFF \
		-DRADOS_URLS=ON \
		-DUSE_RADOS_RECOV=ON

override_dh_auto_test:

override_dh_auto_clean:
	dh_clean

override_dh_install:
	mkdir -p debian/tmp/etc/ganesha/
	mkdir -p debian/tmp/lib/systemd/system
	mkdir -p debian/tmp/etc/default
	mkdir -p debian/tmp/etc/logrotate.d/
	mkdir -p debian/tmp/etc/dbus-1/system.d/
	mkdir -p debian/tmp/usr/lib/
	mkdir -p debian/tmp/usr/lib/ganesha/
	mkdir -p debian/tmp/usr/sbin/
	cp src/config_samples/ganesha.conf.example debian/tmp/etc/ganesha/ganesha.conf
	cp src/config_samples/vfs.conf debian/tmp/etc/ganesha/vfs.conf
	cp src/config_samples/ceph.conf debian/tmp/etc/ganesha/ceph.conf
	cp src/config_samples/rgw.conf debian/tmp/etc/ganesha/rgw.conf
	cp src/config_samples/rgw_bucket.conf debian/tmp/etc/ganesha/rgw_bucket.conf
	cp src/config_samples/logrotate_ganesha debian/tmp/etc/logrotate.d/nfs-ganesha
	cp src/scripts/systemd/nfs-ganesha.service.debian8 src/scripts/systemd/nfs-ganesha.service
	cp src/scripts/systemd/nfs-ganesha-lock.service.debian8 src/scripts/systemd/nfs-ganesha-lock.service
	cp src/scripts/systemd/nfs-ganesha* debian/tmp/lib/systemd/system/
	cp src/scripts/systemd/sysconfig/nfs-ganesha debian/tmp/etc/default/
	cp src/scripts/ganeshactl/org.ganesha.nfsd.conf debian/tmp/etc/dbus-1/system.d/nfs-ganesha-dbus.conf
	install -m 755 src/scripts/nfs-ganesha-config.sh debian/tmp/usr/lib/ganesha/
	make -C build install && dh_install --sourcedir=./src
