#!/usr/bin/make -f
# Sample debian.rules file - Copyright 1994,1995 by Ian Jackson.
#
# Invoke each target with `./debian/rules <target>'.  All targets should be
# invoked with the package root as the current directory.

# The name of the package

L = sv
P = doc-linux-$(L)-html
T = doc-linux-$(L)-text
R = debian/$(P)
R2 = debian/$(T)

DIRECTORIES = \
        $(R) \
        $(R)/DEBIAN \
        $(R)/usr/share/doc/HOWTO/$(L)-html/mini \
        $(R2)/usr/share/doc/HOWTO/$(L)-txt/mini \
        $(R)/usr/share/doc/$(P) \
				$(R)/usr/share/doc-base \
				$(R2)/usr/share/doc/$(T)

$(DIRECTORIES):
	install -d -g root -o root -m 755 $@
	chmod g-s $@

# Builds the binary package.
build:
	$(checkdir)
	touch build

# Clean $(DIRECTORIES)
clean-dir:
	$(checkdir)
	rm -rf $(R) $(R2)

# Undoes the effect of `make -f rules build'.
clean: clean-dir
	$(checkdir)
	[ ! -f Makefile ] || make distclean cleanconfig
	rm -f debian/files* debian/substvars core debian/*~ HOWTO/*~ 
	rm -f HOWTO/mini/*~ build debian/*.debhelper

# Makes a binary package.
binary-indep: $(DIRECTORIES) checkroot build
	$(checkdir)


binary-arch: $(DIRECTORIES) checkroot build
	$(checkdir)

	cp HOWTO/*.sgml.gz $(R)/usr/share/doc/HOWTO/$(L)-html 
	gunzip $(R)/usr/share/doc/HOWTO/$(L)-html/*.gz
	(cd $(R)/usr/share/doc/HOWTO/$(L)-html && make -f $(CURDIR)/debian/sgml-Makefile html && rm -f *.sgml && $(CURDIR)/debian/sgml2docbase HOWTO/Swedish $(CURDIR)/$(R)/usr/share/doc-base)

	cp HOWTO/mini/*.sgml.gz $(R)/usr/share/doc/HOWTO/$(L)-html/mini 
	gunzip $(R)/usr/share/doc/HOWTO/$(L)-html/mini/*.gz
	(cd $(R)/usr/share/doc/HOWTO/$(L)-html/mini && make -f $(CURDIR)/debian/sgml-Makefile html && rm -f *.sgml && $(CURDIR)/debian/sgml2docbase HOWTO/Swedish/mini $(CURDIR)/$(R)/usr/share/doc-base)


	cp HOWTO/*.sgml.gz $(R2)/usr/share/doc/HOWTO/$(L)-txt 
	gunzip $(R2)/usr/share/doc/HOWTO/$(L)-txt/*.gz
	(cd $(R2)/usr/share/doc/HOWTO/$(L)-txt && make -f $(CURDIR)/debian/sgml-Makefile txt && rm -f *.sgml && gzip -9 *.txt)

	cp HOWTO/mini/*.sgml.gz $(R2)/usr/share/doc/HOWTO/$(L)-txt/mini 
	gunzip $(R2)/usr/share/doc/HOWTO/$(L)-txt/mini/*.gz
	(cd $(R2)/usr/share/doc/HOWTO/$(L)-txt/mini && make -f $(CURDIR)/debian/sgml-Makefile txt && rm -f *.sgml && gzip -9 *.txt)

	cp debian/changelog $(R)/usr/share/doc/$(P)/changelog.Debian
	cp debian/copyright $(R)/usr/share/doc/$(P)
	cp debian/changelog $(R2)/usr/share/doc/$(T)/changelog.Debian
	cp debian/copyright $(R2)/usr/share/doc/$(T)
	gzip -9 $(R)/usr/share/doc/$(P)/changelog.Debian
	gzip -9 $(R2)/usr/share/doc/$(T)/changelog.Debian

	chown -R root.root $(R)
	chown -R root.root $(R2)
	chmod -R g-ws $(R)
	chmod -R g-ws $(R2)

#	dh_dhelp -p$(P) -P$(R)

	dh_installdeb -p$(P) -P$(R)
	dh_installdeb -p$(T) -P$(R2)
	dh_installdocs -p$(P) -P$(R)
	dh_installdocs -p$(T) -P$(R2)
	dh_md5sums -p$(P) -P$(R)
	dh_md5sums -p$(T) -P$(R2)
	
	dpkg-gencontrol -p$(P) -P$(R) -isp
	dpkg-gencontrol -p$(T) -P$(R2) -isp
	dpkg --build $(R) ..
	dpkg --build $(R2) ..

define checkdir
	test -f debian/rules
endef

# Below here is fairly generic really

binary:		binary-indep binary-arch

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

checkroot:
	$(checkdir)
	test root = "`whoami`"

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