MARSHAL_PREFIX = indicate_marshal
MARSHAL_FILE = indicate-marshal
ENUM_FILE = indicate-enum-types

INCLUDES= \
	-DG_LOG_DOMAIN=\"libindicate\"

EXTRA_DIST = \
	indicate-interface.xml \
	indicate-listener.xml \
	listener-marshal.list \
	indicate.pc.in

BUILT_SOURCES = \
	dbus-indicate-server.h \
	dbus-indicate-client.h \
	dbus-listener-server.h \
	dbus-listener-client.h \
	listener-marshal.c \
	listener-marshal.h \
	$(ENUM_FILE).h \
	$(ENUM_FILE).c

lib_LTLIBRARIES = \
	libindicate.la

libindicateincludedir=$(includedir)/libindicate-0.1/libindicate

indicate_headers = \
	indicator.h \
	indicator-message.h \
	listener.h \
	server.h \
	interests.h \
	$(ENUM_FILE).h

libindicateinclude_HEADERS = \
	$(indicate_headers)

libindicate_la_SOURCES = \
	$(indicate_headers) \
	dbus-indicate-server.h \
	dbus-indicate-client.h \
	dbus-listener-server.h \
	dbus-listener-client.h \
	indicate-enum-types.c \
	server.c \
	listener.c \
	listener-marshal.c \
	listener-marshal.h \
	indicator.c \
	indicator-message.c \
	interests-priv.h

libindicate_la_LDFLAGS = \
	-version-info $(LIBINDICATE_CURRENT):$(LIBINDICATE_REVISION):$(LIBINDICATE_AGE) \
	-no-undefined \
	-export-symbols-regex "^[^_d].*"

libindicate_la_CFLAGS = \
	$(LIBINDICATE_CFLAGS)

libindicate_la_LIBADD = \
	$(LIBINDICATE_LIBS)

dbus-indicate-server.h: indicate-interface.xml
	dbus-binding-tool \
		--prefix=_indicate_server \
		--mode=glib-server \
		--output=dbus-indicate-server.h \
		$(srcdir)/indicate-interface.xml

dbus-indicate-client.h: indicate-interface.xml
	dbus-binding-tool \
		--prefix=_indicate_client \
		--mode=glib-client \
		--output=dbus-indicate-client.h \
		$(srcdir)/indicate-interface.xml

dbus-listener-server.h: indicate-listener.xml
	dbus-binding-tool \
		--prefix=_indicate_listener \
		--mode=glib-server \
		--output=dbus-listener-server.h \
		$(srcdir)/indicate-listener.xml

dbus-listener-client.h: indicate-listener.xml
	dbus-binding-tool \
		--prefix=_indicate_listener \
		--mode=glib-client \
		--output=dbus-listener-client.h \
		$(srcdir)/indicate-listener.xml

listener-marshal.h: $(srcdir)/listener-marshal.list
	glib-genmarshal --header \
		--prefix=_indicate_listener_marshal $(srcdir)/listener-marshal.list \
		> listener-marshal.h

listener-marshal.c: $(srcdir)/listener-marshal.list
	glib-genmarshal --body \
		--prefix=_indicate_listener_marshal $(srcdir)/listener-marshal.list \
		> listener-marshal.c

pkgconfig_DATA = indicate.pc
pkgconfigdir = $(libdir)/pkgconfig

$(ENUM_FILE).h: s-enum-types-h
	@true
s-enum-types-h: $(indicate_headers) Makefile
	( cd $(srcdir) && glib-mkenums \
			--fhead "#ifndef _INDICATE_ENUM_TYPES_H_\n#define _INDICATE_ENUM_TYPES_H_\n\n#include <glib-object.h>\n\nG_BEGIN_DECLS\n" \
			--fprod "/* enumerations from \"@filename@\" */\n" \
			--vhead "GType @enum_name@_get_type(void);\n#define INDICATE_TYPE_@ENUMSHORT@ (@enum_name@_get_type())\n"	\
			--ftail "G_END_DECLS\n\n#endif /* _INDICATE_ENUM_TYPES_H_ */" \
		interests.h ) > tmp-$(ENUM_FILE).h \
	&& (cmp -s tmp-$(ENUM_FILE).h $(ENUM_FILE).h || cp tmp-$(ENUM_FILE).h $(ENUM_FILE).h ) \
	&& rm -f tmp-$(ENUM_FILE).h	\
	&& echo timestamp > $(@F)

$(ENUM_FILE).c: s-enum-types-c
	@true
s-enum-types-c: $(indicate_headers) Makefile
	( cd $(srcdir) && glib-mkenums \
			--fhead "#include \"interests.h\"\n#include <glib-object.h>" \
			--fprod "\n/* enumerations from \"@filename@\" */" \
			--vhead "GType\n@enum_name@_get_type (void)\n{\n  static GType etype = 0;\n  if (etype == 0) {\n    static const G@Type@Value values[] = {" 	\
			--vprod "      { @VALUENAME@, \"@VALUENAME@\", \"@valuenick@\" }," \
			--vtail "      { 0, NULL, NULL }\n    };\n    etype = g_@type@_register_static (\"@EnumName@\", values);\n  }\n  return etype;\n}\n" \
		interests.h ) > tmp-$(ENUM_FILE).c \
	&& (cmp -s tmp-$(ENUM_FILE).c $(ENUM_FILE).c || cp tmp-$(ENUM_FILE).c $(ENUM_FILE).c ) \
	&& rm -f tmp-$(ENUM_FILE).c \
	&& echo timestamp > $(@F)

CLEANFILES = \
	$(ENUM_FILE).c \
	$(ENUM_FILE).h \
	s-enum-types-c \
	s-enum-types-h

if USE_GIR

gobjectintrospection_gir_DATA = \
	Indicate-0.1.gir
gobjectintrospection_girdir = $(datadir)/gir

gobjectintrospection_type_DATA = \
	Indicate-0.1.typelib
gobjectintrospection_typedir = $(libdir)/girepository

irscanner_headers = $(patsubst %,$(srcdir)/%,$(indicate_headers))
Indicate-0.1.gir: $(irscanner_headers)
	$(G_IR_SCANNER) \
		-v --namespace Indicate \
		--nsversion=0.1 \
		--add-include-path=$(srcdir) \
		--include=GObject-2.0 \
		--include=GLib-2.0 \
		--include=GdkPixbuf-2.0 \
		--library=indicate --pkg indicate \
		--output Indicate-0.1.gir $(irscanner_headers)

Indicate-0.1.typelib: Indicate-0.1.gir
	$(G_IR_COMPILER) \
		--includedir=$(srcdir) Indicate-0.1.gir \
		-o Indicate-0.1.typelib

DISTCLEANFILES = \
	Indicate-0.1.gir \
	Indicate-0.1.typelib

endif
