blob: daaa551de2d8f1614959cf3291f27b2afcb96950 [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]
Andrew Geisslerd1e89492021-02-12 15:35:20 -060013 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()
Brad Bishop19323692019-04-05 15:28:33 -040020 return val
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080021
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080022try:
23 sysroot = os.environ['OECORE_NATIVE_SYSROOT']
24except KeyError:
Brad Bishop19323692019-04-05 15:28:33 -040025 print("Not in environment setup, bailing")
26 sys.exit(1)
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080027
Brad Bishop19323692019-04-05 15:28:33 -040028template_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"])
Andrew Geisslereff27472021-10-29 15:35:00 -050030native_template_file = os.path.join(sysroot, 'usr/share/meson/meson.native.template')
31native_file = os.path.join(sysroot, 'usr/share/meson/meson.native')
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080032
Brad Bishop19323692019-04-05 15:28:33 -040033with 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)
Andrew Geisslereff27472021-10-29 15:35:00 -050038
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)