#!/usr/bin/make -f
# Sample debian/rules that uses debhelper.
# GNU copyright 1997 to 1999 by Joey Hess.

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

export DEB_BUILD_MAINT_OPTIONS = hardening=+all
DPKG_EXPORT_BUILDFLAGS = 1
include /usr/share/dpkg/buildflags.mk

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

ifeq ($(DEB_HOST_ARCH_OS),linux)
	CONFIGURE_ARGS += --with-selinux
	CONFIGURE_ARGS += --with-systemdenvfile=/etc/default/smartmontools
	CONFIGURE_ARGS += --with-systemdsystemunitdir=/usr/lib/systemd/system
	CONFIGURE_ARGS += --with-libsystemd=auto
endif

ifeq ($(DEB_HOST_ARCH_OS),kfreebsd)
	CFLAGS += -I/usr/include/freebsd
endif

CFLAGS += -fsigned-char -Wall

%:
	dh $@

override_dh_autoreconf:
	dh_autoreconf
	./autogen.sh

override_dh_auto_configure:
	CFLAGS="${CFLAGS}" CXXFLAGS="${CFLAGS}" \
	dh_auto_configure -- \
	    --build=$(DEB_BUILD_GNU_TYPE) \
	    --host=$(DEB_HOST_GNU_TYPE) \
	    --prefix=/usr \
	    --sysconfdir=/etc \
	    --mandir=/usr/share/man \
	    --with-initscriptdir=no \
	    --docdir=/usr/share/doc/smartmontools \
	    --with-attributelog=/var/lib/smartmontools/attrlog. \
	    --with-drivedbinstdir=/usr/share/smartmontools \
	    --with-drivedbdir=/var/lib/smartmontools/drivedb \
	    --with-exampledir=/usr/share/doc/smartmontools/examples/ \
	    --with-savestates=/var/lib/smartmontools/smartd. \
	    --with-smartdplugindir=/etc/smartmontools/smartd_warning.d \
	    --with-smartdscriptdir=/usr/share/smartmontools \
	    ${CONFIGURE_ARGS} \
	;

override_dh_installinit:
	dh_installinit --no-start

override_dh_install:
	dh_install
	$(RM) -v \
	    debian/smartmontools/lib/systemd/system/smartd.service \
	    debian/smartmontools/usr/lib/systemd/system/smartd.service \
	    debian/smartmontools/usr/share/doc/smartmontools/ChangeLog \
	    debian/smartmontools/usr/share/doc/smartmontools/COPYING \
	    debian/smartmontools/usr/share/doc/smartmontools/INSTALL \
	    debian/smartmontools/usr/share/doc/smartmontools/TODO \
	;

override_dh_fixperms:
	dh_fixperms
	chmod -c 755 \
	    $(CURDIR)/debian/smartmontools/etc/smartmontools/run.d/10mail \
	    $(CURDIR)/debian/smartmontools/usr/share/smartmontools/smartd-runner \
	;
