gen-bootlin-toolchains 20 KB

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