#!/usr/bin/make -f
# -*- makefile -*-

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

DEB_HOST_ARCH ?= $(shell dpkg-architecture -qDEB_HOST_ARCH)

CLANG_V	= 6.0
CLANG	= clang-$(CLANG_V)
GCC	= gcc

%:
	dh $@  --with autoreconf --parallel

override_dh_auto_configure:
	dh_auto_configure -- --with-llvm=/usr/lib/llvm-$(CLANG_V) CLANG_FORMAT=clang-format-$(CLANG_V)
	
override_dh_auto_build:
	dh_auto_build

ifeq ($(DEB_HOST_ARCH),$(DEB_BUILD_ARCH))
	if which help2man >/dev/null 2>&1; then \
	  v=$$(creduce/creduce --help| awk '/^creduce/ { print $$2 }'); \
	  help2man --name='C and C++ program reducer' --version-string=$$v creduce/creduce > debian/creduce.1; \
	fi
endif

override_dh_auto_test:
# these are time consuming ...
ifeq (,$(findstring nocheck, $(DEB_BUILD_OPTIONS)))
  ifeq (,$(filter $(DEB_HOST_ARCH),m68k sh4 s390 sparc))
	cd tests && CLANG="$(CLANG)" GCC="$(GCC)" ./run_tests
  endif
endif

override_dh_auto_install:
	dh_auto_install
	install -D -m 644 debian/creduce.1 debian/creduce/usr/share/man/man1/creduce.1

override_dh_auto_clean:
	rm -rf tests/tmp_*
	dh_auto_clean
