• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2
3# This is in its own file rather than inside meson.build
4# because a) mixing the two is ugly and b) trying to
5# make special characters such as \n go through all
6# backends is a fool's errand.
7
8import sys, subprocess
9
10h_array = ['--fhead',
11           "#pragma once\n\n#include <gst/gst.h>\n#include <gst/gl/gstgl_fwd.h>\nG_BEGIN_DECLS\n",
12           '--fprod',
13           "\n/* enumerations from \"@basename@\" */\n",
14           '--vhead',
15           "GST_GL_API\nGType @enum_name@_get_type (void);\n#define GST_TYPE_@ENUMSHORT@ (@enum_name@_get_type())\n",
16           '--ftail',
17           "G_END_DECLS"
18]
19
20c_array = ['--fhead',
21           "#ifdef HAVE_CONFIG_H\n#include \"config.h\"\n#endif\n#include \"gl-enumtypes.h\"\n\n#include <gst/gl/gl.h>\n\n#define C_ENUM(v) ((gint) v)\n#define C_FLAGS(v) ((guint) v)",
22           '--fprod',
23           "\n/* enumerations from \"@basename@\" */",
24           '--vhead',
25           "GType\n@enum_name@_get_type (void)\n{\n  static gsize static_g_define_type_id = 0;\n  if (g_once_init_enter (&static_g_define_type_id)) {\n    static const G@Type@Value values[] = {",
26           '--vprod',
27           "      { C_@TYPE@ (@VALUENAME@), \"@VALUENAME@\", \"@valuenick@\" },",
28           '--vtail',
29           "      { 0, NULL, NULL }\n    };\n    GType g_define_type_id = g_@type@_register_static (\"@EnumName@\", values);\n    g_once_init_leave (&static_g_define_type_id, g_define_type_id);\n  }\n  return static_g_define_type_id;\n}\n"
30]
31
32cmd = []
33argn = 1
34# Find the full command needed to run glib-mkenums
35# On UNIX-like, this is just the full path to glib-mkenums
36# On Windows, this is the full path to interpreter + full path to glib-mkenums
37for arg in sys.argv[1:]:
38    cmd.append(arg)
39    argn += 1
40    if arg.endswith('glib-mkenums') or arg.lower().endswith('glib-mkenums.exe'):
41        break
42ofilename = sys.argv[argn]
43headers = sys.argv[argn + 1:]
44
45if ofilename.endswith('.h'):
46    arg_array = h_array
47else:
48    arg_array = c_array
49
50cmd_array = cmd + arg_array + headers
51pc = subprocess.Popen(cmd_array, stdout=subprocess.PIPE)
52(stdo, _) = pc.communicate()
53if pc.returncode != 0:
54    sys.exit(pc.returncode)
55open(ofilename, 'wb').write(stdo)
56