1 <refentry id="glib-genmarshal" lang="en">
4 <title>glib-genmarshal</title>
5 <productname>GObject</productname>
8 <contrib>Developer</contrib>
9 <firstname>Emmanuele</firstname>
10 <surname>Bassi</surname>
13 <contrib>Original developer</contrib>
14 <firstname>Tim</firstname>
15 <surname>Janik</surname>
21 <refentrytitle>glib-genmarshal</refentrytitle>
22 <manvolnum>1</manvolnum>
23 <refmiscinfo class="manual">User Commands</refmiscinfo>
27 <refname>glib-genmarshal</refname>
28 <refpurpose>C code marshaller generation utility for GLib closures</refpurpose>
33 <command>glib-genmarshal</command>
34 <arg choice="opt" rep="repeat">OPTION</arg>
35 <arg choice="opt" rep="repeat">FILE</arg>
39 <refsect1><title>Description</title>
40 <para><command>glib-genmarshal</command> is a small utility that generates C code
41 marshallers for callback functions of the GClosure mechanism in the GObject
42 sublibrary of GLib. The marshaller functions have a standard signature,
43 they get passed in the invoking closure, an array of value structures holding
44 the callback function parameters and a value structure for the return value
45 of the callback. The marshaller is then responsible to call the respective C
46 code function of the closure with all the parameters on the stack and to
47 collect its return value.
50 <para><command>glib-genmarshal</command> takes a list of marshallers to generate as
51 input. The marshaller list is either read from files passed as additional arguments
52 on the command line; or from standard input, by using <literal>-</literal> as the
56 <refsect2><title>Marshaller list format</title>
58 The marshaller lists are processed line by line, a line can contain a
59 comment in the form of
60 <informalexample><programlisting>
62 </programlisting></informalexample>
63 or a marshaller specification of the form
65 <replaceable>RTYPE</replaceable>:<replaceable>PTYPE</replaceable>
66 <replaceable>RTYPE</replaceable>:<replaceable>PTYPE</replaceable>,<replaceable>PTYPE</replaceable>
67 <replaceable>RTYPE</replaceable>:<replaceable>PTYPE</replaceable>,<replaceable>PTYPE</replaceable>,<replaceable>PTYPE</replaceable>
71 The <replaceable>RTYPE</replaceable> part specifies the callback's return
72 type and the <replaceable>PTYPE</replaceable>s right to the colon specify
73 the callback's parameter list, except for the first and the last arguments
74 which are always pointers.
77 <refsect2><title>Parameter types</title>
79 Currently, the following types are supported:
82 <term><replaceable>VOID</replaceable></term>
84 indicates no return type, or no extra parameters.
85 If <replaceable>VOID</replaceable> is used as the parameter list, no
86 additional parameters may be present.
91 <term><replaceable>BOOLEAN</replaceable></term>
93 for boolean types (gboolean)
98 <term><replaceable>CHAR</replaceable></term>
100 for signed char types (gchar)
105 <term><replaceable>UCHAR</replaceable></term>
107 for unsigned char types (guchar)
112 <term><replaceable>INT</replaceable></term>
114 for signed integer types (gint)
119 <term><replaceable>UINT</replaceable></term>
121 for unsigned integer types (guint)
126 <term><replaceable>LONG</replaceable></term>
128 for signed long integer types (glong)
133 <term><replaceable>ULONG</replaceable></term>
135 for unsigned long integer types (gulong)
140 <term><replaceable>INT64</replaceable></term>
142 for signed 64bit integer types (gint64)
147 <term><replaceable>UINT64</replaceable></term>
149 for unsigned 64bit integer types (guint64)
154 <term><replaceable>ENUM</replaceable></term>
156 for enumeration types (gint)
161 <term><replaceable>FLAGS</replaceable></term>
163 for flag enumeration types (guint)
168 <term><replaceable>FLOAT</replaceable></term>
170 for single-precision float types (gfloat)
175 <term><replaceable>DOUBLE</replaceable></term>
177 for double-precision float types (gdouble)
182 <term><replaceable>STRING</replaceable></term>
184 for string types (gchar*)
189 <term><replaceable>BOXED</replaceable></term>
191 for boxed (anonymous but reference counted) types (GBoxed*)
196 <term><replaceable>PARAM</replaceable></term>
198 for GParamSpec or derived types (GParamSpec*)
203 <term><replaceable>POINTER</replaceable></term>
205 for anonymous pointer types (gpointer)
210 <term><replaceable>OBJECT</replaceable></term>
212 for GObject or derived types (GObject*)
217 <term><replaceable>VARIANT</replaceable></term>
219 for GVariant types (GVariant*)
224 <term><replaceable>NONE</replaceable></term>
226 deprecated alias for <replaceable>VOID</replaceable>
231 <term><replaceable>BOOL</replaceable></term>
233 deprecated alias for <replaceable>BOOLEAN</replaceable>
241 <refsect1><title>Options</title>
245 <term><option>--header</option></term>
247 Generate header file contents of the marshallers. This option is mutually
248 exclusive with the <option>--body</option> option.
253 <term><option>--body</option></term>
255 Generate C code file contents of the marshallers. This option is mutually
256 exclusive with the <option>--header</option> option.
261 <term><option>--prefix=<replaceable>PREFIX</replaceable></option></term>
263 Specify marshaller prefix. The default prefix is <literal>`g_cclosure_user_marshal'</literal>.
268 <term><option>--skip-source</option></term>
270 Skip source location remarks in generated comments.
275 <term><option>--stdinc</option></term>
277 Use the standard marshallers of the GObject library, and include
278 <filename>glib-object.h</filename> in generated header files. This
279 option is mutually exclusive with the <option>--nostdinc</option>
285 <term><option>--nostdinc</option></term>
287 Do not use the standard marshallers of the GObject library, and skip
288 <filename>glib-object.h</filename> include directive in generated header files.
289 This option is mutually exclusive with the <option>--stdinc</option> option.
294 <term><option>--internal</option></term>
296 Mark generated functions as internal, using <literal>G_GNUC_INTERNAL</literal>.
301 <term><option>--valist-marshallers</option></term>
303 Generate valist marshallers, for use with <function>g_signal_set_va_marshaller()</function>.
308 <term><option>-v</option>, <option>--version</option></term>
310 Print version information.
315 <term><option>--g-fatal-warnings</option></term>
317 Make warnings fatal, that is, exit immediately once a warning occurs.
322 <term><option>-h</option>, <option>--help</option></term>
324 Print brief help and exit.
329 <term><option>-v</option>, <option>--version</option></term>
331 Print version and exit.
336 <term><option>--output=FILE</option></term>
338 Write output to <replaceable>FILE</replaceable> instead of the standard output.
343 <term><option>--prototypes</option></term>
345 Generate function prototypes before the function definition in the C source
346 file, in order to avoid a <literal>missing-prototypes</literal> compiler
347 warning. This option is only useful when using the <option>--body</option>
353 <term><option>--pragma-once</option></term>
355 Use the <literal>once</literal> pragma instead of an old style header guard
356 when generating the C header file. This option is only useful when using the
357 <option>--header</option> option.
362 <term><option>--include-header=<replaceable>HEADER</replaceable></option></term>
364 Adds a <literal>#include</literal> directive for the given file in the C
365 source file. This option is only useful when using the <option>--body</option>
371 <term><option>-D <replaceable>SYMBOL[=VALUE]</replaceable></option></term>
373 Adds a <literal>#define</literal> C pre-processor directive for
374 <replaceable>SYMBOL</replaceable> and its given <replaceable>VALUE</replaceable>,
375 or "1" if the value is unset. You can use this option multiple times; if you do,
376 all the symbols will be defined in the same order given on the command line, before
377 the symbols undefined using the <option>-U</option> option. This option is only
378 useful when using the <option>--body</option> option.
383 <term><option>-U <replaceable>SYMBOL</replaceable></option></term>
385 Adds a <literal>#undef</literal> C pre-processor directive to undefine the
386 given <replaceable>SYMBOL</replaceable>. You can use this option multiple times;
387 if you do, all the symbols will be undefined in the same order given on the
388 command line, after the symbols defined using the <option>-D</option> option.
389 This option is only useful when using the <option>--body</option> option.
394 <term><option>--quiet</option></term>
396 Minimizes the output of <command>glib-genmarshal</command>, by printing only
397 warnings and errors. This option is mutually exclusive with the
398 <option>--verbose</option> option.
403 <term><option>--verbose</option></term>
405 Increases the verbosity of <command>glib-genmarshal</command>, by printing
406 debugging information. This option is mutually exclusive with the
407 <option>--quiet</option> option.
414 <refsect1><title>Using <command>glib-genmarshal</command> with Meson</title>
416 Meson supports generating closure marshallers using <command>glib-genmarshal</command>
417 out of the box in its "gnome" module.
421 In your <filename>meson.build</filename> file you will typically call the
422 <literal>gnome.genmarshal()</literal> method with the source list of marshallers
425 <informalexample><programlisting>
426 gnome = import('gnome')
427 marshal_files = gnome.genmarshal('marshal',
428 sources: 'marshal.list',
431 </programlisting></informalexample>
433 The <literal>marshal_files</literal> variable will contain an array of two elements
434 in the following order:
437 <listitem><para>a build target for the source file</para></listitem>
438 <listitem><para>a build target for the header file</para></listitem>
441 You should use the returned objects to provide a dependency on every other
442 build target that references the source or header file; for instance, if you
443 are using the source to build a library:
445 <informalexample><programlisting>
446 mainlib = library('project',
447 sources: project_sources + marshal_files,
450 </programlisting></informalexample>
452 Additionally, if you are including the generated header file inside a build
453 target that depends on the library you just built, you must ensure that the
454 internal dependency includes the generated header as a required source file:
456 <informalexample><programlisting>
457 mainlib_dep = declare_dependency(sources: marshal_files[1], link_with: mainlib)
458 </programlisting></informalexample>
460 You should not include the generated source file as well, otherwise it will
461 be built separately for every target that depends on it, causing build
462 failures. To know more about why all this is required, please refer to the
463 <ulink url="https://mesonbuild.com/FAQ.html#how-do-i-tell-meson-that-my-sources-use-generated-headers">
464 corresponding Meson FAQ entry</ulink>.
467 For more information on how to use the method, see the
468 <ulink url="https://mesonbuild.com/Gnome-module.html#gnomegenmarshal">Meson
469 documentation for <literal>gnome.genmarshal()</literal></ulink>.
473 <refsect1><title>Using <command>glib-genmarshal</command> with Autotools</title>
475 In order to use <command>glib-genmarshal</command> in your project when using
476 Autotools as the build system, you will first need to modify your
477 <filename>configure.ac</filename> file to ensure you find the appropriate
478 command using <command>pkg-config</command>, similarly as to how you discover
479 the compiler and linker flags for GLib.
481 <informalexample><programlisting>
482 PKG_PROG_PKG_CONFIG([0.28])
484 PKG_CHECK_VAR([GLIB_GENMARSHAL], [glib-2.0], [glib_genmarshal])
485 </programlisting></informalexample>
487 In your <filename>Makefile.am</filename> file you will typically need very
488 simple rules to generate the C files needed for the build.
490 <informalexample><programlisting>
491 marshal.h: marshal.list
492 $(AM_V_GEN)$(GLIB_GENMARSHAL) \
497 marshal.c: marshal.list marshal.h
498 $(AM_V_GEN)$(GLIB_GENMARSHAL) \
499 --include-header=marshal.h \
504 BUILT_SOURCES += marshal.h marshal.c
505 CLEANFILES += marshal.h marshal.c
506 EXTRA_DIST += marshal.list
507 </programlisting></informalexample>
509 In the example above, the first rule generates the header file and depends on
510 a <filename>marshal.list</filename> file in order to regenerate the result in
511 case the marshallers list is updated. The second rule generates the source file
512 for the same <filename>marshal.list</filename>, and includes the file generated
517 <refsect1><title>Example</title>
519 To generate marshallers for the following callback functions:
521 <informalexample><programlisting>
522 void foo (gpointer data1,
524 void bar (gpointer data1,
527 gfloat baz (gpointer data1,
531 </programlisting></informalexample>
533 The <filename>marshaller.list</filename> file has to look like this:
541 and you call glib-genmarshal like this:
544 glib-genmarshal --header marshaller.list > marshaller.h
545 glib-genmarshal --body marshaller.list > marshaller.c
548 The generated marshallers have the arguments encoded in their function name.
549 For this particular list, they are
552 g_cclosure_user_marshal_VOID__VOID(...),
553 g_cclosure_user_marshal_VOID__INT(...),
554 g_cclosure_user_marshal_FLOAT__BOOLEAN_UCHAR(...).
557 They can be used directly for GClosures or be passed in as the
558 GSignalCMarshaller c_marshaller; argument upon creation of signals:
560 <informalexample><programlisting>
561 GClosure *cc_foo, *cc_bar, *cc_baz;
563 cc_foo = g_cclosure_new (NULL, foo, NULL);
564 g_closure_set_marshal (cc_foo, g_cclosure_user_marshal_VOID__VOID);
565 cc_bar = g_cclosure_new (NULL, bar, NULL);
566 g_closure_set_marshal (cc_bar, g_cclosure_user_marshal_VOID__INT);
567 cc_baz = g_cclosure_new (NULL, baz, NULL);
568 g_closure_set_marshal (cc_baz, g_cclosure_user_marshal_FLOAT__BOOLEAN_UCHAR);
569 </programlisting></informalexample>
571 <refsect1><title>See also</title>
574 <refentrytitle>glib-mkenums</refentrytitle>
575 <manvolnum>1</manvolnum>