#!/usr/bin/make -f

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

export DEB_HOST_GNU_TYPE  ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
export DEB_BUILD_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)

# FOR AUTOCONF 2.52 AND NEWER ONLY
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

CFLAGS = -Wall -g
ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
  CFLAGS += -O0
else
  CFLAGS += -O2
endif

OVERRIDES = SUPPRESS_AUTOFOO=yes

%:
	dh $@

override_dh_auto_configure:
	rm -f config.sub config.guess
	cp /usr/share/misc/config.sub config.sub
	cp /usr/share/misc/config.guess config.guess
	( [ -f configure ] && [ -f config.hin ] ) \
		|| ( aclocal && autoconf && autoheader )
	$(RM) aclocal.m4
	./configure CFLAGS="$(CFLAGS)" $(confflags) \
		--prefix=/usr --mandir=\$${prefix}/share/man

override_dh_auto_build:
	$(MAKE) $(OVERRIDES) all
ifeq (,$(findstring nocheck,$(DEB_BUILD_OPTIONS)))
	$(MAKE) check
endif

override_dh_auto_clean:
	[ ! -f Makefile ] || $(MAKE) $(OVERRIDES) distclean

override_dh_auto_install:
	$(MAKE) $(OVERRIDES) prefix=debian/xcftools/usr install
