1import os 2import rtconfig 3import platform 4import subprocess 5 6def generate_ldscript(input, output): 7 8 if not os.path.exists(input): 9 print('Error: file', input, 'not found') 10 return 11 12 if os.path.exists(output): 13 os.remove(output) 14 15 if rtconfig.PLATFORM == 'gcc': 16 17 gcc_cmd = os.path.join(rtconfig.EXEC_PATH, rtconfig.CC) 18 19 # gcc -E -P -x c $input -o $output 20 if (platform.system() == 'Windows'): 21 child = subprocess.Popen([gcc_cmd, '-E', '-P', '-x', 'c', input, '-o', output], stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) 22 else: 23 child = subprocess.Popen(gcc_cmd + f' -E -P -x c {input} -o {output}', stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) 24 25 child.communicate() 26 27 print(output, 'is generated from', input) 28