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

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

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

CPPFLAGS=`dpkg-buildflags --get CPPFLAGS`
# Work Arround: libgoogle-perftools-dev by depends on some architecures
ifneq (,$(findstring $(DEB_HOST_ARCH),i386 amd64 powerpc ppc64el arm64 armel armhf))
CPPFLAGS += -DUSE_TCMALLOC
LIBTCMALLOC = -ltcmalloc_minimal
endif
export CPPFLAGS
export LIBTCMALLOC

LDFLAGS += -latomic
LDFLAGS += `dpkg-buildflags --get LDFLAGS`
export LDFLAGS

CFLAGS += $(CPPFLAGS)
ifneq (,$(filter x-fpic,$(DEB_BUILD_OPTIONS)))
	CFLAGS += -fPIC
endif
export CFLAGS

%:
	dh $@

override_dh_auto_build-indep:
	$(MAKE)

override_dh_auto_test:
	$(MAKE) tests

override_dh_auto_install:
	install -d $(CURDIR)/debian/yrmcds/etc
	install -m 0644 $(CURDIR)/etc/yrmcds.conf $(CURDIR)/debian/yrmcds/etc/yrmcds.conf
	sed -i 's/^user = nobody/user = yrmcds/g' $(CURDIR)/debian/yrmcds/etc/yrmcds.conf
	sed -i 's/^group = nogroup/group = yrmcds/g' $(CURDIR)/debian/yrmcds/etc/yrmcds.conf
	install -d $(CURDIR)/debian/yrmcds/usr/sbin
	install $(CURDIR)/yrmcdsd $(CURDIR)/debian/yrmcds/usr/sbin/yrmcdsd

override_dh_systemd_enable:
	dh_systemd_enable --name=yrmcds
