1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/media/libopus/gen-sources.py Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,70 @@ 1.4 +# This Source Code Form is subject to the terms of the Mozilla Public 1.5 +# License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 +# file, You can obtain one at http://mozilla.org/MPL/2.0/. 1.7 + 1.8 +# This file takes the .mk files from an upstream opus repo and generates the 1.9 +# sources.mozbuild file. It is invoked as part of update.sh 1.10 + 1.11 +import sys 1.12 +import re 1.13 + 1.14 +def add_value(values, text): 1.15 + text = text.replace('\\', '') 1.16 + text = text.strip() 1.17 + if text: 1.18 + values.append(text) 1.19 + 1.20 +def write_values(output, values): 1.21 + for value in sorted(values, key=lambda x: x.lower()): 1.22 + output.write(" '%s',\n" % value) 1.23 + output.write(']\n\n') 1.24 + 1.25 +def generate_sources_mozbuild(path): 1.26 + makefiles = [ 1.27 + 'celt_sources.mk', 1.28 + 'opus_sources.mk', 1.29 + 'silk_sources.mk', 1.30 + ] 1.31 + 1.32 + var_definition = re.compile('([A-Z_]*) = (.*)') 1.33 + with open('sources.mozbuild', 'w') as output: 1.34 + 1.35 + output.write('# THIS FILE WAS AUTOMATICALLY GENERATED BY %s. DO NOT EDIT.\n' % sys.argv[0]) 1.36 + for makefile in makefiles: 1.37 + values = [] 1.38 + definition_started = False 1.39 + 1.40 + with open('%s/%s' % (path, makefile), 'r') as mk: 1.41 + for line in mk: 1.42 + line = line.rstrip() 1.43 + result = var_definition.match(line) 1.44 + if result: 1.45 + if definition_started: 1.46 + write_values(output, values) 1.47 + values = [] 1.48 + definition_started = True 1.49 + 1.50 + # Some variable definitions have the first entry on the 1.51 + # first line. Eg: 1.52 + # 1.53 + # CELT_SOURCES = celt/bands.c 1.54 + # 1.55 + # So we treat the first group as the variable name and 1.56 + # the second group as a potential value. 1.57 + # 1.58 + # Note that we write the variable name in lower case (so 1.59 + # "CELT_SOURCES" in the .mk file becomes "celt_sources" 1.60 + # in the .mozbuild file) because moz.build reserves 1.61 + # upper-case variable names for build system outputs. 1.62 + output.write('%s = [\n' % result.group(1).lower()) 1.63 + add_value(values, result.group(2)) 1.64 + else: 1.65 + add_value(values, line) 1.66 + write_values(output, values) 1.67 + 1.68 +if __name__ == '__main__': 1.69 + if len(sys.argv) != 2: 1.70 + print "Usage: %s /path/to/opus" % (sys.argv[0]) 1.71 + sys.exit(1) 1.72 + 1.73 + generate_sources_mozbuild(sys.argv[1])