summaryrefslogtreecommitdiffstats
path: root/generator/nanopb_generator.py
diff options
context:
space:
mode:
authorPetteri Aimonen <jpa@git.mail.kapsi.fi>2013-03-04 19:27:42 +0200
committerPetteri Aimonen <jpa@git.mail.kapsi.fi>2013-03-04 19:27:42 +0200
commit64bf72d73d2b1a9bc3be1f7bba117a9664de7c1f (patch)
treea86c705f4452d5b12aa50506b2ff8c1d068e225c /generator/nanopb_generator.py
parent104710b26c1c4c6aaeb71141dcf1e72e5016b046 (diff)
Add generator option to configure #include directives.
This suits complex projects, where there are multiple interdependent .proto files in various directories. Patch by Michael Haberler.
Diffstat (limited to 'generator/nanopb_generator.py')
-rw-r--r--generator/nanopb_generator.py19
1 files changed, 14 insertions, 5 deletions
diff --git a/generator/nanopb_generator.py b/generator/nanopb_generator.py
index e38d3822..c3b5fbee 100644
--- a/generator/nanopb_generator.py
+++ b/generator/nanopb_generator.py
@@ -450,12 +450,14 @@ def generate_header(dependencies, headername, enums, messages, options):
symbol = make_identifier(headername)
yield '#ifndef _PB_%s_\n' % symbol
yield '#define _PB_%s_\n' % symbol
- yield '#include <pb.h>\n\n'
+ yield options.libformat % ('pb.h')
+ yield '\n'
for dependency in dependencies:
noext = os.path.splitext(dependency)[0]
- yield '#include "%s.%s.h"\n' % (noext,options.extension)
-
+ yield options.genformat % (noext + '.' + options.extension + '.h')
+ yield '\n'
+
yield '#ifdef __cplusplus\n'
yield 'extern "C" {\n'
yield '#endif\n\n'
@@ -490,7 +492,8 @@ def generate_source(headername, enums, messages):
yield '/* Automatically generated nanopb constant definitions */\n'
yield '/* Generated by %s at %s. */\n\n' % (nanopb_version, time.asctime())
- yield '#include "%s"\n\n' % headername
+ yield options.genformat % (headername)
+ yield '\n'
for msg in messages:
yield msg.default_decl(False)
@@ -583,7 +586,13 @@ optparser = OptionParser(
optparser.add_option("-x", dest="exclude", metavar="FILE", action="append", default=[],
help="Exclude file from generated #include list.")
optparser.add_option("-e", "--extension", dest="extension", metavar="EXTENSION", default="pb",
- help="use extension instead of 'pb' for generated files.")
+ help="Set extension to use instead of 'pb' for generated files. [default: %default]")
+optparser.add_option("-Q", "--generated-include-format", dest="genformat",
+ metavar="FORMAT", default='#include "%s"\n',
+ help="Set format string to use for including other .pb.h files. [default: %default]")
+optparser.add_option("-L", "--library-include-format", dest="libformat",
+ metavar="FORMAT", default='#include <%s>\n',
+ help="Set format string to use for including the nanopb pb.h header. [default: %default]")
optparser.add_option("-q", "--quiet", dest="quiet", action="store_true", default=False,
help="Don't print anything except errors.")
optparser.add_option("-v", "--verbose", dest="verbose", action="store_true", default=False,