#!/usr/bin/make -f
# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

pwmnd                      := wmnd
pwmnd_snmp                 := wmnd-snmp

define dh_auto_command
        $(subst override_,,$1) --verbose --buildsystem=autoconf --parallel \
                               --package="$2"                              \
                               --builddirectory="BUILD-$2"                 \
                               --tmpdir="debian/$2"                        \
                               -O --destdir="debian/$2"  $3
endef

DEB_BUILD_MAINT_OPTIONS := hardening=+all
DEB_CFLAGS_MAINT_APPEND := $(shell getconf LFS_CFLAGS) -Wall
DPKG_EXPORT_BUILDFLAGS  := 1

include /usr/share/dpkg/buildflags.mk

include /usr/share/dpkg/architecture.mk

ifneq ($(DEB_HOST_GNU_TYPE),$(DEB_BUILD_GNU_TYPE))
  CC  := $(DEB_HOST_GNU_TYPE)-gcc
else
  CC  := gcc
endif

CONFFLAGS                 :=  --enable-trend
ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS))$(findstring nostrip,$(DEB_BUILD_OPTIONS)))
CONFFLAGS                 += --enable-debug
endif

%:
	dh $@

override_dh_auto_configure:
	$(call dh_auto_command,$@,$(pwmnd),                                        \
	                 -- $(CONFFLAGS)                                           \
	                 --docdir="\$${prefix}/share/doc/$(pwmnd)"                 \
	                 --enable-drivers="linux_proc"                             )

	$(call dh_auto_command,$@,$(pwmnd_snmp),                                   \
	                 -- $(CONFFLAGS)                                           \
	                 --docdir="\$${prefix}/share/doc/$(pwmnd_snmp)"            \
	                 --enable-drivers="linux_proc generic_snmp"                \
	                 LIBS="$(LIBS) -lsnmp"                                     )


override_dh_auto_build override_dh_auto_clean override_dh_auto_install:
	$(call dh_auto_command,$@,$(pwmnd))

	$(call dh_auto_command,$@,$(pwmnd_snmp))

override_dh_installchangelogs:
	dh_installchangelogs -k NEWS.rst
