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] |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 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() |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 20 | return val |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 21 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 22 | try: |
| 23 | sysroot = os.environ['OECORE_NATIVE_SYSROOT'] |
| 24 | except KeyError: |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 25 | print("Not in environment setup, bailing") |
| 26 | sys.exit(1) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 27 | |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 28 | template_file = os.path.join(sysroot, 'usr/share/meson/meson.cross.template') |
| 29 | cross_file = os.path.join(sysroot, 'usr/share/meson/%smeson.cross' % os.environ["TARGET_PREFIX"]) |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame] | 30 | native_template_file = os.path.join(sysroot, 'usr/share/meson/meson.native.template') |
| 31 | native_file = os.path.join(sysroot, 'usr/share/meson/meson.native') |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 32 | |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 33 | with 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 Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame] | 38 | |
| 39 | with 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) |