#!/usr/bin/make -f
# Sample debian/rules that uses debhelper. GNU copyright 1997 by Joey Hess.

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

ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
        CONFIGUREARGS=--with-debug
else
        CONFIGUREARGS=
endif

CDEFS  := -D_FILE_OFFSET_BITS=64 -g
LDDEFS := -Wl,-z,defs -Wl,--as-needed

build: build-arch build-indep
build-arch: build-stamp
build-indep: build-stamp
build-stamp:
	dh_testdir

	if [ ! -f MCONFIG ]; then \
		USE_PAM=1 ./configure $(CONFIGUREARGS); \
		sed -e 's/^CFLAGS=\(.*\)$$/CFLAGS=$(CDEFS) \1 -fno-strict-aliasing/' \
		    -e 's/^LDFLAGS=\(.*\)$$/LDFLAGS=$(LDDEFS) \1/' \
			MCONFIG > MCONFIG.new; \
		mv MCONFIG.new MCONFIG; \
		echo CFLAGS+=-DUSE_PAM=1 \
			`dpkg-buildflags --get CFLAGS` \
			`dpkg-buildflags --get CPPFLAGS` >> MCONFIG; \
		echo LIBS+=-lpam `dpkg-buildflags --get LDFLAGS` >> MCONFIG; \
	fi
	$(MAKE)
	touch build-stamp

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp

	[ ! -f MCONFIG ] || $(MAKE) distclean

	dh_clean

install: build
	dh_testdir
	dh_testroot
	dh_prep
	dh_installdirs

	cp ftpd/ftpd debian/ftpd-ssl/usr/sbin/in.ftpd
	cp ftpd/ftpd.8 debian/ftpd-ssl/usr/share/man/man8/in.ftpd.8
	cp ftpd/*.5 debian/*.5 debian/ftpd-ssl/usr/share/man/man5
	ln -sf in.ftpd.8 debian/ftpd-ssl/usr/share/man/man8/ftpd.8
	cp debian/ftpchroot debian/ftpusers debian/ftpd-ssl/etc
	cp debian/pam.d/ftp debian/ftpd-ssl/etc/pam.d
	cp debian/openssl.cnf debian/ftpd-ssl/etc/ftpd-ssl/

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

# Build architecture-dependent files here.
binary-arch: build install
	dh_testdir
	dh_testroot
	dh_installdocs
	dh_installexamples
	dh_installchangelogs ChangeLog
	dh_strip
	dh_compress
	dh_fixperms
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

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