

import sys, os, json
from pathlib import Path

BASEDIR=os.getcwd()

JSONFILE=sys.argv[1]
COMPILE=sys.argv[2]
FLAGS=sys.argv[3]
OBJPAT=sys.argv[4]
CPAT=sys.argv[5]
OBJECTS=sys.argv[6:]


JSON = json.loads(Path(JSONFILE).read_text())

for base in OBJECTS:
    obj = BASEDIR + "/" + OBJPAT.replace("FILE", base)
    file = BASEDIR + "/" + CPAT.replace("FILE", base)
    flags = FLAGS.replace("-I./", f"-I{BASEDIR}/")
    command = f"{COMPILE} {obj} {flags} {file}"
    JSON.append({"file": file, "command": command, "directory": BASEDIR })

Path(JSONFILE).write_text(json.dumps(JSON, indent=4))


