1#!/usr/bin/env python 2 3import os 4import sys 5import argparse 6import subprocess 7from shutil import copy 8 9def exec_command(cmd, log_path='out/build.log', **kwargs): 10 process = subprocess.Popen(cmd) 11 process.wait() 12 ret_code = process.returncode 13 14 if ret_code != 0: 15 raise Exception("{} failed, return code is {}".format(cmd, ret_code)) 16 17def musl_copy_file(src, dest): 18 dest_dir = os.path.dirname(dest) 19 if not os.path.exists(dest_dir): 20 os.makedirs(dest_dir) 21 copy(src, dest) 22 23def main(): 24 parser = argparse.ArgumentParser(description=__doc__) 25 26 parser.add_argument('--input', 27 required = True, 28 help = 'The header source path', 29 metavar = 'FILE') 30 31 parser.add_argument('--output', 32 required = True, 33 help = 'The output directory', 34 metavar = 'FILE') 35 36 parser.add_argument('--ldpath', 37 required = True, 38 help = 'The ld file path', 39 metavar = 'FILE') 40 41 parser.add_argument('--crtplus', 42 required = True, 43 help = 'The crtplus file path', 44 metavar = 'FILE') 45 46 args = parser.parse_args() 47 48 if os.path.basename(args.input) == 'crtn.o': 49 ldargs = [args.ldpath, "-r", args.input, args.crtplus, "-o", args.output] 50 exec_command(ldargs) 51 else: 52 musl_copy_file(args.input, args.output) 53 54if __name__ == "__main__": 55 sys.exit(main()) 56