#!/usr/bin/make -f
# Derived from dh_make example.

#export DH_VERBOSE=1
#export DH_COMPAT=4

include /usr/share/dpatch/dpatch.make

tmp := $(CURDIR)/debian/openvas-plugins

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

build: build-stamp
build-stamp: config.status
	dh_testdir
	$(MAKE) 
	touch $@

config.status: configure patch
	CFLAGS="$(CFLAGS)" ./configure --sysconfdir=/etc --prefix=/usr \
          --mandir='$${prefix}/share/man' --localstatedir=/var/run \
          --with-fetchcmd=wget  --libdir=/var/lib

clean: clean-patched unpatch
clean-patched: patch-stamp
	dh_testdir
	dh_testroot
	touch openvas.tmpl
	[ ! -f Makefile ] || $(MAKE) distclean
	dh_clean build-stamp

install: build-stamp
	dh_testdir
	dh_testroot
	dh_clean -k
	$(MAKE) install prefix=$(tmp)/usr sysconfdir=$(tmp)/etc localstatedir=$(tmp)/var/run libdir=$(tmp)/var/lib
# After we install we audit the plugins available
	( cd audit &&  sh audit-plugins $(tmp)/var/lib/openvas/plugins )
# If the audit passes we continue
	rm -rf $(tmp)/var/run 

binary-indep:
# Nothing to do, no arch-indep packages here.

binary-arch: install
	dh_testdir
	dh_testroot
	dh_installdebconf
	dh_installdocs docs/plugins_api.txt
	dh_installexamples extra/update-openvas-plugins \
		extra/describe-openvas-plugin
	dh_installchangelogs 
ifeq "$(findstring nostrip,$(DEB_BUILD_OPTIONS))" ""
	dh_strip
	strip --strip-unneeded --remove-section=.comment --remove-section=.note \
          $(tmp)/var/lib/openvas/plugins/*.nes
endif
	dh_compress
	dh_fixperms
	chmod -x $(tmp)/var/lib/openvas/plugins/*.nes
	dh_installdeb
	dpkg-shlibdeps -Tdebian/openvas-plugins.substvars \
          $(tmp)/var/lib/openvas/plugins/*.nes
	dh_gencontrol
	dh_md5sums
	dh_builddeb

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