gen_ld.py 835 B

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