#!/usr/bin/make -f
# -*- makefile -*-
#
# rules file for Sagan
# Written by Pierre Chifflier
#
# This file was originally written by Joey Hess and Craig Small.
# As a special exception, when this file is copied by dh-make into a
# dh-make output file, you may use that output file without restriction.
# This special exception was added by Craig Small in version 0.37 of dh-make.

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

export DEB_BUILD_MAINT_OPTIONS = hardening=+all
export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed -fPIE -pie

# No dbgsym generation.
export DEB_BUILD_OPTIONS=noddebs

DEB_HOST_ARCH ?= $(shell dpkg-architecture -qDEB_HOST_ARCH)

ifeq ($(DEB_HOST_ARCH),$(filter $(DEB_HOST_ARCH),i386 kfreebsd-i386 hurd-i386))
	CONFS:=--enable-system-strstr --with-postgresql-includes=/usr/include/postgresql --disable-libdnet LIBS="-lm -lestr -lee"
else
	CONFS:=--with-postgresql-includes=/usr/include/postgresql --disable-libdnet LIBS="-lm -lestr -lee"
endif

override_dh_auto_configure:
	dh_testdir
	dh_auto_configure -- $(CONFS) CFLAGS="$(CFLAGS) -fPIE"

override_dh_auto_install:
	dh_auto_install
	rm -rf debian/sagan/var/run/sagan
	rm -fr debian/sagan/usr/bin
	sed -i \
		-e 's|/usr/local/etc|/etc|' \
		-e 's|/var/run/sagan.fifo|/var/run/sagan/sagan.fifo|' \
		-e 's|^\(.*\)apc-emu.rules|#\1apc-emu.rules|' \
		-e 's|^\(.*\)bonding.rules|#\1bonding.rules|' \
		-e 's|^\(.*\)cacti-thold.rules|#\1cacti-thold.rules|' \
		-e 's|^\(.*\)ossec-mi.rules|#\1ossec-mi.rules|' \
		-e 's|^\(.*\)sonicwall.rules|#\1sonicwall.rules|' \
		debian/sagan/etc/sagan.conf

%:
	dh $@ --with autoreconf
