"""update_mk.py - Update meta-kernel to set absolute paths Create a new meta-kernel file, by replacing relative PATH_VALUES of kernels root dir with absolute path, so the meta-kernels file can be used from anywhere in the directory tree. """ import os import re INPUT_FILE = "kernels/mk/solo_ANC_soc-flown-mk.tm" OUTPUT_FILE = "kernels/meta-kernel.irap.tm" def update_meta_kernel (): """ Search line like : PATH_VALUES = ( '..' ) Replace with : PATH_VALUES = ( os.getenv ("SPICE_DIR") ) """ expr = re.compile ("\s*PATH_VALUES.*\([^)]*\).*") replace = "( '%s' )" % os.getenv ("SPICE_DIR") with open (OUTPUT_FILE, "w") as output : for line in open (INPUT_FILE): r = expr.match (line) if r: line = re.sub ("\([^)]*\)", replace, line) print (line, end = "", file = output) print ("Generation", OUTPUT_FILE) if __name__ == "__main__": update_meta_kernel ()