def make()

in memory_statistics/memory_statistics.py [0:0]


def make(sources, includes, flags, opt):
    args = ['make', '-B', '-f', os.path.join(__THIS_FILE_PATH__, 'makefile')]

    cflags = f'-O{opt}'
    for inc_dir in includes:
        cflags += ' -I "'+os.path.abspath(inc_dir)+'"'
    for flag in flags:
        cflags += f' -D {flag}'

    args += ['CFLAGS=' + cflags]
    args += ['SRCS=' + " ".join(sources)]

    proc = subprocess.Popen(args, stdout=subprocess.PIPE, universal_newlines=True)
    (results, _) = proc.communicate()
    print(results)

    # Run `make clean` to remove object files generated during previous make invocation.
    # This is so that memory_statistics.py cleans up after itself when running it locally.
    args = ['make', '-f', os.path.join(__THIS_FILE_PATH__, 'makefile'), 'clean']
    args += ['SRCS=' + " ".join(sources)]
    proc = subprocess.Popen(args)

    return results