Generating the .defs files.
| Appendix H. Wrapping C Libraries |

## Generating the .defs files.

The .defs file are text files, in a lisp format, that describe the API of a C library, including its

- objects (GObjects, widgets, interfaces, boxed-types and plain structs)
- functions
- enums
- signals
- properties
- vfuncs

At the moment, we have separate tools for generating different parts of these .defs, so we split them up into separate files. For instance, in gtkmm/gtk/src, you will find these files:

- gtk.defs: Includes the other files.
- gtk_methods.defs: Objects and functions.
- gtk_enums.defs: Enums.
- gtk_signals.def: Signals and properties.
- gtk_vfuncs.defs: vfuncs (function pointer member fields in structs), written by hand.

### Generating the methods .defs

This .defs file describes objects and their functions. It is generated by the h2defs.py script which you can find in pygtk's codegen directory. For instance,

    $ ./h2defs.py /usr/include/gtk-2.0/gtk/*.h > gtk_methods.defs

### Generating the enums .defs

This .defs files describes enum types and their possible values. It is generated by the enums.pl script which you can find in glibmm's tools directory. For instance,

    $ ./enum.pl /usr/include/gtk-2.0/gtk/*.h > gtk_enums.defs

### Generating the signals and properties .defs

This .defs file describes signals and properties. It is generated by the special extra_defs utility that is in every wrapping project, such as gtkmm/tools/extra_defs_gen/. For instance

    $ cd tools/extra_defs_gen
    $ ./generate_extra_defs > gtk_signals.defs

You must edit the source code of your own extra_defs_gen tool in order to generate the .defs for the C types that you wish to wrap. Start by renaming the file:

    $ cd tools/extra_defs_gen
    $ mv generate_defs_gda.cc generate_defs_example.cc

Then edit the Makefile.am so that it mentions the new file name, and edit the new .cc file to specify the correct types. For instance, your main() function might look like this:

    #include <libsomething.h>

    int main (int argc, char *argv[])
    {
        libexample_init(argc, argv);

        std::cout << get_defs(EXAMPLE_TYPE_SOMETHING)
                  << get_defs(EXAMPLE_TYPE_THING);
        return 0;
    }

### Writing the vfuncs .defs

Appendix H. Wrapping C Libraries |  | The .hg and .ccg files