summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorJuan J. Martinez <jjm@usebox.net>2021-01-03 10:15:31 +0000
committerJuan J. Martinez <jjm@usebox.net>2021-01-03 10:15:31 +0000
commit325061c34e876476593f48656ac966bddbb54ae0 (patch)
tree8ea1acf3a08d52fa988f5b213e21f250f9968227 /tools
parentd49c62663b6a2229e9849769591873005c762618 (diff)
downloadubox-msx-lib-325061c34e876476593f48656ac966bddbb54ae0.tar.gz
ubox-msx-lib-325061c34e876476593f48656ac966bddbb54ae0.zip
Added a dep generating tool that should be multi-platform
Making thins easier in windows.
Diffstat (limited to 'tools')
-rwxr-xr-xtools/mkdeps.py68
1 files changed, 68 insertions, 0 deletions
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 <jjm@usebox.net>",
+ )
+
+ 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()