#!/usr/bin/make -f
#-*- makefile -*-
# Made with the aid of dh_make, by Craig Small
# Sample debian/rules that uses debhelper. GNU copyright 1997 by Joey Hess.
# Some lines taken from debmake, by Christoph Lameter.

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

export DH_COMPAT=1

ROOT=`pwd`/debian/tmp
ETCDIR=etc
# LOGROTATEDIR= $(ETCDIR)/logrotate.d
BUILD_DIR=`pwd`/debian/build
INSTALL_DIR=`pwd`/debian/tmp

INSTALLFLAGS= -c -D
INSTPGMFLAGS= -s
INSTBINFLAGS= -m 0755
INSTMANFLAGS= -m 0644
INSTCONFFLAGS= -m 0644

# export DH_COMPAT=2
# export DH_OPTIONS

configure: configure.in

Makefile: configure
	@echo "--- Configuring ---"
	cp config.guess debian/config.guess
	cp /usr/share/misc/config.guess .
	cp config.sub debian/config.sub
	cp /usr/share/misc/config.sub .
	./configure $(CONFFLAGS) --prefix=/usr --mandir=\$${prefix}/share/man --infodir=\$${prefix}/share/info
# Have to do the following to fix libtool's behaviour
	sed < libtool > libtool-2 \
	-e 's/^hardcode_libdir_flag_spec.*$$/hardcode_libdir_flag_spec=" -D__LIBTOOL_IS_A_FOOL__ "/' \
	-e '/^archive_cmds="/s/"$$/ \\$$deplibs"/'
	mv libtool-2 libtool
	chmod 755 libtool

build-stamp:
	@echo "--- Compiling ---"
	dh_testdir
	$(MAKE) 
	touch build-stamp

build: Makefile build-stamp

clean:
	@echo "--- Cleaning ---"
	dh_testdir
	dh_testroot
	rm -f build-stamp install-stamp
	rm -rf debian/build
	if [ -f debian/config.sub ]; then mv debian/config.sub . ; fi
	if [ -f debian/config.guess ]; then mv debian/config.guess . ; fi
	# Add here commands to clean up after the build process.
	-$(MAKE) clean
	-$(MAKE) distclean
	dh_clean

install: build
	@echo "--- Installing ---"
	dh_testdir
	dh_testroot
	dh_installdirs
	# Add here commands to install the package into debian/tmp.
	$(MAKE) install DESTDIR=`pwd`/debian/tmp
	touch install-stamp

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

# Build architecture-dependent files here.
binary-arch: build install powertweak-extra powertweakd powertweak-gtk

powertweakd:
	@echo "--- Building $@ ---"
	dh_testdir
	dh_testroot
	dh_installdebconf -p$@ -P$(BUILD_DIR)/$@
	dh_installdocs -p$@ -P$(BUILD_DIR)/$@
	dh_installmenu -p$@ -P$(BUILD_DIR)/$@
	dh_installinit -p$@ -P$(BUILD_DIR)/$@
	dh_installchangelogs ChangeLog -p$@ -P$(BUILD_DIR)/$@
	/usr/bin/install $(INSTALLFLAGS) $(INSTCONFFLAGS) debian/powertweakd.default $(BUILD_DIR)/$@/etc/default/powertweakd

# Install the logrotate config file
#	/usr/bin/install $(INSTALLFLAGS) $(INSTCONFFLAGS) debian/powertweakd.logrotate $(BUILD_DIR)/$@/$(LOGROTATEDIR)/powertweakd

# Install the powertweak man page
	/usr/bin/install $(INSTALLFLAGS) $(INSTCONFFLAGS) debian/powertweakd.8 $(BUILD_DIR)/$@/usr/share/man/man8/powertweakd.8

	dh_movefiles -p$@ -P$(BUILD_DIR)/$@

#	dh_link
	dh_strip	-p$@ -P$(BUILD_DIR)/$@
	dh_compress	-p$@ -P$(BUILD_DIR)/$@
	dh_fixperms	-p$@ -P$(BUILD_DIR)/$@
	dh_installdeb	-p$@ -P$(BUILD_DIR)/$@
	dh_shlibdeps	-p$@ -P$(BUILD_DIR)/$@
	dh_gencontrol	-p$@ -P$(BUILD_DIR)/$@
	dh_md5sums	-p$@ -P$(BUILD_DIR)/$@
	dh_builddeb	-p$@ -P$(BUILD_DIR)/$@

powertweak-extra:
	@echo "--- Building $@ ---"
	dh_testdir
	dh_testroot
	dh_installdocs -p$@ -P$(BUILD_DIR)/$@
	dh_installchangelogs ChangeLog -p$@ -P$(BUILD_DIR)/$@

	dh_movefiles -p$@ -P$(BUILD_DIR)/$@

	dh_strip	-p$@ -P$(BUILD_DIR)/$@
	dh_compress	-p$@ -P$(BUILD_DIR)/$@
	dh_fixperms	-p$@ -P$(BUILD_DIR)/$@
	dh_installdeb	-p$@ -P$(BUILD_DIR)/$@
	dh_shlibdeps	-p$@ -P$(BUILD_DIR)/$@
	dh_gencontrol	-p$@ -P$(BUILD_DIR)/$@
	dh_md5sums	-p$@ -P$(BUILD_DIR)/$@
	dh_builddeb	-p$@ -P$(BUILD_DIR)/$@

powertweak-gtk:
	@echo "--- Building $@ ---"
	dh_testdir
	dh_testroot
	dh_installdocs -p$@ -P$(BUILD_DIR)/$@
	dh_installmenu -p$@ -P$(BUILD_DIR)/$@
#	dh_installmanpages -p$@ -P$(BUILD_DIR)/$@ powertweakconfig.8
	/usr/bin/install $(INSTALLFLAGS) $(INSTCONFFLAGS) powertweak.xpm $(BUILD_DIR)/$@/usr/X11R6/include/X11/pixmaps/powertweak.xpm
	dh_installchangelogs ChangeLog -p$@ -P$(BUILD_DIR)/$@
	dh_movefiles -p$@ -P$(BUILD_DIR)/$@

# Install the gpowertweak man page
	/usr/bin/install $(INSTALLFLAGS) $(INSTCONFFLAGS) debian/powertweak-gtk.8x $(BUILD_DIR)/$@/usr/share/man/man8/gpowertweak.8x

	dh_undocumented -p$@ -P$(BUILD_DIR)/$@
	dh_strip	-p$@ -P$(BUILD_DIR)/$@
	dh_compress	-p$@ -P$(BUILD_DIR)/$@
	dh_fixperms	-p$@ -P$(BUILD_DIR)/$@
	dh_installdeb	-p$@ -P$(BUILD_DIR)/$@
	dh_shlibdeps	-p$@ -P$(BUILD_DIR)/$@
	dh_gencontrol	-p$@ -P$(BUILD_DIR)/$@
	dh_md5sums	-p$@ -P$(BUILD_DIR)/$@
	dh_builddeb	-p$@ -P$(BUILD_DIR)/$@

powertweak:
	@echo "--- Building $@ ---"
	dh_testdir
	dh_testroot
	dh_installdocs -p$@ -P$(BUILD_DIR)/$@
	dh_installchangelogs -p$@ -P$(BUILD_DIR)/$@
	dh_compress	-p$@ -P$(BUILD_DIR)/$@
	dh_fixperms	-p$@ -P$(BUILD_DIR)/$@
	dh_installdeb	-p$@ -P$(BUILD_DIR)/$@
	dh_gencontrol	-p$@ -P$(BUILD_DIR)/$@
	dh_md5sums	-p$@ -P$(BUILD_DIR)/$@
	dh_builddeb	-p$@ -P$(BUILD_DIR)/$@


source diff:                                                                  
	@echo >&2 'source and diff are obsolete - use dpkg-source -b'; false

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