include $(MAKETOP)/usr/src/GNUtoolchain

SUBDIRS = gst-plugins-good-1.2.3
TARBALL = $(SUBDIRS).tar.xz
INST_SUBDIRS = $(patsubst %,install-%,$(SUBDIRS))
CLEAN_SUBDIRS = $(patsubst %,clean-%,$(SUBDIRS))

PATCH_LIST = \
0001-v4l2src-Add-NV16-color-format-support.patch \
0002-v4l2bufferpool-Reattach-the-output-buffer-size-only-.patch \
0003-v4l2bufferpool-Change-the-buffer-number-to-be-queued.patch \
0004-v4l2bufferpool-Associate-a-V4L2-buffer-with-a-videos.patch \
0005-v4l2src-v4l2bufferpool-Keep-the-information-whether-.patch \
0006-v4l2bufferpool-Send-a-videosink_buffer_creation_requ.patch \
0007-v4l2bufferpool-Send-multiple-dmabuf-file-descriptors.patch \
0008-v4l2object-Compensate-for-the-interpretation-differe.patch \
0009-v4l2bufferpool-Set-the-minimum-number-of-the-buffers.patch \
0010-v4l2src-v4l2bufferpool-Set-the-required-number-of-th.patch \
0011-v4l2sink-RCar-Gen2-v4l2sink-support-GStreamer-1.2.3.patch \
0012-v4l2bufferpool-Support-userptr-mode.patch \
0013-v4l2bufferpool-Fix-assertion-buffer-NULL-failed-warn.patch \
0014-v4l2bufferpool-Fix-plane-intialize-issue-in-kernel-3.patch \
0015-v4l2bufferpool-Fix-mmap-mode-issue.patch \
0016-v4l2src-support-v4l2src-for-rcar.patch \
0017-v4l2bufferpool-Support-dmabuf-import-mode.patch \
0018-v4l2src-Support-crop-function-for-v4l2src.patch \
0019-v4l2bufferpool-Remove-workaround-for-NV16-wrong-byte.patch \
0020-v4l2object-Workaround-for-v4l2src-and-v4l2sink-not-n.patch \
0021-v4l2bufferpool-improve-userptr-implement.patch \
0022-v4l2src-Add-Copyright.patch \
0023-v4l2bufferpool-Support-dmabuf-for-v4l2src-in-case-do.patch \
0024-v4l2object-Support-format-UYVY-for-v4l2sink.patch \
0025-v4l2object-Fix-issue-crop-affect-to-scale-down.patch \
0026-Update-the-Copyright-year.patch \
0027-v4l2-Fix-memory-leak-in-v4l2sink.patch


ifeq (arm,$(GNUCC_ARCH))
SYSROOT="--sysroot=$(MAKETOP)"
CFLAGS="$(SYSROOT) -g -O2 $(GNUCC_ARCH_CFLAGS_EXTRA)"
CPPFLAGS=$(CFLAGS)
LDFLAGS=$(SYSROOT)
endif

all: $(SUBDIRS)

$(SUBDIRS):
	if test ! -f $@/Makefile; then				\
		touch-autotools.scm $@;				\
		(cd $@; CFLAGS=$(CFLAGS) CPPFLAGS=$(CPPFLAGS) LDFLAGS=$(LDFLAGS)	\
		 ./configure --host=$(GNUCC_PREFIX)		\
		 --build=`./config.guess`			\
		 --prefix=$(CROSS_C_ROOT_PATH)/usr		\
		 --disable-silent-rules				\
		 --disable-x					\
		 --enable-experimental				\
		 --disable-cairo				\
		 --disable-flac					\
		 --disable-gdk_pixbuf				\
		 --disable-examples				\
		 --disable-esd				\
		)						\
	fi;							\
	$(MAKE) -C $@ all

install: $(INST_SUBDIRS)

$(INST_SUBDIRS):
	tar xvf $(TARBALL)
	PATCH_LIST="$(PATCH_LIST)";\
	for x in $$PATCH_LIST; do\
		echo $$x;\
		patch -p1 -d $(SUBDIRS) < patch/$$x;\
	done

	dir=`echo $@ |sed -e 's/install-//'`;			\
	if test ! -f $$dir/Makefile; then			\
		touch-autotools.scm $${dir};			\
		(cd $${dir};					\
		 CFLAGS=$(CFLAGS) CPPFLAGS=$(CPPFLAGS) LDFLAGS=$(LDFLAGS)	\
		 ./autogen.sh --host=$(GNUCC_PREFIX)		\
		 --build=`./config.guess`			\
		 --prefix=$(CROSS_C_ROOT_PATH)/usr		\
		 --disable-silent-rules				\
		 --disable-gtk-doc 				\
		 --disable-gtk-doc-html				\
		 --disable-valgrind				\
		 --disable-debug				\
		 --disable-examples				\
		 --enable-oss					\
		 --enable-gst_v4l2				\
		 --without-libv4l2				\
		 --disable-directsound				\
		 --disable-waveform				\
		 --disable-oss4					\
		 --disable-sunaudio				\
		 --disable-osx_audio				\
		 --disable-osx_video				\
		 --disable-aalib				\
		 --disable-libcaca				\
		 --disable-libdv				\
		 --disable-shout2				\
		 --disable-dv1394				\
		 --enable-nls					\
		 --enable-cairo					\
		 --enable-flac					\
		 --enable-gdk_pixbuf				\
		 --disable-jack					\
		 --enable-jpeg					\
		 --enable-libpng				\
		 --disable-orc					\
		 --enable-pulse					\
		 --enable-soup					\
		 --enable-speex					\
		 --enable-taglib				\
		 --disable-vpx					\
		 --disable-wavpack				\
		 --enable-x					\
		 --enable-xvideo				\
		 --enable-xshm 				\
		)						\
	fi;							\
	$(MAKE) -C $${dir} install

clean: $(CLEAN_SUBDIRS)

$(CLEAN_SUBDIRS):
	rm -rf $(SUBDIRS)		


.PHONY:	all install $(SUBDIRS) $(INST_SUBDIRS) $(CLEAN_SUBDIRS)
