blob: 808e2a062f66e7fdb89f0c1a97a4c27352bd8932 [file] [log] [blame]
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08001#!/usr/bin/env python3
2
3import os
Brad Bishop19323692019-04-05 15:28:33 -04004import string
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08005import sys
6
Brad Bishop19323692019-04-05 15:28:33 -04007class Template(string.Template):
8 delimiter = "@"
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08009
Brad Bishop19323692019-04-05 15:28:33 -040010class Environ():
11 def __getitem__(self, name):
12 val = os.environ[name]
13 val = ["'%s'" % x for x in val.split()]
14 val = ', '.join(val)
15 val = '[%s]' % val
16 return val
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080017
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080018try:
19 sysroot = os.environ['OECORE_NATIVE_SYSROOT']
20except KeyError:
Brad Bishop19323692019-04-05 15:28:33 -040021 print("Not in environment setup, bailing")
22 sys.exit(1)
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080023
Brad Bishop19323692019-04-05 15:28:33 -040024template_file = os.path.join(sysroot, 'usr/share/meson/meson.cross.template')
25cross_file = os.path.join(sysroot, 'usr/share/meson/%smeson.cross' % os.environ["TARGET_PREFIX"])
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080026
Brad Bishop19323692019-04-05 15:28:33 -040027with open(template_file) as in_file:
28 template = in_file.read()
29 output = Template(template).substitute(Environ())
30 with open(cross_file, "w") as out_file:
31 out_file.write(output)