#!/usr/bin/make -f
# -*- makefile -*-
# Sample debian/rules that uses debhelper.
#
# This file was originally written by Joey Hess and Craig Small.
# As a special exception, when this file is copied by dh-make into a
# dh-make output file, you may use that output file without restriction.
# This special exception was added by Craig Small in version 0.37 of dh-make.
#
# Modified to make a template file for a multi-binary package with separated
# build-arch and build-indep targets  by Bill Allombert 2001

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

# This has to be exported to make some magic below work.
export DH_OPTIONS

CWD=$(shell pwd)
SRCPKGNAME=$(shell dpkg-parsechangelog | grep-dctrl -s "Source" -n -)
SRCPKGVERS=$(shell dpkg-parsechangelog | grep-dctrl -s "Version" -n - | sed -e 's,-.*,,g')
ORIGTARGZ=../$(SRCPKGNAME)_$(SRCPKGVERS).orig.tar.gz

XSD_ARCHIVE:=$(shell ls -1 xsd-*+dep.tar.bz2)
XSD_SRCDIR:=$(CWD)/$(shell ls -1 xsd-*+dep.tar.bz2 | sed -e 's,\.tar.*,,g')

# Renesas SH4 needs -mieee option.
ifeq ($(DEB_HOST_ARCH_CPU),sh4)
  export CXXFLAGS += -mieee
endif

maintainer_origtargz:	$(XSD_ARCHIVE)
	tar -czf $(ORIGTARGZ) *.tar*


maintainer_quilt:	$(CWD)/xsd-srcdir
$(CWD)/xsd-srcdir:	$(XSD_ARCHIVE) $(CWD)/debian/patches/_series
	tar -xjf $(XSD_ARCHIVE)
	test -d $(XSD_SRCDIR)
	mv $(XSD_SRCDIR) $(CWD)/xsd-srcdir
	mv $(CWD)/debian/patches/_series $(CWD)/debian/patches/series
	test -s $(CWD)/xsd-srcdir/build-0.3/system/config.sub -a -s /usr/share/misc/config.sub && \
		cp -vf /usr/share/misc/config.sub $(CWD)/xsd-srcdir/build-0.3/system/config.sub
	test -s $(CWD)/xsd-srcdir/build-0.3/system/config.guess -a -s /usr/share/misc/config.guess && \
		cp -vf /usr/share/misc/config.guess $(CWD)/xsd-srcdir/build-0.3/system/config.guess
	dh_quilt_patch
	grep -q "^xsd.git-0ca328cb9026aa53064a147226ef5b296426ea5f.patch" $(CWD)/debian/patches/series && tar -C $(CWD)/xsd-srcdir -xzvf $(CWD)/bug604256.tar.gz


%:
	dh --with quilt --skip-patches --parallel --sourcedirectory=$(CWD)/xsd-srcdir $@


override_dh_auto_configure:	maintainer_quilt
	mv $(CWD)/debian/patches/series $(CWD)/debian/patches/_series


override_dh_quilt_patch:	$(CWD)/debian/patches/_series


override_dh_auto_install:
	MAKEFLAGS="$$MAKEFLAGS install_prefix=$(CWD)/debian/xsdcxx/usr" $(MAKE) -C $(CWD)/xsd-srcdir -f makefile install
	mv $(CWD)/debian/xsdcxx/usr/share/doc/xsd $(CWD)/debian/xsdcxx/usr/share/doc/xsdcxx
	mv $(CWD)/debian/xsdcxx/usr/bin/xsd $(CWD)/debian/xsdcxx/usr/bin/xsdcxx
	mv $(CWD)/debian/xsdcxx/usr/share/man/man1/xsd.1 $(CWD)/debian/xsdcxx/usr/share/man/man1/xsdcxx.1
	rm -rf $(CWD)/debian/xsdcxx/usr/share/doc/libxsd
	find $(CWD)/debian/xsdcxx \( -name "COPYRIGHT*" -o -name "FLOSSE*" -o -name "LICENSE*" -o -name "GPL*" \) -exec rm -v {} \;


override_dh_quilt_unpatch:	override_dh_auto_clean
override_dh_auto_clean:
	rm -rf $(CWD)/xsd-srcdir $(CWD)/.pc
	-mv $(CWD)/debian/patches/series $(CWD)/debian/patches/_series
	test -f $(CWD)/debian/patches/_series


.PHONY: maintainer_origtargz maintainer_quilt override_dh_auto_configure override_dh_auto_clean
