#! /usr/bin/make -f

# Uncomment the following line to enable OpenSSL support. (If it's installed.)
#USE_SSL=yes

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

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

# support the DEB_BUILD_OPTIONS variable (partly stolen from gnome-utils)
CFLAGS := -O2
LDFLAGS :=
ifneq (,$(findstring debug,$(DEB_BUILD_OPTIONS)))
  CFLAGS += -g
  LDFLAGS += -g
endif
export CFLAGS
export LDFLAGS

CONFIGURE_FLAGS = \
	--with-shadow --enable-fhs --sysconfdir=/etc/netatalk		\
	--with-tcp-wrappers --mandir=/usr/share/man --prefix=/usr	\
	--enable-timelord --enable-overwrite				\
	--with-cracklib=/var/cache/cracklib/cracklib_dict
ifneq "x$(USE_SSL)" "xyes"
CONFIGURE_FLAGS += --without-ssl-dir
endif

configure: configure-stamp
configure-stamp:
	dh_testdir

	./configure $(CONFIGURE_FLAGS)

	touch configure-stamp

build: configure-stamp build-stamp
build-stamp:
	dh_testdir

	$(MAKE)

	touch build-stamp

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp configure-stamp

	-$(MAKE) distclean

	dh_clean

install: build
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs

	$(MAKE) install DESTDIR=$(CURDIR)/debian/tmp

	# Manually move a file that would get installed in the wrong place.
	mv debian/tmp/etc/netatalk/netatalk.conf debian/netatalk/etc/default/netatalk

	# Install logcheck files
	install -m 644 debian/logcheck/ignore.d.server debian/netatalk/etc/logcheck/ignore.d.server/netatalk
	install -m 644 debian/logcheck/violations.ignore.d debian/netatalk/etc/logcheck/violations.ignore.d/netatalk

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

binary-arch: build install
	dh_testdir
	dh_testroot
	dh_movefiles

	dh_installdocs
	dh_installexamples
	dh_installinit --update-rcd-params="defaults 50 50"
	dh_installman
	dh_undocumented
	dh_installchangelogs ChangeLog
	dh_link
	dh_strip
	dh_compress
	dh_fixperms
	dh_makeshlibs
	dh_installdeb
	dh_shlibdeps
	dh_perl
	dh_gencontrol
	dh_md5sums
	dh_builddeb

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