#!/usr/bin/make -f
# Sample debian/rules that uses debhelper.
# GNU copyright 1997 to 1999 by Joey Hess.

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

# for quilt
include /usr/share/quilt/quilt.make


CFLAGS = -fsigned-char -Wall
ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
        CFLAGS += -O0
else
        CFLAGS += -O2
endif
ifeq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS)))
        INSTALL_PROGRAM = install -s
else
        INSTALL_PROGRAM = install
endif


configure: configure-stamp
configure-stamp: debian/stamp-patched
	dh_testdir
	./autogen.sh
	CFLAGS="${CFLAGS}" ./configure --prefix=/usr		 \
				--sysconfdir=/etc		 \
				--mandir=/usr/share/man		 \
				--with-initscriptdir=/etc/init.d \
				--with-docdir=/usr/share/doc/smartmontools

	touch configure-stamp


build: build-stamp
build-stamp: configure-stamp
	dh_testdir

	# Add here commands to compile the package.
	$(MAKE)

	#/usr/bin/docbook-to-man debian/smartmontools.sgml > smartmontools.1

	touch build-stamp

clean: unpatch
	dh_testdir
	dh_testroot
	# rm -f debian/logcheck.logcheck.ignore.*

	# Add here commands to clean up after the build process.
	-$(MAKE) distclean
	rm -f build-stamp configure-stamp \
	      Makefile.in examplescripts/Makefile.in aclocal.m4 configure
	dh_clean

install: build
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs

	$(MAKE) DESTDIR=$(CURDIR)/debian/smartmontools \
		INSTALL_PROGRAM="${INSTALL_PROGRAM}" install-sbinPROGRAMS
	$(MAKE) DESTDIR=$(CURDIR)/debian/smartmontools \
		install-sysconfDATA
	$(MAKE) DESTDIR=$(CURDIR)/debian/smartmontools \
		install-man
	$(MAKE) DESTDIR=$(CURDIR)/debian/smartmontools \
		examplesdir='$$(docdir)/examples'      \
		-C examplescripts/ install-examplesSCRIPTS install-examplesDATA

	install -D -m 755 debian/smartmontools-bug \
		$(CURDIR)/debian/smartmontools/usr/share/bug/smartmontools
	install -D -m 755 debian/smartd-runner \
		$(CURDIR)/debian/smartmontools/usr/share/smartmontools/smartd-runner
	install -D -m 755 debian/10mail \
		$(CURDIR)/debian/smartmontools/etc/smartmontools/run.d/10mail

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

# Build architecture-dependent files here.
binary-arch: build install
	dh_testdir
	dh_testroot
#	dh_installdebconf	
	dh_installdocs
	dh_installexamples
	dh_installmenu
	dh_installlogrotate
#	dh_installemacsen
#	dh_installpam
#	dh_installmime
	dh_installinit
	dh_installcron
	dh_installman
	dh_installinfo
#	dh_installlogcheck
#	dh_undocumented
	dh_installchangelogs CHANGELOG
	dh_link
	dh_strip
	dh_compress
	dh_fixperms
#	dh_makeshlibs
	dh_installdeb
#	dh_perl
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

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