glib-genmarshal (1) - Linux Man Pages
glib-genmarshal: C code marshaller generation utility for GLib closures
glib-genmarshal - C code marshaller generation utility for GLib closures
- glib-genmarshal [OPTION...] [FILE...]
glib-genmarshal takes a list of marshallers to generate as input. The marshaller list is either read from files passed as additional arguments on the command line; or from standard input, by using - as the input file.
Marshaller list format
The marshaller lists are processed line by line, a line can contain a comment in the form of
or a marshaller specification of the form
RTYPE:PTYPE RTYPE:PTYPE,PTYPE RTYPE:PTYPE,PTYPE,PTYPE
Currently, the following types are supported:
- indicates no return type, or no extra parameters. If VOID is used as the parameter list, no additional parameters may be present.
- for boolean types (gboolean)
- for signed char types (gchar)
- for unsigned char types (guchar)
- for signed integer types (gint)
- for unsigned integer types (guint)
- for signed long integer types (glong)
- for unsigned long integer types (gulong)
- for signed 64bit integer types (gint64)
- for unsigned 64bit integer types (guint64)
- for enumeration types (gint)
- for flag enumeration types (guint)
- for single-precision float types (gfloat)
- for double-precision float types (gdouble)
- for string types (gchar*)
- for boxed (anonymous but reference counted) types (GBoxed*)
- for GParamSpec or derived types (GParamSpec*)
- for anonymous pointer types (gpointer)
- for GObject or derived types (GObject*)
- for GVariant types (GVariant*)
- deprecated alias for VOID
- deprecated alias for BOOLEAN
- Generate header file contents of the marshallers. This option is mutually exclusive with the --body option.
- Generate C code file contents of the marshallers. This option is mutually exclusive with the --header option.
- Specify marshaller prefix. The default prefix is `g_cclosure_user_marshal'.
- Skip source location remarks in generated comments.
- Use the standard marshallers of the GObject library, and include glib-object.h in generated header files. This option is mutually exclusive with the --nostdinc option.
- Do not use the standard marshallers of the GObject library, and skip glib-object.h include directive in generated header files. This option is mutually exclusive with the --stdinc option.
- Mark generated functions as internal, using G_GNUC_INTERNAL.
- Generate valist marshallers, for use with g_signal_set_va_marshaller().
- Print version information.
- Make warnings fatal, that is, exit immediately once a warning occurs.
- Print brief help and exit.
- Print version and exit.
- Write output to FILE instead of the standard output.
- Generate function prototypes before the function definition in the C source file, in order to avoid a missing-prototypes compiler warning. This option is only useful when using the --body option.
- Use the once pragma instead of an old style header guard when generating the C header file. This option is only useful when using the --header option.
- Adds a #include directive for the given file in the C source file. This option is only useful when using the --body option.
- Adds a #define C pre-processor directive for SYMBOL and its given VALUE, or "1" if the value is unset. You can use this option multiple times; if you do, all the symbols will be defined in the same order given on the command line, before the symbols undefined using the -U option. This option is only useful when using the --body option.
- Adds a #undef C pre-processor directive to undefine the given SYMBOL. You can use this option multiple times; if you do, all the symbols will be undefined in the same order given on the command line, after the symbols defined using the -D option. This option is only useful when using the --body option.
- Minimizes the output of glib-genmarshal, by printing only warnings and errors. This option is mutually exclusive with the --verbose option.
- Increases the verbosity of glib-genmarshal, by printing debugging information. This option is mutually exclusive with the --quiet option.
USING GLIB-GENMARSHAL WITH MESON
Meson supports generating closure marshallers using glib-genmarshal out of the box in its "gnome" module.
In your meson.build file you will typically call the gnome.genmarshal() method with the source list of marshallers to generate:
gnome = import('gnome') marshal_files = gnome.genmarshal('marshal', sources: 'marshal.list', internal: true, )
The marshal_files variable will contain an array of two elements in the following order:
- • a build target for the source file
- • a build target for the header file
You should use the returned objects to provide a dependency on every other build target that references the source or header file; for instance, if you are using the source to build a library:
mainlib = library('project', sources: project_sources + marshal_files, ... )
Additionally, if you are including the generated header file inside a build target that depends on the library you just built, you must ensure that the internal dependency includes the generated header as a required source file:
mainlib_dep = declare_dependency(sources: marshal_files, link_with: mainlib)
You should not include the generated source file as well, otherwise it will be built separately for every target that depends on it, causing build failures. To know more about why all this is required, please refer to the m[blue]corresponding Meson FAQ entrym.
USING GLIB-GENMARSHAL WITH AUTOTOOLS
In order to use glib-genmarshal in your project when using Autotools as the build system, you will first need to modify your configure.ac file to ensure you find the appropriate command using pkg-config, similarly as to how you discover the compiler and linker flags for GLib.
PKG_PROG_PKG_CONFIG([0.28]) PKG_CHECK_VAR([GLIB_GENMARSHAL], [glib-2.0], [glib_genmarshal])
In your Makefile.am file you will typically need very simple rules to generate the C files needed for the build.
marshal.h: marshal.list $(AM_V_GEN)$(GLIB_GENMARSHAL) \ --header \ --output=$@ \ $< marshal.c: marshal.list marshal.h $(AM_V_GEN)$(GLIB_GENMARSHAL) \ --include-header=marshal.h \ --body \ --output=$@ \ $< BUILT_SOURCES += marshal.h marshal.c CLEANFILES += marshal.h marshal.c EXTRA_DIST += marshal.list
In the example above, the first rule generates the header file and depends on a marshal.list file in order to regenerate the result in case the marshallers list is updated. The second rule generates the source file for the same marshal.list, and includes the file generated by the header rule.
To generate marshallers for the following callback functions:
void foo (gpointer data1, gpointer data2); void bar (gpointer data1, gint param1, gpointer data2); gfloat baz (gpointer data1, gboolean param1, guchar param2, gpointer data2);
The marshaller.list file has to look like this:
VOID:VOID VOID:INT FLOAT:BOOLEAN,UCHAR
and you call glib-genmarshal like this:
glib-genmarshal --header marshaller.list > marshaller.h glib-genmarshal --body marshaller.list > marshaller.c
The generated marshallers have the arguments encoded in their function name. For this particular list, they are
g_cclosure_user_marshal_VOID__VOID(...), g_cclosure_user_marshal_VOID__INT(...), g_cclosure_user_marshal_FLOAT__BOOLEAN_UCHAR(...).
They can be used directly for GClosures or be passed in as the GSignalCMarshaller c_marshaller; argument upon creation of signals:
GClosure *cc_foo, *cc_bar, *cc_baz; cc_foo = g_cclosure_new (NULL, foo, NULL); g_closure_set_marshal (cc_foo, g_cclosure_user_marshal_VOID__VOID); cc_bar = g_cclosure_new (NULL, bar, NULL); g_closure_set_marshal (cc_bar, g_cclosure_user_marshal_VOID__INT); cc_baz = g_cclosure_new (NULL, baz, NULL); g_closure_set_marshal (cc_baz, g_cclosure_user_marshal_FLOAT__BOOLEAN_UCHAR);
- corresponding Meson FAQ entry
documentation for gnome.genmarshal()