#!/usr/bin/make -f

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

build:

%:
	dh $@ --with systemd,python2

# Be explicit about what should and should not be (re)started on install.
# cumulus-core and cumulus-support are started by 'path' services when the
# directory changes.
# cumulus-firstboot is a first-boot after image install service (and causes
# ssh to be stopped # when it is started).
# We don't ever want to restart firstboot, stopssh, or fastfailover because
# of their side effects.
# bootlog, and ztp should only run during bootup
# Because we do the override, we need to list all the services
# here as either start or --no-start.
#
# Unfortunately, there is some kind of bug in dh_systemd_start, such
# that it adds all the services as a start, if any of them are marked
# as start.  So this rule is now entirely empty, and the "appropriate"
# set is inline directly in postinst, preinst, and prerm.
override_dh_systemd_start:
	@echo Output of following is directly in postinst dh_systemd_start --name=aclinit --name=acltool --name=asic-monitor --name=bmcd --name=decode-syseeprom --name=ledmgrd --name=pwmd --name=smond --name=sysmonitor

override_dh_systemd_enable:
	dh_systemd_enable --name=cumulus-firstboot cumulus-firstboot.service
	dh_systemd_enable --name=stopssh stopssh.service
	dh_systemd_enable --name=cumulus-core cumulus-core.service
	dh_systemd_enable --name=cumulus-support cumulus-support.service
	dh_systemd_enable --name=ledmgrd ledmgrd.service
	dh_systemd_enable --name=smond smond.service
	dh_systemd_enable --name=asic-monitor asic-monitor.service
	dh_systemd_enable --name=acltool acltool.service
	dh_systemd_enable --name=pwmd pwmd.service
	dh_systemd_enable --name=aclinit aclinit.service
	dh_systemd_enable --name=decode-syseeprom decode-syseeprom.service
	dh_systemd_enable --name=cumulus-fastfailover cumulus-fastfailover.service
	dh_systemd_enable --name=bootlog bootlog.service
	dh_systemd_enable --name=ztp ztp.service
	dh_systemd_enable --name=sysmonitor sysmonitor.service
	dh_systemd_enable --name=cumulus-pstore cumulus-pstore.service
	dh_systemd_enable --no-enable --name=bmcd bmcd.service

override_dh_installinit:

override_dh_pysupport:

override_dh_auto_build:
	rm -rf man
	mkdir man
	for r in $$(ls rst/*.rst) ; do \
		dst_file="man/$$(basename $$r .rst)" ; \
		rst2man --halt=2 $$r > $$dst_file || { \
			echo "Error: problems genertaing man page: $$r" ; \
			exit 1 ; } ; \
	done
	dh_auto_build

DECOMMENT = debian/cumulus-tools/usr/cumulus/bin/ecmpcalc debian/cumulus-tools/usr/cumulus/bin/cl-route-check
override_dh_install:
	dh_install
	@for f in $(DECOMMENT) ; do ./decomment.py $$f $$f ; done
