|
| 1 | +import argparse |
| 2 | +import json |
| 3 | +import os |
| 4 | +import pathlib |
| 5 | +import shutil |
| 6 | +import subprocess |
| 7 | +import sys |
| 8 | + |
| 9 | +DEFAULT_STACK_SIZE = 50 |
| 10 | +OVERLAY_SIZE = 2048 |
| 11 | + |
| 12 | +def main(): |
| 13 | + ap = argparse.ArgumentParser(description='compile Pawn source files into binaries') |
| 14 | + ap.add_argument('config', type=str, help='config file to use') |
| 15 | + ap.add_argument('--pawncc', type=str, help='Path to "pawncc" executable', default="pawncc") |
| 16 | + ap.add_argument('--include', '-i', type=str, help='Path to Pawn include folder in InfiniTime sources', default="src/pawn/programs/include") |
| 17 | + args = ap.parse_args() |
| 18 | + |
| 19 | + with open(args.config, 'r') as fd: |
| 20 | + data = json.load(fd) |
| 21 | + |
| 22 | + for name, app in data.items(): |
| 23 | + print("Compiling Pawn: " + name) |
| 24 | + |
| 25 | + source = app["source"] |
| 26 | + if not os.path.exists(source): |
| 27 | + source = os.path.join(os.path.dirname(sys.argv[0]), source) |
| 28 | + |
| 29 | + args = [args.pawncc, "-p" + os.path.join(args.include, "infinitime.inc"), "-i" + args.include] |
| 30 | + if not app.get("debug", False): |
| 31 | + args.append("-O3") |
| 32 | + args.append("-d0") |
| 33 | + if app.get("overlays", False): |
| 34 | + args.append("-V" + str(OVERLAY_SIZE)) |
| 35 | + args.append("-S" + str(app.get("stack_size", DEFAULT_STACK_SIZE))) |
| 36 | + |
| 37 | + args.append(source) |
| 38 | + |
| 39 | + subprocess.check_call(args) # The output will be written to the current directory with the ".amx" extension |
| 40 | + |
| 41 | + sourcePath = pathlib.Path(source) |
| 42 | + shutil.move(sourcePath.stem + ".amx", sourcePath.stem + ".bin") |
| 43 | + |
| 44 | +if __name__ == '__main__': |
| 45 | + main() |
0 commit comments