#!/usr/bin/make -f
# Sample debian/rules file; from GNU Hello,  Copyright 1994,1995 by Ian Jackson.

package = debdelta

D = debian/tmp

docdir = $(D)/usr/share/doc/$(package)
mandir = $(D)/usr/share/man/man1/

CC = gcc
CFLAGS = -g -Wall
INSTALL_PROGRAM = install

ifeq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
  CFLAGS += -O2
endif
ifeq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS)))
  INSTALL_PROGRAM += -s
endif

build:
	$(checkdir)
	$(MAKE) CC="$(CC)" CFLAGS="$(CFLAGS)" LDFLAGS="-lz" minigzip
	touch build

clean:
	$(checkdir)
	rm -f build *~ */*~ debian/files* debian/substvars
	rm -f minigzip
	rm -rf $(D)

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 $(D)
	install -d $(D)/DEBIAN $(D)/usr/bin $(docdir) $(mandir) $(D)/usr/lib/debdelta
	#install -m 755 debian/postinst debian/prerm $(D)/DEBIAN
	install -m 755 debian/postrm $(D)/DEBIAN/
	$(INSTALL_PROGRAM)  minigzip $(D)/usr/lib/debdelta/minigzip
	cp  debdelta $(D)/usr/bin/debdelta
	install -d $(D)/etc/debdelta
	cp etc/sources.conf $(D)/etc/debdelta/sources.conf
	echo /etc/debdelta/sources.conf >> $(D)/DEBIAN/conffiles
	chmod +x  $(D)/usr/bin/debdelta
	ln -s debdelta  $(D)/usr/bin/debpatch
	ln -s debdelta  $(D)/usr/bin/debdeltas
	ln -s debdelta  $(D)/usr/bin/debdelta-upgrade
	cp  FAQ README debian/copyright debian/changelog $(docdir)
	cd $(docdir) && gzip -9 changelog README FAQ
	cp *.1 $(mandir)
	gzip -9 $(mandir)/*.1 
	dpkg-shlibdeps $(D)/usr/lib/debdelta/minigzip
	dpkg-gencontrol -isp
	chown -R root:root $(D)
	chmod -R u+w,go=rX $(D)
	dpkg --build $(D) ..

define checkdir
	test -f debdelta -a -f debian/rules
endef

binary: binary-indep binary-arch

checkroot:
	$(checkdir)
	test $$(id -u) = 0

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