Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | |
| 3 | import os |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame^] | 4 | import string |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 5 | import sys |
| 6 | |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame^] | 7 | class Template(string.Template): |
| 8 | delimiter = "@" |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 9 | |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame^] | 10 | class 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 Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 17 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 18 | try: |
| 19 | sysroot = os.environ['OECORE_NATIVE_SYSROOT'] |
| 20 | except KeyError: |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame^] | 21 | print("Not in environment setup, bailing") |
| 22 | sys.exit(1) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 23 | |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame^] | 24 | template_file = os.path.join(sysroot, 'usr/share/meson/meson.cross.template') |
| 25 | cross_file = os.path.join(sysroot, 'usr/share/meson/%smeson.cross' % os.environ["TARGET_PREFIX"]) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 26 | |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame^] | 27 | with 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) |