diff --git a/scripts/irq2nvic_h b/scripts/irq2nvic_h index 92d63b85..1259864f 100755 --- a/scripts/irq2nvic_h +++ b/scripts/irq2nvic_h @@ -27,6 +27,8 @@ method to achive the same thing with C preprocessor is known to the author. (Neither is any non-portable method, for that matter.)""" import sys +import os +import os.path import yaml template_nvic_h = '''\ @@ -112,12 +114,23 @@ def convert(infile, outfile_nvic, outfile_vectornvic): outfile_nvic.write(template_nvic_h.format(**data)) outfile_vectornvic.write(template_vector_nvic_c.format(**data)) +def makeparentdir(filename): + try: + os.makedirs(os.path.dirname(filename)) + except OSError: + # where is my 'mkdir -p'? + pass + def main(): infile = sys.argv[1] if not infile.startswith('./include/libopencm3/') or not infile.endswith('/irq.yaml'): raise ValueError("Arguent must match ./include/libopencm3/**/irq.yaml") nvic_h = infile.replace('irq.yaml', 'nvic.h') vector_nvic_c = infile.replace('./include/libopencm3/', './lib/').replace('irq.yaml', 'vector_nvic.c') + + makeparentdir(nvic_h) + makeparentdir(vector_nvic_c) + convert(open(infile), open(nvic_h, 'w'), open(vector_nvic_c, 'w')) if __name__ == "__main__":