#!/usr/bin/make -f
# Sample debian/rules that uses debhelper.
# GNU copyright 1997 to 1999 by Joey Hess.
# Modified for arpwatch based on Adam Heath's and Ben Collins' work in 2001 by
# KELEMEN Peter <fuji@debian.org>

# Some local stuff.
package = arpwatch
DESTDIR = $(CURDIR)/debian/$(package)
LOCALDIR = $(CURDIR)/debian/local
CC = gcc
CFLAGS := -O2 -Wall
IEN := install -m755
IE := $(IEN) -s
ID := install -m644
ifneq (,$(findstring debug,$(DEB_BUILD_OPTIONS)))
	CFLAGS += -g
	ifneq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS)))
		IE := $(IEN)
	endif
endif
# DBS
TAR_DIR := arpwatch-2.1a13
include debian/scripts/dbs-build.mk
# dpkg-arch
ifeq (,$(DEB_BUILD_GNU_TYPE))
	include debian/scripts/dpkg-arch.mk
endif
# features
configure_args :=
configure_args += --prefix=/usr --mandir=\$${prefix}/share/man\
	--infodir=\$${prefix}/share/info
ifneq ($(DEB_HOST_GNU_TYPE),$(DEB_BUILD_GNU_TYPE))
	configure_args += --build=$(DEB_BUILD_GNU_TYPE)
endif

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

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

configure: configure-stamp
configure-stamp:
	dh_testdir
	# Add here commands to configure the package.

	touch configure-stamp

build: $(STAMP_DIR)/pre-build-stamp $(STAMP_DIR)/build-stamp

$(STAMP_DIR)/pre-build-stamp: $(unpacked) $(patched)
	dh_testdir
	cd $(BUILD_TREE) && chmod +w * && CFLAGS="$(CFLAGS)" CC="$(CC)" \
		./configure $(configure_args) --host=$(DEB_BUILD_GNU_TYPE)
	#$(MAKE) depend -C $(BUILD_TREE)
	touch $(STAMP_DIR)/pre-build-stamp

$(STAMP_DIR)/build-stamp:
	dh_testdir
	cd $(BUILD_TREE) && $(MAKE)
	touch $(STAMP_DIR)/build-stamp

##build: configure-stamp build-stamp
##build-stamp:
##	dh_testdir
##
##	# Add here commands to compile the package.
##	$(MAKE)
##	#/usr/bin/docbook-to-man debian/arpwatch.sgml > arpwatch.1
##
##	touch build-stamp

clean:
	dh_testdir
	rm -rf $(SOURCE_DIR) $(STAMP_DIR)
	perl debian/scripts/dh_split clean
##	dh_testroot
##	rm -f build-stamp configure-stamp
##
##	# Add here commands to clean up after the build process.
##	-$(MAKE) distclean
##
	dh_clean

install: build $(dh_mak_deps)
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs

	# Add here commands to install the package into debian/arpwatch.
	$(MAKE) DESTDIR=$(DESTDIR) install -C $(BUILD_TREE) #prefix=$(DESTDIR)

	$(ID) $(LOCALDIR)/ethercodes.dat $(DESTDIR)/usr/share/arpwatch

	chmod 0700 $(DESTDIR)/var/lib/arpwatch

	$(IEN) $(BUILD_TREE)/arp2ethers $(DESTDIR)/usr/sbin
	$(IEN) $(BUILD_TREE)/arpfetch $(DESTDIR)/usr/sbin
	$(IEN) $(BUILD_TREE)/bihourly $(DESTDIR)/usr/sbin
	$(IEN) $(BUILD_TREE)/massagevendor $(DESTDIR)/usr/sbin
	$(IEN) $(LOCALDIR)/dmassagevendor $(DESTDIR)/usr/sbin

	$(ID) $(BUILD_TREE)/arpwatch.8 $(DESTDIR)/usr/share/man/man8
	$(ID) $(BUILD_TREE)/arpsnmp.8 $(DESTDIR)/usr/share/man/man8
	$(ID) $(BUILD_TREE)/arp2ethers.8 $(DESTDIR)/usr/share/man/man8
	$(ID) $(BUILD_TREE)/arpfetch.8 $(DESTDIR)/usr/share/man/man8
	$(ID) $(BUILD_TREE)/bihourly.8 $(DESTDIR)/usr/share/man/man8
	$(ID) $(BUILD_TREE)/massagevendor.8 $(DESTDIR)/usr/share/man/man8
	$(ID) $(LOCALDIR)/dmassagevendor.8 $(DESTDIR)/usr/share/man/man8
	$(ID) $(LOCALDIR)/arpwatch.conf $(DESTDIR)/etc/arpwatch.conf

	cp $(LOCALDIR)/override $(DESTDIR)/usr/share/lintian/overrides/$(package)

	# Namespace cleanup here.

# 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_mak_deps)
	dh_testdir
	dh_testroot
#	dh_installdebconf	
	dh_installdocs
	dh_installexamples
	dh_installmenu
#	dh_installlogrotate
#	dh_installemacsen
#	dh_installpam
#	dh_installmime
	dh_installinit -- defaults 40
	dh_installcron
	dh_installman
	dh_installinfo
#	dh_undocumented
	dh_installchangelogs
	dh_link
ifeq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS)))
	dh_strip
endif
	dh_compress
	dh_fixperms --exclude=/var/lib/arpwatch
#	dh_makeshlibs
	dh_installdeb
#	dh_perl
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

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