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"]) 30 31with open(template_file) as in_file: 32 template = in_file.read() 33 output = Template(template).substitute(Environ()) 34 with open(cross_file, "w") as out_file: 35 out_file.write(output) 36