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

export DEB_BUILD_MAINT_OPTIONS=hardening=+pie,+bindnow

# --fail-missing for dh_install
# --link-doc for dh_installdocs
%:
	dh $@ --with autoreconf --fail-missing --link-doc=freeipmi-common

override_dh_auto_configure:
	: # suppress multiarch support for now
	dh_auto_configure -- --libdir=/usr/lib

override_dh_auto_install:
	dh_auto_install

	: # Clean up duplicate/unneeded copyright/installation files
	rm -f $(CURDIR)/debian/tmp/usr/share/doc/freeipmi/COPYING*
	rm -f $(CURDIR)/debian/tmp/usr/share/doc/freeipmi/DISCLAIMER*
	rm -f $(CURDIR)/debian/tmp/usr/share/doc/freeipmi/INSTALL
	rm -f $(CURDIR)/debian/tmp/usr/share/doc/freeipmi/ChangeLog

	: # We don't need the libtool metadata nor the init scripts
	rm $(CURDIR)/debian/tmp/usr/lib/libfreeipmi.la
	rm $(CURDIR)/debian/tmp/usr/lib/libipmiconsole.la
	rm $(CURDIR)/debian/tmp/usr/lib/libipmimonitoring.la
	rm $(CURDIR)/debian/tmp/usr/lib/libipmidetect.la
	rm $(CURDIR)/debian/tmp/etc/init.d/bmc-watchdog
	rm $(CURDIR)/debian/tmp/etc/init.d/ipmidetectd
	rm $(CURDIR)/debian/tmp/etc/init.d/ipmiseld

	: # chrpath -- operate only on files (not on still dangling symlinks)
	/usr/bin/find  $(CURDIR)/debian/*/usr/sbin -type f \
	| xargs grep -L '#!/bin/sh' \
	| xargs chrpath -d
	chrpath -d $(CURDIR)/debian/*/usr/lib/*.so.*

	: # assure no dir.gz
	rm -f $(CURDIR)/debian/tmp/usr/share/info/dir

	: # Use Debian specific init files with "matching" names
	dh_installinit -pfreeipmi-bmc-watchdog \
	 --name=bmc-watchdog
	dh_installinit -pfreeipmi-ipmidetect \
	 --name=ipmidetectd
	dh_installinit -pfreeipmi-ipmiseld \
	 --name=ipmiseld

override_dh_installlogrotate:
	dh_installlogrotate --name=bmc-watchdog

override_dh_fixperms-indep:
	dh_fixperms

	: # since it contains sensitive information
	chmod 640      $(CURDIR)/debian/freeipmi-common/etc/freeipmi/freeipmi.conf
	chown root:adm $(CURDIR)/debian/freeipmi-common/etc/freeipmi/freeipmi.conf

override_dh_installchangelogs:
	dh_installchangelogs --keep
