Jens Wiklander | c0bc808 | 2018-02-27 20:25:25 +0100 | [diff] [blame^] | 1 | #!/usr/bin/env python |
| 2 | # SPDX-License-Identifier: BSD-2-Clause |
| 3 | # Copyright (c) 2018, Linaro Limited |
| 4 | |
| 5 | import argparse |
| 6 | import shutil |
| 7 | import os |
| 8 | import re |
| 9 | |
| 10 | def get_args(): |
| 11 | parser = argparse.ArgumentParser() |
| 12 | parser.add_argument('--br', required=True, |
| 13 | help='Path to buildroot tree') |
| 14 | parser.add_argument('--out', required=True, |
| 15 | help='Path to buildroot out directory') |
| 16 | parser.add_argument('--top-dir', required=True, |
| 17 | help='Replaces %TOP_DIR% in defconfig files') |
| 18 | parser.add_argument('--br-ext-optee', required=True, |
| 19 | help='Path the OP-TEE external buildroot tree') |
| 20 | parser.add_argument('--br-defconfig', required=True, action='append', |
| 21 | help='Buildroot defconfig file') |
| 22 | parser.add_argument('--make-cmd', required=True, |
| 23 | help='Make command') |
| 24 | return parser.parse_args() |
| 25 | |
| 26 | def concatenate_files(top_dir, dst, srcs): |
| 27 | with open(dst, 'w') as outfile: |
| 28 | for fname in srcs: |
| 29 | with open(fname) as infile: |
| 30 | for line in infile: |
| 31 | outfile.write(line.replace('%TOP_DIR%', top_dir)) |
| 32 | |
| 33 | def main(): |
| 34 | args = get_args() |
| 35 | |
| 36 | if not os.path.isdir(args.out): |
| 37 | os.makedirs(args.out) |
| 38 | |
| 39 | concatenate_files(args.top_dir, args.out + '/defconfig', args.br_defconfig) |
| 40 | |
| 41 | if os.path.isabs(args.out): |
| 42 | out = args.out |
| 43 | else: |
| 44 | out = '../' + args.out |
| 45 | |
| 46 | if os.path.isabs(args.br_ext_optee): |
| 47 | br_ext_optee = args.br_ext_optee |
| 48 | else: |
| 49 | br_ext_optee = '../' + args.br_ext_optee |
| 50 | |
| 51 | os.execlp(args.make_cmd, args.make_cmd, '-C', args.br, 'O=' + out, |
| 52 | 'BR2_EXTERNAL=' + br_ext_optee, |
| 53 | 'BR2_DEFCONFIG=' + out + '/defconfig', 'defconfig') |
| 54 | |
| 55 | if __name__ == "__main__": |
| 56 | main() |