#!/usr/bin/make -f
#	Debian rules file for gzip, requires the debhelper package.
#	Crafted by Bdale Garbee, bdale@gag.com, 5 November 2000

# Comment this to turn off debhelper verbose mode.
export DH_VERBOSE=1

DEB_BUILD_GNU_TYPE = $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)
DEB_HOST_GNU_TYPE = $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
ifneq ($(DEB_BUILD_GNU_TYPE),$(DEB_HOST_GNU_TYPE))
CONFARGS = --host=$(DEB_HOST_GNU_TYPE)
endif

ifeq ($(shell dpkg-architecture -qDEB_HOST_ARCH),amd64)
CFLAGS=-g -O2 -Wall -DUNALIGNED_OK
else
CFLAGS=-g -O2 -Wall
endif

reconf-stamp:
	cp -f /usr/share/misc/config.sub build-aux/config.sub
	cp -f /usr/share/misc/config.guess build-aux/config.guess
	autoreconf -v
	touch $@

configure: configure-stamp
configure-stamp: reconf-stamp
	dh_testdir
	mkdir -p build
	cd build && ../configure \
		--prefix=/usr --bindir=/bin \
		--infodir=`pwd`/debian/gzip/usr/share/info \
		--mandir=`pwd`/debian/gzip/usr/share/man $(CONFARGS)
	touch $@

configure-indep: configure-indep-stamp
configure-indep-stamp: reconf-stamp
	dh_testdir
	mkdir -p build-indep
	cd build-indep && ../configure --host=i686-w64-mingw32
	touch $@

build: build-arch build-indep

build-arch: build-stamp 
build-stamp: configure-stamp
	dh_testdir
	$(MAKE) -C build
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
ifeq ($(DEB_BUILD_GNU_TYPE),$(DEB_HOST_GNU_TYPE))
	$(MAKE) -C build check
endif
endif
	touch $@

build-indep: build-indep-stamp
build-indep-stamp: configure-indep-stamp
	dh_testdir
	$(MAKE) -C build-indep
	touch $@

clean:
	dh_testdir
	dh_testroot
	-rm -f build-stamp build-indep-stamp configure-stamp configure-indep-stamp reconf-stamp
	-rm -rf build build-indep
	dh_clean

install: build
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs
	$(MAKE) -C build install prefix=`pwd`/debian/gzip/usr bindir=`pwd`/debian/gzip/bin 

install-indep: build-indep
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs
	i686-w64-mingw32-strip build-indep/gzip.exe
	install -m 0755 build-indep/gzip.exe debian/gzip-win32/usr/share/win32/

binary-indep:	build-indep install-indep
	dh_testdir -i
	dh_testroot -i
	dh_installdocs -i README* TODO
	dh_installchangelogs -i ChangeLog
	dh_lintian -i
	dh_compress -i
	dh_fixperms -i
	dh_installdeb -i
	dh_gencontrol -i
	dh_md5sums -i
	dh_builddeb -i

binary-arch:	build install
	dh_testdir -s
	dh_testroot -s
	dh_installdocs -s README* TODO
	dh_installman *.1
	dh_installinfo -s doc/gzip.info
	dh_installchangelogs -s ChangeLog
	dh_link -s
	dh_lintian -s
	dh_strip -s
	dh_compress -s
	ln -s gunzip.1.gz debian/gzip/usr/share/man/man1/uncompress.1.gz
	ln -s zgrep.1.gz debian/gzip/usr/share/man/man1/zegrep.1.gz
	ln -s zgrep.1.gz debian/gzip/usr/share/man/man1/zfgrep.1.gz
	dh_fixperms -s
	# You may want to make some executables suid here.
	dh_makeshlibs -s
	dh_installdeb -s
	dh_shlibdeps -s
	dh_gencontrol -s
	dh_md5sums -s
	dh_builddeb -s

binary: binary-indep binary-arch
.PHONY: build clean binary-indep binary-arch binary install configure
.PHONY: build-indep install-indep configure-indep

