subprojects: add libdrm wrap
[platform/upstream/gstreamer.git] / scripts / generate_init_static_plugins.py
1 #!/usr/bin/env python3
2
3 import argparse
4 import os
5 from string import Template
6
7 TEMPLATE = Template('''
8 #include <gst/gst.h>
9
10 $plugins_declaration
11
12 void
13 gst_init_static_plugins (void)
14 {
15   $plugins_registration
16 }
17 ''')
18
19 if __name__ == "__main__":
20     parser = argparse.ArgumentParser()
21     parser.add_argument(dest="output", help="Output file")
22     parser.add_argument(dest="plugins", help="The list of plugins")
23
24     options = parser.parse_args()
25
26     names = set()
27     for plugin in options.plugins.split(os.pathsep):
28         filename = os.path.basename(plugin)
29         if filename.startswith('libgst') and filename.endswith('.a'):
30             names.add(filename[len('libgst'):-len('.a')])
31
32     registration = ['GST_PLUGIN_STATIC_REGISTER(%s);' % name for name in names]
33     declaration = ['GST_PLUGIN_STATIC_DECLARE(%s);' % name for name in names]
34
35     with open(options.output, "w") as f:
36         f.write(TEMPLATE.substitute({
37             'plugins_declaration': '\n'.join(declaration),
38             'plugins_registration': '\n  '.join(registration),
39             }))