#!/usr/bin/make -f

#export DH_VERBOSE=1

export DEB_BUILD_MAINT_OPTIONS = hardening=+all
DPKG_EXPORT_BUILDFLAGS = 1
include /usr/share/dpkg/buildflags.mk
include /usr/share/dpkg/architecture.mk

confflags =
confflags += SHARED=yes
confflags += HOST=$(DEB_HOST_GNU_CPU)-$(DEB_HOST_GNU_SYSTEM)
ifneq ($(DEB_HOST_GNU_TYPE),$(DEB_BUILD_GNU_TYPE))
export PKG_CONFIG = $(DEB_HOST_GNU_TYPE)-pkg-config
confflags += CROSS_COMPILE=$(DEB_HOST_GNU_TYPE)-
endif
ifeq ($(DEB_HOST_ARCH_OS),linux)
confflags += LIBKMOD=yes
confflags += HWDB=yes
endif
confflags += PREFIX=/usr
confflags += LIBDIR=/usr/lib/$(DEB_HOST_MULTIARCH)
confflags += INCDIR=/usr/include/$(DEB_HOST_MULTIARCH)
confflags += SBINDIR=/usr/bin
confflags += IDSDIR=/usr/share/misc
confflags += STRIP=

build-indep:
build-arch:
	dh_testdir
	OPT="$(CFLAGS)" $(MAKE) $(confflags)
build: build-indep build-arch

clean:
	dh_testdir
	dh_testroot
	[ ! -f Makefile ] || $(MAKE) clean
	dh_clean

# Build architecture-independent files here.
binary-indep: build-indep

# Build architecture-dependent files here.
binary-arch: build-arch
	dh_testdir
	dh_testroot
	dh_prep
	dh_installdirs -a

	$(MAKE) $(confflags) install install-lib DESTDIR=debian/tmp

	# pciutils-udeb
	# Reduce by removing subsystem ids and comments.
	cat /usr/share/misc/pci.ids | \
	  perl -ne 'print unless /^(\s*#|\s*$|\t\t)/' | \
	  gzip -9n >debian/pciutils-udeb/usr/share/misc/pci.ids.gz

	dh_install -a
	dh_installdocs -a
	dh_installexamples -a
	dh_installmenu -a
	dh_installman -a
	dh_installchangelogs -a ChangeLog
	dh_strip -a
	dh_lintian -a
	dh_compress -a
	dh_fixperms -a
	dh_makeshlibs -a -V 'libpci3 (>= 1:3.5.2-1)' --add-udeb=libpci3-udeb
	dh_installdeb -a
	dh_shlibdeps -a
	dh_gencontrol -a
	dh_md5sums -a
	dh_builddeb -a

binary: binary-indep binary-arch

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