#!/usr/bin/make -f

SHELL=/bin/bash

PACKAGE = argus-server

CFLAGS = -Wall -g

ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
CFLAGS += -O0
else
CFLAGS += -O2
endif

export DEB_HOST_GNU_TYPE  ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
export DEB_BUILD_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)

ifeq ($(DEB_BUILD_GNU_TYPE), $(DEB_HOST_GNU_TYPE))
  confflags += --build $(DEB_HOST_GNU_TYPE)
else
  confflags += --build $(DEB_BUILD_GNU_TYPE) --host $(DEB_HOST_GNU_TYPE)
endif

tmp = debian/argus-server

clean:
	dh_testroot
	[ ! -f Makefile ] || $(MAKE) -f Makefile.in realclean ALLDIRS="clients common server"
	dh_clean

build: config.status
	dh_testdir
	dh_installdirs
	$(MAKE)

config.status:
	./configure $(confflags) \
	--prefix=/usr \
	--libdir=/usr/lib \
	--exec-prefix=/usr \
	--sbindir=/usr/sbin \
	--bindir=/usr/bin \
	--sysconfdir=/etc \
	--mandir=/usr/share/man \
	--includedir=/usr/include CFLAGS="$(CFLAGS)"
	
binary-indep: build
	dh_testroot

binary-arch: build
	dh_testroot
	#
	# Build main argus package.
	#
	
	dh_installdirs

	chmod 750 $(tmp)/var/log/argus
	chgrp adm $(tmp)/var/log/argus
	
	#
	# Install documentation.
	#
	
	dh_installman

	dh_installchangelogs ChangeLog
	dh_installdocs

	dh_install
	
	dh_installppp

	dh_installinit --noscripts

	dh_installdebconf
	dh_installlogrotate

	dh_installdeb

	dh_strip
	
	dh_compress
	dh_fixperms -Xlog

	dh_lintian
	
	dh_md5sums

	dh_shlibdeps
	dh_gencontrol
	dh_builddeb

source diff:
	@echo >&2 'source and diff are obsolete - use dpkg-source -b'; false

binary: binary-indep binary-arch
