#!/usr/bin/make -f

package = unzip
docdir = debian/tmp/usr/share/doc/$(package)
history = History.552

CC = gcc
CFLAGS = -g -Wall $$(getconf LFS_CFLAGS)
DEFINES = -DACORN_FTYPE_NFS -DWILD_STOP_AT_DIR -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_MBCS 
INSTALL_PROGRAM = install

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

build: patch
	$(MAKE) -f unix/Makefile LF2="" \
		CC="$(CC)" CF="$(CFLAGS) -I. $(DEFINES)" unzips
	touch build

clean: unpatch
	rm -f build
	-$(MAKE) -f unix/Makefile clean
	rm -rf *~ debian/tmp debian/*~ debian/files* debian/substvars

binary-indep: build

binary-arch: build
	rm -rf debian/tmp
	install -d debian/tmp/DEBIAN $(docdir)
	cd debian/tmp && install -d usr/bin usr/man/man1
	$(MAKE) -f unix/Makefile install prefix=`pwd`/debian/tmp/usr \
		INSTALL_PROGRAM="$(INSTALL_PROGRAM)"
	cat debian/copyright.in LICENSE > $(docdir)/copyright
	cp debian/changelog $(docdir)/changelog.Debian
	cp -p History.* BUGS ToDo $(docdir)
	cd $(docdir) && gzip -9 changelog.Debian History.*
	ln -s $(history).gz $(docdir)/changelog.gz
	gzip -r9 debian/tmp/usr/man
	cd debian/tmp && mv usr/man usr/share
	dpkg-shlibdeps unzip
	dpkg-gencontrol -isp
	cd debian/tmp && \
		md5sum `find * -type f ! -regex "DEBIAN/.*"` > DEBIAN/md5sums
	chown -R root:root debian/tmp
	chmod -R go=rX debian/tmp
	dpkg --build debian/tmp ..

binary: binary-indep binary-arch

patch: patch-stamp
patch-stamp:
	dpatch apply-all

unpatch:
	dpatch deapply-all
	rm -rf patch-stamp debian/patched

.PHONY: binary binary-arch binary-indep clean
