ACLOCAL_AMFLAGS = -I m4
SUBDIRS = t debugviewer snd2png

doc_DATA = \
	README.asciidoc \
	INSTALL.asciidoc \
	COPYING \
	doc/basetest.html \
	doc/testapi.html 

backendexecdir = $(pkglibexecdir)/backend
backendexec_SCRIPTS = \
	backend/baseclass.pm \
	backend/console_proxy.pm \
	backend/driver.pm \
	backend/ipmi.pm \
	backend/qemu.pm \
	backend/s390x.pm \
	backend/svirt.pm

consolesexecdir = $(pkglibexecdir)/consoles
consolesexec_SCRIPTS = \
	consoles/console.pm \
	consoles/localXvnc.pm \
	consoles/remoteVnc.pm \
	consoles/remoteWindow.pm \
	consoles/s3270.pm \
	consoles/sshX3270.pm \
	consoles/sshVirtsh.pm \
	consoles/sshXtermVt.pm \
	consoles/ttyConsole.pm \
	consoles/vnc_base.pm \
	consoles/VNC.pm

pkglibexec_SCRIPTS = \
	autotest.pm \
	basetest.pm \
	bmwqemu.pm \
	testapi.pm \
	mmapi.pm \
	lockapi.pm \
	commands.pm \
	distribution.pm \
	ocr.pm \
	cv.pm \
	needle.pm \
	crop.py \
	os-autoinst-openvswitch

bin_SCRIPTS = isotovideo

install-exec-hook:
	sed -i -e "s,\$$installprefix = undef;,\$$installprefix = '$(pkglibexecdir)';," $(DESTDIR)$(bindir)/isotovideo && \
	sed -i -e "s,\$$sysdir = undef;,\$$sysdir = '$(pkglibexecdir)';," $(DESTDIR)$(pkglibexecdir)/cv.pm

pkglibexec_FOLDERS = \
	distri \
	tools \
	inst \
	inst.d \
	dmidata

# sort the above out so it is not done directory wise

pkglibexec_PROGRAMS = videoencoder

videoencoder_SOURCES = videoencoder.cpp
videoencoder_CFLAGS = -Wall -W $(OPENCV_CFLAGS)
videoencoder_LDADD = $(OPENCV_LIBS) $(THEORAENC_LIBS) -lm

EXTRA_DIST = \
	autogen.sh \
	ppmclibs/tinycv.i \
	$(backendhelpexec_SCRIPTS) $(backendexec_SCRIPTS) \
	$(doc_DATA) $(pkglibexec_DATA) $(pkglibexec_SCRIPTS) $(packagestate_DATA_FOLDERS) $(pkglibexec_FOLDERS) \
	etc/dbus-1/system.d/org.opensuse.os_autoinst.switch.conf \
	systemd/os-autoinst-openvswitch.service

CLEANFILES = \
	$(ppmcexec_SCRIPTS) \
	ppmclibs/tinycv_wrap.cxx \
	doc/basetest.html \
	doc/testapi.html 

PERL_MODULE = ppmclibs/blib/arch/auto/tinycv/tinycv.so

ppmclibs/Makefile: ppmclibs/Makefile.PL
	cd ppmclibs && \
	perl Makefile.PL OPTIMIZE="$(CXXFLAGS)"

$(PERL_MODULE): ppmclibs/Makefile
	$(MAKE) -C ppmclibs

install-exec-local: $(PERL_MODULE)
	$(MAKE) -C ppmclibs pure_install DESTDIR="$(DESTDIR)" INSTALLDIRS="$(INSTALLDIRS)"

all-local: $(PERL_MODULE)

doc/%.html: %.pm
	pod2html $< > $@

install-data-local:
	$(MKDIR_P) $(DESTDIR)/$(packagestatedir) ; \
	for i in $(packagestate_DATA_FOLDERS) ; do \
		cp -r $(top_srcdir)/$$i "$(DESTDIR)/$(packagestatedir)" ; \
	done
	$(MKDIR_P) "$(DESTDIR)/$(pkgdatadir)" ; \
	for i in $(pkglibexec_FOLDERS) ; do \
		cp -r $(top_srcdir)/$$i "$(DESTDIR)/$(pkglibexecdir)" ; \
	done
	install -D -m 644 $(top_srcdir)/etc/os-autoinst/kvm2usb.yml "$(DESTDIR)/etc/os-autoinst/kvm2usb.yml"
	install -D -m 644 $(top_srcdir)/etc/dbus-1/system.d/org.opensuse.os_autoinst.switch.conf "$(DESTDIR)/etc/dbus-1/system.d/org.opensuse.os_autoinst.switch.conf"
	install -D -m 644 $(top_srcdir)/systemd/os-autoinst-openvswitch.service "$(DESTDIR)/usr/lib/systemd/system/os-autoinst-openvswitch.service"

uninstall-local:
	for i in $(packagestate_DATA_FOLDERS) ; do \
		rm -rf "$(DESTDIR)/$(packagestatedir)/$$i" ; \
	done
	for i in $(pkglibexec_FOLDERS) ; do \
		rm -rf "$(DESTDIR)/$(pkglibexecdir)/$$i" ; \
	done

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 ) > 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
	rm -rf `find $(distdir) -name .gitignore`

distclean-local: clean-local

check-local:
	$(srcdir)/tools/tidy --check
	PERL5LIB=tools/lib/perlcritic:$$PERL5LIB perlcritic --gentle --include Perl::Critic::Policy::HashKeyQuote $(srcdir)

clean-local:
	@if test -e ppmclibs/Makefile; then $(MAKE) -C ppmclibs distclean; fi
	-rm -rf *.tar.*
