1#!/usr/bin/env python
2# Copyright 2014 The Chromium Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6# Script for converting celt_pitch_xcorr_arm.s -> celt_pitch_xcorr_arm.S
7# using the arm2gnu.pl script.
8
9import os
10import sys
11
12
13USAGE = ('Usage:\n'
14         './convert_rtcd_assembler.py arm2gnu_script input_file output_file')
15
16
17def main(argv):
18  if len(argv) != 3:
19    print >> sys.stderr, ('Error: You must pass the following arguments:\n'
20                          ' * arm2gnu_script_path\n'
21                          ' * input_file\n'
22                          ' * output_file')
23    print USAGE
24    return 1
25
26  arm2gnu_script = os.path.abspath(argv[0])
27  if not os.path.exists(arm2gnu_script):
28    print >> sys.stderr, ('Error: Cannot find arm2gnu.pl script at: %s.' %
29                          arm2gnu_script)
30    return 2
31
32  input_file = os.path.abspath(argv[1])
33  if not os.path.exists(input_file):
34    print >> sys.stderr, 'Error: Cannot find input file at: %s.' % input_file
35    return 3
36
37  output_file = argv[2]
38
39  # Ensure the output file's directory path exists.
40  output_dir = os.path.dirname(output_file)
41  if not os.path.exists(output_dir):
42    os.makedirs(output_dir)
43
44  cmd = ('perl %s %s | '
45         'sed "s/OPUS_ARM_MAY_HAVE_[A-Z]*/1/g" | '
46         'sed "/.include/d" '
47         '> %s') % (arm2gnu_script, input_file, output_file)
48  print cmd
49  return os.system(cmd)
50
51if __name__ == '__main__':
52  sys.exit(main(sys.argv[1:]))
53