#!/usr/bin/make -f
################################################################################
# OpenOffice.org source package rules file
################################################################################
# Authors:
# Chris Halls <halls@debian.org>
# Rene Engelhard <rene@debian.org>
# Copyright 2002-2011 Software in the Public Interest, Inc.
# Licensed under the GNU General Public License, version 2.  See the file
# /usr/share/common-licenses/GPL or <http://www.gnu.org/copyleft/gpl.txt>.
################################################################################

clean:
	dh_testroot
	dh_testdir

	dh_clean

	$(MAKE) -f debian/rules control

control: debian/control
debian/control: $(wildcard debian/control.in) $(wildcard debian/mirror.1und1.de_debian_dists_sid_main_binary-amd64_Packages) debian/rules
	rm -f debian/control

	cat debian/control.in >> debian/control

	python debian/scripts/gentranspkgs.py < debian/mirror.1und1.de_debian_dists_sid_main_binary-amd64_Packages > debian/control.ooo
	cat debian/control.ooo >> debian/control
	rm -f debian/control.ooo

	# break old packages for the extensions. The dependency of them would
	# be fullfilled - but we don't have /usr/lib/openoffice/program/unopkg here
	# anymore
	perl -pi -e 's#(.*libreoffice-common.*)$$#\1\nBreaks: openoffice.org-presenter-console (<< 1:3.3.0-1), openoffice.org-wiki-publisher (<< 1:3.3.0-1), openoffice.org-sdbc-postgresql (<< 1:3.3.0-1), openoffice.org-report-builder (<< 1:3.3.0-1), openoffice.org-mysql-connector (<< 1:3.3.0-1), openoffice.org-presentation-minimizer (<< 1:3.3.0-1), docvert-openoffice.org (<< 1:3.3.0-7), openoffice.org-dmaths (<< 1:3.3.0-7), openoffice.org-voikko (<< 1:3.3.0-7)#' debian/control

	# got renamed in OOo 3.3
	perl -pi -e 's#(Package:.*hi$$)#\1-in#' debian/control

	# prevent loosing of bash-completion file when openoffice.org-common
	# rm_conffiles office.sh while it's still the file libreoffice has
	perl -pi -e 's#(Depends: libreoffice-common$$)#\1 \(>= 1:3.3.0~rc4-2\)#' debian/control


.DELETE_ON_ERROR: debian/control

build: control

install: build
	dh_testdir
	dh_testroot

	if [ -x /usr/bin/dh_prep ]; then dh_prep; else dh_clean -k; fi

	# add oo* compat links
	for i in base calc draw impress math writer; do \
		mkdir -p debian/openoffice.org-$$i/usr/bin && \
		ln -s /usr/bin/lo$$i debian/openoffice.org-$$i/usr/bin/oo$$i; \
	done
	ln -s /usr/bin/loweb debian/openoffice.org-writer/usr/bin/ooweb
	mkdir -p debian/openoffice.org-common/usr/bin
	ln -s /usr/bin/lofromtemplate debian/openoffice.org-common/usr/bin/oofromtemplate
	ln -s /usr/bin/libreoffice debian/openoffice.org-common/usr/bin/openoffice.org
	# and the same for the manpages
	for i in base calc draw impress math writer; do \
		mkdir -p debian/openoffice.org-$$i/usr/share/man/man1 && \
		ln -s /usr/share/man/man1/lo$$i.1.gz debian/openoffice.org-$$i/usr/share/man/man1/oo$$i.1.gz; \
	done
	ln -s /usr/share/man/man1/loweb.1.gz debian/openoffice.org-writer/usr/share/man/man1/ooweb.1.gz
	mkdir -p debian/openoffice.org-common/usr/share/man/man1
	ln -s /usr/share/man/man1/lofromtemplate.1.gz debian/openoffice.org-common/usr/share/man/man1/oofromtemplate.1.gz
	ln -s /usr/share/man/man1/libreoffice.1.gz debian/openoffice.org-common/usr/share/man/man1/openoffice.1.gz

binary-indep: install
	dh_testdir
	dh_testroot
	dh_installchangelogs -i
	dh_installdocs -i
	dh_link -i
	dh_lintian -i
	dh_compress -i
	dh_installdeb -i
	dh_gencontrol -i
	dh_md5sums -i
	dh_builddeb -i

binary-arch: build
	dh_testdir
	dh_testroot
	dh_installchangelogs -s
	dh_installdocs -s
	dh_link -s
	dh_lintian -s
	dh_compress -s
	dh_installdeb -s
	dh_gencontrol -s
	dh_md5sums -s
	dh_builddeb -s

binary: binary-indep binary-arch

.PHONY: control

# vim:set noet ai sts=8 sw=8 tw=0:
