Created
April 27, 2015 08:54
-
-
Save gergelypolonkai/1e2fdedb136de3ca67f0 to your computer and use it in GitHub Desktop.
Registering a GLib EnumType using glib-mkenums and GNU Autotools
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /*** BEGIN file-header ***/ | |
| /* gswe-enumtypes.c - Enumeration types for SWE-GLib | |
| * | |
| * Copyright © 2013 Gergely Polonkai | |
| * | |
| * SWE-GLib is free software: you can redistribute it and/or modify | |
| * it under the terms of the GNU General Public License as published by | |
| * the Free Software Foundation; either version 3 of the License, or | |
| * (at your option) any later version. | |
| * | |
| * SWE-GLib is distributed in the hope that it will be useful, | |
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| * GNU General Public License for more details. | |
| * | |
| * You should have received a copy of the GNU General Public License | |
| * along with this library; if not, see <http://www.gnu.org/licenses/>. | |
| */ | |
| #include "swe-glib.h" | |
| #include "gswe-enumtypes.h" | |
| #include "@filename@" | |
| /*** END file-header ***/ | |
| /*** BEGIN file-production ***/ | |
| /* enumerations from "@filename@" */ | |
| /*** END file-production ***/ | |
| /*** BEGIN value-header ***/ | |
| GType | |
| @enum_name@_get_type(void) | |
| { | |
| static volatile gsize g_define_type_id__volatile = 0; | |
| gswe_init(); | |
| if (g_once_init_enter(&g;_define_type_id__volatile)) { | |
| static const G@Type@Value values[] = { | |
| /*** END value-header ***/ | |
| /*** BEGIN value-production ***/ | |
| { | |
| @VALUENAME@, | |
| "@VALUENAME@", | |
| "@valuenick@" | |
| }, | |
| /*** END value-production ***/ | |
| /*** BEGIN value-tail ***/ | |
| { 0, NULL, NULL } | |
| }; | |
| GType g_define_type_id = g_@type@_register_static( | |
| g_intern_static_string("@EnumName@"), | |
| values | |
| ); | |
| g_once_init_leave(&g;_define_type_id__volatile, g_define_type_id); | |
| } | |
| return g_define_type_id__volatile; | |
| } | |
| /*** END value-tail ***/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /*** BEGIN file-header ***/ | |
| /* gswe-enumtypes.h - Enumeration types for SWE-GLib | |
| * | |
| * Copyright © 2013 Gergely Polonkai | |
| * | |
| * SWE-GLib is free software: you can redistribute it and/or modify | |
| * it under the terms of the GNU General Public License as published by | |
| * the Free Software Foundation; either version 3 of the License, or | |
| * (at your option) any later version. | |
| * | |
| * SWE-GLib is distributed in the hope that it will be useful, | |
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| * GNU General Public License for more details. | |
| * | |
| * You should have received a copy of the GNU General Public License | |
| * along with this library; if not, see <http://www.gnu.org/licenses/>. | |
| */ | |
| #ifndef __GSWE_ENUM_TYPES_H__ | |
| #define __GSWE_ENUM_TYPES_H__ | |
| #include <glib-object.h> | |
| /*** END file-header ***/ | |
| /*** BEGIN file-production ***/ | |
| /* enumerations from "@filename@" */ | |
| #include "@filename@" | |
| /*** END file-production ***/ | |
| /*** BEGIN value-header ***/ | |
| GType @enum_name@_get_type(void); | |
| #define @ENUMPREFIX@_TYPE_@ENUMSHORT@ (@enum_name@_get_type()) | |
| /*** END value-header ***/ | |
| /*** BEGIN file-tail ***/ | |
| #endif /* __GSWE_ENUM_TYPES_H__ */ | |
| /*** END file-tail ***/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| gswe_enum_headers = headers-that-contain-enums.h | |
| gswe-enumtypes.h: $(gswe_enum_headers) gswe-enumtypes.h.template | |
| $(GLIB_MKENUMS) --template $(filter %.template,$^) $(filter-out %.template,$^) > \ | |
| gswe-enumtypes.h.tmp && mv gswe-enumtypes.h.tmp gswe-enumtypes.h | |
| gswe-enumtypes.c: $(gswe_enum_headers) gswe-enumtypes.h gswe-enumtypes.c.template | |
| $(GLIB_MKENUMS) --template $(filter %.template,$^) $(filter-out %.template,$^) > \ | |
| gswe-enumtypes.c.tmp && mv gswe-enumtypes.c.tmp gswe-enumtypes.c |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The filenames should be gswe-enumtypes.c.template and gswe-enumtypes.h.template.
Also, gswe-enumtypes.c:37 and gswe-enumtypes.c:58 have a typo, they should be "... &g_define_type..." not "... &g;_define_type..."
Thanks for the examples though, they are helpful :)