summaryrefslogtreecommitdiff
path: root/Makefile.introspection
diff options
context:
space:
mode:
authorJohan Dahlin <jdahlin@litl.com>2009-12-14 17:21:54 -0200
committerJohan Dahlin <johan@gnome.org>2009-12-14 20:59:56 -0200
commitca7865b8b29e8a764e3511d556e16c00432c2fd2 (patch)
tree703be5f949a57e370ea9716c38506033aca0fd6d /Makefile.introspection
parentdb381df952f39a2a50ca29e83bfe1d3235edd3ee (diff)
downloadgobject-introspection-ca7865b8b29e8a764e3511d556e16c00432c2fd2.tar.gz
Add a Makefile.introspection
This will make it easier for third-party projects to use introspection by having easy make rules.
Diffstat (limited to 'Makefile.introspection')
-rw-r--r--Makefile.introspection134
1 files changed, 134 insertions, 0 deletions
diff --git a/Makefile.introspection b/Makefile.introspection
new file mode 100644
index 00000000..9d060d90
--- /dev/null
+++ b/Makefile.introspection
@@ -0,0 +1,134 @@
+# -*- Mode: make -*-
+# Copyright 2009 Johan Dahlin
+#
+# This file is free software; the author(s) gives unlimited
+# permission to copy and/or distribute it, with or without
+# modifications, as long as this notice is preserved.
+#
+# * Input variables:
+#
+# INTROSPECTION_GIRS - List of GIRS that should be generated
+# INTROSPECTION_SCANNER - Command to invoke scanner, normally set by
+# GOBJECT_INTROSPECTION_REQUIRE/CHECK() in introspection.m4
+# INTROSPECTION_SCANNER_ARGS - Additional args to pass in to the scanner
+# INTROSPECTION_COMPILER - Command to invoke compiler, normally set by
+# GOBJECT_INTROSPECTION_REQUIRE/CHECK() in introspection.m4
+# INTROSPECTION_COMPILER_ARGS - Additional args to pass in to the compiler
+#
+# * Simple tutorial
+#
+# Add this to configure.ac:
+# -Wno-portability to AM_INIT_AUTOMAKE
+# GOBJECT_INTROSPECTION_CHECK([0.6.7])
+#
+# Add this to Makefile.am where your library/program is built:
+# include $(INTROSPECTION_MAKEFILE)
+# INTROSPECTION_GIRS = YourLib-1.0.gir
+# YourLib_1_0_gir_NAMESPACE = YourLib
+# YourLib_1_0_gir_VERSION = 1.0
+# YourLib_1_0_gir_LIBS = libyourlib.la
+# YourLib_1_0_gir_FILES = $(libyourlib_1_0_SOURCES)
+# girdir = $(INTROSPECTION_GIRDIR)
+# dist_gir_DATA = YourLib-1.0.gir
+# typelibdir = $(INTROSPECTION_TYPELIBDIR)
+# typelib_DATA = YourLib-1.0.typelib
+# CLEANFILES = $(dist_gir_DATA) $(typelib_DATA)
+#
+
+# Make sure the required variables are set, these should under normal
+# circumstances come from introspection.m4
+$(if $(INTROSPECTION_GIRS),,$(error Need to define INTROSPECTION_GIRS))
+$(if $(INTROSPECTION_SCANNER),,$(error Need to define INTROSPECTION_SCANNER))
+$(if $(INTROSPECTION_COMPILER),,$(error Need to define INTROSPECTION_COMPILER))
+
+#
+# Creates a GIR by scanning C headers/sources
+# $(1) - Name of the gir file (output)
+#
+# 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.
+# Required variables:
+# FILES - C sources and headers which should be scanned
+#
+# One of these variables are required:
+# LIBS - Library where the symbol represented in the gir can be found
+# PROGRAM - Program where the symbol represented in the gir can be found
+#
+# Optional variables
+# NAMESPACE - Namespace of the gir, first letter capital,
+# rest should be lower case, for instance: 'Gtk', 'Clutter', 'ClutterGtk'.
+# If not present the namespace will be fetched from the gir filename,
+# the part before the first dash. For 'Gtk-2.0', namespace will be 'Gtk'.
+# VERSION - Version of the gir, if not present, will be fetched from gir
+# filename, the part after the first dash. For 'Gtk-2.0', version will be '2.0'.
+# LIBTOOL - Command to invoke libtool, usually set by automake
+# SCANNERFLAGS - Flags to pass in to the scanner, see g-ir-scanner(1) for a list
+# CFLAGS - Flags to pass in to the parser when scanning headers
+# PACKAGES - list of pkg-config names which cflags are required to parse
+# the headers of this gir
+# INCLUDES - Gir files to include without the .gir suffix, for instance
+# GLib-2.0, Gtk-2.0. This is needed for all libraries which you depend on that
+# provides introspection information.
+#
+define introspection-scanner
+
+# Transform the gir filename to something which can reference through a variable
+# without automake/make complaining, eg Gtk-2.0.gir -> Gtk_2_0_gir
+_gir_name = $(subst -,_,$(subst .,_,$(1)))
+
+# Basic sanity check, to make sure required variables are set
+$(if $($(_gir_name)_FILES),,$(error Need to define $(_gir_name)_FILES))
+$(if $(or $($(_gir_name)_LIBS),
+ $($(_gir_name)_PROGRAM)),,
+ $(error Need to define $(_gir_name)_LIBS or $(_gir_name)_PROGRAM))
+
+# Namespace and Version is either fetched from the gir filename
+# or the _NAMESPACE/_VERSION variable combo
+_gir_namespace = $(or $($(_gir_name)_NAMESPACE),$(firstword $(subst -, ,$(1))))
+_gir_version = $(or $($(_gir_name)_VERSION),$(lastword $(subst -, ,$(1:.gir=))))
+
+# _PROGRAM is an optional variable which needs it's own --program argument
+_gir_program = $(if $($(_gir_name)_PROGRAM),--program=$($(_gir_name)_PROGRAM))
+
+# Variables which provides a list of things
+_gir_libraries = $(foreach lib,$($(_gir_name)_LIBS),--library=$(lib))
+_gir_packages = $(foreach pkg,$($(_gir_name)_PACKAGES),--pkg=$(pkg))
+_gir_includes = $(foreach include,$($(_gir_name)_INCLUDES),--include=$(include))
+
+# Reuse the LIBTOOL variable from by automake if it's set
+_gir_libtool = $(if $(LIBTOOL),--libtool="$(LIBTOOL)")
+
+# Only dependencies we know are actually filenames goes into _FILES, make
+# sure these are built before running the scanner. Libraries and programs
+# needs to be added manually.
+$(1): $$($(_gir_name)_FILES) $(INTROSPECTION_PARSER)
+ ## Invoke the scanner
+ $(INTROSPECTION_SCANNER) $(INTROSPECTION_SCANNER_ARGS) \
+ --namespace=$(_gir_namespace) \
+ --nsversion=$(_gir_version) \
+ $(_gir_libtool) \
+ $(_gir_program) \
+ $(_gir_libraries) \
+ $(_gir_packages) \
+ $(_gir_includes) \
+ $($(_gir_name)_SCANNERFLAGS) \
+ $($(_gir_name)_CFLAGS) \
+ $($(_gir_name)_FILES) \
+ ## Output should go last as it makes it easier to read compilation logs
+ --output $(1)
+endef
+
+$(foreach gir,$(INTROSPECTION_GIRS),$(eval $(call introspection-scanner,$(gir))))
+
+#
+# Compiles a gir into a typelib
+# $(1): gir filename (input)
+# $(2): typelib filename (output)
+#
+define introspection-compiler
+$(INTROSPECTION_COMPILER) $(INTROSPECTION_COMPILER_ARGS) --includedir=. $(1) -o $(2)
+endef
+
+# Simple rule to compile a typelib.
+%.typelib: %.gir $(INTROSPECTION_COMPILER)
+ $(call introspection-compiler,$<,$@)