#!/usr/bin/make -f

PACKAGE  = ccbuild
CXXFLAGS += -std=gnu++0x

include debian/debian-save-restore.mk

# autoreconf(1) changes few
FILE_LIST_PRESERVE = \
 INSTALL \
 Makefile.in \
 aclocal.m4 \
 configure \
 doc/ccbuild/Makefile

override_dh_auto_clean:
	$(file-state-save)

	# Do all manually. Makefile would run ./config.status --recheck
	find .  -type f \
		-name $(PACKAGE) \
		-o -name Makefile \
		-o -name "*.o" \
		-o -name "config.*" \
		-o -name .dirstamp \
		| xargs --no-run-if-empty rm

	find . -type d -name .deps \
		| xargs --no-run-if-empty rm -r

	# Due to autoreconf(1)
	rm -f	INSTALL Makefile.in aclocal.m4 config.* configure \
		src/SourceScanner/yylex.cc

override_dh_auto_configure:
	# See patch 20. We have to regenerate ./configure
	cp -vf /usr/share/misc/config.sub .
	cp -vf /usr/share/misc/config.guess .
	autoreconf -vfi
	dh_auto_configure

override_dh_auto_build:
	# For some reason, the only way to pass flags is in CXX
	@echo "# environment: CXX $(CXX) CFLAGS $(CFLAGS) CXXFLAGS $(CXXFLAGS)"
	$(MAKE) CXX="g++ $(CXXFLAGS)" DESTDIR=$(CURDIR)/debian/ccbuild install

override_dh_installchangelogs:
	$(file-state-restore)
	dh_installchangelogs ChangeLog

%:
	dh  $@

# End of file
