#!/usr/bin/make -f
# This is fairly complicated since it can be called either to build the
# source package, or to build a kernel module package.

#export DH_VERBOSE=1

clean:
	dh_testdir
	dh_testroot
	
	$(MAKE) clean PROG_EXTRA=sensord
	
	rm -f debian/lm-sensors-*.README.Debian
	
	rm -f *-stamp
	dh_clean 


# Build everything that goes into the Debian package.  Use recursive make
# invocations to build all of the interesting components.
build: build-stamp
build-stamp:
	dh_testdir

	# binary programs and librairies
	$(MAKE) user \
		PREFIX=/usr \
		PROG_EXTRA=sensord \
		EXLDFLAGS=""

	touch build-stamp

install: install-stamp
install-stamp: build
	dh_testdir 
	dh_testroot 
	dh_clean -s -k 
	dh_installdirs -s

	$(MAKE) user_install DESTDIR=$(CURDIR)/debian/tmp PREFIX=/usr MANDIR=/usr/share/man \
		PROG_EXTRA=sensord EXLDFLAGS=""

	# Install extra files as needed
	install -m 0644 debian/sensord.logcheck debian/sensord/etc/logcheck/ignore.d.server/sensord
	install -m 0644 debian/sensord.logcheck debian/sensord/etc/logcheck/ignore.d.workstation/sensord
	install -m 0644 etc/sensors.conf.eg debian/lm-sensors/usr/share/lm-sensors/sensors.conf.eg

	# Install isadump only if it has been built (on i386 archs only)
	if [ -x prog/dump/isadump ] ; then \
	        cp -f prog/dump/isadump debian/lm-sensors/usr/sbin ; \
		mkdir -p debian/lm-sensors/usr/share/man/man8 ; \
	        cp -f prog/dump/isadump.8 debian/lm-sensors/usr/share/man/man8 ; \
	fi
	# Install isaset only if it has been built (on i386 archs only)
	if [ -x prog/dump/isaset ] ; then \
	        cp -f prog/dump/isaset debian/lm-sensors/usr/sbin ; \
		mkdir -p debian/lm-sensors/usr/share/man/man8 ; \
	        cp -f prog/dump/isaset.8 debian/lm-sensors/usr/share/man/man8 ; \
	fi

	dh_install -s --sourcedir=debian/tmp

	touch install-stamp


# Build architecture-independent files here.
binary-indep: build install
# We have nothing to do by default.

# Build architecture-dependant files that arn't kernel modules here.
binary-arch: build install
	dh_testdir 
	dh_testroot
	dh_installchangelogs -s CHANGES
	dh_installdocs -s -XCVS
	dh_installexamples -s -XCVS -XModule.mk
	dh_installmodules -s --name=i2c
	dh_installinit -psensord
	dh_installinit -plm-sensors --no-start -- start 47 S .  # Should start after modutils (20) and mountnfs (45)
	dh_installman -s
	dh_link -s
	dh_strip -s
	dh_compress -s -X.pl
	dh_fixperms -s
	dh_perl -s
	dh_makeshlibs -s -V
	dh_installdeb -s
	dh_shlibdeps -s
	dh_gencontrol -s
	dh_md5sums -s
	dh_builddeb -s

binary: binary-arch binary-indep
.PHONY: clean build install binary-indep binary-arch binary
