include $(MAKETOP)/usr/src/GNUtoolchain

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

PATCH_LIST = 0001-vspfilter-Add-a-new-plugin-converting-colorspace-and.patch \
             0002-Set-a-default-video-converter-by-.-configure-script.patch \
             0003-playsink-Insert-videoscale-into-the-pipeline-when-vs.patch \
             0004-playsink-Move-the-queue-plugin-insertion-after-the-v.patch \
             0005-vspfilter-Specify-the-width-of-the-V4L2-output-port-.patch \
             0006-vspfilter-Remove-an-unnecessary-switch-statement.patch \
             0007-vspfilter-Replace-this-plugin-s-own-definition-with-.patch \
             0008-vspfilter-Get-the-parameters-of-a-video-stream-from-.patch \
             0009-vspfilter-Wrap-the-frame-transformation-function-to-.patch \
             0010-vspfilter-Set-a-dmabuf-descriptor-to-a-v4l2-plane-wh.patch \
             0011-vspfilter-Override-the-transform-function-of-the-Gst.patch \
             0012-vspfilter-Set-the-stride-obtained-from-a-buffer-meta.patch \
             0013-vspfilter-Support-the-dmabuf-handling.patch \
             0014-vspfilter-Change-returned-values-of-the-functions-th.patch \
             0015-vspfilter-Dynamically-specify-the-name-of-a-wpf-outp.patch \
             0016-vspfilter-Initialize-the-length-and-the-data_offset-.patch \
             0017-vspfilter-Set-the-memory-I-O-mode-for-V4L2-to-a-GstV.patch \
             0018-vspfilter-Pass-a-GstVspFilterFrameInfo-structure-as-.patch \
             0019-vspfilter-Obtain-the-V4L2-I-O-memory-types-from-GstV.patch \
             0020-vspfilter-Pass-the-V4L2-memory-I-O-types-obtained-fr.patch \
             0021-vspfilter-Remove-the-v4l2_memory-of-GstVspFilterVspI.patch \
             0022-vspfilter-Improve-the-readability-of-gst_vsp_filter_.patch \
             0023-vspfilter-Support-the-planar-color-formats-for-dmabu.patch \
             0024-vspfilter-Handle-dmabuf-file-descriptors-passed-into.patch \
             0025-vspfilter-Unset-already_device_initialized-flags-in-.patch \
             0026-vspfilter-Move-the-media-controller-open-to-the-stat.patch \
             0027-vspfilter-Add-the-missing-media-controller-close.patch \
             0028-vspfilter-Clear-already_setup_info-flag-to-reinitial.patch \
             0029-vspfilter-Keep-resz_subdev_fd-in-the-GstVspFilterVsp.patch \
             0030-vspfilter-Add-missing-uds-subdev-close-invocations.patch \
             0031-vspfilter-Set-ip_name-as-null-when-it-is-freed-for-t.patch \
             0032-vspfilter-Add-missing-subdev-closes-of-output-and-ca.patch \
             0033-vspfilter-Clear-is_stream_started-flag-when-doing-st.patch \
             0034-vspfilter-Override-the-set_caps-method-of-the-gstbas.patch \
             0035-vspfilter-Remove-the-transform_frame-method.patch \
             0036-vspfilter-Set-strides-of-both-input-and-output-buffe.patch \
             0037-vspfilter-Change-the-GstVideoFrame-variable-type-in-.patch \
             0038-vspfilter-Group-the-frame-information-retrieval-into.patch \
             0039-vspfilter_support_nv12_size_check.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-ogg					\
		 --disable-x					\
		 --disable-gst_v4l				\
		 --disable-cdparanoia				\
		 --disable-gnome_vfs				\
		 --disable-ivorbis				\
		 --disable-ogg					\
		 --disable-oggtest				\
		 --disable-pango				\
		 --disable-theora				\
		 --disable-vorbis				\
		 --disable-vorbistest				\
		)						\
	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      			\
		 --disable-freetypetest    			\
		 --disable-cdparanoia    			\
		 --disable-libvisual      			\
		 --enable-vspfilter				\
		 --enable-nls					\
		 --enable-alsa					\
		 --enable-ivorbis				\
		 --enable-ogg					\
		 --disable-orc					\
		 --disable-pango				\
		 --enable-theora				\
		 --enable-vorbis				\
		 --enable-x					\
		 --enable-xvideo				\
		 --enable-xshm 				\
		)						\
	fi;							\
	$(MAKE) -C $${dir} install ;\
    install -m644 conf/gstvspfilter-koelsch.conf $(CROSS_C_ROOT_PATH)/etc/gstvspfilter.conf


clean: $(CLEAN_SUBDIRS)

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


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