#!/usr/bin/make -f
# -*- makefile -*-

# The package build supports three optional features. To enable/disable them,
# modify DEB_BUILD_OPTIONS accordingly:
#  * PAM support        default: ON     disable: DEB_BUILD_OPTIONS=nopam
#  * SELinux support    default: ON     disable: DEB_BUILD_OPTIONS=noselinux
#  * audit support      default: OFF    enable:  DEB_BUILD_OPTIONS=withaudit
#
# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1


# Set system type (Linux, HURD, etc.)
DEB_HOST_ARCH_OS = $(shell dpkg-architecture -qDEB_HOST_ARCH_OS)

# Enable cross-compiling support
DEB_HOST_GNU_TYPE  = $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
DEB_BUILD_GNU_TYPE = $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)
ifneq ($(DEB_HOST_GNU_TYPE),$(DEB_BUILD_GNU_TYPE))
export CC=$(DEB_HOST_GNU_TYPE)-gcc
endif

# Standard compiler flags 
CFLAGS += -Wall -Wno-unused -Wno-comment

# debug is disabled by default
ifneq (,$(findstring debug,$(DEB_BUILD_OPTIONS)))
  DEBUG_DEFS = -DDEBUGGING=1
else
  DEBUG_DEFS = -DDEBUGGING=0
endif
export DEBUG_DEFS

# PAM is enabled by default
ifeq (,$(findstring nopam,$(DEB_BUILD_OPTIONS)))
    PAM_DEFS = -DUSE_PAM
    PAM_LIBS = -lpam
    export PAM_DEFS PAM_LIBS
endif

# SELinux and audit are only available on Linux
ifeq ($(DEB_HOST_ARCH_OS), linux)
# SELinux is enabled by default
ifeq (,$(findstring noselinux,$(DEB_BUILD_OPTIONS)))
    SELINUX_DEFS = -DWITH_SELINUX
    SELINUX_LIBS = -lselinux
    export SELINUX_DEFS SELINUX_LIBS
endif

# audit is disabled by default
ifneq (,$(findstring withaudit,$(DEB_BUILD_OPTIONS)))
    AUDIT_DEFS = -DWITH_AUDIT
    AUDIT_LIBS = -laudit
    export AUDIT_DEFS AUDIT_LIBS
endif
endif # Linux


%:
	dh $@  --with=systemd


override_dh_auto_install:
	# Empty target to bypass the auto-detected install target in Makefile


override_dh_install:
	dh_install
	install -m 644 debian/crontab.main debian/cron/etc/crontab
	install -m 644 debian/placeholder debian/cron/etc/cron.d/.placeholder
	install -m 644 debian/placeholder debian/cron/etc/cron.hourly/.placeholder
	install -m 644 debian/placeholder debian/cron/etc/cron.daily/.placeholder
	install -m 644 debian/placeholder debian/cron/etc/cron.weekly/.placeholder
	install -m 644 debian/placeholder debian/cron/etc/cron.monthly/.placeholder


override_dh_installinit:
	dh_installinit -- start 89 2 3 4 5 .


override_dh_compress:
	dh_compress -Xexamples
