.\" Man page generated from reStructuredText. . . .nr rst2man-indent-level 0 . .de1 rstReportMargin \\$1 \\n[an-margin] level \\n[rst2man-indent-level] level margin: \\n[rst2man-indent\\n[rst2man-indent-level]] - \\n[rst2man-indent0] \\n[rst2man-indent1] \\n[rst2man-indent2] .. .de1 INDENT .\" .rstReportMargin pre: . RS \\$1 . nr rst2man-indent\\n[rst2man-indent-level] \\n[an-margin] . nr rst2man-indent-level +1 .\" .rstReportMargin post: .. .de UNINDENT . RE .\" indent \\n[an-margin] .\" old: \\n[rst2man-indent\\n[rst2man-indent-level]] .nr rst2man-indent-level -1 .\" new: \\n[rst2man-indent\\n[rst2man-indent-level]] .in \\n[rst2man-indent\\n[rst2man-indent-level]]u .. .TH "GLIB-MKENUMS" "" "" .SH NAME glib-mkenums \- C language enum description generation utility .\" This has to be duplicated from above to make it machine-readable by `reuse`: .\" SPDX-FileCopyrightText: 2003 Matthias Clasen .\" SPDX-FileCopyrightText: 2009 Christian Persch .\" SPDX-FileCopyrightText: 2010 Allison Karlitskaya .\" SPDX-FileCopyrightText: 2012, 2013, 2016 Red Hat, Inc. .\" SPDX-FileCopyrightText: 2017, 2019, 2022 Emmanuele Bassi .\" SPDX-FileCopyrightText: 2018, 2020 Centricular .\" SPDX-FileCopyrightText: 2020 Aleksander Morgado .\" SPDX-License-Identifier: LGPL-2.1-or-later . .SH SYNOPSIS .nf \fBglib\-mkenums\fP [OPTION…] [FILE…] .fi .sp .SH DESCRIPTION .sp \fBglib\-mkenums\fP is a small utility that parses C code to extract enum definitions and produces enum descriptions based on text templates specified by the user. Typically, you can use this tool to generate enumeration types for the GType type system, for GObject properties and signal marshalling; additionally, you can use it to generate enumeration values of GSettings schemas. .sp \fBglib\-mkenums\fP takes a list of valid C code files as input. The options specified control the text that generated, substituting various keywords enclosed in \fB@\fP characters in the templates. .sp Since version 2.74, GLib provides the \fBG_DEFINE_ENUM_TYPE\fP and \fBG_DEFINE_FLAGS_TYPE\fP C pre\-processor macros. These macros can be used to define a GType for projects that have few, small enumeration types without going through the complexities of generating code at build time. .SS PRODUCTION TEXT SUBSTITUTIONS .sp Certain keywords enclosed in \fB@\fP characters will be substituted in the emitted text. For the substitution examples of the keywords below, the following example enum definition is assumed: .INDENT 0.0 .INDENT 3.5 .sp .EX typedef enum { PREFIX_THE_XVALUE = 1 << 3, PREFIX_ANOTHER_VALUE = 1 << 4 } PrefixTheXEnum; .EE .UNINDENT .UNINDENT .sp \fB@EnumName@\fP .INDENT 0.0 .INDENT 3.5 The name of the enum currently being processed, enum names are assumed to be properly namespaced and to use mixed capitalization to separate words (e.g. \fBPrefixTheXEnum\fP). .UNINDENT .UNINDENT .sp \fB@enum_name@\fP .INDENT 0.0 .INDENT 3.5 The enum name with words lowercase and word\-separated by underscores (e.g. \fBprefix_the_xenum\fP). .UNINDENT .UNINDENT .sp \fB@ENUMNAME@\fP .INDENT 0.0 .INDENT 3.5 The enum name with words uppercase and word\-separated by underscores (e.g. \fBPREFIX_THE_XENUM\fP). .UNINDENT .UNINDENT .sp \fB@ENUMSHORT@\fP .INDENT 0.0 .INDENT 3.5 The enum name with words uppercase and word\-separated by underscores, prefix stripped (e.g. \fBTHE_XENUM\fP). .UNINDENT .UNINDENT .sp \fB@ENUMPREFIX@\fP .INDENT 0.0 .INDENT 3.5 The prefix of the enum name (e.g. \fBPREFIX\fP). .UNINDENT .UNINDENT .sp \fB@VALUENAME@\fP .INDENT 0.0 .INDENT 3.5 The enum value name currently being processed with words uppercase and word\-separated by underscores, this is the assumed literal notation of enum values in the C sources (e.g. \fBPREFIX_THE_XVALUE\fP). .UNINDENT .UNINDENT .sp \fB@valuenick@\fP .INDENT 0.0 .INDENT 3.5 A nick name for the enum value currently being processed, this is usually generated by stripping common prefix words of all the enum values of the current enum, the words are lowercase and underscores are substituted by a minus (e.g. \fBthe\-xvalue\fP). .UNINDENT .UNINDENT .sp \fB@valuenum@\fP .INDENT 0.0 .INDENT 3.5 The integer value for the enum value currently being processed. If the evaluation fails then \fBglib\-mkenums\fP will exit with an error status, but this only happens if \fB@valuenum@\fP appears in your value production template. (Since: 2.26) .UNINDENT .UNINDENT .sp \fB@type@\fP .INDENT 0.0 .INDENT 3.5 This is substituted either by ‘enum’ or ‘flags’, depending on whether the enum value definitions contained bit\-shift operators (e.g. \fBflags\fP). .UNINDENT .UNINDENT .sp \fB@Type@\fP .INDENT 0.0 .INDENT 3.5 The same as \fB@type@\fP with the first letter capitalized (e.g. \fBFlags\fP). .UNINDENT .UNINDENT .sp \fB@TYPE@\fP .INDENT 0.0 .INDENT 3.5 The same as \fB@type@\fP with all letters uppercased (e.g. \fBFLAGS\fP). .UNINDENT .UNINDENT .sp \fB@filename@\fP .INDENT 0.0 .INDENT 3.5 The full path of the input file currently being processed (e.g. \fB/build/environment/project/src/foo.h\fP). .UNINDENT .UNINDENT .sp \fB@basename@\fP .INDENT 0.0 .INDENT 3.5 The base name of the input file currently being processed (e.g. \fBfoo.h\fP). Typically you want to use \fB@basename@\fP in place of \fB@filename@\fP in your templates, to improve the reproducibility of the build. (Since: 2.22) .UNINDENT .UNINDENT .SS TRIGRAPH EXTENSIONS .sp Some C comments are treated specially in the parsed enum definitions, such comments start out with the trigraph sequence \fB/*<\fP and end with the trigraph sequence \fB>*/\fP\&. .sp The following options can be specified per enum definition: .sp \fBskip\fP .INDENT 0.0 .INDENT 3.5 Indicates this enum definition should be skipped. .UNINDENT .UNINDENT .sp \fBflags\fP .INDENT 0.0 .INDENT 3.5 Indicates this enum should be treated as a flags definition. .UNINDENT .UNINDENT .sp \fBunderscore_name\fP .INDENT 0.0 .INDENT 3.5 Specifies the word separation used in the \fB*_get_type()\fP function. For instance, \fB/*< underscore_name=gnome_vfs_uri_hide_options >*/\fP\&. .UNINDENT .UNINDENT .sp \fBsince\fP .INDENT 0.0 .INDENT 3.5 Specifies the version tag that will be used to substitute the \fB@enumsince@\fP keyword in the template, useful when documenting methods generated from the enums (e.g. \fBSince: @enumsince@\fP). (Since: 2.66) .UNINDENT .UNINDENT .sp The following options can be specified per value definition: .sp \fBskip\fP .INDENT 0.0 .INDENT 3.5 Indicates the value should be skipped. .UNINDENT .UNINDENT .sp \fBnick\fP .INDENT 0.0 .INDENT 3.5 Specifies the otherwise auto\-generated nickname. .UNINDENT .UNINDENT .sp Examples: .INDENT 0.0 .INDENT 3.5 .sp .EX typedef enum /*< skip >*/ { PREFIX_FOO } PrefixThisEnumWillBeSkipped; typedef enum /*< flags,prefix=PREFIX,since=1.0 >*/ { PREFIX_THE_ZEROTH_VALUE, /*< skip >*/ PREFIX_THE_FIRST_VALUE, PREFIX_THE_SECOND_VALUE, PREFIX_THE_THIRD_VALUE, /*< nick=the\-last\-value >*/ } PrefixTheFlagsEnum; .EE .UNINDENT .UNINDENT .SH OPTIONS .sp \fB\-\-fhead \fP .INDENT 0.0 .INDENT 3.5 Emits \fBTEXT\fP prior to processing input files. .sp You can specify this option multiple times, and the \fBTEXT\fP will be concatenated. .sp When used along with a template file, \fBTEXT\fP will be prepended to the template’s \fBfile\-header\fP section. .UNINDENT .UNINDENT .sp \fB\-\-fprod \fP .INDENT 0.0 .INDENT 3.5 Emits \fBTEXT\fP every time a new input file is being processed. .sp You can specify this option multiple times, and the \fBTEXT\fP will be concatenated. .sp When used along with a template file, \fBTEXT\fP will be appended to the template’s \fBfile\-production\fP section. .UNINDENT .UNINDENT .sp \fB\-\-ftail \fP .INDENT 0.0 .INDENT 3.5 Emits \fBTEXT\fP after all input files have been processed. .sp You can specify this option multiple times, and the \fBTEXT\fP will be concatenated. .sp When used along with a template file, \fBTEXT\fP will be appended to the template’s \fBfile\-tail\fP section. .UNINDENT .UNINDENT .sp \fB\-\-eprod \fP .INDENT 0.0 .INDENT 3.5 Emits \fBTEXT\fP every time an enum is encountered in the input files. .UNINDENT .UNINDENT .sp \fB\-\-vhead \fP .INDENT 0.0 .INDENT 3.5 Emits \fBTEXT\fP before iterating over the set of values of an enum. .sp You can specify this option multiple times, and the \fBTEXT\fP will be concatenated. .sp When used along with a template file, \fBTEXT\fP will be prepended to the template’s \fBvalue\-header\fP section. .UNINDENT .UNINDENT .sp \fB\-\-vprod \fP .INDENT 0.0 .INDENT 3.5 Emits \fBTEXT\fP for every value of an enum. .sp You can specify this option multiple times, and the \fBTEXT\fP will be concatenated. .sp When used along with a template file, \fBTEXT\fP will be appended to the template’s \fBvalue\-production\fP section. .UNINDENT .UNINDENT .sp \fB\-\-vtail \fP .INDENT 0.0 .INDENT 3.5 Emits \fBTEXT\fP after iterating over all values of an enum. .sp You can specify this option multiple times, and the \fBTEXT\fP will be concatenated. .sp When used along with a template file, \fBTEXT\fP will be appended to the template’s \fBvalue\-tail\fP section. .UNINDENT .UNINDENT .sp \fB\-\-comments \fP .INDENT 0.0 .INDENT 3.5 Template for auto\-generated comments, the default (for C code generations) is \fB\(dq/* @comment@ */\(dq\fP\&. .UNINDENT .UNINDENT .sp \fB\-\-template \fP .INDENT 0.0 .INDENT 3.5 Read templates from the given file. The templates are enclosed in specially\-formatted C comments: .INDENT 0.0 .INDENT 3.5 .sp .EX /*** BEGIN section ***/ /*** END section ***/ .EE .UNINDENT .UNINDENT .sp \fBsection\fP may be \fBfile\-header\fP, \fBfile\-production\fP, \fBfile\-tail\fP, \fBenumeration\-production\fP, \fBvalue\-header\fP, \fBvalue\-production\fP, \fBvalue\-tail\fP or \fBcomment\fP\&. .UNINDENT .UNINDENT .sp \fB\-\-identifier\-prefix \fP .INDENT 0.0 .INDENT 3.5 Indicates what portion of the enum name should be interpreted as the prefix (e.g. the \fBGtk\fP in \fBGtkDirectionType\fP). Normally this will be figured out automatically, but you may need to override the default if your namespace is capitalized oddly. .UNINDENT .UNINDENT .sp \fB\-\-symbol\-prefix \fP .INDENT 0.0 .INDENT 3.5 Indicates what prefix should be used to correspond to the identifier prefix in related C function names (e.g. the \fBgtk\fP in \fBgtk_direction_type_get_type\fP). Equivalently, this is the lowercase version of the prefix component of the enum value names (e.g. the \fBGTK\fP in \fBGTK_DIR_UP\fP). The default value is the identifier prefix, converted to lowercase. .UNINDENT .UNINDENT .sp \fB\-\-help\fP .INDENT 0.0 .INDENT 3.5 Print brief help and exit. .UNINDENT .UNINDENT .sp \fB\-\-version\fP .INDENT 0.0 .INDENT 3.5 Print version and exit. .UNINDENT .UNINDENT .sp \fB\-\-output \fP .INDENT 0.0 .INDENT 3.5 Write output to \fBFILE\fP instead of stdout. .UNINDENT .UNINDENT .sp \fB@RSPFILE\fP .INDENT 0.0 .INDENT 3.5 When passed as the sole argument, read and parse the actual arguments from \fBRSPFILE\fP\&. Useful on systems with a low command\-line length limit. For example, Windows has a limit of 8191 characters. .UNINDENT .UNINDENT .SH USING TEMPLATES .sp Instead of passing the various sections of the generated file to the command line of \fBglib\-mkenums\fP, it’s strongly recommended to use a template file, especially for generating C sources. .sp A C header template file will typically look like this: .INDENT 0.0 .INDENT 3.5 .sp .EX /*** BEGIN file\-header ***/ #pragma once /* Include the main project header */ #include \(dqproject.h\(dq G_BEGIN_DECLS /*** END file\-header ***/ /*** BEGIN file\-production ***/ /* enumerations from \(dq@basename@\(dq */ /*** END file\-production ***/ /*** BEGIN value\-header ***/ GType @enum_name@_get_type (void) G_GNUC_CONST; #define @ENUMPREFIX@_TYPE_@ENUMSHORT@ (@enum_name@_get_type ()) /*** END value\-header ***/ /*** BEGIN file\-tail ***/ G_END_DECLS /*** END file\-tail ***/ .EE .UNINDENT .UNINDENT .sp A C source template file will typically look like this: .INDENT 0.0 .INDENT 3.5 .sp .EX /*** BEGIN file\-header ***/ #include \(dqconfig.h\(dq #include \(dqenum\-types.h\(dq /*** END file\-header ***/ /*** BEGIN file\-production ***/ /* enumerations from \(dq@basename@\(dq */ /*** END file\-production ***/ /*** BEGIN value\-header ***/ GType @enum_name@_get_type (void) { static GType static_g_@type@_type_id = 0; if (g_once_init_enter_pointer (&static_g_@type@_type_id)) { static const G@Type@Value values[] = { /*** END value\-header ***/ /*** BEGIN value\-production ***/ { @VALUENAME@, \(dq@VALUENAME@\(dq, \(dq@valuenick@\(dq }, /*** END value\-production ***/ /*** BEGIN value\-tail ***/ { 0, NULL, NULL } }; GType g_@type@_type_id = g_@type@_register_static (g_intern_static_string (\(dq@EnumName@\(dq), values); g_once_init_leave_pointer (&static_g_@type@_type_id, g_@type@_type_id); } return static_g_@type@_type_id; } /*** END value\-tail ***/ .EE .UNINDENT .UNINDENT .sp Template files are easier to modify and update, and can be used to generate various types of outputs using the same command line or tools during the build. .SH USING GLIB-MKENUMS WITH MESON .sp Meson supports generating enumeration types using \fBglib\-mkenums\fP out of the box in its \fBgnome\fP module. .sp In your \fBmeson.build\fP file you will typically call the \fBgnome.mkenums_simple()\fP method to generate idiomatic enumeration types from a list of headers to inspect: .INDENT 0.0 .INDENT 3.5 .sp .EX project_headers = [ \(aqproject\-foo.h\(aq, \(aqproject\-bar.h\(aq, \(aqproject\-baz.h\(aq, ] gnome = import(\(aqgnome\(aq) enum_files = gnome.mkenums_simple(\(aqenum\-types\(aq, sources: project_headers, ) .EE .UNINDENT .UNINDENT .sp The \fBenum_files\fP variable will contain an array of two elements in the following order: .INDENT 0.0 .IP 1. 3 a build target for the source file .IP 2. 3 a build target for the header file .UNINDENT .sp 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: .INDENT 0.0 .INDENT 3.5 .sp .EX mainlib = library(\(aqproject\(aq, sources: project_sources + enum_files, … ) .EE .UNINDENT .UNINDENT .sp 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: .INDENT 0.0 .INDENT 3.5 .sp .EX mainlib_dep = declare_dependency(sources: enum_files[1], link_with: mainlib) .EE .UNINDENT .UNINDENT .sp 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 \fI\%corresponding Meson FAQ entry\fP\&. .sp If you are generating C header and source files that require special templates, you can use \fBgnome.mkenums()\fP to provide those headers, for instance: .INDENT 0.0 .INDENT 3.5 .sp .EX enum_files = gnome.mkenums(\(aqenum\-types\(aq, sources: project_headers, h_template: \(aqenum\-types.h.in\(aq, c_template: \(aqenum\-types.c.in\(aq, install_header: true, ) .EE .UNINDENT .UNINDENT .sp For more information, see the \fI\%Meson documentation\fP for \fBgnome.mkenums()\fP\&. .SH USING GLIB-MKENUMS WITH AUTOTOOLS .sp In order to use \fBglib\-mkenums\fP in your project when using Autotools as the build system, you will first need to modify your \fBconfigure.ac\fP file to ensure you find the appropriate command using \fBpkg\-config\fP, similarly as to how you discover the compiler and linker flags for GLib: .INDENT 0.0 .INDENT 3.5 .sp .EX PKG_PROG_PKG_CONFIG([0.28]) PKG_CHECK_VAR([GLIB_MKENUMS], [glib\-2.0], [glib_mkenums]) .EE .UNINDENT .UNINDENT .sp In your \fBMakefile.am\fP file you will typically use rules like these: .INDENT 0.0 .INDENT 3.5 .sp .EX # A list of headers to inspect project_headers = \e project\-foo.h \e project\-bar.h \e project\-baz.h enum\-types.h: $(project_headers) enum\-types.h.in $(AM_V_GEN)$(GLIB_MKENUMS) \e \-\-template=enum\-types.h.in \e \-\-output=$@ \e $(project_headers) enum\-types.c: $(project_headers) enum\-types.c.in enum\-types.h $(AM_V_GEN)$(GLIB_MKENUMS) \e \-\-template=enum\-types.c.in \e \-\-output=$@ \e $(project_headers) # Build the enum types files before every other target BUILT_SOURCES += enum\-types.h enum\-types.c CLEANFILES += enum\-types.h enum\-types.c EXTRA_DIST += enum\-types.h.in enum\-types.c.in .EE .UNINDENT .UNINDENT .sp In the example above, we have a variable called \fBproject_headers\fP where we reference all header files we want to inspect for generating enumeration GTypes. In the \fBenum\-types.h\fP rule we use \fBglib\-mkenums\fP with a template called \fBenum\-types.h.in\fP in order to generate the header file; similarly, in the \fBenum\-types.c\fP rule we use a template called \fBenum\-types.c.in\fP\&. .SH SEE ALSO .sp \fI\%glib\-genmarshal(1)\fP .\" Generated by docutils manpage writer. .