Welcome to mirror list, hosted at ThFree Co, Russian Federation.

read-sources-list.py « meson - gitlab.xiph.org/xiph/opus.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: fcbec501966cd8e96f77b9d9c4a96d34d4f21cca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/usr/bin/env python3
#
# opus/read-sources-list.py
#
# Parses .mk files and extracts list of source files.
# Prints one line per source file list, with filenames space-separated.

import sys

if len(sys.argv) < 2:
  sys.exit('Usage: {} sources_foo.mk [sources_bar.mk...]'.format(sys.argv[0]))

for input_fn in sys.argv[1:]:
  with open(input_fn, 'r', encoding='utf8') as f:
    text = f.read()
    text = text.replace('\\\n', '')

    # Remove empty lines
    lines = [line for line in text.split('\n') if line.strip()]

    # Print SOURCES_XYZ = file1.c file2.c
    for line in lines:
      values = line.strip().split('=', maxsplit=2)
      if len(values) != 2:
        raise RuntimeError('Unable to parse line "{}" from file "{}"'.format(line, input_fn))
      var, files = values
      sources_list = [f for f in files.split(' ') if f]
      print(var.strip(), '=', ' '.join(sources_list))