#!/usr/bin/make -f

CPPFLAGS = $(shell dpkg-buildflags --get CPPFLAGS)
CFLAGS   = $(shell dpkg-buildflags --get CFLAGS)
LDFLAGS  = $(shell dpkg-buildflags --get LDFLAGS)

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

build: build-arch build-indep
build-arch: build-stamp
build-indep: build-stamp
build-stamp:
	dh_testdir
	dh_autoreconf
	./configure --prefix=/usr --mandir=/usr/share/man \
	  --with-ssl \
	  --with-ipv6 \
	  --with-perl=/usr/lib/$(DEB_HOST_MULTIARCH) \
	  --without-tcl \
	  --program-transform-name='s/epic/epic4/' \
	  --libexecdir=/usr/lib/epic4 --program-prefix=$(CURDIR)/debian/epic4
	$(MAKE) CFLAGS="$(CFLAGS) $(CPPFLAGS)" LDFLAGS="$(LDFLAGS)"
	touch build-stamp


build: build-stamp

clean:
	dh_testdir
	rm -f patch-stamp build-stamp install-stamp
	[ ! -f Makefile ] || $(MAKE) distclean
	dh_clean


install: build
	dh_testdir
	dh_testroot
	dh_prep
	dh_installdirs
	$(MAKE) install

binary-indep:
# Nothing to see, move along...


binary-arch: build install
	dh_testdir
	dh_testroot
	dh_installdocs -a doc/* -XCVS -Xdoc/epic.1
	dh_installmenu -a
ifndef DEBUG
	dh_strip -a
endif
	install -m 644 $(CURDIR)/debian/local \
		       $(CURDIR)/debian/epic4/usr/share/epic4/script/local
	dh_installchangelogs -a
	dh_installexamples -a
	install -m 644 debian/epic4.irc $(CURDIR)/debian/epic4/etc/epic4
	install -m 644 $(CURDIR)/debian/local \
		       $(CURDIR)/debian/epic4/usr/share/epic4/script/local
	rmdir $(CURDIR)/debian/epic4/usr/share/epic4/help/
	echo "irc.debian.org:6667" > $(CURDIR)/debian/epic4/etc/epic4/servers
	dh_link -a
	dh_compress -a
	dh_fixperms -a
	dh_makeshlibs -a
	dh_shlibdeps -a
	dh_gencontrol -a
	dh_installdeb -a
	dh_md5sums -a
	dh_builddeb -a


binary:		binary-indep binary-arch


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