#!/usr/bin/make -f
# Made with the aid of debmake, by Christoph Lameter,
# based on the sample debian/rules file for GNU hello by Ian Jackson.

CFLAGS=-O2 -Wall -g

ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
CFLAGS=-O0 -Wall -g
endif

ifneq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS)))
STRIP=y
endif

package=xdelta

build:
	$(checkdir)
	CPPFLAGS=`glib-config --cflags` CFLAGS="${CFLAGS}" ./configure --prefix=/usr --mandir=\$${prefix}/share/man --infodir=\$${prefix}/share/info
	make
	touch build

autofiles:
	libtoolize --automake --copy --force
	aclocal
	automake
	autoheader
	autoconf
	rm -rf autom4te.cache

clean:
	$(checkdir)
	-rm -f build
	-make distclean
	-rm -f `find . -name "*~"`
	-rm -rf debian/tmp debian/files* core debian/substvars debian/libxdelta2 debian/libxdelta2-dev

binary-indep:	checkroot build
	$(checkdir)
# There are no architecture-independent files to be uploaded
# generated by this package.  If there were any they would be
# made here.

binary-arch:	checkroot build
	$(checkdir)
	-rm -rf debian/tmp
	install -d debian/tmp
	cd debian/tmp && install -d `cat ../dirs`
	cd debian && install -d libxdelta2-dev/usr/share/doc/libxdelta2-dev
	cd debian && install -d libxdelta2/usr/share/doc/libxdelta2
	install -m 644 debian/copyright debian/libxdelta2-dev/usr/share/doc/libxdelta2-dev/
	install -m 644 debian/copyright debian/libxdelta2/usr/share/doc/libxdelta2/
	install -m 644 debian/changelog debian/libxdelta2-dev/usr/share/doc/libxdelta2-dev/changelog.Debian
	install -m 644 debian/changelog debian/libxdelta2/usr/share/doc/libxdelta2/changelog.Debian
	make install prefix=`pwd`/debian/tmp/usr
	strip --remove-section=.comment --remove-section=.note --strip-unneeded debian/tmp/usr/lib/libxdelta.so.2.0.0
	strip --remove-section=.comment --remove-section=.note --strip-unneeded debian/tmp/usr/lib/libedsio.so.0.0.0
	# install -m 644 doc/xdelta.info debian/tmp/usr/info
	chmod a-x debian/tmp/usr/lib/*
	rm -f debian/tmp/usr/bin/edsio-comp
	install -m 644 debian/xdelta-config.man debian/tmp/usr/share/man/man1/xdelta-config.1
	debstd ChangeLog NEWS README AUTHORS
	rmdir debian/tmp/usr/include
	[ -n "$(STRIP)" ] || dh_strip
	dpkg-gencontrol -isp -pxdelta
	chown -R root.root debian/tmp
	chmod -R go=rX debian/tmp
	dpkg --build debian/tmp ..

define checkdir
	test -f debian/rules
endef

# Below here is fairly generic really

binary:		binary-indep binary-arch

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

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