#!/usr/bin/make -f
# -*- makefile -*-
# Sample debian/rules that uses debhelper.
# GNU copyright 1997 to 1999 by Joey Hess.
#
# $Id$
#

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

# Define package name variable for a one-stop change.
PACKAGE_NAME = PBPKG

# These are used for cross-compiling and for saving the configure script
# from having to guess our platform (since we know it already)
DEB_HOST_GNU_TYPE   ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
DEB_BUILD_GNU_TYPE  ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)

CFLAGS = -Wall -g

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

# Build both architecture dependent and independent
build: build-arch 

# Build architecture dependent
build-arch: build-arch-stamp

build-arch-stamp: 
	dh_testdir

	# Compile the package.
	$(MAKE)
	chmod 644 script*/*
	touch build-stamp

# Clean up
clean:
	dh_testdir
	dh_testroot
	rm -f build-arch-stamp #CONFIGURE-STAMP#
	# Clean temporary document directory
	rm -rf debian/doc-temp
	# Clean up.
	-$(MAKE) distclean
	rm -f config.log
ifneq "$(wildcard /usr/share/misc/config.sub)" ""
	cp -f /usr/share/misc/config.sub config.sub
endif
ifneq "$(wildcard /usr/share/misc/config.guess)" ""
	cp -f /usr/share/misc/config.guess config.guess
endif

	dh_clean

# Install architecture dependent and independent
install: install-arch

# Install architecture dependent
install-arch: build-arch
	dh_testdir
	dh_testroot
	dh_clean -k -s
	dh_installdirs -s

	# Install the package files into build directory:
	dh_install -s
	rm -rf $(CURDIR)/debian/$(PACKAGE_NAME)
	mkdir -p $(CURDIR)/debian/$(PACKAGE_NAME)/usr/bin
	mkdir -p $(CURDIR)/debian/$(PACKAGE_NAME)/usr/share/man/man1
	install -p -m 755 afio $(CURDIR)/debian/$(PACKAGE_NAME)/usr/bin
	install -p -m 644 afio.1 $(CURDIR)/debian/$(PACKAGE_NAME)/usr/share/man/man1

# Must not depend on anything. This is to be called by
# binary-arch/binary-indep
# in another 'make' thread.
binary-common:
	dh_testdir
	dh_testroot
	#dh_installchangelogs changelog
	dh_installdocs
	dh_installman
	dh_link
	dh_strip
	dh_compress
	dh_fixperms
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

# Build architecture dependant packages using the common target.
binary-arch: build-arch install-arch
	$(MAKE) -f debian/rules DH_OPTIONS=-a binary-common

# Build architecture depdendent and independent packages
binary: binary-arch
.PHONY: clean binary

