Add support for Meson as alternative/parallel build system
[platform/upstream/gst-plugins-base.git] / gst-libs / gst / rtsp / rtsp_mkenum.py
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
8 import sys, os, shutil, subprocess
9
10 h_array = [
11     '--fhead',
12     "#ifndef __gst_rtsp_ENUM_TYPES_H__\n#define __gst_rtsp_ENUM_TYPES_H__\n\n#include <glib-object.h>\n\nG_BEGIN_DECLS\n",
13     '--fprod',
14     "\n/* enumerations from \"@filename@\" */\n",
15     '--vhead',
16     "GType @enum_name@_get_type (void);\n#define GST_TYPE_@ENUMSHORT@ (@enum_name@_get_type())\n",
17     '--ftail',
18     "G_END_DECLS\n\n#endif /* __gst_rtsp_ENUM_TYPES_H__ */"
19 ]
20
21 c_array = ['--fhead',
22            "#include \"gstrtsp-enumtypes.h\"\n\n#include \"rtsp.h\"",
23            '--fprod',
24            "\n/* enumerations from \"@filename@\" */",
25            '--vhead',
26            "GType\n@enum_name@_get_type (void)\n{\n  static volatile gsize g_define_type_id__volatile = 0;\n  if (g_once_init_enter (&g_define_type_id__volatile)) {\n    static const G@Type@Value values[] = {",
27            '--vprod',
28            "      { @VALUENAME@, \"@VALUENAME@\", \"@valuenick@\" },",
29            '--vtail',
30            "      { 0, NULL, NULL }\n    };\n    GType g_define_type_id = g_@type@_register_static (\"@EnumName@\", values);\n    g_once_init_leave (&g_define_type_id__volatile, g_define_type_id);\n  }\n  return g_define_type_id__volatile;\n}\n"
31 ]
32
33
34 cmd = []
35 argn = 1
36 # Find the full command needed to run glib-mkenums
37 # On UNIX-like, this is just the full path to glib-mkenums
38 # On Windows, this is the full path to interpreter + full path to glib-mkenums
39 for arg in sys.argv[1:]:
40     cmd.append(arg)
41     argn += 1
42     if arg.endswith('glib-mkenums'):
43         break
44 ofilename = sys.argv[argn]
45 headers = sys.argv[argn + 1:]
46
47 if ofilename.endswith('.h'):
48     arg_array = h_array
49 else:
50     arg_array = c_array
51
52 cmd_array = cmd + arg_array + headers
53 pc = subprocess.Popen(cmd_array, stdout=subprocess.PIPE)
54 (stdo, _) = pc.communicate()
55 if pc.returncode != 0:
56     sys.exit(pc.returncode)
57 open(ofilename, 'wb').write(stdo)