#! /usr/bin/make -f

# Parsing of DEB_BUILD_OPTIONS flags.
# Note that nostrip is handled automatically by debhelper.
CFLAGS := -g -Wall
ifneq (,$(filter noopt,$(DEB_BUILD_OPTIONS)))
    CFLAGS += -O0
else
    CFLAGS += -O2
endif
ifneq (,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
    NUMJOBS = $(patsubst parallel=%,%,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
    MAKEFLAGS += -j$(NUMJOBS)
endif

# Temporary root
DEBTMP := $(CURDIR)/debian/tmp

build: build-stamp
build-stamp:
	dh_testdir
	CFLAGS="$(CFLAGS)" ./configure \
		--mandir='$${prefix}/share/man' \
		--enable-nfsv41 \
		--disable-tirpc \
		--with-tcp-wrappers
	$(MAKE) $(MAKEFLAGS)
	touch build-stamp

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp
	rm -rf $(DEBTMP)
	[ ! -f Makefile ] || $(MAKE) distclean
	dh_clean

binary-indep: build
binary-arch: build
	dh_testdir
	dh_testroot
	dh_prep
	dh_installdirs
	mkdir $(DEBTMP)
	$(MAKE) DESTDIR='$(DEBTMP)' install
	dh_install
	dh_installdocs -A
	dh_installdocs -pnfs-common debian/README.Debian.nfsv4
	install -m 0755 debian/nfs-common.init debian/nfs-common/etc/init.d/nfs-common
	install -m 0755 debian/nfs-kernel-server.init debian/nfs-kernel-server/etc/init.d/nfs-kernel-server
	dh_installman
	dh_link
	dh_installchangelogs ChangeLog
	dh_lintian
	dh_strip
	dh_compress
	dh_fixperms
	chmod u+s debian/nfs-common/sbin/mount.nfs
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

binary: binary-indep binary-arch
.PHONY: build clean binary-indep binary-arch binary
