Annotation of embedaddon/strongswan/src/libstrongswan/plugins/plugin_constructors.py, revision 1.1.1.1

1.1       misho       1: #!/usr/bin/env python
                      2: #
                      3: # Copyright (C) 2017 Tobias Brunner
                      4: # HSR Hochschule fuer Technik Rapperswil
                      5: #
                      6: # This program is free software; you can redistribute it and/or modify it
                      7: # under the terms of the GNU General Public License as published by the
                      8: # Free Software Foundation; either version 2 of the License, or (at your
                      9: # option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
                     10: #
                     11: # This program is distributed in the hope that it will be useful, but
                     12: # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
                     13: # or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
                     14: # for more details.
                     15: 
                     16: from argparse import ArgumentParser
                     17: 
                     18: def generate_output(plugins):
                     19:        """Generate a source file containing plugin constructor registrations"""
                     20:        print("/**")
                     21:        print(" * Register plugin constructors for static libraries")
                     22:        print(" * Created by {0}".format(__file__))
                     23:        print(" */")
                     24:        print("")
                     25:        print("#include <plugins/plugin.h>")
                     26:        print("#include <plugins/plugin_loader.h>")
                     27:        print("")
                     28: 
                     29:        for plugin in plugins:
                     30:                print("plugin_t *{0}_plugin_create();".format(plugin.replace('-', '_')))
                     31: 
                     32:        print("")
                     33:        print("static void register_plugins() __attribute__ ((constructor));")
                     34:        print("static void register_plugins()")
                     35:        print("{")
                     36: 
                     37:        for plugin in plugins:
                     38:                print(' plugin_constructor_register("{0}", {1}_plugin_create);'.format(plugin, plugin.replace('-', '_')))
                     39: 
                     40:        print("}")
                     41: 
                     42:        print("")
                     43:        print("static void unregister_plugins() __attribute__ ((destructor));")
                     44:        print("static void unregister_plugins()")
                     45:        print("{")
                     46: 
                     47:        for plugin in plugins:
                     48:                print(' plugin_constructor_register("{0}", NULL);'.format(plugin))
                     49: 
                     50:        print("}")
                     51:        print("")
                     52: 
                     53: parser = ArgumentParser(description = "Generate constructor registration for a list of plugins")
                     54: parser.add_argument('plugins', metavar="plugin", nargs="*",
                     55:                                        help = "name of a plugin for which to generate constructor registration")
                     56: 
                     57: 
                     58: args = parser.parse_args()
                     59: generate_output(args.plugins);

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>