BUILT_GIRSOURCES =
SUBSTITUTED_GIRSOURCES =

STATIC_GIRSOURCES =               \
        gir/DBus-1.0.gir           \
        gir/DBusGLib-1.0.gir        \
        gir/fontconfig-2.0.gir      \
        gir/freetype2-2.0.gir       \
        gir/GL-1.0.gir              \
        gir/libxml2-2.0.gir         \
        gir/xft-2.0.gir             \
        gir/xlib-2.0.gir            \
        gir/xfixes-4.0.gir          \
        gir/xrandr-1.3.gir
EXTRA_DIST += $(STATIC_GIRSOURCES)

gir/cairo-1.0.gir: gir/cairo-1.0.gir.in Makefile
	[ -d $(@D) ] || $(mkdir_p) $(@D) ; \
	sed \
	-e s,%CAIRO_SHARED_LIBRARY%,$(CAIRO_SHARED_LIBRARY), \
	-e s,%CAIRO_GIR_PACKAGE%,$(CAIRO_GIR_PACKAGE), \
	< $< > $@.tmp && mv $@.tmp $@
BUILT_SOURCES += gir/cairo-1.0.gir
SUBSTITUTED_GIRSOURCES += gir/cairo-1.0.gir
CLEANFILES += gir/cairo-1.0.gir
EXTRA_DIST += gir/cairo-1.0.gir.in

# Doesn't seem to work to do gir/%.typelib =(
gir/cairo-1.0.typelib: g-ir-compiler
gir/DBus-1.0.typelib: g-ir-compiler
gir/DBusGLib-1.0.typelib: g-ir-compiler
gir/fontconfig-2.0.typelib: g-ir-compiler
gir/freetype2-2.0.typelib: g-ir-compiler
gir/GL-1.0.typelib: g-ir-compiler
gir/libxml2-2.0.typelib: g-ir-compiler
gir/xft-2.0.typelib: g-ir-compiler
gir/xlib-2.0.typelib: g-ir-compiler
gir/xfixes-4.0.typelib: g-ir-compiler
gir/xrandr-1.3.typelib: g-ir-compiler

# glib with source (to enable documentation)
if WITH_GLIBSRC
     GLib_2_0_gir_DOCSRC = $(GLIBSRC)/glib/*.c
     GObject_2_0_gir_DOCSRC = $(GLIBSRC)/gobject/*.c
     GModule_2_0_gir_DOCSRC = $(GLIBSRC)/gmodule/*.c
     Gio_2_0_gir_DOCSRC = $(GLIBSRC)/gio/*.c
else
    GLib_2_0_gir_DOCSRC = 
    GObject_2_0_gir_DOCSRC = 
    GModule_2_0_gir_DOCSRC = 
    Gio_2_0_gir_DOCSRC = 

endif

# glib
GLIB_INCLUDEDIR=$(shell pkg-config --variable=includedir glib-2.0)/glib-2.0
GLIB_LIBDIR=$(shell pkg-config --variable=libdir glib-2.0)

if OS_WIN32
GLIB_LIBRARY=libglib-2.0-0
else
GLIB_LIBRARY=glib-2.0
endif

GLib_2_0_gir_LIBS = $(GLIB_LIBRARY) $(GOBJECT_LIBRARY)
GLib_2_0_gir_SCANNERFLAGS = \
            --external-library \
            --reparse-validate \
            --identifier-prefix=G \
            --symbol-prefix=g \
            --symbol-prefix=glib \
            --c-include="glib.h" \
            $(GLib_2_0_gir_DOCSRC)
GLib_2_0_gir_PACKAGES = glib-2.0
GLib_2_0_gir_CFLAGS = \
            -I$(GLIB_INCLUDEDIR) \
            -I$(GLIB_LIBDIR)/glib-2.0/include \
            -DGETTEXT_PACKAGE=Dummy \
            -DGLIB_COMPILATION \
            -D__G_I18N_LIB_H__
GLib_2_0_gir_FILES =  \
                $(GLIB_LIBDIR)/glib-2.0/include/glibconfig.h \
		$(GLIB_INCLUDEDIR)/glib/*.h \
		$(GLIB_INCLUDEDIR)/gobject/glib-types.h \
                gir/glib-2.0.c
if HAVE_GIO_UNIX
GLib_2_0_gir_FILES += $(GLIB_INCLUDEDIR)/glib-unix.h
endif

BUILT_GIRSOURCES += GLib-2.0.gir

GLib-2.0.gir: g-ir-scanner g-ir-compiler$(EXEEXT)

gir/DBusGLib-1.0.typelib: GObject-2.0.gir

# gobject
GOBJECT_INCLUDEDIR=$(shell pkg-config --variable=includedir gobject-2.0)/glib-2.0
GOBJECT_LIBDIR=$(shell pkg-config --variable=libdir gobject-2.0)

if OS_WIN32
GOBJECT_LIBRARY=libgobject-2.0-0
else
GOBJECT_LIBRARY=gobject-2.0
endif

GObject-2.0.gir: GLib-2.0.gir
GObject_2_0_gir_LIBS = $(GOBJECT_LIBRARY)
GObject_2_0_gir_SCANNERFLAGS = \
            --external-library \
            --reparse-validate \
            --identifier-prefix=G \
            --c-include="glib-object.h" \
            --add-include-path=. \
            $(GObject_2_0_gir_DOCSRC)

GObject_2_0_gir_PACKAGES = gobject-2.0
GObject_2_0_gir_INCLUDES = GLib-2.0
GObject_2_0_gir_CFLAGS = \
            -DGOBJECT_COMPILATION \
            -I$(GOBJECT_INCLUDEDIR) \
            -I$(GOBJECT_LIBDIR)/glib-2.0/include
GObject_2_0_gir_FILES = \
	$(filter-out $(GOBJECT_INCLUDEDIR)/gobject/glib-types.h, $(wildcard $(GOBJECT_INCLUDEDIR)/gobject/*.h)) \
	gir/gobject-2.0.c

BUILT_GIRSOURCES += GObject-2.0.gir

# gmodule
GMODULE_INCLUDEDIR=$(shell pkg-config --variable=includedir gmodule-2.0)/glib-2.0
GMODULE_LIBDIR=$(shell pkg-config --variable=libdir gmodule-2.0)

if OS_WIN32
GMODULE_LIBRARY=libgmodule-2.0-0
else
GMODULE_LIBRARY=gmodule-2.0
endif

GModule-2.0.gir: GLib-2.0.gir

GModule_2_0_gir_LIBS = $(GMODULE_LIBRARY)
GModule_2_0_gir_SCANNERFLAGS = \
            --external-library \
            --identifier-prefix=G \
            --c-include="gmodule.h" \
            --add-include-path=. \
            $(GModule_2_0_gir_DOCSRC)

GModule_2_0_gir_PACKAGES = gmodule-2.0
GModule_2_0_gir_INCLUDES = GLib-2.0
GModule_2_0_gir_CFLAGS = \
            -I$(GMODULE_INCLUDEDIR) \
            -I$(GMODULE_LIBDIR)/glib-2.0/include
GModule_2_0_gir_FILES = $(GLIB_INCLUDEDIR)/gmodule.h

BUILT_GIRSOURCES += GModule-2.0.gir

# gio
GIO_INCLUDEDIR=$(shell pkg-config --variable=includedir gio-2.0)/glib-2.0
GIO_LIBDIR=$(shell pkg-config --variable=libdir gio-2.0)

if OS_WIN32
GIO_LIBRARY=libgio-2.0-0
else
GIO_LIBRARY=gio-2.0
endif

if HAVE_GIO_UNIX
GIO_UNIX_HDRS=$(shell pkg-config --variable=includedir gio-unix-2.0)/gio-unix-2.0/gio/*.h
GIO_UNIX_PACKAGES = gio-unix-2.0
else
GIO_UNIX_HDRS=
GIO_UNIX_PACKAGES =
endif
GIO_CINCLUDES=$(patsubst %,--c-include='%',$(shell echo $(GIO_UNIX_HDRS)))

Gio-2.0.gir: GObject-2.0.gir

Gio_2_0_gir_LIBS = $(GIO_LIBRARY)
Gio_2_0_gir_SCANNERFLAGS = \
            --external-library \
            --reparse-validate \
            --warn-all \
            --identifier-prefix=G \
            --c-include="gio/gio.h" \
            $(GIO_CINCLUDES) \
            --add-include-path=. \
            $(Gio_2_0_gir_DOCSRC)

Gio_2_0_gir_PACKAGES = gio-2.0 $(GIO_UNIX_PACKAGES)
Gio_2_0_gir_INCLUDES = GObject-2.0
Gio_2_0_gir_CFLAGS = \
            -DGIO_COMPILATION \
            -I$(GIO_LIBDIR)/glib-2.0/include
Gio_2_0_gir_FILES = \
            $(GIO_UNIX_HDRS) \
            $(filter-out %/gsettingsbackend.h, $(shell echo $(GIO_INCLUDEDIR)/gio/*.h)) \
            gir/gio-2.0.c

BUILT_GIRSOURCES += Gio-2.0.gir
EXTRA_DIST += gir/glib-2.0.c gir/gobject-2.0.c gir/gio-2.0.c

# girepository
GIRepository-2.0.gir: GObject-2.0.gir libgirepository-1.0.la

GIRepository_2_0_gir_LIBS = libgirepository-1.0.la
GIRepository_2_0_gir_SCANNERFLAGS = \
	--warn-all \
        --identifier-prefix=GI \
        --symbol-prefix=g \
        --c-include="girepository.h" \
        --add-include-path=.
GIRepository_2_0_gir_PACKAGES = gobject-2.0
GIRepository_2_0_gir_INCLUDES = GObject-2.0
GIRepository_2_0_gir_EXPORT_PACKAGES = gobject-introspection-1.0
GIRepository_2_0_gir_CFLAGS = \
    -I$(top_srcdir)/girepository -I$(top_srcdir) \
    -DGI_COMPILATION
GIRepository_2_0_gir_FILES = \
        $(top_srcdir)/girepository/girepository.h   \
        $(top_srcdir)/girepository/girepository.c   \
        $(top_srcdir)/girepository/gi*info.c	    \
        $(top_srcdir)/girepository/gi*info.h	    \
        $(top_srcdir)/girepository/gitypelib.h	    \
        $(top_srcdir)/girepository/gitypes.h

BUILT_GIRSOURCES += GIRepository-2.0.gir

CLEANFILES += $(BUILT_GIRSOURCES)

INTROSPECTION_GIRS += $(BUILT_GIRSOURCES)

girdir = $(GIR_DIR)
gir_DATA = $(STATIC_GIRSOURCES) $(SUBSTITUTED_GIRSOURCES) $(BUILT_GIRSOURCES)

typelibsdir = $(libdir)/girepository-1.0
typelibs_DATA = $(gir_DATA:.gir=.typelib)

CLEANFILES += $(typelibs_DATA)
