#!/usr/bin/make -f

PKG_VERSION = 5.52
DEB_TARBALL = unzip552.tar.gz
DEB_TAR_SRCDIR = unzip-$(PKG_VERSION)
DEB_DH_INSTALL_SOURCEDIR = build-tree/$(DEB_TAR_SRCDIR)

CC = gcc
CFLAGS = -s -Wall
DEFINES = -DACORN_FTYPE_NFS -DWILD_STOP_AT_DIR

include /usr/share/cdbs/1/rules/tarball.mk
include /usr/share/cdbs/1/rules/debhelper.mk
include /usr/share/cdbs/1/rules/dpatch.mk

ifeq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
    CFLAGS += -O2
endif
ifneq (,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
    NUMJOBS = $(patsubst parallel=%,%,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
    MAKEFLAGS += -j$(NUMJOBS)
endif

# Damnit... dpatch.mk does not include a way to add dpatch options,
# thus we have to do a trick in order to apply patches to our subdirectory ...
export PATH := $(CURDIR)/debian:$(PATH)
debian/stamp-patched deapply-dpatches: debian/dpatch
debian/dpatch:
	echo '#!/bin/sh' >$@
	echo 'exec /usr/bin/dpatch -d $(DEB_DH_INSTALL_SOURCEDIR) $$*' >>$@
	chmod a+x $@

clean::
	rm -f debian/dpatch *.cdbs-config_list debian/stamp-*

common-build-arch common-build-indep:: debian/stamp-build
debian/stamp-build:
	cd $(DEB_DH_INSTALL_SOURCEDIR) && \
	$(MAKE) -f unix/Makefile LF2="" CC="$(CC)" \
		CF="$(CFLAGS) -I. $(DEFINES)" unzips
	touch $@

binary-post-install/unzip::
	rm -rf debian/unzip/usr/share/doc
	uudecode debian/zip-26.b64 -o debian/unzip/usr/share/icons/hicolor/26x26/mimetypes/application-zip.png
	uudecode debian/zip-48.b64 -o debian/unzip/usr/share/icons/hicolor/48x48/mimetypes/application-zip.png
	uudecode debian/zip-64.b64 -o debian/unzip/usr/share/icons/hicolor/64x64/mimetypes/application-zip.png
