This site has been retired. For up to date information, see handbook.gnome.org or gitlab.gnome.org.


[Home] [TitleIndex] [WordIndex

Checklist

Checklist for making a GObject based library using autotools provide introspection support. It's not comprehensive, you'll need to adapt this for the library you're adding introspection support to.

There are 2 ways to add introspection support, one adds the introspection m4 to the distribution, and the library will still build even if introspection is not installed. The other method will add a build dependency on introspection (you will need introspection installed to run ./autogen or ./configure)

Method 1 - Recommended - most portable

  Create an m4 directory in the root
  copy gobject-introspection/m4/introspection.m4 to m4/
  or 
  copy /usr/share/aclocal/introspection.m4 to m4/

#-- these may be in the file already, or you may need to modify the existing lines.
  AC_PREREQ(2.62)
  AM_INIT_AUTOMAKE([-Wno-portability])

#
# Gobject Introspection
#
#-- add the correct m4 directory location.
  AC_CONFIG_MACRO_DIR([m4])

#-- any typos here, and you will end up with a message about HAVE_INTROSPECTION not being defined
  GOBJECT_INTROSPECTION_CHECK([1.30.0])

  ACLOCAL_AMFLAGS = -I m4 ${ACLOCAL_FLAGS}
  DISTCHECK_CONFIGURE_FLAGS = --enable-introspection
  EXTRA_DIST = m4/introspection.m4
  SUBDIRS = m4 ...

Method 2 - Add a build dependency on Introspection

Introspection will be required to build the library, however you will not have to update the m4 files in the future.

 GOBJECT_INTROSPECTION_CHECK([1.30.0])

  DISTCHECK_CONFIGURE_FLAGS = --enable-introspection

or just add to the existing DISTCHECK_CONFIGURE_FLAGS

Method 1 and Method 2

  -include $(INTROSPECTION_MAKEFILE)
  INTROSPECTION_GIRS =
  INTROSPECTION_SCANNER_ARGS = --add-include-path=$(srcdir) --warn-all
  INTROSPECTION_COMPILER_ARGS = --includedir=$(srcdir)

  if HAVE_INTROSPECTION
  introspection_sources = $(libfoo_1_0_la_SOURCES)

  Foo-1.0.gir: libfoo-1.0.la
  Foo_1_0_gir_INCLUDES = GObject-2.0
  Foo_1_0_gir_CFLAGS = $(INCLUDES)
  Foo_1_0_gir_LIBS = libfoo-1.0.la
  Foo_1_0_gir_FILES = $(introspection_sources)
  INTROSPECTION_GIRS += Foo-1.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

You can also check out a complete example at http://git.gnome.org/cgit/gtk+/tree/gtk/Makefile.am#n962

Makefile variable documentation

INTROSPECTION_GIRS is the entry point, you should list all the gir files you want to build there in the XXX-Y.gir format where X is the name of the gir (for example Gtk) and Y is the version (for example 2.0).

If output is Gtk-2.0.gir then you should name the variables like Gtk_2_0_gir_NAMESPACE, Gtk_2_0_gir_VERSION etc.


2024-10-23 11:36