import sys

from check_objects import to_recompile
from compile import do_compile
from link_and_load import link_and_load
import random
import glob

if __name__ == "__main__":
    if len(sys.argv) < 4:
        sys.stderr.write("Expected different parameters!\n")
        sys.stderr.write("    %s address taskname [file]*\n")
    else:
        address = sys.argv[1]
        taskname = sys.argv[2]
        files = [a.replace("\\", "/") for a in sum([glob.glob(f) for f in sys.argv[3:]], [])]

        new_files = to_recompile(address, files)
        for f in new_files:
            do_compile(address, f, str(random.random()), f, "PO", ["--debug"])

        link_and_load(address, taskname, files)
