## Process this file with automake to create Makefile.in

ACLOCAL_AMFLAGS = -I m4

SUBDIRS = \
	creavision \
	simplelog \
	wxutil \
	wxcamwindow \
	po \
	man \
	doc \
	src

EXTRA_DIST = \
	autogen.sh \
	AGRAIMENTS.txt \
	eviacam.kdevelop

dist_pkgdata_DATA = THANKS

AM_CPPFLAGS = \
	-I$(top_srcdir) \
	-I$(top_srcdir)/creavision \
	-I$(top_srcdir)/wxcamwindow \
	-I$(top_srcdir)/simplelog \
	-I$(top_srcdir)/wxutil

maintainer-clean-local:
	-rm -rf win32/Release
	-rm -rf win32/Debug
	-rm -rf debian-build
	-rm -f win32/*.exe
	-rm -f win32/*.suo
	-rm -f win32/*.ncb
	-rm -rf autom4te.cache
	-rm -f eviacam.kdevelop.pcs
	-rm -f eviacam.kdevses
	-rm *~
	-rm creavision/*~
	-rm creavision/libwebcam/*~
	-rm wxutil/*~
	-rm wxcamwindow/*~
	-rm src/*~	

dist-hook:
	@if test -d "$(srcdir)/.git"; \
	then \
		echo Creating ChangeLog && \
		( cd "$(top_srcdir)" && \
		  echo '# Generated by Makefile. Do not edit.'; echo; \
		  $(top_srcdir)/missing --run git log --stat ) > ChangeLog.tmp \
		&& mv -f ChangeLog.tmp $(distdir)/ChangeLog \
		|| ( rm -f ChangeLog.tmp ; \
			echo Failed to generate ChangeLog >&2 ); \
	else \
		echo A git clone is required to generate a ChangeLog >&2; \
	fi


GITTAGCMD= \
	if [ -z "$$TAG" ]; then \
		git describe --tags; \
	else \
		echo $$TAG; \
	fi

GITTAG= `$(GITTAGCMD)`

GITVERSION= `$(GITTAGCMD) | cut -d 'v' -f 2- | cut -d '-' -f 1`
	
# make tarball form repository
# if no specific tag selected check that the build directory is clean
git-dist:
	@if [ -z "$$TAG" ]; then \
		make -C po update-po ; \
		if [ -n "$$(git status --porcelain)" ]; then \
			read -p "Working directory not clean, continue?" -n 1 -r ; \
			echo ; \
			if [[ ! $$REPLY =~ ^[Yy]$$ ]]; then \
				exit 1 ; \ 
			fi ; \
		fi ; \
	fi
	@git archive --format=tar --prefix=$(PACKAGE)-$(GITVERSION)/ $(GITTAG) | xz > $(PACKAGE)_$(GITVERSION).orig.tar.xz ; \
	gpg2 -o $(PACKAGE)_$(GITVERSION).orig.tar.xz.asc -a --detach-sign $(PACKAGE)_$(GITVERSION).orig.tar.xz


##
## Debian packages
##

## make a Debian binary package
deb: configure git-dist
	-$(RM) -r debian-build
	-mkdir debian-build
	cd debian-build ; \
	mv ../$(PACKAGE)_$(GITVERSION).orig.tar.xz* . ; \
	tar xJf $(PACKAGE)_$(GITVERSION).orig.tar.xz ; \
	cd $(PACKAGE)-$(GITVERSION) ; \
	cp -a "$(abs_srcdir)/debian" . ; \
	dpkg-buildpackage -B -rfakeroot --force-sign ; \
	cd .. ; \
	$(RM) -r $(PACKAGE)-$(GITVERSION)

## make a Debian source package
deb-src: configure git-dist
	-$(RM) -r debian-src
	-mkdir debian-src
	cd debian-src ; \
	mv ../$(PACKAGE)_$(GITVERSION).orig.tar.xz* . ; \
	tar xJf $(PACKAGE)_$(GITVERSION).orig.tar.xz ; \
	cd $(PACKAGE)-$(GITVERSION) ; \
	cp -a "$(abs_srcdir)/debian" . ; \
	dpkg-buildpackage -S -i -rfakeroot --force-sign --check-command=lintian ; \
	cd .. ; \
	$(RM) -r $(PACKAGE)-$(GITVERSION)
	

## make a Debian .changes files without sources
deb-src-changes: configure
	cd debian-src ; \
	tar xJf $(PACKAGE)_$(GITVERSION).orig.tar.xz ; \
	cd $(PACKAGE)-$(GITVERSION) ; \
	cp -a "$(abs_srcdir)/debian" . ; \
	dpkg-buildpackage -S -i -rfakeroot --force-sign --changes-option=-sd ; \
	cd .. ; \
	$(RM) -r $(PACKAGE)-$(GITVERSION)

## make a Debian binary package (non signed)
deb-nosig: configure git-dist
	-$(RM) -r debian-build
	-mkdir debian-build
	cd debian-build ; \
	mv ../$(PACKAGE)_$(GITVERSION).orig.tar.xz* . ; \
	tar xfvz $(PACKAGE)_$(GITVERSION).orig.tar.gz ; \
	cd $(PACKAGE)-$(GITVERSION) ; \
	cp -a "$(abs_srcdir)/debian" . ; \
	dpkg-buildpackage -B -rfakeroot -uc ; \
	cd .. ; \
	$(RM) -r $(PACKAGE)-$(GITVERSION)

## make a Debian source package  (non signed)
deb-src-nosig: configure git-dist
	-$(RM) -r debian-src
	-mkdir debian-src
	cd debian-src ; \
	mv ../$(PACKAGE)_$(GITVERSION).orig.tar.xz* . ; \
	tar xfvz $(PACKAGE)_$(GITVERSION).orig.tar.gz ; \
	cd $(PACKAGE)-$(GITVERSION) ; \
	cp -a "$(abs_srcdir)/debian" . ; \
	dpkg-buildpackage -S -i -rfakeroot -uc -us ; \
	cd .. ; \
	$(RM) -r $(PACKAGE)-$(GITVERSION)


##
## RPM packages
##
#rpm:	configure dist-bzip2
#	(cd rpm && $(MAKE) $(AM_MAKEFLAGS) Makefile *.spec) || exit 1
#	(cd rpm && $(MAKE) $(AM_MAKEFLAGS) this) || exit 1
