2 # Copyright 2009 Johan Dahlin
4 # This file is free software; the author(s) gives unlimited
5 # permission to copy and/or distribute it, with or without
6 # modifications, as long as this notice is preserved.
10 # INTROSPECTION_GIRS - List of GIRS that should be generated
11 # INTROSPECTION_SCANNER - Command to invoke scanner, normally set by
12 # GOBJECT_INTROSPECTION_REQUIRE/CHECK() in introspection.m4
13 # INTROSPECTION_SCANNER_ARGS - Additional args to pass in to the scanner
14 # INTROSPECTION_COMPILER - Command to invoke compiler, normally set by
15 # GOBJECT_INTROSPECTION_REQUIRE/CHECK() in introspection.m4
16 # INTROSPECTION_COMPILER_ARGS - Additional args to pass in to the compiler
20 # Add this to configure.ac:
21 # -Wno-portability to AM_INIT_AUTOMAKE
22 # GOBJECT_INTROSPECTION_CHECK([0.6.7])
24 # Add this to Makefile.am where your library/program is built:
25 # include $(INTROSPECTION_MAKEFILE)
26 # INTROSPECTION_GIRS = YourLib-1.0.gir
27 # YourLib_1_0_gir_NAMESPACE = YourLib
28 # YourLib_1_0_gir_VERSION = 1.0
29 # YourLib_1_0_gir_LIBS = libyourlib.la
30 # YourLib_1_0_gir_FILES = $(libyourlib_1_0_SOURCES)
31 # girdir = $(INTROSPECTION_GIRDIR)
32 # dist_gir_DATA = YourLib-1.0.gir
33 # typelibdir = $(INTROSPECTION_TYPELIBDIR)
34 # typelib_DATA = YourLib-1.0.typelib
35 # CLEANFILES = $(dist_gir_DATA) $(typelib_DATA)
38 # Make sure the required variables are set, these should under normal
39 # circumstances come from introspection.m4
40 $(if $(INTROSPECTION_SCANNER),,$(error Need to define INTROSPECTION_SCANNER))
41 $(if $(INTROSPECTION_COMPILER),,$(error Need to define INTROSPECTION_COMPILER))
45 ## Transform the gir filename to something which can reference through a variable
46 ## without automake/make complaining, eg Gtk-2.0.gir -> Gtk_2_0_gir
47 _gir_name = $(subst -,_,$(subst .,_,$(1)))
49 # Namespace and Version is either fetched from the gir filename
50 # or the _NAMESPACE/_VERSION variable combo
51 _gir_namespace = $(or $($(_gir_name)_NAMESPACE),$(firstword $(subst -, ,$(1))))
52 _gir_version = $(or $($(_gir_name)_VERSION),$(lastword $(subst -, ,$(1:.gir=))))
54 # _PROGRAM is an optional variable which needs it's own --program argument
55 _gir_program = $(if $($(_gir_name)_PROGRAM),--program=$($(_gir_name)_PROGRAM))
57 # Variables which provides a list of things
58 _gir_libraries = $(foreach lib,$($(_gir_name)_LIBS),--library=$(lib))
59 _gir_packages = $(foreach pkg,$($(_gir_name)_PACKAGES),--pkg=$(pkg))
60 _gir_includes = $(foreach include,$($(_gir_name)_INCLUDES),--include=$(include))
62 # Reuse the LIBTOOL variable from by automake if it's set
63 _gir_libtool = $(if $(LIBTOOL),--libtool="$(LIBTOOL)")
65 # Macros for AM_SILENT_RULES prettiness
66 _gir_silent_scanner = $(_gir_silent_scanner_$(V))
67 _gir_silent_scanner_ = $(_gir_silent_scanner_$(AM_DEFAULT_VERBOSITY))
68 _gir_silent_scanner_0 = @echo " GISCAN $(1)";
70 _gir_silent_compiler = $(_gir_silent_compiler_$(V))
71 _gir_silent_compiler_ = $(_gir_silent_compiler_$(AM_DEFAULT_VERBOSITY))
72 _gir_silent_compiler_0 = @echo " GICOMP $(1)";
75 # Creates a GIR by scanning C headers/sources
76 # $(1) - Name of the gir file (output)
78 # If output is Gtk-2.0.gir then you should name the variables like
79 # Gtk_2_0_gir_NAMESPACE, Gtk_2_0_gir_VERSION etc.
81 # FILES - C sources and headers which should be scanned
83 # One of these variables are required:
84 # LIBS - Library where the symbol represented in the gir can be found
85 # PROGRAM - Program where the symbol represented in the gir can be found
88 # NAMESPACE - Namespace of the gir, first letter capital,
89 # rest should be lower case, for instance: 'Gtk', 'Clutter', 'ClutterGtk'.
90 # If not present the namespace will be fetched from the gir filename,
91 # the part before the first dash. For 'Gtk-2.0', namespace will be 'Gtk'.
92 # VERSION - Version of the gir, if not present, will be fetched from gir
93 # filename, the part after the first dash. For 'Gtk-2.0', version will be '2.0'.
94 # LIBTOOL - Command to invoke libtool, usually set by automake
95 # SCANNERFLAGS - Flags to pass in to the scanner, see g-ir-scanner(1) for a list
96 # CFLAGS - Flags to pass in to the parser when scanning headers
97 # PACKAGES - list of pkg-config names which cflags are required to parse
98 # the headers of this gir
99 # INCLUDES - Gir files to include without the .gir suffix, for instance
100 # GLib-2.0, Gtk-2.0. This is needed for all libraries which you depend on that
101 # provides introspection information.
104 define introspection-scanner
106 # Basic sanity check, to make sure required variables are set
107 $(if $($(_gir_name)_FILES),,$(error Need to define $(_gir_name)_FILES))
108 $(if $(or $($(_gir_name)_LIBS),
109 $($(_gir_name)_PROGRAM)),,
110 $(error Need to define $(_gir_name)_LIBS or $(_gir_name)_PROGRAM))
112 # Only dependencies we know are actually filenames goes into _FILES, make
113 # sure these are built before running the scanner. Libraries and programs
114 # needs to be added manually.
115 $(1): $$($(_gir_name)_FILES) $(INTROSPECTION_PARSER)
116 $(_gir_silent_scanner) $(INTROSPECTION_SCANNER) $(INTROSPECTION_SCANNER_ARGS) \
117 --namespace=$(_gir_namespace) \
118 --nsversion=$(_gir_version) \
124 $($(_gir_name)_SCANNERFLAGS) \
125 $($(_gir_name)_CFLAGS) \
126 $($(_gir_name)_FILES) \
130 $(foreach gir,$(INTROSPECTION_GIRS),$(eval $(call introspection-scanner,$(gir))))
133 # Compiles a gir into a typelib
134 # $(1): gir filename (input)
135 # $(2): typelib filename (output)
137 define introspection-compiler
138 $(_gir_silent_compiler) $(INTROSPECTION_COMPILER) $(INTROSPECTION_COMPILER_ARGS) --includedir=. $(1) -o $(2)
141 # Simple rule to compile a typelib.
142 %.typelib: %.gir $(INTROSPECTION_COMPILER)
143 $(call introspection-compiler,$<,$@)