mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-02-18 04:05:34 +00:00
meson: use gnome.mkenums() with template files for enum file gen
Saves us a custom script. Template files are nicer than passing multiline templating stuff through to glib-mkenums. And we can get rid of our custom python script.
This commit is contained in:
parent
597e43cffc
commit
21d3f9a0e4
4 changed files with 73 additions and 67 deletions
|
@ -1,54 +0,0 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
# This is in its own file rather than inside meson.build
|
||||
# because a) mixing the two is ugly and b) trying to
|
||||
# make special characters such as \n go through all
|
||||
# backends is a fool's errand.
|
||||
|
||||
import sys, os, shutil, subprocess
|
||||
|
||||
h_array = ['--fhead',
|
||||
"#ifndef __GST_ENUM_TYPES_H__\n#define __GST_ENUM_TYPES_H__\n\n#include <glib-object.h>\n\nG_BEGIN_DECLS\n",
|
||||
'--fprod',
|
||||
"\n/* enumerations from \"@filename@\" */\n",
|
||||
'--vhead',
|
||||
"GType @enum_name@_get_type (void);\n#define GST_TYPE_@ENUMSHORT@ (@enum_name@_get_type())\n",
|
||||
'--ftail',
|
||||
"G_END_DECLS\n\n#endif /* __GST_ENUM_TYPES_H__ */"]
|
||||
|
||||
c_array = [
|
||||
'--fhead',
|
||||
"#include \"gst_private.h\"\n#include <gst/gst.h>\n#define C_ENUM(v) ((gint) v)\n#define C_FLAGS(v) ((guint) v)\n ",
|
||||
'--fprod',
|
||||
"\n/* enumerations from \"@filename@\" */",
|
||||
'--vhead',
|
||||
"GType\n@enum_name@_get_type (void)\n{\n static gsize id = 0;\n static const G@Type@Value values[] = {",
|
||||
'--vprod',
|
||||
" { C_@TYPE@(@VALUENAME@), \"@VALUENAME@\", \"@valuenick@\" },",
|
||||
'--vtail',
|
||||
" { 0, NULL, NULL }\n };\n\n if (g_once_init_enter (&id)) {\n GType tmp = g_@type@_register_static (\"@EnumName@\", values);\n g_once_init_leave (&id, tmp);\n }\n\n return (GType) id;\n}"
|
||||
]
|
||||
|
||||
cmd = []
|
||||
argn = 1
|
||||
# Find the full command needed to run glib-mkenums
|
||||
# On UNIX-like, this is just the full path to glib-mkenums
|
||||
# On Windows, this is the full path to interpreter + full path to glib-mkenums
|
||||
for arg in sys.argv[1:]:
|
||||
cmd.append(arg)
|
||||
argn += 1
|
||||
if arg.endswith('glib-mkenums'):
|
||||
break
|
||||
ofilename = sys.argv[argn]
|
||||
headers = sys.argv[argn + 1:]
|
||||
|
||||
if ofilename.endswith('.h'):
|
||||
arg_array = h_array
|
||||
else:
|
||||
arg_array = c_array
|
||||
|
||||
pc = subprocess.Popen(cmd + arg_array + headers, stdout=subprocess.PIPE)
|
||||
(stdo, _) = pc.communicate()
|
||||
if pc.returncode != 0:
|
||||
sys.exit(pc.returncode)
|
||||
open(ofilename, 'wb').write(stdo)
|
41
gst/gstenumtypes.c.template
Normal file
41
gst/gstenumtypes.c.template
Normal file
|
@ -0,0 +1,41 @@
|
|||
/*** BEGIN file-header ***/
|
||||
#include "gst/gst_private.h"
|
||||
#include <gst/gst.h>
|
||||
#define C_ENUM(v) ((gint) v)
|
||||
#define C_FLAGS(v) ((guint) v)
|
||||
|
||||
/*** END file-header ***/
|
||||
|
||||
/*** BEGIN file-production ***/
|
||||
/* enumerations from "@basename@" */
|
||||
/*** END file-production ***/
|
||||
|
||||
/*** BEGIN value-header ***/
|
||||
GType
|
||||
@enum_name@_get_type (void)
|
||||
{
|
||||
static gsize id = 0;
|
||||
static const G@Type@Value values[] = {
|
||||
/*** END value-header ***/
|
||||
|
||||
/*** BEGIN value-production ***/
|
||||
{ C_@TYPE@(@VALUENAME@), "@VALUENAME@", "@valuenick@" },
|
||||
/*** END value-production ***/
|
||||
|
||||
/*** BEGIN value-tail ***/
|
||||
{ 0, NULL, NULL }
|
||||
};
|
||||
|
||||
if (g_once_init_enter (&id)) {
|
||||
GType tmp = g_@type@_register_static ("@EnumName@", values);
|
||||
g_once_init_leave (&id, tmp);
|
||||
}
|
||||
|
||||
return (GType) id;
|
||||
}
|
||||
|
||||
/*** END value-tail ***/
|
||||
|
||||
/*** BEGIN file-tail ***/
|
||||
|
||||
/*** END file-tail ***/
|
24
gst/gstenumtypes.h.template
Normal file
24
gst/gstenumtypes.h.template
Normal file
|
@ -0,0 +1,24 @@
|
|||
/*** BEGIN file-header ***/
|
||||
#ifndef __GST_ENUM_TYPES_H__
|
||||
#define __GST_ENUM_TYPES_H__
|
||||
|
||||
#include <glib-object.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
/*** END file-header ***/
|
||||
|
||||
/*** BEGIN file-production ***/
|
||||
|
||||
/* enumerations from "@basename@" */
|
||||
/*** 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 ***/
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __GST_ENUM_TYPES_H__ */
|
||||
/*** END file-tail ***/
|
|
@ -163,21 +163,16 @@ configure_file(input : 'gstversion.h.in',
|
|||
install_dir : 'include/gstreamer-1.0/gst',
|
||||
configuration : cdata)
|
||||
|
||||
mkenums = find_program('build_mkenum.py')
|
||||
glib_mkenums = find_program('glib-mkenums')
|
||||
gst_enums = gnome.mkenums('gstenumtypes',
|
||||
sources : gst_headers,
|
||||
h_template : 'gstenumtypes.h.template',
|
||||
c_template : 'gstenumtypes.c.template',
|
||||
install_header : true,
|
||||
install_dir : join_paths(get_option('includedir'), 'gstreamer-1.0/gst'))
|
||||
|
||||
gstenum_h = custom_target('gstenum_h',
|
||||
output : 'gstenumtypes.h',
|
||||
input : gst_headers,
|
||||
install : true,
|
||||
install_dir : 'include/gstreamer-1.0/gst',
|
||||
command : [mkenums, glib_mkenums, '@OUTPUT@', '@INPUT@'])
|
||||
gstenum_h = gst_enums[0]
|
||||
gstenum_c = gst_enums[1]
|
||||
|
||||
gstenum_c = custom_target('gstenum_c',
|
||||
output : 'gstenumtypes.c',
|
||||
input : gst_headers,
|
||||
depends : [gstenum_h],
|
||||
command : [mkenums, glib_mkenums, '@OUTPUT@', '@INPUT@'])
|
||||
|
||||
subdir('parse')
|
||||
subdir('printf')
|
||||
|
|
Loading…
Reference in a new issue