lib_LTLIBRARIES = libgstreamer-@GST_MAJORMINOR@.la

if GST_DISABLE_REGISTRY
GST_REGISTRY_SRC =
else
GST_REGISTRY_SRC = gstregistrybinary.c
endif

if GST_DISABLE_PARSE
SUBDIRS_PARSE =
GST_PARSE_LA =
else
SUBDIRS_PARSE = parse
GST_PARSE_LA = parse/libgstparse.la
endif

if GST_DISABLE_TRACE
GST_TRACE_SRC =
else
GST_TRACE_SRC = gsttrace.c
endif

if GST_DISABLE_PLUGIN
GST_PLUGIN_SRC =
else
GST_PLUGIN_SRC = gstplugin.c
endif

SUBDIRS = $(SUBDIRS_PARSE)

DIST_SUBDIRS = parse

# make variables for all generated source and header files to make the
# distinction clear

built_header_configure = gstconfig.h gstversion.h
built_header_make = gstenumtypes.h gstmarshal.h
built_source_make = gstenumtypes.c gstmarshal.c

EXTRA_libgstreamer_@GST_MAJORMINOR@_la_SOURCES = \
	gstmarshal.list gsttrace.c \
	gstregistrybinary.c


# temporarily not used
#	glib-compat.c

libgstreamer_@GST_MAJORMINOR@_la_SOURCES = \
	gst.c			\
	gstobject.c		\
	gstbin.c		\
	gstbuffer.c		\
	gstbufferlist.c		\
	gstbus.c		\
	gstcaps.c		\
	gstchildproxy.c		\
	gstclock.c		\
	gstdatetime.c		\
	gstdebugutils.c		\
	gstelement.c		\
	gstelementfactory.c	\
	gsterror.c		\
	gstevent.c		\
	gstfilter.c		\
	gstformat.c		\
	gstghostpad.c		\
	gstindex.c 		\
	gstindexfactory.c 	\
	gstinfo.c		\
	gstinterface.c		\
	gstiterator.c		\
	gstmessage.c		\
	gstminiobject.c		\
	gstpad.c		\
	gstpadtemplate.c	\
	gstparamspecs.c		\
	gstpipeline.c		\
	gstplugin.c		\
	gstpluginfeature.c	\
	gstpluginloader.c	\
	gstpoll.c		\
	gstpreset.c             \
	gstquark.c		\
	gstquery.c		\
	gstregistry.c		\
	gstregistrychunks.c	\
	gstsegment.c		\
	gststructure.c		\
	gstsystemclock.c	\
	gsttaglist.c		\
	gsttagsetter.c		\
	gsttask.c		\
	gsttaskpool.c		\
	$(GST_TRACE_SRC)	\
	gsttypefind.c		\
	gsttypefindfactory.c	\
	gsturi.c		\
	gstutils.c		\
	gstvalue.c		\
	gstparse.c		\
	$(GST_REGISTRY_SRC)

# do not put files in the distribution that are generated
nodist_libgstreamer_@GST_MAJORMINOR@_la_SOURCES = $(built_source_make)

# BUILT_SOURCES are built on make all/check/install before all other targets
BUILT_SOURCES = \
        $(built_header_configure)	\
        $(built_header_make)		\
        $(built_source_make)
# CLEANFILES is for files generated by make
CLEANFILES = $(built_header_make) $(built_source_make) $(as_dll_cleanfiles) *.gcno *.gcda *.gcov *.gcov.out
# DISTCLEANFILES is for files generated by configure
DISTCLEANFILES = $(built_header_configure)

libgstreamer_@GST_MAJORMINOR@_la_CFLAGS =		\
	-D_GNU_SOURCE					\
	-DGST_EXPORTS					\
	-DG_LOG_DOMAIN=g_log_domain_gstreamer 		\
	-DGST_MAJORMINOR=\""$(GST_MAJORMINOR)"\" 	\
	-DGST_DISABLE_DEPRECATED			\
	$(VALGRIND_CFLAGS)				\
	$(GST_ALL_CFLAGS)

libgstreamer_@GST_MAJORMINOR@_la_LIBADD =		\
	$(GST_PARSE_LA)					\
	$(GST_ALL_LIBS)					\
	$(WIN32_LIBS)					\
	$(XML_LIBS)					\
	$(LIBM)

libgstreamer_@GST_MAJORMINOR@_la_LDFLAGS =		\
	$(GST_LIB_LDFLAGS) $(GST_ALL_LDFLAGS) $(GST_LT_LDFLAGS)

libgstreamer_@GST_MAJORMINOR@includedir = $(includedir)/gstreamer-@GST_MAJORMINOR@/gst

gst_headers =			\
	gst.h			\
	glib-compat.h		\
	gstobject.h		\
	gstbin.h		\
	gstbuffer.h		\
	gstbufferlist.h		\
	gstbus.h		\
	gstcaps.h		\
	gstchildproxy.h		\
	gstclock.h		\
	gstcompat.h		\
	gstdatetime.h		\
	gstdebugutils.h		\
	gstelement.h		\
	gstelementfactory.h	\
	gsterror.h		\
	gstevent.h		\
	gstfilter.h		\
	gstformat.h		\
	gstghostpad.h		\
	gstindex.h		\
	gstindexfactory.h	\
	gstinfo.h		\
	gstinterface.h		\
	gstiterator.h		\
	gstmacros.h		\
	gstmessage.h		\
	gstminiobject.h		\
	gstpad.h		\
	gstpadtemplate.h	\
	gstparamspecs.h		\
	gstpipeline.h		\
	gstplugin.h		\
	gstpluginfeature.h	\
	gstpoll.h		\
	gstpreset.h             \
	gstquery.h		\
	gstsegment.h		\
	gststructure.h		\
	gstsystemclock.h	\
	gsttaglist.h		\
	gsttagsetter.h		\
	gsttask.h		\
	gsttaskpool.h		\
	gsttrace.h		\
	gsttypefind.h		\
	gsttypefindfactory.h	\
	gsturi.h		\
	gstutils.h		\
	gstvalue.h		\
	gstregistry.h		\
	gstparse.h

libgstreamer_@GST_MAJORMINOR@include_HEADERS = $(gst_headers) math-compat.h

nodist_libgstreamer_@GST_MAJORMINOR@include_HEADERS = \
	$(built_header_configure) $(built_header_make)

noinst_HEADERS = 		\
	gettext.h		\
	glib-compat-private.h	\
	gst-i18n-lib.h		\
	gst-i18n-app.h		\
	gstelementdetails.h	\
	gstpluginloader.h	\
	gstquark.h		\
	gstregistrybinary.h     \
	gstregistrychunks.h     \
	gst_private.h

gstmarshal.h: gstmarshal.list
	$(AM_V_GEN)glib-genmarshal --header --prefix=gst_marshal $(srcdir)/gstmarshal.list > gstmarshal.h.tmp && \
	mv gstmarshal.h.tmp gstmarshal.h

gstmarshal.c: gstmarshal.list gst_private.h
	$(AM_V_GEN)echo "#include \"gst_private.h\"" > gstmarshal.c.tmp && \
	echo "#include \"glib-object.h\"" >> gstmarshal.c.tmp && \
	echo "#include \"gstmarshal.h\"" >> gstmarshal.c.tmp && \
	glib-genmarshal --body --prefix=gst_marshal $(srcdir)/gstmarshal.list >> gstmarshal.c.tmp && \
	mv gstmarshal.c.tmp gstmarshal.c

gstenumtypes.h: $(gst_headers)
	$(AM_V_GEN)glib-mkenums \
	--fhead "#ifndef __GST_ENUM_TYPES_H__\n#define __GST_ENUM_TYPES_H__\n\n#include <glib-object.h>\n\nG_BEGIN_DECLS\n" \
	--fprod "\n/* enumerations from \"@filename@\" */\n" \
	--vhead "GType @enum_name@_get_type (void);\n#define GST_TYPE_@ENUMSHORT@ (@enum_name@_get_type())\n"         \
	--ftail "G_END_DECLS\n\n#endif /* __GST_ENUM_TYPES_H__ */" \
	$^ > gstenumtypes.h

gstenumtypes.c: $(gst_headers)
	$(AM_V_GEN)glib-mkenums \
	--fhead "#include \"gst_private.h\"\n#include <gst/gst.h>\n#define C_ENUM(v) ((gint) v)\n#define C_FLAGS(v) ((guint) v)\n " \
	--fprod "\n/* enumerations from \"@filename@\" */" \
	--vhead "GType\n@enum_name@_get_type (void)\n{\n  static gsize id = 0;\n  static const G@Type@Value values[] = {"     \
	--vprod "    { C_@TYPE@(@VALUENAME@), \"@VALUENAME@\", \"@valuenick@\" }," \
	--vtail "    { 0, NULL, NULL }\n  };\n\n  if (g_once_init_enter (&id)) {\n    GType tmp = g_@type@_register_static (\"@EnumName@\", values);\n    g_once_init_leave (&id, tmp);\n  }\n\n  return (GType) id;\n}" \
	$^ > gstenumtypes.c

%.c.gcov: .libs/libgstreamer_@GST_MAJORMINOR@_la-%.gcda %.c
	$(GCOV) -b -f -o $^ > $@.out

gcov: $(libgstreamer_@GST_MAJORMINOR@_la_SOURCES:=.gcov)

if HAVE_INTROSPECTION
BUILT_GIRSOURCES = Gst-@GST_MAJORMINOR@.gir

gir_headers=$(patsubst %,$(srcdir)/%, $(libgstreamer_@GST_MAJORMINOR@include_HEADERS))
gir_sources=$(patsubst %,$(srcdir)/%, $(libgstreamer_@GST_MAJORMINOR@_la_SOURCES))

Gst-@GST_MAJORMINOR@.gir: $(INTROSPECTION_SCANNER) libgstreamer-@GST_MAJORMINOR@.la
	$(AM_V_GEN)$(INTROSPECTION_SCANNER) -v --namespace Gst \
		--nsversion=@GST_MAJORMINOR@ \
		-I$(top_srcdir) \
		-I$(top_builddir) \
		-DIN_GOBJECT_INTROSPECTION=1 \
		--c-include='gst/gst.h' \
		--library=libgstreamer-0.11.la \
		--include=GLib-2.0 \
		--include=GObject-2.0 \
		--include=GModule-2.0 \
		--libtool="$(top_builddir)/libtool" \
		--pkg glib-2.0 \
		--pkg gobject-2.0 \
		--pkg gmodule-no-export-2.0 \
		--pkg gthread-2.0 \
		--pkg-export gstreamer-0.11 \
		--output $@ \
		$(gir_headers) \
		$(gir_sources)

# INTROSPECTION_GIRDIR/INTROSPECTION_TYPELIBDIR aren't the right place to
# install anything - we need to install inside our prefix.
girdir = $(datadir)/gir-1.0
gir_DATA = $(BUILT_GIRSOURCES)

typelibsdir = $(libdir)/girepository-1.0/

typelibs_DATA = $(BUILT_GIRSOURCES:.gir=.typelib)

%.typelib: %.gir $(INTROSPECTION_COMPILER)
	$(AM_V_GEN)$(INTROSPECTION_COMPILER) --includedir=$(srcdir) --includedir=$(builddir) $(INTROSPECTION_COMPILER_OPTS) $< -o $(@F)

CLEANFILES += $(BUILT_GIRSOURCES) $(typelibs_DATA)
endif

# try to prevent packaging errors
check-libexecdir-consistency:
	@if test "${GST_PLUGIN_SCANNER_INSTALLED}" != "${libexecdir}/gstreamer-$(GST_MAJORMINOR)/gst-plugin-scanner"; then \
	  echo "*** Inconsistent libexecdir! Please use ./configure --libexecdir=/foo/bar"; \
	  echo "*** to set the libexecdir and not make libexecdir=/foo/bar or the like."; \
	  echo "*** The same goes for prefix, libdir etc."; \
	  echo "*** ${GST_PLUGIN_SCANNER_INSTALLED} != ${libexecdir}/gstreamer-$(GST_MAJORMINOR)/gst-plugin-scanner"; \
	  exit 1; \
	fi

all-local: check-libexecdir-consistency