CC			= gcc
CXX			= g++
V4L_UTILS_VERSION	= 0.9.0-test
CFLAGS			= -g -O2
WITH_LIBV4L		= yes
WITH_V4LUTILS		= yes

LIBV4L_ARGS=
ifeq ($(WITH_LIBV4L),no)
ifeq ($(WITH_V4LUTILS),yes)
	LIBV4L_ARGS="LINKTYPE=static"
endif
endif

all:
  ifeq ($(WITH_LIBV4L),yes)
	echo with Libv4l $(LIBV4L_ARGS)
	$(MAKE) -C lib $(LIBV4L_ARGS) $@
  else ifeq ($(WITH_V4LUTILS),yes)
	echo with Libv4l static
	$(MAKE) -C lib $(LIBV4L_ARGS) $@
  endif
  ifeq ($(WITH_V4LUTILS),yes)
	$(MAKE) -C utils $(LIBV4L_ARGS) $@
  endif

install:
  ifeq ($(WITH_LIBV4L),yes)
	$(MAKE) -C lib $@
  endif
  ifeq ($(WITH_V4LUTILS),yes)
	$(MAKE) -C utils $@
  endif

sync-with-kernel:
	@if [ ! -f $(KERNEL_DIR)/include/linux/videodev2.h -o \
	      ! -f $(KERNEL_DIR)/include/linux/ivtv.h -o \
	      ! -f $(KERNEL_DIR)/include/media/v4l2-chip-ident.h ]; then \
	  echo "Error you must set KERNEL_DIR to point to an extracted kernel source dir"; \
	  exit 1; \
	fi
	cp -a $(KERNEL_DIR)/include/linux/videodev2.h include/linux
	cp -a $(KERNEL_DIR)/include/linux/ivtv.h include/linux
	cp -a $(KERNEL_DIR)/include/media/v4l2-chip-ident.h include/media
	$(MAKE) -C utils $@

clean::
	rm -f include/*/*~
	$(MAKE) -C lib $@
	$(MAKE) -C utils $@

tag:
	@git tag -a -m "Tag as v4l-utils-$(V4L_UTILS_VERSION)" v4l-utils-$(V4L_UTILS_VERSION)
	@echo "Tagged as v4l-utils-$(V4L_UTILS_VERSION)"

archive-no-tag:
	@git archive --format=tar --prefix=v4l-utils-$(V4L_UTILS_VERSION)/ v4l-utils-$(V4L_UTILS_VERSION) > v4l-utils-$(V4L_UTILS_VERSION).tar
	@bzip2 -f v4l-utils-$(V4L_UTILS_VERSION).tar

archive: clean tag archive-no-tag

export: clean
	tar --transform s/^\./v4l-utils-$(V4L_UTILS_VERSION)/g \
		--exclude=.git -jcvf \
		/tmp/v4l-utils-$(V4L_UTILS_VERSION).tar.bz2 .

include Make.rules
