1#!/usr/bin/env python3 2 3import os 4import string 5import sys 6 7class Template(string.Template): 8 delimiter = "@" 9 10class Environ(): 11 def __getitem__(self, name): 12 val = os.environ[name] 13 val = val.split() 14 if len(val) > 1: 15 val = ["'%s'" % x for x in val] 16 val = ', '.join(val) 17 val = '[%s]' % val 18 elif val: 19 val = "'%s'" % val.pop() 20 return val 21 22try: 23 sysroot = os.environ['OECORE_NATIVE_SYSROOT'] 24except KeyError: 25 print("Not in environment setup, bailing") 26 sys.exit(1) 27 28template_file = os.path.join(sysroot, 'usr/share/meson/meson.cross.template') 29cross_file = os.path.join(sysroot, 'usr/share/meson/%smeson.cross' % os.environ["TARGET_PREFIX"]) 30native_template_file = os.path.join(sysroot, 'usr/share/meson/meson.native.template') 31native_file = os.path.join(sysroot, 'usr/share/meson/meson.native') 32 33with open(template_file) as in_file: 34 template = in_file.read() 35 output = Template(template).substitute(Environ()) 36 with open(cross_file, "w") as out_file: 37 out_file.write(output) 38 39with open(native_template_file) as in_file: 40 template = in_file.read() 41 output = Template(template).substitute({'OECORE_NATIVE_SYSROOT': os.environ['OECORE_NATIVE_SYSROOT']}) 42 with open(native_file, "w") as out_file: 43 out_file.write(output) 44