#!/usr/bin/make -f

CFLAGS += -D_POSIX_SOURCE -DDOT_IS_LAST -DDONTEXIT

# The following files get overwritten by the build process. We back them up
# first.
BACKUP_FILES = doc/bc.info \
	       doc/dc.info
BACKED_UP_FILES = $(BACKUP_FILES:%=%.debian-backup)

%:
	dh $@

override_dh_auto_configure:
	dh_auto_configure -- --prefix=/usr --with-readline

override_dh_auto_build: $(BACKED_UP_FILES)
	(cd doc && makeinfo --html --no-split --ifinfo bc.texi)
	(cd doc && makeinfo --html --no-split --ifinfo dc.texi)
	dh_auto_build

override_dh_auto_clean: restore
	dh_auto_clean

%.debian-backup:
	@# Back up automatically generated files so that we can restore them in
	@# the clean target, as required by Policy. We do this by copying the
	@# matching stem, foo, to foo.debian-backup.
	cp -f $* $@

restore:
	for file in $(BACKUP_FILES); do \
	    [ ! -f $${file}.debian-backup ] || mv $${file}.debian-backup $${file}; \
	done

.PHONY: restore
