1
0

llvm_arm.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #
  2. # File : llvm_arm.py
  3. # This file is part of RT-Thread RTOS
  4. # COPYRIGHT (C) 2006 - 2018, RT-Thread Development Team
  5. #
  6. # This program is free software; you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation; either version 2 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License along
  17. # with this program; if not, write to the Free Software Foundation, Inc.,
  18. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. #
  20. # Change Logs:
  21. # Date Author Notes
  22. # 2023-05-17 Flybreak The first version
  23. import os
  24. import re
  25. import platform
  26. def GetLLVM_ARMRoot(rtconfig):
  27. exec_path = rtconfig.EXEC_PATH
  28. lib_path = 'lib/clang-runtimes/arm-none-eabi'
  29. root_path = os.path.join(exec_path, '..', lib_path)
  30. return root_path
  31. def CheckHeader(rtconfig, filename):
  32. root = GetLLVM_ARMRoot(rtconfig)
  33. if os.path.isdir(root):
  34. for config in os.listdir(root):
  35. fn = os.path.join(root, config, 'include', filename)
  36. if os.path.isfile(fn):
  37. return True
  38. return False
  39. def GetPicoLibcVersion(rtconfig):
  40. version = None
  41. root = GetLLVM_ARMRoot(rtconfig)
  42. if CheckHeader(rtconfig, 'picolibc.h'): # get version from picolibc.h file
  43. for config in os.listdir(root):
  44. fn = os.path.join(root, config, 'include', 'picolibc.h')
  45. f = open(fn, 'r')
  46. if f:
  47. for line in f:
  48. if line.find('__PICOLIBC_VERSION__') != -1 and line.find('"') != -1:
  49. version = re.search(r'\"([^"]+)\"', line).groups()[0]
  50. f.close()
  51. return version
  52. return version