lib_LTLIBRARIES = libdmapsharing-4.0.la

libdmapsharing_4_0_la_SOURCES = \
	dmap-av-connection.c \
	dmap-av-record.c \
	dmap-av-share.c \
	dmap-control-connection.c \
	dmap-control-player.c \
	dmap-control-share.c \
	dmap-connection.c \
	dmap-container-db.c \
	dmap-container-record.c \
	dmap-db.c \
	dmap-enums.c \
	dmap-error.c \
	dmap-md5.c \
	dmap-mdns-service.c \
	dmap-private-utils.c \
	dmap-record.c \
	dmap-record-factory.c \
	dmap-share.c \
	dmap-structure.c \
	dmap-utils.c \
	dmap-image-connection.c \
	dmap-image-record.c \
	dmap-image-share.c

if TESTS_ENABLED
libdmapsharing_4_0_la_SOURCES += \
	test-dmap-av-record.c \
	test-dmap-av-record-factory.c \
	test-dmap-container-db.c \
	test-dmap-container-record.c \
	test-dmap-db.c \
	test-dmap-image-record.c \
	test-dmap-image-record-factory.c
endif

if USE_AVAHI
libdmapsharing_4_0_la_SOURCES += \
	dmap-mdns-avahi.c \
	dmap-mdns-browser-avahi.c \
	dmap-mdns-publisher-avahi.c
else
libdmapsharing_4_0_la_SOURCES += \
	dmap-mdns-browser-dnssd.c \
	dmap-mdns-publisher-dnssd.c
endif

if USE_GSTREAMERAPP
libdmapsharing_4_0_la_SOURCES += \
	dmap-transcode-stream.c \
	dmap-transcode-mp3-stream.c \
	dmap-transcode-qt-stream.c \
	dmap-transcode-wav-stream.c \
	gst-util.c
endif

libdmapsharing_4_0_la_CFLAGS = \
	-Wall \
	-Wextra \
	-DG_LOG_DOMAIN=\"libdmapsharing\" \
	-I$(top_srcdir) \
	-I$(top_builddir) \
	$(GDKPIXBUF_CFLAGS) \
	$(SOUP_CFLAGS) \
	$(GSTREAMERAPP_CFLAGS) \
	$(MDNS_CFLAGS) \
	$(WARN_CFLAGS)

libdmapsharing_4_0_la_LDFLAGS = \
	-version-info @SO_VERSION@ \
	$(CHECK_LIBS) \
	$(GLIB_LIBS) \
	$(GTHREAD_LIBS) \
	$(GOBJECT_LIBS) \
	$(GDKPIXBUF_LIBS) \
	$(MDNS_LIBS) \
	$(GSTREAMERAPP_LIBS) \
	$(SOUP_LIBS)

libdmapsharingincludedir = \
	$(includedir)/libdmapsharing-@API_VERSION@/libdmapsharing

maintained_headers = \
	dmap-av-connection.h \
	dmap-av-record.h \
	dmap-av-share.h \
	dmap-cc.h \
	dmap-control-connection.h \
	dmap-control-share.h \
	dmap-control-player.h \
	dmap.h \
	dmap-connection.h \
	dmap-container-db.h \
	dmap-container-record.h \
	dmap-db.h \
	dmap-error.h \
	dmap-md5.h \
	dmap-mdns-browser.h \
	dmap-mdns-publisher.h \
	dmap-mdns-service.h \
	dmap-record.h \
	dmap-record-factory.h \
	dmap-share.h \
	dmap-utils.h \
	dmap-image-connection.h \
	dmap-image-record.h \
	dmap-image-share.h \
	dmap-transcode-stream.h

generated_headers = \
	dmap-enums.h

libdmapsharinginclude_HEADERS = \
	$(maintained_headers) \
	$(generated_headers)

noinst_HEADERS = \
	dmap-config.h \
	dmap-connection-private.h \
	dmap-transcode-mp3-stream.h \
	dmap-transcode-qt-stream.h \
	dmap-transcode-stream-private.h \
	dmap-transcode-wav-stream.h \
	dmap-mdns-avahi.h \
	dmap-private-utils.h \
	dmap-share-private.h \
	dmap-structure.h \
	gst-util.h \
	test-dmap-av-record-factory.h \
	test-dmap-av-record.h \
	test-dmap-container-db.h \
	test-dmap-container-record.h \
	test-dmap-db.h \
	test-dmap-image-record-factory.h \
	test-dmap-image-record.h

BUILT_SOURCES = \
	dmap-enums.c \
	dmap-enums.h \
	unit-test.stamp

CLEANFILES = $(BUILT_SOURCES) \
	../tests/unit-test.c \
	*-suite.c \
	*-suite.h \
	pedansee.conf

dmap-enums.c: $(maintained_headers) Makefile dmap-enums.h
	@glib-mkenums \
			--fhead "/* Automatically generated by glib-mkenums */\n\n#include \"dmap-control-share.h\"\n#include \"dmap-control-player.h\"\n#include \"dmap-mdns-publisher.h\"\n#include \"dmap-mdns-browser.h\"\n#include \"dmap-connection.h\"\n#include \"dmap-error.h\"\n#include \"dmap-enums.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" \
		$(maintained_headers) >$@

dmap-enums.h: $(maintained_headers) Makefile
	@glib-mkenums \
			--fhead "/* Automatically generated by glib-mkenums */\n\n#ifndef _DMAP_ENUMS_H\n#define _DMAP_ENUMS_H\n\n#include <glib-object.h>\n\nG_BEGIN_DECLS\n\n" \
			--fprod "\n/* enumerations from \"@filename@\" */\n" \
			--vhead "GType @enum_name@_get_type (void) G_GNUC_CONST;\n#define DMAP_TYPE_@ENUMNAME@ (@enum_name@_get_type())\n" \
			--ftail "G_END_DECLS\n\n#endif /* _DMAP_ENUMS_H */" $(maintained_headers) >$@

unit-test.stamp: *.c
	./generate-test-suites
	mv unit-test.c ../tests
	touch unit-test.stamp

if HAVE_INTROSPECTION
include $(INTROSPECTION_MAKEFILE)
INTROSPECTION_SCANNER_ARGS = --add-include-path=$(srcdir) --warn-all
INTROSPECTION_COMPILER_ARGS = --includedir=$(srcdir)
introspection_sources = $(libdmapsharinginclude_HEADERS) $(libdmapsharinginclude_SOURCES)

Dmap-4.0.gir: libdmapsharing-4.0.la
Dmap_4_0_gir_NAMESPACE = Dmap 
Dmap_4_0_gir_SCANNERFLAGS = --symbol-prefix=dmap --c-include=libdmapsharing/dmap.h
Dmap_4_0_gir_LIBS = libdmapsharing-4.0.la
Dmap_4_0_gir_FILES = $(introspection_sources)
Dmap_4_0_gir_INCLUDES = GObject-2.0 Soup-3.0 Gst-1.0
Dmap_4_0_gir_CFLAGS = $(INCLUDES) $(libdmapsharing_4_0_la_CFLAGS)

INTROSPECTION_GIRS = Dmap-4.0.gir

girdir = $(datadir)/gir-1.0
gir_DATA = $(INTROSPECTION_GIRS)

typelibdir = $(libdir)/girepository-1.0
typelib_DATA = $(INTROSPECTION_GIRS:.gir=.typelib)

CLEANFILES += $(gir_DATA) $(typelib_DATA)
endif

check-local:
	make clean
	make CFLAGS="-fprofile-arcs -ftest-coverage -g"
	../tests/unit-test
	set -e; for i in $(libdmapsharing_4_0_la_SOURCES); do \
		gcov -r -o .libs/libdmapsharing_4_0_la-$${i%.c}.o $$i >/dev/null; \
	done
	../tests/summarize-coverage ${libdmapsharing_4_0_la_SOURCES:.c=.c.gcov}
if HAVE_PEDANSEE
	echo    "[flags]" >pedansee.conf
	echo    "	skip-unit-test-present = true" >>pedansee.conf
	echo    "	skip-return-value-used = true" >>pedansee.conf
	echo    "[ignore-return-check]" >>pedansee.conf
	echo    "	# Ignore dmap_structure_add; return cannot indicate error." >>pedansee.conf
	echo    "	# Ignore g_object_ref; return value merely a convenience." >>pedansee.conf
	echo -n "	name = " >>pedansee.conf
	echo -n "dmap_structure_add;" >>pedansee.conf
	echo -n "g_object_ref;" >>pedansee.conf
	echo -n "g_string_ascii_up;" >>pedansee.conf
	echo -n "g_string_append_len;" >>pedansee.conf
	echo >>pedansee.conf
	echo    "[ignore-entirely]" >>pedansee.conf
	echo -n "       name = " >>pedansee.conf
	pedansee-conf-gobject *.c >>pedansee.conf
	echo -n  	      "dmap_mdns_browser_new;" >>pedansee.conf
	echo -n  	      "dmap_mdns_browser_start;" >>pedansee.conf
	echo -n  	      "dmap_mdns_browser_stop;" >>pedansee.conf
	echo -n  	      "dmap_mdns_browser_error_quark;" >>pedansee.conf
	echo -n  	      "dmap_mdns_browser_get_services;" >>pedansee.conf
	echo -n  	      "dmap_mdns_browser_get_service_type;" >>pedansee.conf
	echo -n		      "dmap_mdns_publisher_new;" >>pedansee.conf
	echo -n		      "dmap_mdns_publisher_error_quark;" >>pedansee.conf
	echo -n		      "dmap_mdns_publisher_rename_at_port;" >>pedansee.conf
	echo -n		      "dmap_mdns_publisher_publish;" >>pedansee.conf
	echo -n		      "dmap_mdns_publisher_withdraw;" >>pedansee.conf
	echo -n		      "dmap_connection_get;" >>pedansee.conf

	set -e; for i in $(libdmapsharing_4_0_la_SOURCES); do \
		if [ $$i = dmap-enums.c ]; then # Skip this generated code. \
			continue; \
		fi; \
		$(PEDANSEE) -c pedansee.conf $$i -- -x c $(DEFS) $(libdmapsharing_4_0_la_CFLAGS); \
	done

	set -e; for i in $(maintained_headers) \
	                 $(noinst_HEADERS); do \
		if [ $$i = dmap-share-private.h ]; then # Skip this code. \
			continue; \
		fi; \
		if [ $$i = dmap-connection-private.h ]; then # Skip this code. \
			continue; \
		fi; \
		$(PEDANSEE) -c pedansee.conf $$i -- -x c $(DEFS) $(libdmapsharing_4_0_la_CFLAGS); \
	done
endif

EXTRA_DIST = generate-test-suites
