From 325061c34e876476593f48656ac966bddbb54ae0 Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Sun, 3 Jan 2021 10:15:31 +0000 Subject: Added a dep generating tool that should be multi-platform Making thins easier in windows. --- tools/mkdeps.py | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100755 tools/mkdeps.py (limited to 'tools') diff --git a/tools/mkdeps.py b/tools/mkdeps.py new file mode 100755 index 0000000..241d22d --- /dev/null +++ b/tools/mkdeps.py @@ -0,0 +1,68 @@ +#!/usr/bin/env python3 + +import subprocess +import glob +import os +import sys +import re +from argparse import ArgumentParser + +__version__ = "0.1" + + +def main(): + + FIX_RE = r"([^:]+:)" + + parser = ArgumentParser(description="mkdeps for SDCC", + epilog="Copyright (C) 2021 Juan J Martinez ", + ) + + parser.add_argument( + "--version", action="version", version="%(prog)s " + __version__) + + parser.add_argument("-b", "--build-dir", dest="build", default=None, type=str, + help="Directory to build") + parser.add_argument("-I", "--include", dest="include", default=None, type=str, + help="Include directory") + parser.add_argument("-v", "--verbose", dest="verbose", action="store_true", + help="Enable verbose output") + + parser.add_argument("dir", help="Directory to scan") + parser.add_argument("deps", help="Dependencies makefile") + + args = parser.parse_args() + + fix_path = args.dir if args.build is None else args.build + fix_path = r"%s\1" % (fix_path.rstrip(os.sep) + os.sep) + inc = ["-I%s" % d for d in args.include.split(":")] + cmd = ["sdcc", "-MM"] + inc + result = [] + for d in glob.glob(os.path.join(args.dir, "*.c")): + if args.verbose: + print("running %r" % ' '.join(cmd + [d])) + out = subprocess.run(cmd + [d], stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + if out.returncode: + sys.exit("Error: %s" % out.stderr) + + result.append(re.sub(FIX_RE, fix_path, out.stdout.decode('utf-8'))) + + try: + old = open(args.deps, "rt").read() + except Exception: + if args.verbose: + print("%r not found, will generate" % args.deps) + old = None + + new = ''.join(result) + + if new != old: + with open(args.deps, "wt") as fd: + fd.write(new) + else: + print("%r didn't change, skipping" % args.deps) + + +if __name__ == "__main__": + main() -- cgit v1.2.3