gen-bootlin-toolchains 20 KB

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