#!/usr/bin/make -f
# debian/rules for the Debian pkgconfig package.
# Copyright © 2004 Scott James Remnant <scott@netsplit.com>

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

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

DEB_HOST_ARCH      ?= $(shell dpkg-architecture -qDEB_HOST_ARCH)
DEB_HOST_GNU_TYPE  ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
DEB_BUILD_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)
ifeq ($(DEB_BUILD_GNU_TYPE), $(DEB_HOST_GNU_TYPE))
	confflags += --build=$(DEB_HOST_GNU_TYPE)
else
	confflags += --build=$(DEB_BUILD_GNU_TYPE) --host=$(DEB_HOST_GNU_TYPE)
endif

build: build-stamp
build-stamp:
	dh_testdir

	./configure --prefix=/usr \
		--mandir=\$${prefix}/share/man \
		--infodir=\$${prefix}/share/info --disable-shared \
		--with-pc-path=/usr/local/lib/pkgconfig:/usr/local/lib/pkgconfig/$(DEB_BUILD_GNU_TYPE):/usr/local/share/pkgconfig:/usr/lib/pkgconfig:/usr/lib/pkgconfig/$(DEB_BUILD_GNU_TYPE):/usr/share/pkgconfig \
		$(confflags) CFLAGS='$(CFLAGS)' 
	$(MAKE)

	touch build-stamp

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp

	-$(MAKE) -k distclean
	rm -f config.cache config.log config.status
	rm -f */config.cache */config.log */config.status
	rm -f conftest* */conftest*
	rm -rf autom4te.cache */autom4te.cache

	dh_clean

# Make it as clean as svn can make it.
svnclean: clean
	rm -rf `svn propget svn:ignore`

install: build
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs

	$(MAKE) prefix=`pwd`/debian/pkg-config/usr install

# Build architecture-independent files here.
binary-indep: build install
# Nothing to do

# Build architecture-dependent files here.
binary-arch: build install
	dh_testdir
	dh_testroot

	dh_installdocs
	dh_installman pkg-config.1
	dh_installchangelogs ChangeLog
	dh_link
	dh_strip
	dh_compress
	dh_fixperms
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

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