include $(MAKETOP)/usr/src/GNUtoolchain

SUBDIRS = gst-omx-1.0.0
TARBALL = $(SUBDIRS).tar.xz
INST_SUBDIRS = $(patsubst %,install-%,$(SUBDIRS))
CLEAN_SUBDIRS = $(patsubst %,clean-%,$(SUBDIRS))

PATCH_LIST = \
0001-omxvideodec-don-t-disable-output-port-but-allocate-o.patch \
0002-omxvideodec-populate-output-buffers-in-the-component.patch \
0003-omxvideodec-update-the-cached-data-of-output-port-de.patch \
0004-omxvideodec-change-supported-color-formats-list-crea.patch \
0005-omxh264dec-allow-to-accept-H.264-stream-in-a-nal-uni.patch \
0006-omxvideodec-set-OMX-buffer-flags-if-GST_BUFFER_FLAG_.patch \
0007-omxvideodec-remove-the-data-packets-left-queued-in-t.patch \
0008-omxwmvdec-support-VC-1-stream-decoding.patch \
0009-omxwmvdec-support-VC-1-advanced-profile.patch \
0010-omxvideodec-don-t-start-the-output-thread-before-set.patch \
0011-omxvideodec-don-t-use-gst_buffer_map-when-copying-to.patch \
0012-gstomx-Once-reinitialize-an-instance-and-then-retry-.patch \
0013-gstomx-fix-a-missing-g_free.patch \
0014-gstomx-Once-reinitialize-an-instance-and-then-retry-.patch \
0015-omxmpeg4videodec-conform-caps-template-to-the-defini.patch \
0016-Revert-omxvideodec-remove-the-data-packets-left-queu.patch \
0017-Revert-omxh264dec-allow-to-accept-H.264-stream-in-a-.patch \
0018-gstomx.conf-use-REL-OMXIL-library-and-give-a-top-pri.patch \
0019-gstomx.conf-Use-REL-OMXIL-library.patch \
0020-gstomx-set-the-default-path-of-gstomx.conf.patch \
0021-omxvideodec-support-zero-copy-buffer-output-to-the-d.patch \
0022-omxvideodec-Fix-incorrect-UV-plane-addressing.patch \
0023-omxvideodec-Generalize-the-output-buffer-creation-fo.patch \
0024-omxvideodec-Group-the-input-buffer-copying-into-a-fu.patch \
0025-omxh264dec-Retrieve-necessary-information-from-codec.patch \
0026-omxh264dec-Support-the-frame-unit-input-into-REL-OMX.patch \
0027-omxvideodec-Don-t-set-the-OMX_BUFFERFLAG_ENDOFFRAME-.patch \
0028-omxh264dec-Remove-parsed-field-from-the-template-cap.patch \
0029-gstomx-Move-output-buffers-sending-into-the-omx-comp.patch \
0030-Support-audiodec-and-aacdec.patch \
0031-omxvideodec-Add-addtional-arguments-to-gst_omx_memor.patch \
0032-omxvideodec-Create-multiple-GstMemory-instances-for-.patch \
0033-omxvideodec-Don-t-set-the-offset-and-the-size-of-the.patch \
0034-omxvideodec-Don-t-set-the-offset-in-the-memory-when-.patch \
0035-gstomx-Set-the-used-flag-of-the-GstOMXBuffer-if-the-.patch \
0036-gstomx-Add-private-data-field-to-GstOMXBuffer-in-ord.patch \
0037-omxvideodec-Don-t-release-the-buffer-that-haven-t-be.patch \
0038-omxvideodec-Set-the-already_acquired-flag-when-the-f.patch \
0039-omxvideodec-Fix-the-condition-that-allows-to-handle-.patch \
0040-omxvideodec-Set-a-structure-object-to-the-private_da.patch \
0041-omxvideodec-Set-up-our-buffer-pool-and-notify-the-pa.patch \
0042-gstomxvideodec-Update-the-output-port-definition-cac.patch \
0043-omxvideodec-Add-the-condition-for-returning-a-buffer.patch \
0044-omxvideodec-Create-the-gst-omx-buffer-pool-instance.patch \
0045-omxvideodec-Fix-the-buffer-index-determination-to-ac.patch \
0046-omxvideodec-Associate-dmabuf-file-descriptors-with-o.patch \
0047-omxvideodec-Keep-the-information-whether-the-videosi.patch \
0048-omxvideodec-Get-a-GstBuffer-associated-with-a-videos.patch \
0049-omxvideodec-Send-multiple-dmabuf-file-descriptors-wi.patch \
0050-omxvideodec-Fix-the-duplicated-dereferencing-of-our-.patch \
0051-omxvideodec-Free-the-buffers-queued-in-our-buffer-po.patch \
0052-Revert-omxvideodec-Free-the-buffers-queued-in-our-bu.patch \
0053-omxbufferpool-fix-memory-leak-if-used-on-output-port.patch \
0054-omxbufferpool-return-buffers-to-the-pool-instead-of-.patch \
0055-omxvideodec-Support-option-of-decode-for-user-can-ch.patch \
0056-omxvideodec-Fix-not-negotiated-error-due-to-pixel-as.patch \
0057-omxh264dec-Add-setting-for-StoreUnit-and-Deinterlace.patch \
0058-omxvideodec-Support-no-reorder-option.patch \
0059-omxvideodec-Remove-bug-in-decoder-message.patch \
0060-omxvideoenc-Support-omxh264enc-for-RCarGen2.patch \
0061-omxvideodec-Change-reset-to-flush.patch \
0062-omxvideodec-Workaround-the-timestamp-issue-with-h264.patch \
0063-omxvideodec-Manually-calculate-timestamp-if-not-prov.patch \
0064-omxh264dec-Fix-slow-issue-with-filler-data.patch \
0065-omxvideodec-Workaround-for-Decoder-initialized-error.patch \
0066-omxvideodec-Update-for-no-copy-option.patch \
0067-omxvideodec-Fix-a-compile-error-when-HAVE_MMNGRBUF-i.patch \
0068-omxvideoenc-Support-NV16.patch \
0069-Revert-gstomx-Once-reinitialize-an-instance-and-then.patch \
0070-omx-Update-Copyright-for-omxh264dec-and-omxaacdec.patch \
0071-omxvideodec-Add-config-to-disable-to-export-dmabuf-f.patch \
0072-omxvideodec-Skip-the-video-decoder-negotiation-when-.patch \
0073-omxvideodec-Fix-the-assertion-error-when-recieving-a.patch \
0074-gstomx.conf-Disable-the-usage-of-hacks-for-Bellagio-.patch \
0075-gstomx-Workaround-a-restriction-when-nBufferSize-is-.patch \
0076-Update-the-Copyright-year.patch \
0077-gstomx.conf-Fix-the-typo-in-hacks-of-omxh264dec.patch \
0078-omxvideodec-Fix-a-memory-error-due-to-mistakenly-spe.patch \
0079-omxvideodec-Activate-the-buffer-pool-of-gst-omx-by-i.patch \
0080-Revert-omxvideodec-Fix-the-duplicated-dereferencing-.patch \
0081-omxh264dec-Fix-a-missing-dereferencing-of-a-renewed-.patch \
0001-omx-fix-two-serious-message-handling-bugs.patch \
0001-omxvideodec-release-frames-with-old-PTS-to-avoid-mem.patch \
0001-omxvideodec-Fix-an-incorrect-plane-size-calculation-.patch \
0002-omxvideodec-Align-a-memory-size-specified-when-expor.patch \
0003-omxvideodec-Export-a-first-dmabuf-file-descriptor-wi.patch \
0004-omxvideodec-Group-the-dmabuf-exporting-into-a-functi.patch \
0082-omxvideodec-Avoid-detaching-buffer-metadata-when-ret.patch \
0001-omxh264dec-Fix-out-of-bounds-access.patch

PANA_PATCH_LIST = \
pana-gstomx.conf-patch-20141224.patch			\
pana-gstomx.conf-patch-20150216.patch

ifeq (arm,$(GNUCC_ARCH))
SYSROOT="--sysroot=$(MAKETOP)"
CFLAGS="$(SYSROOT) -g -O2 $(GNUCC_ARCH_CFLAGS_EXTRA) -Wno-deprecated-declarations "
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-debug						\
		 --enable-experimental \
		 --with-omx-target=rcar \
		)						\
	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

	PATCH_LIST="$(PANA_PATCH_LIST)";\
	for x in $$PATCH_LIST; do\
		echo $$x;\
		patch -p1 -d $(SUBDIRS) < patch/$$x;\
	done

	install -D -m 755 $(SUBDIRS)/omx/openmax/OMX_Types.h	${MAKETOP}/usr/include/OMX_Types.h
	dir=`echo $@ |sed -e 's/install-//'`;			\
	if test ! -f $$dir/Makefile; then			\
		 autoreconf --force --install \
		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		\
		 --sysconfdir=$(CROSS_C_ROOT_PATH)/etc		\
		 --disable-gtk-doc				\
		 --disable-gtk-doc-html				\
		 --disable-valgrind				\
		 --enable-experimental				\
		 --with-omx-target=rcar				\
		 --enable-nls					\
		 ;						\
		 sed -i 's!\(^core-name=/usr\)/local\(/lib/libomxr_core.so\)!\1\2!g' config/rcar/gstomx.conf		\
		)						\
	fi;							\
	$(MAKE) -C $${dir} install

clean: $(CLEAN_SUBDIRS)

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


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