gen-bootlin-toolchains 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566
  1. #!/usr/bin/env python3
  2. import os.path
  3. import re
  4. import requests
  5. import textwrap
  6. import sys
  7. BASE_URL = "https://toolchains.bootlin.com/downloads/releases/toolchains"
  8. AUTOGENERATED_COMMENT = """# This file was auto-generated by support/scripts/gen-bootlin-toolchains
  9. # Do not edit
  10. """
  11. # In the below dict:
  12. # - 'conditions' indicate the cumulative conditions under which the
  13. # toolchain will be made available. In several situations, a given
  14. # toolchain is usable on several architectures variants (for
  15. # example, an ARMv6 toolchain can be used on ARMv7)
  16. # - 'test_options' indicate one specific configuration where the
  17. # toolchain can be used. It is used to create the runtime test
  18. # cases. If 'test_options' does not exist, the code assumes it can
  19. # be made equal to 'conditions'
  20. # - 'prefix' is the prefix of the cross-compilation toolchain tools
  21. arches = {
  22. 'aarch64': {
  23. 'conditions': ['BR2_aarch64'],
  24. 'prefix': 'aarch64',
  25. },
  26. 'aarch64be': {
  27. 'conditions': ['BR2_aarch64_be'],
  28. 'prefix': 'aarch64_be',
  29. },
  30. 'arcle-750d': {
  31. 'conditions': ['BR2_arcle', 'BR2_arc750d'],
  32. 'prefix': 'arc',
  33. 'gdbserver': False,
  34. },
  35. 'arcle-hs38': {
  36. 'conditions': ['BR2_arcle', 'BR2_archs38'],
  37. 'prefix': 'arc',
  38. },
  39. 'armv5-eabi': {
  40. 'conditions': ['BR2_arm', 'BR2_ARM_CPU_ARMV5', 'BR2_ARM_EABI'],
  41. 'test_options': ['BR2_arm', 'BR2_arm926t', 'BR2_ARM_EABI'],
  42. 'prefix': 'arm',
  43. },
  44. 'armv6-eabihf': {
  45. 'conditions': ['BR2_arm', 'BR2_ARM_CPU_ARMV6', 'BR2_ARM_EABIHF'],
  46. 'test_options': ['BR2_arm', 'BR2_arm1176jzf_s', 'BR2_ARM_EABIHF'],
  47. 'prefix': 'arm',
  48. },
  49. 'armv7-eabihf': {
  50. 'conditions': ['BR2_arm', '(BR2_ARM_CPU_ARMV7A && BR2_ARM_EABIHF) || BR2_ARM_CPU_ARMV8A'],
  51. 'test_options': ['BR2_arm', 'BR2_cortex_a8', 'BR2_ARM_EABIHF'],
  52. 'prefix': 'arm',
  53. },
  54. 'armebv7-eabihf': {
  55. 'conditions': ['BR2_armeb', '(BR2_ARM_CPU_ARMV7A && BR2_ARM_EABIHF) || BR2_ARM_CPU_ARMV8A'],
  56. 'test_options': ['BR2_armeb', 'BR2_cortex_a8', 'BR2_ARM_EABIHF'],
  57. 'prefix': 'armeb',
  58. },
  59. 'armv7m': {
  60. 'conditions': ['BR2_arm', 'BR2_ARM_CPU_ARMV7M', 'BR2_BINFMT_FLAT'],
  61. 'test_options': ['BR2_arm', 'BR2_cortex_m4'],
  62. 'prefix': 'arm',
  63. },
  64. 'm68k-68xxx': {
  65. 'conditions': ['BR2_m68k_m68k'],
  66. 'test_options': ['BR2_m68k', 'BR2_m68k_68040'],
  67. 'prefix': 'm68k',
  68. },
  69. 'm68k-coldfire': {
  70. 'conditions': ['BR2_m68k_cf'],
  71. 'test_options': ['BR2_m68k', 'BR2_m68k_cf5208'],
  72. 'prefix': 'm68k',
  73. },
  74. 'microblazebe': {
  75. 'conditions': ['BR2_microblazebe'],
  76. 'prefix': 'microblaze',
  77. 'gdbserver': False
  78. },
  79. 'microblazeel': {
  80. 'conditions': ['BR2_microblazeel'],
  81. 'prefix': 'microblazeel',
  82. 'gdbserver': False
  83. },
  84. 'mips32': {
  85. # Not sure it could be used by other mips32 variants?
  86. 'conditions': ['BR2_mips', 'BR2_mips_32', '!BR2_MIPS_SOFT_FLOAT'],
  87. 'prefix': 'mips',
  88. },
  89. 'mips32el': {
  90. # Not sure it could be used by other mips32el variants?
  91. 'conditions': ['BR2_mipsel', 'BR2_mips_32', '!BR2_MIPS_SOFT_FLOAT'],
  92. 'prefix': 'mipsel',
  93. },
  94. 'mips32r5el': {
  95. 'conditions': ['BR2_mipsel', 'BR2_mips_32r5', '!BR2_MIPS_SOFT_FLOAT'],
  96. 'prefix': 'mipsel',
  97. },
  98. 'mips32r6el': {
  99. 'conditions': ['BR2_mipsel', 'BR2_mips_32r6', '!BR2_MIPS_SOFT_FLOAT'],
  100. 'prefix': 'mipsel',
  101. },
  102. 'mips64-n32': {
  103. # Not sure it could be used by other mips64 variants?
  104. 'conditions': ['BR2_mips64', 'BR2_mips_64', 'BR2_MIPS_NABI32', '!BR2_MIPS_SOFT_FLOAT'],
  105. 'prefix': 'mips64',
  106. },
  107. 'mips64el-n32': {
  108. # Not sure it could be used by other mips64el variants?
  109. 'conditions': ['BR2_mips64el', 'BR2_mips_64', 'BR2_MIPS_NABI32', '!BR2_MIPS_SOFT_FLOAT'],
  110. 'prefix': 'mips64el',
  111. },
  112. 'mips64r6el-n32': {
  113. 'conditions': ['BR2_mips64el', 'BR2_mips_64r6', 'BR2_MIPS_NABI32', '!BR2_MIPS_SOFT_FLOAT'],
  114. 'prefix': 'mips64el',
  115. },
  116. 'openrisc': {
  117. 'conditions': ['BR2_or1k'],
  118. 'prefix': 'or1k',
  119. 'gdbserver': False,
  120. },
  121. 'powerpc-440fp': {
  122. # Not sure it could be used by other powerpc variants?
  123. 'conditions': ['BR2_powerpc', 'BR2_powerpc_440fp'],
  124. 'prefix': 'powerpc',
  125. },
  126. 'powerpc-e300c3': {
  127. # Not sure it could be used by other powerpc variants?
  128. 'conditions': ['BR2_powerpc', 'BR2_powerpc_e300c3'],
  129. 'prefix': 'powerpc',
  130. },
  131. 'powerpc-e500mc': {
  132. # Not sure it could be used by other powerpc variants?
  133. 'conditions': ['BR2_powerpc', 'BR2_powerpc_e500mc'],
  134. 'prefix': 'powerpc',
  135. },
  136. 'powerpc64-e5500': {
  137. 'conditions': ['BR2_powerpc64', 'BR2_powerpc_e5500'],
  138. 'prefix': 'powerpc64',
  139. },
  140. 'powerpc64-e6500': {
  141. 'conditions': ['BR2_powerpc64', 'BR2_powerpc_e6500'],
  142. 'prefix': 'powerpc64',
  143. },
  144. 'powerpc64-power8': {
  145. 'conditions': ['BR2_powerpc64', 'BR2_powerpc_power8'],
  146. 'prefix': 'powerpc64',
  147. },
  148. 'powerpc64le-power8': {
  149. 'conditions': ['BR2_powerpc64le', 'BR2_powerpc_power8'],
  150. 'prefix': 'powerpc64le',
  151. },
  152. 'riscv32-ilp32d': {
  153. 'conditions': ['BR2_riscv', 'BR2_riscv_g', 'BR2_RISCV_32', 'BR2_RISCV_ABI_ILP32D'],
  154. 'prefix': 'riscv32',
  155. },
  156. 'riscv64-lp64d': {
  157. 'conditions': ['BR2_riscv', 'BR2_riscv_g', 'BR2_RISCV_64', 'BR2_RISCV_ABI_LP64D', 'BR2_USE_MMU'],
  158. 'prefix': 'riscv64',
  159. },
  160. 's390x-z13': {
  161. 'conditions': ['BR2_s390x', 'BR2_s390x_z13'],
  162. 'prefix': 's390x',
  163. },
  164. 'sh-sh4': {
  165. 'conditions': ['BR2_sh', 'BR2_sh4'],
  166. 'prefix': 'sh4',
  167. },
  168. 'sh-sh4aeb': {
  169. 'conditions': ['BR2_sh', 'BR2_sh4aeb'],
  170. 'prefix': 'sh4aeb',
  171. },
  172. 'sparc64': {
  173. 'conditions': ['BR2_sparc64', 'BR2_sparc_v9'],
  174. 'prefix': 'sparc64',
  175. },
  176. 'sparcv8': {
  177. 'conditions': ['BR2_sparc', 'BR2_sparc_v8'],
  178. 'prefix': 'sparc',
  179. },
  180. 'x86-64': {
  181. 'conditions': ['BR2_x86_64',
  182. 'BR2_X86_CPU_HAS_MMX',
  183. 'BR2_X86_CPU_HAS_SSE',
  184. 'BR2_X86_CPU_HAS_SSE2'],
  185. 'test_options': ['BR2_x86_64', 'BR2_x86_x86_64'],
  186. 'prefix': 'x86_64',
  187. },
  188. 'x86-64-v2': {
  189. 'conditions': ['BR2_x86_64',
  190. 'BR2_X86_CPU_HAS_MMX',
  191. 'BR2_X86_CPU_HAS_SSE',
  192. 'BR2_X86_CPU_HAS_SSE2',
  193. 'BR2_X86_CPU_HAS_SSE3',
  194. 'BR2_X86_CPU_HAS_SSSE3',
  195. 'BR2_X86_CPU_HAS_SSE4',
  196. 'BR2_X86_CPU_HAS_SSE42'],
  197. 'test_options': ['BR2_x86_64', 'BR2_x86_x86_64_v2'],
  198. 'prefix': 'x86_64',
  199. },
  200. 'x86-64-v3': {
  201. 'conditions': ['BR2_x86_64',
  202. 'BR2_X86_CPU_HAS_MMX',
  203. 'BR2_X86_CPU_HAS_SSE',
  204. 'BR2_X86_CPU_HAS_SSE2',
  205. 'BR2_X86_CPU_HAS_SSE3',
  206. 'BR2_X86_CPU_HAS_SSSE3',
  207. 'BR2_X86_CPU_HAS_SSE4',
  208. 'BR2_X86_CPU_HAS_SSE42',
  209. 'BR2_X86_CPU_HAS_AVX',
  210. 'BR2_X86_CPU_HAS_AVX2'],
  211. 'test_options': ['BR2_x86_64', 'BR2_x86_x86_64_v3'],
  212. 'prefix': 'x86_64',
  213. },
  214. 'x86-64-v4': {
  215. 'conditions': ['BR2_x86_64',
  216. 'BR2_X86_CPU_HAS_MMX',
  217. 'BR2_X86_CPU_HAS_SSE',
  218. 'BR2_X86_CPU_HAS_SSE2',
  219. 'BR2_X86_CPU_HAS_SSE3',
  220. 'BR2_X86_CPU_HAS_SSSE3',
  221. 'BR2_X86_CPU_HAS_SSE4',
  222. 'BR2_X86_CPU_HAS_SSE42',
  223. 'BR2_X86_CPU_HAS_AVX',
  224. 'BR2_X86_CPU_HAS_AVX2',
  225. 'BR2_X86_CPU_HAS_AVX512'],
  226. 'test_options': ['BR2_x86_64', 'BR2_x86_x86_64_v4'],
  227. 'prefix': 'x86_64',
  228. },
  229. 'x86-64-core-i7': {
  230. 'conditions': ['BR2_x86_64',
  231. 'BR2_X86_CPU_HAS_MMX',
  232. 'BR2_X86_CPU_HAS_SSE',
  233. 'BR2_X86_CPU_HAS_SSE2',
  234. 'BR2_X86_CPU_HAS_SSE3',
  235. 'BR2_X86_CPU_HAS_SSSE3',
  236. 'BR2_X86_CPU_HAS_SSE4',
  237. 'BR2_X86_CPU_HAS_SSE42'],
  238. 'test_options': ['BR2_x86_64', 'BR2_x86_corei7'],
  239. 'prefix': 'x86_64',
  240. },
  241. 'x86-core2': {
  242. 'conditions': ['BR2_i386',
  243. 'BR2_X86_CPU_HAS_MMX',
  244. 'BR2_X86_CPU_HAS_SSE',
  245. 'BR2_X86_CPU_HAS_SSE2',
  246. 'BR2_X86_CPU_HAS_SSE3',
  247. 'BR2_X86_CPU_HAS_SSSE3'],
  248. 'test_options': ['BR2_i386', 'BR2_x86_core2'],
  249. 'prefix': 'i686',
  250. },
  251. 'x86-i686': {
  252. 'conditions': ['BR2_i386',
  253. '!BR2_x86_i486',
  254. '!BR2_x86_i586',
  255. '!BR2_x86_x1000',
  256. '!BR2_x86_pentium_mmx',
  257. '!BR2_x86_geode',
  258. '!BR2_x86_c3',
  259. '!BR2_x86_winchip_c6',
  260. '!BR2_x86_winchip2'],
  261. 'test_options': ['BR2_i386',
  262. 'BR2_x86_i686'],
  263. 'prefix': 'i686',
  264. },
  265. 'xtensa-lx60': {
  266. 'conditions': ['BR2_xtensa', 'BR2_XTENSA_CUSTOM', 'BR2_XTENSA_LITTLE_ENDIAN'],
  267. 'prefix': 'xtensa',
  268. },
  269. }
  270. class Toolchain:
  271. def __init__(self, arch, libc, variant, version):
  272. self.arch = arch
  273. self.libc = libc
  274. self.variant = variant
  275. self.version = version
  276. self.fname_prefix = "%s--%s--%s-%s" % (self.arch, self.libc, self.variant, self.version)
  277. self.option_name = "BR2_TOOLCHAIN_EXTERNAL_BOOTLIN_%s_%s_%s" % \
  278. (self.arch.replace("-", "_").upper(), self.libc.upper(), self.variant.replace("-", "_").upper())
  279. self.fragment = requests.get(self.fragment_url).text.split("\n")
  280. self.sha256 = requests.get(self.hash_url).text.split(" ")[0]
  281. @property
  282. def tarball_url(self):
  283. return os.path.join(BASE_URL, self.arch, "tarballs",
  284. self.fname_prefix + ".tar.xz")
  285. @property
  286. def hash_url(self):
  287. return os.path.join(BASE_URL, self.arch, "tarballs",
  288. self.fname_prefix + ".sha256")
  289. @property
  290. def fragment_url(self):
  291. return os.path.join(BASE_URL, self.arch, "fragments",
  292. self.fname_prefix + ".frag")
  293. def gen_config_in_options(self, f):
  294. f.write("config %s\n" % self.option_name)
  295. f.write("\tbool \"%s %s %s %s\"\n" %
  296. (self.arch, self.libc, self.variant, self.version))
  297. depends = []
  298. selects = []
  299. for c in arches[self.arch]['conditions']:
  300. depends.append(c)
  301. if not arches[self.arch].get('gdbserver', True):
  302. selects.append("BR2_TOOLCHAIN_EXTERNAL_HAS_NO_GDBSERVER")
  303. for frag in self.fragment:
  304. # libc type
  305. if frag.startswith("BR2_TOOLCHAIN_EXTERNAL_CUSTOM_UCLIBC"):
  306. selects.append("BR2_TOOLCHAIN_EXTERNAL_UCLIBC")
  307. elif frag.startswith("BR2_TOOLCHAIN_EXTERNAL_CUSTOM_GLIBC"):
  308. # glibc needs mmu support
  309. if "BR2_USE_MMU" not in depends:
  310. depends.append("BR2_USE_MMU")
  311. selects.append("BR2_TOOLCHAIN_EXTERNAL_GLIBC")
  312. elif frag.startswith("BR2_TOOLCHAIN_EXTERNAL_CUSTOM_MUSL"):
  313. # musl needs mmu support
  314. if "BR2_USE_MMU" not in depends:
  315. depends.append("BR2_USE_MMU")
  316. selects.append("BR2_TOOLCHAIN_EXTERNAL_MUSL")
  317. # gcc version
  318. if frag.startswith("BR2_TOOLCHAIN_EXTERNAL_GCC_"):
  319. m = re.match("^BR2_TOOLCHAIN_EXTERNAL_GCC_([0-9_]*)=y$", frag)
  320. assert m, "Cannot get gcc version for toolchain %s" % self.fname_prefix
  321. selects.append("BR2_TOOLCHAIN_GCC_AT_LEAST_%s" % m[1])
  322. # respect the GCC requirement for the selected CPU/arch tuning
  323. depends.append("!BR2_ARCH_NEEDS_GCC_AT_LEAST_%s" % str(int(m[1]) + 1))
  324. # kernel headers version
  325. if frag.startswith("BR2_TOOLCHAIN_EXTERNAL_HEADERS_"):
  326. m = re.match("^BR2_TOOLCHAIN_EXTERNAL_HEADERS_([0-9_]*)=y$", frag)
  327. assert m, "Cannot get kernel headers version for toolchain %s" % self.fname_prefix
  328. selects.append("BR2_TOOLCHAIN_HEADERS_AT_LEAST_%s" % m[1])
  329. # C++
  330. if frag.startswith("BR2_TOOLCHAIN_EXTERNAL_CXX"):
  331. selects.append("BR2_INSTALL_LIBSTDCPP")
  332. # SSP
  333. if frag.startswith("BR2_TOOLCHAIN_EXTERNAL_HAS_SSP"):
  334. selects.append("BR2_TOOLCHAIN_HAS_SSP")
  335. # wchar
  336. if frag.startswith("BR2_TOOLCHAIN_EXTERNAL_WCHAR"):
  337. selects.append("BR2_USE_WCHAR")
  338. # locale
  339. if frag.startswith("BR2_TOOLCHAIN_EXTERNAL_LOCALE"):
  340. # locale implies the availability of wchar
  341. selects.append("BR2_USE_WCHAR")
  342. selects.append("BR2_ENABLE_LOCALE")
  343. # thread support
  344. if frag.startswith("BR2_TOOLCHAIN_EXTERNAL_HAS_THREADS"):
  345. selects.append("BR2_TOOLCHAIN_HAS_THREADS")
  346. if frag.startswith("BR2_TOOLCHAIN_EXTERNAL_HAS_THREADS_DEBUG"):
  347. selects.append("BR2_TOOLCHAIN_HAS_THREADS_DEBUG")
  348. if frag.startswith("BR2_TOOLCHAIN_EXTERNAL_HAS_THREADS_NPTL"):
  349. selects.append("BR2_TOOLCHAIN_HAS_THREADS_NPTL")
  350. # RPC
  351. if frag.startswith("BR2_TOOLCHAIN_EXTERNAL_INET_RPC"):
  352. selects.append("BR2_TOOLCHAIN_HAS_NATIVE_RPC")
  353. # D language
  354. if frag.startswith("BR2_TOOLCHAIN_EXTERNAL_DLANG"):
  355. selects.append("BR2_TOOLCHAIN_HAS_DLANG")
  356. # fortran
  357. if frag.startswith("BR2_TOOLCHAIN_EXTERNAL_FORTRAN"):
  358. selects.append("BR2_TOOLCHAIN_HAS_FORTRAN")
  359. # OpenMP
  360. if frag.startswith("BR2_TOOLCHAIN_EXTERNAL_OPENMP"):
  361. selects.append("BR2_TOOLCHAIN_HAS_OPENMP")
  362. for depend in depends:
  363. f.write("\tdepends on %s\n" % depend)
  364. for select in selects:
  365. f.write("\tselect %s\n" % select)
  366. f.write("\thelp\n")
  367. desc = "Bootlin toolchain for the %s architecture, using the %s C library. " % \
  368. (self.arch, self.libc)
  369. if self.variant == "stable":
  370. desc += "This is a stable version, which means it is using stable and proven versions of gcc, gdb and binutils."
  371. else:
  372. desc += "This is a bleeding-edge version, which means it is using the latest versions of gcc, gdb and binutils."
  373. f.write(textwrap.fill(desc, width=62, initial_indent="\t ", subsequent_indent="\t ") + "\n")
  374. f.write("\n")
  375. f.write("\t https://toolchains.bootlin.com/\n")
  376. f.write("\n")
  377. def gen_mk(self, f):
  378. f.write("ifeq ($(%s),y)\n" % self.option_name)
  379. f.write("TOOLCHAIN_EXTERNAL_BOOTLIN_VERSION = %s\n" % self.version)
  380. f.write("TOOLCHAIN_EXTERNAL_BOOTLIN_SOURCE = %s--%s--%s-$(TOOLCHAIN_EXTERNAL_BOOTLIN_VERSION).tar.xz\n" %
  381. (self.arch, self.libc, self.variant))
  382. f.write("TOOLCHAIN_EXTERNAL_BOOTLIN_SITE = %s\n" %
  383. os.path.join(BASE_URL, self.arch, "tarballs"))
  384. f.write("endif\n\n")
  385. pass
  386. def gen_hash(self, f):
  387. f.write("# From %s\n" % self.hash_url)
  388. f.write("sha256 %s %s\n" % (self.sha256, os.path.basename(self.tarball_url)))
  389. def gen_test(self, f):
  390. if self.variant == "stable":
  391. variant = "Stable"
  392. else:
  393. variant = "BleedingEdge"
  394. testname = "TestExternalToolchainBootlin" + \
  395. self.arch.replace("-", "").capitalize() + \
  396. self.libc.capitalize() + variant
  397. f.write("\n\n")
  398. f.write("class %s(TestExternalToolchain):\n" % testname)
  399. f.write(" config = \"\"\"\n")
  400. if 'test_options' in arches[self.arch]:
  401. test_options = arches[self.arch]['test_options']
  402. else:
  403. test_options = arches[self.arch]['conditions']
  404. for opt in test_options:
  405. if opt.startswith("!"):
  406. f.write(" # %s is not set\n" % opt[1:])
  407. else:
  408. f.write(" %s=y\n" % opt)
  409. f.write(" BR2_TOOLCHAIN_EXTERNAL=y\n")
  410. f.write(" BR2_TOOLCHAIN_EXTERNAL_BOOTLIN=y\n")
  411. f.write(" %s=y\n" % self.option_name)
  412. f.write(" # BR2_TARGET_ROOTFS_TAR is not set\n")
  413. f.write(" \"\"\"\n")
  414. f.write(" toolchain_prefix = \"%s-linux\"\n" % arches[self.arch]['prefix'])
  415. f.write("\n")
  416. f.write(" def test_run(self):\n")
  417. f.write(" TestExternalToolchain.common_check(self)\n")
  418. def __repr__(self):
  419. return "Toolchain(arch=%s libc=%s variant=%s version=%s, option=%s)" % \
  420. (self.arch, self.libc, self.variant, self.version, self.option_name)
  421. def get_toolchains():
  422. toolchains = list()
  423. for arch, details in arches.items():
  424. print(arch)
  425. url = os.path.join(BASE_URL, arch, "available_toolchains")
  426. page = requests.get(url).text
  427. fnames = sorted(re.findall(r'<td><a href="(\w[^"]+)"', page))
  428. # This dict will allow us to keep only the latest version for
  429. # each toolchain.
  430. tmp = dict()
  431. for fname in fnames:
  432. parts = fname.split('--')
  433. assert parts[0] == arch, "Arch does not match: %s vs. %s" % (parts[0], arch)
  434. libc = parts[1]
  435. if parts[2].startswith("stable-"):
  436. variant = "stable"
  437. version = parts[2][len("stable-"):]
  438. elif parts[2].startswith("bleeding-edge-"):
  439. variant = "bleeding-edge"
  440. version = parts[2][len("bleeding-edge-"):]
  441. tmp[(arch, libc, variant)] = version
  442. if len(tmp) == 0:
  443. print("ERROR: no toolchains found for architecture %s" % arch)
  444. sys.exit(1)
  445. toolchains += [Toolchain(k[0], k[1], k[2], v) for k, v in tmp.items()]
  446. return toolchains
  447. def gen_config_in_options(toolchains, fpath):
  448. with open(fpath, "w") as f:
  449. f.write(AUTOGENERATED_COMMENT)
  450. f.write("config BR2_TOOLCHAIN_EXTERNAL_BOOTLIN_ARCH_SUPPORTS\n")
  451. f.write("\tbool\n")
  452. for arch, details in arches.items():
  453. conditions = details['conditions'].copy()
  454. f.write("\tdefault y if %s\n" % " && ".join(conditions))
  455. f.write("\n")
  456. f.write("if BR2_TOOLCHAIN_EXTERNAL_BOOTLIN\n\n")
  457. f.write("config BR2_TOOLCHAIN_EXTERNAL_PREFIX\n")
  458. f.write("\tdefault \"$(ARCH)-linux\"\n")
  459. f.write("\n")
  460. f.write("config BR2_PACKAGE_PROVIDES_TOOLCHAIN_EXTERNAL\n")
  461. f.write("\tdefault \"toolchain-external-bootlin\"\n")
  462. f.write("\n")
  463. f.write("choice\n")
  464. f.write("\tprompt \"Bootlin toolchain variant\"\n")
  465. for toolchain in toolchains:
  466. toolchain.gen_config_in_options(f)
  467. f.write("endchoice\n")
  468. f.write("endif\n")
  469. def gen_mk(toolchains, fpath):
  470. with open(fpath, "w") as f:
  471. f.write("#" * 80 + "\n")
  472. f.write("#\n")
  473. f.write("# toolchain-external-bootlin\n")
  474. f.write("#\n")
  475. f.write("#" * 80 + "\n")
  476. f.write("\n")
  477. f.write(AUTOGENERATED_COMMENT)
  478. for toolchain in toolchains:
  479. toolchain.gen_mk(f)
  480. f.write("$(eval $(toolchain-external-package))\n")
  481. def gen_hash(toolchains, fpath):
  482. with open(fpath, "w") as f:
  483. f.write(AUTOGENERATED_COMMENT)
  484. for toolchain in toolchains:
  485. toolchain.gen_hash(f)
  486. def gen_runtime_test(toolchains, fpath):
  487. with open(fpath, "w") as f:
  488. f.write(AUTOGENERATED_COMMENT)
  489. f.write("from tests.toolchain.test_external import TestExternalToolchain\n")
  490. for toolchain in toolchains:
  491. toolchain.gen_test(f)
  492. def gen_toolchains(toolchains):
  493. maindir = "toolchain/toolchain-external/toolchain-external-bootlin"
  494. gen_config_in_options(toolchains, os.path.join(maindir, "Config.in.options"))
  495. gen_mk(toolchains, os.path.join(maindir, "toolchain-external-bootlin.mk"))
  496. gen_hash(toolchains, os.path.join(maindir, "toolchain-external-bootlin.hash"))
  497. gen_runtime_test(toolchains,
  498. os.path.join("support", "testing", "tests", "toolchain", "test_external_bootlin.py"))
  499. toolchains = get_toolchains()
  500. gen_toolchains(toolchains)