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

# mega rule -- Joey knows how to do the rest
%:
	dh $@ --with autotools_dev

override_dh_clean:
	dh_clean

	-rm debian/freeipmi-ipmidetectd.debhelper.log

	: # Remove pulled in default file for watchdog
	-rm $(CURDIR)/debian/freeipmi-bcm-watchdog.bmc-watchdog.default

	: # Remove some other generated files
	-rm  doc/freeipmi-faq.info doc/stamp-vti doc/version-faq.texi

override_dh_auto_install:
	dh_auto_install
	: # Fix badly installed upstream
	mv $(CURDIR)/debian/tmpvar  $(CURDIR)/debian/tmp/var
	chmod 644 $(CURDIR)/debian/tmp/etc/ipmi_monitoring_sensors.conf
	: # since it containts sensitive information
	chmod 640 $(CURDIR)/debian/tmp/etc/freeipmi.conf
	chown root.adm $(CURDIR)/debian/tmp/etc/freeipmi.conf
	: # Clean up duplicate/unneeded copyright/installation files
	rm $(CURDIR)/debian/tmp/usr/share/doc/freeipmi/COPYING*
	rm $(CURDIR)/debian/tmp/usr/share/doc/freeipmi/DISCLAIMER*
	rm $(CURDIR)/debian/tmp/usr/share/doc/freeipmi/INSTALL*
	rm $(CURDIR)/debian/tmp/usr/share/doc/freeipmi/ChangeLog*

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

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


	: # Copy default file for bmc-watchdog
	cp $(CURDIR)/debian/tmp/etc/sysconfig/bmc-watchdog \
		$(CURDIR)/debian/freeipmi-bcm-watchdog.bmc-watchdog.default

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

override_dh_installchangelogs:
	dh_installchangelogs ChangeLog ChangeLog.0

	#dh_installdocs --link-doc=freeipmi-common
