2 # Copyright 2009-2010 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_SCANNER_ENV - Environment variables to set before running
16 # INTROSPECTION_COMPILER - Command to invoke compiler, normally set by
17 # GOBJECT_INTROSPECTION_REQUIRE/CHECK() in introspection.m4
18 # INTROSPECTION_COMPILER_ARGS - Additional args to pass in to the compiler
22 # Add this to configure.ac:
23 # -Wno-portability to AM_INIT_AUTOMAKE
24 # GOBJECT_INTROSPECTION_CHECK([0.6.7])
26 # Add this to Makefile.am where your library/program is built:
27 # include $(INTROSPECTION_MAKEFILE)
28 # INTROSPECTION_GIRS = YourLib-1.0.gir
29 # YourLib_1_0_gir_NAMESPACE = YourLib
30 # YourLib_1_0_gir_VERSION = 1.0
31 # YourLib_1_0_gir_LIBS = libyourlib.la
32 # YourLib_1_0_gir_FILES = $(libyourlib_1_0_SOURCES)
33 # girdir = $(datadir)/gir-1.0
34 # dist_gir_DATA = YourLib-1.0.gir
35 # typelibdir = $(libdir)/girepository-1.0
36 # typelib_DATA = YourLib-1.0.typelib
37 # CLEANFILES = $(dist_gir_DATA) $(typelib_DATA)
40 # Make sure the required variables are set, these should under normal
41 # circumstances come from introspection.m4
42 $(if $(INTROSPECTION_SCANNER),,$(error Need to define INTROSPECTION_SCANNER))
43 $(if $(INTROSPECTION_COMPILER),,$(error Need to define INTROSPECTION_COMPILER))
47 ## Transform the gir filename to something which can reference through a variable
48 ## without automake/make complaining, eg Gtk-2.0.gir -> Gtk_2_0_gir
49 _gir_name = $(subst /,_,$(subst -,_,$(subst .,_,$(1))))
51 # Namespace and Version is either fetched from the gir filename
52 # or the _NAMESPACE/_VERSION variable combo
53 _gir_namespace = $(or $($(_gir_name)_NAMESPACE),$(firstword $(subst -, ,$(notdir $(1)))))
54 _gir_version = $(or $($(_gir_name)_VERSION),$(lastword $(subst -, ,$(1:.gir=))))
56 # _PROGRAM is an optional variable which needs it's own --program argument
57 _gir_program = $(if $($(_gir_name)_PROGRAM),--program=$($(_gir_name)_PROGRAM))
59 # Variables which provides a list of things
60 _gir_libraries = $(foreach lib,$($(_gir_name)_LIBS),--library=$(lib))
61 _gir_packages = $(foreach pkg,$($(_gir_name)_PACKAGES),--pkg=$(pkg))
62 _gir_includes = $(foreach include,$($(_gir_name)_INCLUDES),--include=$(include))
63 _gir_export_packages = $(foreach pkg,$($(_gir_name)_EXPORT_PACKAGES),--pkg-export=$(pkg))
65 # Reuse the LIBTOOL variable from automake if it's set, but
66 # work around MSYS weirdness: When running g-ir-scanner, MSYS changes
67 # a command-line argument --libtool="/bin/sh ../../libtool" into
68 # --libtool=c:/opt/msys/1.0/bin/libtool. So just use sh.exe without path
69 # because we already "know" where the libtool configure produced is.
70 _gir_libtool = $(if $(findstring MINGW32,$(shell uname -s)),--libtool="$(top_builddir)/libtool",$(if $(LIBTOOL),--libtool="$(LIBTOOL)"))
72 # Macros for AM_SILENT_RULES prettiness
73 _gir_verbosity = $(if $(AM_DEFAULT_VERBOSITY),$(AM_DEFAULT_VERBOSITY),1)
75 _gir_silent_scanner_prefix = $(_gir_silent_scanner_prefix_$(V))
76 _gir_silent_scanner_prefix_ = $(_gir_silent_scanner_prefix_$(_gir_verbosity))
77 _gir_silent_scanner_prefix_0 = @echo " GISCAN $(1)";
78 _gir_silent_scanner_opts = $(_gir_silent_scanner_opts_$(V))
79 _gir_silent_scanner_opts_ = $(_gir_silent_scanner_opts_$(_gir_verbosity))
80 _gir_silent_scanner_opts_0 = --quiet
82 _gir_silent_compiler = $(_gir_silent_compiler_$(V))
83 _gir_silent_compiler_ = $(_gir_silent_compiler_$(_gir_verbosity))
84 _gir_silent_compiler_0 = @echo " GICOMP $(1)";
87 # Creates a GIR by scanning C headers/sources
88 # $(1) - Name of the gir file (output)
90 # If output is Gtk-2.0.gir then you should name the variables like
91 # Gtk_2_0_gir_NAMESPACE, Gtk_2_0_gir_VERSION etc.
93 # FILES - C sources and headers which should be scanned
95 # One of these variables are required:
96 # LIBS - Library where the symbol represented in the gir can be found
97 # PROGRAM - Program where the symbol represented in the gir can be found
100 # NAMESPACE - Namespace of the gir, first letter capital,
101 # rest should be lower case, for instance: 'Gtk', 'Clutter', 'ClutterGtk'.
102 # If not present the namespace will be fetched from the gir filename,
103 # the part before the first dash. For 'Gtk-2.0', namespace will be 'Gtk'.
104 # VERSION - Version of the gir, if not present, will be fetched from gir
105 # filename, the part after the first dash. For 'Gtk-2.0', version will be '2.0'.
106 # LIBTOOL - Command to invoke libtool, usually set by automake
107 # SCANNERFLAGS - Flags to pass in to the scanner, see g-ir-scanner(1) for a list
108 # CFLAGS - Flags to pass in to the parser when scanning headers
109 # LDFLAGS - Linker flags used by the scanner
110 # PACKAGES - list of pkg-config names which cflags are required to parse
111 # the headers of this gir
112 # INCLUDES - Gir files to include without the .gir suffix, for instance
113 # GLib-2.0, Gtk-2.0. This is needed for all libraries which you depend on that
114 # provides introspection information.
115 # EXPORT_PACKAGES - list of pkg-config names that are provided by this gir.
116 # By default the names in the PACKAGES variable will be used.
119 define introspection-scanner
121 # Basic sanity check, to make sure required variables are set
122 $(if $($(_gir_name)_FILES),,$(error Need to define $(_gir_name)_FILES))
123 $(if $(or $(findstring --header-only,$($(_gir_name)_SCANNERFLAGS)),
124 $($(_gir_name)_LIBS),
125 $($(_gir_name)_PROGRAM)),,
126 $(error Need to define $(_gir_name)_LIBS or $(_gir_name)_PROGRAM))
128 # Only dependencies we know are actually filenames goes into _FILES, make
129 # sure these are built before running the scanner. Libraries and programs
130 # needs to be added manually.
131 $(1): $$($(_gir_name)_FILES)
132 @ $(MKDIR_P) $(dir $(1))
133 $(_gir_silent_scanner_prefix) $(INTROSPECTION_SCANNER_ENV) $(INTROSPECTION_SCANNER) $(_gir_silent_scanner_opts) \
134 $(INTROSPECTION_SCANNER_ARGS) \
135 --namespace=$(_gir_namespace) \
136 --nsversion=$(_gir_version) \
140 $(_gir_export_packages) \
143 $($(_gir_name)_SCANNERFLAGS) \
144 $($(_gir_name)_CFLAGS) \
145 $($(_gir_name)_LDFLAGS) \
150 $(foreach gir,$(INTROSPECTION_GIRS),$(eval $(call introspection-scanner,$(gir))))
153 # Compiles a gir into a typelib
154 # $(1): gir filename (input)
155 # $(2): typelib filename (output)
157 define introspection-compiler
158 $(_gir_silent_compiler) $(INTROSPECTION_COMPILER) $(INTROSPECTION_COMPILER_ARGS) --includedir=. $(1) -o $(2)
161 # Simple rule to compile a typelib.
163 $(call introspection-compiler,$<,$@)