# Global include and libs stuff.
INCLUDES = $(DIACANVAS2_CFLAGS) -I.. -DG_LOG_DOMAIN=\"DiaCanvas2\"

if PLATFORM_WIN32
no_undefined = -no-undefined
endif

lib_LTLIBRARIES = libdiacanvas2.la

# Code for the diagram model.
model_headers = \
	dia-canvas.h		\
	dia-canvas-item.h	\
	dia-canvas-group.h	\
	dia-canvas-groupable.h	\
	dia-canvas-editable.h	\
	dia-shape.h		\
	dia-handle.h		\
	dia-event.h		\
	dia-geometry.h		\
	dia-canvas-iter.h	\
	dia-canvas-i18n.h	\
	dia-export-svg.h	\
	dia-export-print.h

model_sources = \
	dia-canvas.c		\
	dia-canvas-item.c	\
	dia-canvas-group.c	\
	dia-canvas-groupable.c	\
	dia-canvas-editable.c	\
	dia-shape.c		\
	dia-handle.c		\
	dia-geometry.c		\
	dia-canvas-iter.c	\
	dia-export-svg.c	\
	dia-export-print.c	\
	diatypes.c

# The linear constraint solver
solver_headers = \
	dia-strength.h		\
	dia-variable.h		\
	dia-constraint.h	\
	dia-solver.h

solver_sources = \
	dia-variable.c		\
	dia-constraint.c	\
	dia-solver.c

# Handly (example) objects
object_headers = \
	dia-canvas-line.h	\
	dia-canvas-element.h	\
	dia-canvas-box.h	\
	dia-canvas-text.h	\
	dia-canvas-image.h

object_sources = \
	dia-canvas-line.c	\
	dia-canvas-element.c	\
	dia-canvas-box.c	\
	dia-canvas-text.c	\
	dia-canvas-image.c

# Views for the canvas, based on GnomeCanvas
view_sources = \
	dia-canvas-view.c	\
	dia-canvas-view-item.c	\
	dia-shape-art.c		\
	dia-shape-x.c		\
	dia-handle-layer.c	\
	dia-selector.c		\
	dia-tool.c		\
	dia-selection-tool.c	\
	dia-handle-tool.c	\
	dia-item-tool.c		\
	dia-default-tool.c	\
	dia-placement-tool.c	\
	dia-stack-tool.c

view_headers = \
	dia-canvas-view.h	\
	dia-shape-art.h		\
	dia-shape-x.h		\
	dia-handle-layer.h	\
	dia-selector.h		\
	dia-tool.h		\
	dia-selection-tool.h	\
	dia-handle-tool.h	\
	dia-item-tool.h		\
	dia-default-tool.h	\
	dia-placement-tool.h	\
	dia-stack-tool.h

all_headers = \
	$(model_headers)	\
	$(solver_headers)	\
	$(object_headers)	\
	$(view_headers)

all_sources = \
	$(model_sources)	\
	$(solver_sources)	\
	$(object_sources)	\
	$(view_sources)		\
	diatypebuiltins.c

libdiacanvas2includedir = $(includedir)/diacanvas
libdiacanvas2include_HEADERS = $(all_headers) diatypebuiltins.h diamarshal.h dia-features.h
libdiacanvas2_la_SOURCES = $(all_sources) 
libdiacanvas2_la_LDFLAGS = $(no_undefined)
libdiacanvas2_la_LIBADD = $(DIACANVAS2_LIBS) 

# Do the unit tests!
test: all
	( cd $(top_srcdir)/unit_tests && $(MAKE) check )

#defs: diacanvas.defs
#
#diacanvas.defs: $(all_headers)
#	$(PYTHON) ../scripts/h2def.py $(all_headers) > diacanvas.defs

# ctags for vi(m)
ctags:
	rm tags; ctags -dt $(all_sources) $(all_headers)

# all autogenerated files need to be generated in the srcdir,
# so old versions get remade and are not confused with newer
# versions in the build dir. thus a development setup requires
# srcdir to be writable, passing --disable-rebuilds to
# ../configure will supress all autogeneration rules.
#
$(srcdir)/diatypebuiltins.c: @REBUILD@ Makefile.am $(all_headers)
	cd $(srcdir) \
	&& glib-mkenums \
			--fhead "#include <glib-object.h>\n" \
			--fhead "#include \"diatypebuiltins.h\"\n\n" \
			--fprod "\n/* enumerations from \"@filename@\" */\n" \
			--fprod "#include \"@filename@\"\n" \
			--vhead "static const G@Type@Value _@enum_name@_values[] = {" \
			--vprod "  { @VALUENAME@, \"@VALUENAME@\", \"@valuenick@\" }," \
			--vtail "  { 0, NULL, NULL }\n};\n\n" \
			--vtail "GType\n@enum_name@_get_type (void)\n{\n" \
			--vtail "  static GType type = 0;\n\n" \
			--vtail "  if (!type)\n" \
			--vtail "    type = g_@type@_register_static (\"@EnumName@\", _@enum_name@_values);\n\n" \
			--vtail "  return type;\n}\n\n" \
		$(all_headers) > xgen-gtbec \
	&& cp xgen-gtbec $(@F) \
	&& rm -f xgen-gtbec

$(srcdir)/diatypebuiltins.h: @REBUILD@ Makefile.am $(all_headers)
	cd $(srcdir) \
	&& glib-mkenums \
			--fhead "#ifndef __DIATYPEBUILTINS_H__\n" \
			--fhead "#define __DIATYPEBUILTINS_H__ 1\n\n" \
			--fhead "#include <glib-object.h>\n\n" \
			--fhead "G_BEGIN_DECLS\n\n" \
			--ftail "G_END_DECLS\n\n" \
			--ftail "#endif /* __DIATYPEBUILTINS_H__ */\n" \
			--fprod "\n/* --- @filename@ --- */" \
			--eprod "#define DIA_TYPE_@ENUMSHORT@ @enum_name@_get_type()\n" \
			--eprod "GType @enum_name@_get_type (void);\n" \
		$(all_headers) > xgen-gth \
	&& cp xgen-gth $(@F) \
	&& rm -f xgen-gth

# Marshaler stuff
$(srcdir)/diamarshal.h: @REBUILD@ Makefile.am diamarshal.list
	cd $(srcdir) \
	&& glib-genmarshal --prefix=dia_marshal diamarshal.list --header >> xgen-gmh \
	&& (cmp -s xgen-gmh diamarshal.h || cp xgen-gmh diamarshal.h) \
	&& rm -f xgen-gmh xgen-gmh~

$(srcdir)/diamarshal.c: @REBUILD@ Makefile.am diamarshal.list
	cd $(srcdir) \
	&& glib-genmarshal --prefix=dia_marshal diamarshal.list --body >> xgen-gmc \
	&& cp xgen-gmc diamarshal.c \
	&& rm -f xgen-gmc xgen-gmc~

EXTRA_DIST = \
	diamarshal.list		\
	diamarshal.c		\
	dia-boxed.defs

BUILT_SOURCES = \
	diatypebuiltins.h	\
	diatypebuiltins.c	\
	diamarshal.h		\
	diamarshal.c

uninstall-local:
	@if test -d $(libdiacanvas2includedir); then \
	  echo " rmdir $(libdiacanvas2includedir)" && \
	  rmdir $(libdiacanvas2includedir); \
	fi
