#! /usr/bin/make -f
# Copyright 1999, Julian Gilbey.  May be redistributed under the terms
# of the GPL version 2 or later.
# Based on the sample debian/rules, GNU copyright 1997 to 1999 by Joey Hess
# and the original fvwm debian/rules file.
# patch-src technique from Brian Russo

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

# This is the debhelper compatability version to use.
TMP = debian/fvwm1

ifneq (,$(findstring debug,$(DEB_BUILD_OPTIONS)))
DEBUGFLAGS := CDEBUGFLAGS=-g CXXDEBUGFLAGS=-g
endif

# apply any patches
patch-src: 
	dh_testdir
	patch -p1 -N -t -b -z .prepatch < debian/i18n.patch
	touch patch-src

# restore to pre-patch state
unpatch-src:
	dh_testdir
	-for i in `grep ^--- debian/i18n.patch | \
	    sed -e 's/^--- fvwm1-1.24r\/\([^	 ]*\)[	 ].*$$/\1/'`; \
	    do [ -f $$i.prepatch ] && mv -f $$i.prepatch $$i; done
	-rm -f `find ./ -maxdepth 10 -xdev -name "*.rej"`
	rm -f patch-src

build: build-stamp
build-stamp: patch-src
	dh_testdir
	xmkmf
	$(MAKE) Makefiles
	$(MAKE) $(DEBUGFLAGS)
	touch build-stamp

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp
	$(MAKE) -f debian/rules unpatch-src
	[ ! -f Makefile ] || $(MAKE) clean
	-./Cleanme
	if [ -f debian/control.suggests ]; then \
	    mv debian/control.suggests debian/control; fi
	dh_clean
	rm -f debian/substvars debian/fvwm1.substvars

INSTALL = install -o root -g root
install: build
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs
	$(INSTALL) -m 755 fvwm/fvwm $(TMP)/usr/bin/fvwm1
	for file in FvwmAudio FvwmAuto FvwmBacker FvwmBanner FvwmClean    \
	  FvwmDebug FvwmIconBox FvwmIdent FvwmPager FvwmSave FvwmSaveDesk \
	  FvwmScroll FvwmWinList GoodStuff; \
	do \
	  $(INSTALL) -m 755 modules/$$file/$$file \
	    $(TMP)/usr/lib/fvwm/$$file; \
	done
	$(INSTALL) -m 644 debian/README.modules \
		$(TMP)/usr/lib/fvwm/README.modules;
#	install -d -g root -m 755 -o root \
#	  debian/tmp/usr/X11R6/include/X11/pixmaps
#	We don't want to install the icons any more; fvwm2 has them now.
#	for file in `ls fvwm_icons/*.xpm | sed s,fvwm_icons/,,`; \
#	do \
#	  install -g root -m 644 -o root fvwm_icons/$$file \
#	    debian/tmp/usr/X11R6/include/X11/pixmaps/$$file; \
#	done
	$(INSTALL) -d -g root -m 755 -o root $(TMP)/usr/share/lintian/overrides
	$(INSTALL) -m 644 debian/lintian-overrides \
		$(TMP)/usr/share/lintian/overrides/fvwm1
	$(INSTALL) -d -g root -m 755 -o root $(TMP)/usr/share/xsessions
	$(INSTALL) -m 644 debian/Fvwm1.desktop \
		$(TMP)/usr/share/xsessions/Fvwm1.desktop

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

# Build architecture-dependent files here.
binary-arch: build install
#	Build dependencies should handle this requirement
#	dh_testversion 2.0.76
	dh_testdir
	dh_testroot
#	dh_installdebconf	
	$(INSTALL) -m 644 debian/system.fvwmrc-menu \
		$(TMP)/etc/X11/fvwm/system.fvwmrc-menu
	dh_installdocs fvwm.README
	dh_installexamples sample.fvwmrc/*
	dh_installmenu
#	dh_installwm
#	dh_installemacsen
#	dh_installpam
#	dh_installinit
#	dh_installcron
#	dh_installmanpages
#	Do it manually, as the files have the wrong extensions
	$(INSTALL) -m 644 fvwm/fvwm.man $(TMP)/usr/share/man/man1/fvwm1.1
#	xpmroot is in fvwm2 now.
#	install -g root -m 644 -o root xpmroot/xpmroot.man \
#	  debian/tmp/usr/X11R6/man/man1/xpmroot.1x
#	Module manpages
	for file in FvwmAudio FvwmAuto FvwmBacker FvwmBanner FvwmClean \
	  FvwmDebug FvwmIconBox FvwmIdent FvwmPager FvwmSave FvwmSaveDesk \
	  FvwmScroll FvwmWinList GoodStuff; \
	do \
	  $(INSTALL) -m 644 modules/$$file/$$file.man \
	    $(TMP)/usr/share/man/man1/$${file}1.1; \
	done
#	dh_installinfo
#	dh_undocumented
	dh_desktop
	dh_installchangelogs ChangeLog
	dh_link
	dh_strip
	dh_compress
	dh_fixperms
#	dh_makeshlibs
	dh_installdeb
#	dh_perl
	dh_shlibdeps -XFvwmAudio
	dh_shlibdeps -XFvwmAudio -- \
	    -dSuggests $(TMP)/usr/lib/fvwm/FvwmAudio \
	    -O | sed -e 's/=.*librplay3/=librplay3/' -e 's/,.*//' \
	    >> debian/fvwm1.substvars
	dh_gencontrol
	dh_md5sums
	dh_builddeb

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

# Local variables:
# mode: makefile
# End:
