1#!/usr/bin/env python2.7
2
3# Copyright 2015, ARM Limited
4# All rights reserved.
5#
6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions are met:
8#
9#   * Redistributions of source code must retain the above copyright notice,
10#     this list of conditions and the following disclaimer.
11#   * Redistributions in binary form must reproduce the above copyright notice,
12#     this list of conditions and the following disclaimer in the documentation
13#     and/or other materials provided with the distribution.
14#   * Neither the name of ARM Limited nor the names of its contributors may be
15#     used to endorse or promote products derived from this software without
16#     specific prior written permission.
17#
18# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS CONTRIBUTORS "AS IS" AND
19# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
22# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
29
30import argparse
31import glob
32import os
33
34
35dir_android = os.path.dirname(os.path.realpath(__file__))
36dir_root = os.path.join(dir_android, '..', '..')
37
38target_mk_default = os.path.abspath(os.path.join(dir_root, 'Android.mk'))
39
40
41parser = argparse.ArgumentParser(
42  description = \
43    'Generate an `Android.mk` to compile VIXL within Android.',
44  formatter_class=argparse.ArgumentDefaultsHelpFormatter
45)
46parser.add_argument('-o', '--output',
47                    default=os.path.relpath(target_mk_default, os.getcwd()),
48                    help='Target file.')
49args = parser.parse_args()
50
51
52sources = glob.glob(os.path.join(dir_root, 'src', 'vixl', '*.cc')) + \
53          glob.glob(os.path.join(dir_root, 'src', 'vixl', 'a64', '*.cc'))
54sources = map(lambda p : os.path.relpath(p, dir_root), sources)
55sources.sort()
56
57test_sources = glob.glob(os.path.join(dir_root, 'test', '*.cc'))
58test_sources = map(lambda p : os.path.relpath(p, dir_root), test_sources)
59test_sources.sort()
60
61android_mk_template = os.path.join(dir_android, 'Android.mk.template')
62with open(android_mk_template, 'r') as template_file:
63  template = template_file.read()
64
65
66template = template.format(vixl_sources=' \\\n  '.join(sources),
67                           vixl_test_files=' \\\n  '.join(test_sources))
68
69
70with open(args.output, 'w') as android_mk:
71  android_mk.write(template)
72
73