123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- from __future__ import print_function
- import re
- import argparse
- import os.path
- import io
- parser = argparse.ArgumentParser()
- parser.add_argument('version', help='version to include')
- parser.add_argument('outfile', help='outfile w/o extension')
- parser.add_argument('inputs', nargs='*', action='store', help='input filenames')
- args = parser.parse_args()
- outname = args.outfile.split("/")[-1]
- pos = outname.find(".")
- if pos > 0:
- outname = outname[:pos]
- include_re = re.compile("^#include ([\"<].*[\">]).*$")
- guard_re = re.compile("^#(?:(?:ifndef|define) [A-Z_]+_H_|endif /\* [A-Z_]+_H_ \*/)")
- includes = []
- is_c = False
- print ("Starting amalgamating file "+ args.outfile)
- for fname in args.inputs:
- if("util.h" in fname):
- is_c = True
- continue
- with io.open(fname, encoding="utf8") as infile:
- print ("Integrating file '" + fname + "'...", end=""),
- for line in infile:
- res = include_re.match(line)
- if res:
- inc = res.group(1)
- if not inc in includes and not inc[0] == '"':
- includes.append(inc)
- print ("done."),
- file = io.open(args.outfile, 'w')
- file.write(u'''/* THIS IS A SINGLE-FILE DISTRIBUTION CONCATENATED FROM THE OPEN62541 SOURCES
- * visit http://open62541.org/ for information about this software
- * Git-Revision: %s
- */
-
- /*
- * Copyright (C) 2015 the contributors as stated in the AUTHORS file
- *
- * This file is part of open62541. open62541 is free software: you can
- * redistribute it and/or modify it under the terms of the GNU Lesser General
- * Public License, version 3 (as published by the Free Software Foundation) with
- * a static linking exception as stated in the LICENSE file provided with
- * open62541.
- *
- * open62541 is distributed in the hope that it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
- * details.
- */\n\n''' % args.version)
- if not is_c:
- file.write(u'''#ifndef %s
- #define %s
- #ifdef __cplusplus
- extern "C" {
- #endif\n\n''' % (outname.upper() + u"_H_", outname.upper() + u"_H_") )
- if not is_c:
- for inc in includes:
- file.write(u"#include " + inc + "\n")
- else:
- file.write(u"#define UA_AMALGAMATE\n")
- file.write(u'''#ifndef UA_DYNAMIC_LINKING
- # define UA_DYNAMIC_LINKING
- #endif\n\n''')
- for fname in args.inputs:
- if "ua_config.h" in fname or "ua_util.h" in fname:
- with io.open(fname, encoding="utf8") as infile:
- print ("Integrating file '" + fname + "'...", end=""),
- for line in infile:
- file.write(line)
- print ("done."),
- file.write(u"#include \"" + outname + ".h\"\n")
- for fname in args.inputs:
- if not "util.h" in fname:
- with io.open(fname, encoding="utf8") as infile:
- file.write(u"/*********************************** amalgamated original file \"" + fname + u"\" ***********************************/\n")
- print ("Integrating file '" + fname + "'...", end=""),
- for line in infile:
- inc_res = include_re.match(line)
- guard_res = guard_re.match(line)
- if not inc_res and not guard_res:
- file.write(line)
- print ("done."),
- if not is_c:
- file.write(u'''
- #ifdef __cplusplus
- } // extern "C"
- #endif
- #endif /* %s */''' % (outname.upper() + u"_H_"))
- file.close()
- print ("The size of "+args.outfile+" is "+ str(os.path.getsize(args.outfile))+" Bytes.")
|