summaryrefslogtreecommitdiff
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
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.
-rw-r--r--game/Makefile2
-rwxr-xr-xtools/mkdeps.py68
2 files changed, 69 insertions, 1 deletions
diff --git a/game/Makefile b/game/Makefile
index da7d699..325247f 100644
--- a/game/Makefile
+++ b/game/Makefile
@@ -1,7 +1,7 @@
all:
mkdir -p ./generated ./bin ./build
make -C data
- cd src && rm -f Makefile.deps && touch Makefile.deps && find . -name "*.c" | xargs -n1 sdcc -I../generated -I../../include -MM | sed -r 's/([^:]+):/..\/build\/\1:/' >> Makefile.deps
+ cd src && ../../tools/mkdeps.py -b ../build -I ../generated:../../include ./ Makefile.deps2
make -C src
.PHONY: all clean
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()