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

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

# Build cache (for accelerating Debian debugging)
BUILDCACHE := $(wildcard ../coq-float.cache)

include /usr/share/coq/coqvars.mk

INCDIRS := -R . Float

FILES_TO_BACKUP := Makefile

%:
	dh $@

.PHONY: override_dh_auto_configure
override_dh_auto_configure:
	for u in $(FILES_TO_BACKUP); do \
	  if [ ! -f "$$u.backup" ]; then cp "$$u" "$$u.backup"; fi \
	done
	coq_makefile $(INCDIRS) $(shell find . -name .pc -prune -or -name \*.v -print ) > Makefile

.PHONY: override_dh_auto_build
override_dh_auto_build:
ifeq ($(BUILDCACHE),)
	$(MAKE) depend
	$(MAKE) all
	$(MAKE) html
else
	@echo "===> Build cache detected, skipping compilation <==="
	rsync -a --exclude=debian --exclude=.git $(BUILDCACHE)/ .
endif

.PHONY: override_dh_auto_install
override_dh_auto_install:

.PHONY: override_dh_clean
override_dh_clean:
	dh_clean
	for u in $(FILES_TO_BACKUP); do \
	  if [ -f "$$u.backup" ]; then mv "$$u.backup" "$$u"; fi \
	done

.PHONY: override_dh_gencontrol
override_dh_gencontrol:
	dh_gencontrol -- -VF:CoqABI="$(COQ_ABI)"
