Nirbheek Chauhan | 5c4f4ac | 2016-08-12 20:56:31 +0530 | [diff] [blame] | 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 = ['--fhead', |
Tim-Philipp Müller | 371e3e4 | 2018-03-13 10:36:56 +0000 | [diff] [blame] | 11 | "#ifndef __GST_AUDIO_ENUM_TYPES_H__\n#define __GST_AUDIO_ENUM_TYPES_H__\n\n#include <gst/gst.h>\n#include <gst/audio/audio-prelude.h>\nG_BEGIN_DECLS\n", |
Nirbheek Chauhan | 5c4f4ac | 2016-08-12 20:56:31 +0530 | [diff] [blame] | 12 | '--fprod', |
| 13 | "\n/* enumerations from \"@filename@\" */\n", |
| 14 | '--vhead', |
Tim-Philipp Müller | 371e3e4 | 2018-03-13 10:36:56 +0000 | [diff] [blame] | 15 | 'GST_AUDIO_API GType @enum_name@_get_type (void);\n#define GST_TYPE_@ENUMSHORT@ (@enum_name@_get_type())\n', |
Nirbheek Chauhan | 5c4f4ac | 2016-08-12 20:56:31 +0530 | [diff] [blame] | 16 | '--ftail', |
| 17 | 'G_END_DECLS\n\n#endif /* __GST_AUDIO_ENUM_TYPES_H__ */', |
| 18 | ] |
| 19 | |
| 20 | c_array = ['--fhead', |
| 21 | "#include \"audio-enumtypes.h\"\n\n#include \"audio.h\" \n#include \"audio-format.h\" \n#include \"audio-channels.h\" \n#include \"audio-info.h\" \n#include \"gstaudioringbuffer.h\"", |
| 22 | '--fprod', |
| 23 | "\n/* enumerations from \"@filename@\" */", |
| 24 | '--vhead', |
| 25 | "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[] = {", |
| 26 | '--vprod', |
| 27 | " { @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 (&g_define_type_id__volatile, g_define_type_id);\n }\n return g_define_type_id__volatile;\n}\n", |
| 30 | ] |
| 31 | |
| 32 | cmd = [] |
| 33 | argn = 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 |
| 37 | for arg in sys.argv[1:]: |
| 38 | cmd.append(arg) |
| 39 | argn += 1 |
Christoph Reiter | 9250eb8 | 2018-05-20 13:40:37 +0200 | [diff] [blame] | 40 | if os.path.splitext(arg)[0].endswith('glib-mkenums'): |
Nirbheek Chauhan | 5c4f4ac | 2016-08-12 20:56:31 +0530 | [diff] [blame] | 41 | break |
| 42 | ofilename = sys.argv[argn] |
| 43 | headers = sys.argv[argn + 1:] |
| 44 | |
| 45 | if ofilename.endswith('.h'): |
| 46 | arg_array = h_array |
| 47 | else: |
| 48 | arg_array = c_array |
| 49 | |
| 50 | cmd_array = cmd + arg_array + headers |
| 51 | pc = subprocess.Popen(cmd_array, stdout=subprocess.PIPE) |
| 52 | (stdo, _) = pc.communicate() |
| 53 | if pc.returncode != 0: |
| 54 | sys.exit(pc.returncode) |
| 55 | open(ofilename, 'wb').write(stdo) |