tcmode-external-sourcery.inc 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. #
  2. # Configuration to use external Sourcery G++ toolchain
  3. #
  4. EXTERNAL_TOOLCHAIN ?= "UNDEFINED"
  5. # Ensure that pseudo builds both 32 bit and 64 bit binaries, as we need the
  6. # 32 bit pseudo to execute the 32 bit external toolchain binaries without
  7. # errors or warnings.
  8. NO32LIBS ?= "0"
  9. # We don't need or want to build a cross-compiler to ship in the sdk/ade, as
  10. # we expect folks to use the Sourcery G++ toolchain on the SDKMACHINE as well.
  11. TOOLCHAIN_HOST_TASK_remove = "packagegroup-cross-canadian-${MACHINE}"
  12. # Ensure that we only attempt to package up locales which are available in the
  13. # external toolchain. In the future, we should examine the external toolchain
  14. # sysroot and determine this accurately.
  15. GLIBC_GENERATE_LOCALES_remove = "en_US.UTF-8"
  16. # The binary locale files are common to the multilibs
  17. localedir = "${exec_prefix}/lib/locale"
  18. # No need to re-compile the locale files
  19. GLIBC_INTERNAL_USE_BINARY_LOCALE ?= "precompiled"
  20. ENABLE_BINARY_LOCALE_GENERATION = ""
  21. # Prefer our recipes which extract files from the external toolchain
  22. PREFERRED_PROVIDER_virtual/${TARGET_PREFIX}gcc ?= "gcc-external-cross-${TARGET_ARCH}"
  23. PREFERRED_PROVIDER_virtual/${TARGET_PREFIX}gcc-initial ?= "gcc-external-cross-${TARGET_ARCH}"
  24. PREFERRED_PROVIDER_virtual/${TARGET_PREFIX}gcc-intermediate ?= "gcc-external-cross-${TARGET_ARCH}"
  25. PREFERRED_PROVIDER_virtual/${TARGET_PREFIX}g++ ?= "gcc-external-cross-${TARGET_ARCH}"
  26. PREFERRED_PROVIDER_virtual/${TARGET_PREFIX}binutils ?= "binutils-external-cross-${TARGET_ARCH}"
  27. PREFERRED_PROVIDER_virtual/${TARGET_PREFIX}compilerlibs ?= "gcc-runtime-external"
  28. PREFERRED_PROVIDER_virtual/${TARGET_PREFIX}libc-for-gcc ?= "glibc-external"
  29. PREFERRED_PROVIDER_virtual/${TARGET_PREFIX}libc-initial ?= "glibc-external"
  30. PREFERRED_PROVIDER_glibc ?= "glibc-external"
  31. PREFERRED_PROVIDER_virtual/libc ?= "glibc-external"
  32. PREFERRED_PROVIDER_virtual/libintl ?= "glibc-external"
  33. PREFERRED_PROVIDER_virtual/libiconv ?= "glibc-external"
  34. PREFERRED_PROVIDER_gdbserver ??= "gdbserver-external"
  35. PREFERRED_PROVIDER_oprofile ??= "oprofile"
  36. # These are defined in default-providers.inc, which is parsed before the
  37. # tcmode, so we can't use ?= for them.
  38. PREFERRED_PROVIDER_libgcc = "libgcc-external"
  39. PREFERRED_PROVIDER_linux-libc-headers = "linux-libc-headers-external"
  40. # Ensure that we don't pull in any internal toolchain recipes
  41. INHERIT += "blacklist"
  42. PNBLACKLIST[uclibc] = "not building with an external toolchain"
  43. PNBLACKLIST[uclibc-initial] = "not building with an external toolchain"
  44. PNBLACKLIST[glibc] = "not building with an external toolchain"
  45. PNBLACKLIST[glibc-initial] = "not building with an external toolchain"
  46. PNBLACKLIST[glibc-intermediate] = "not building with an external toolchain"
  47. PNBLACKLIST[binutils-cross] = "not building with an external toolchain"
  48. PNBLACKLIST[gcc-cross] = "not building with an external toolchain"
  49. PNBLACKLIST[gcc-cross-initial] = "not building with an external toolchain"
  50. PNBLACKLIST[gcc-cross-intermediate] = "not building with an external toolchain"
  51. PNBLACKLIST[gcc-runtime] = "not building with an external toolchain"
  52. PNBLACKLIST[libgcc] = "not building with an external toolchain"
  53. PNBLACKLIST[linux-libc-headers] = "not building with an external toolchain"
  54. PNBLACKLIST[linux-libc-headers-yocto] = "not building with an external toolchain"
  55. PNBLACKLIST[external-sourcery-toolchain] = "using meta-sourcery, not poky's external toolchain"
  56. # Determine the prefixes to check for based on the target architecture (before
  57. # any classes alter TARGET_ARCH)
  58. EXTERNAL_TARGET_SYSTEMS[powerpc] ?= "powerpc-linux-gnu powerpc-mentor-linux-gnu"
  59. EXTERNAL_TARGET_SYSTEMS[powerpc64] ?= "powerpc-linux-gnu powerpc-mentor-linux-gnu"
  60. EXTERNAL_TARGET_SYSTEMS[arm] ?= "arm-none-linux-gnueabi arm-mentor-linux-gnueabi"
  61. EXTERNAL_TARGET_SYSTEMS[mips] ?= "mips-linux-gnu mips-mentor-linux-gnu"
  62. EXTERNAL_TARGET_SYSTEMS[mipsel] ?= "mips-linux-gnu mips-mentor-linux-gnu"
  63. EXTERNAL_TARGET_SYSTEMS[mips64] ?= "mips64-nlm-linux-gnu mips-linux-gnu mips-mentor-linux-gnu"
  64. EXTERNAL_TARGET_SYSTEMS[x86_64] ?= "i686-pc-linux-gnu i686-mentor-linux-gnu x86_64-linux-gnu x86_64-amd-linux-gnu"
  65. EXTERNAL_TARGET_SYSTEMS[i686] ?= "i686-pc-linux-gnu i686-mentor-linux-gnu"
  66. EXTERNAL_TARGET_SYSTEMS[i586] ?= "i686-pc-linux-gnu i686-mentor-linux-gnu"
  67. EXTERNAL_TARGET_SYSTEMS = "${TARGET_SYS}"
  68. def external_target_sys(d):
  69. toolchain_path = d.getVar('EXTERNAL_TOOLCHAIN', True)
  70. for triplet in d.getVar('EXTERNAL_TARGET_SYSTEMS', True).split():
  71. gcc = os.path.join(toolchain_path, 'bin', triplet + '-gcc')
  72. if os.path.exists(gcc):
  73. return triplet
  74. return '${TARGET_SYS}'
  75. EXTERNAL_TARGET_SYS ?= "${@external_target_sys(d)}"
  76. TARGET_PREFIX = "${EXTERNAL_TARGET_SYS}-"
  77. TOOLCHAIN_OPTIONS = " --sysroot=${STAGING_DIR_HOST}"
  78. CSL_IS_PRO = "${@'1' if os.path.exists('${EXTERNAL_TOOLCHAIN}/license') else '0'}"
  79. LDEMULATION = ""
  80. LDEMULATION_ENDIAN = "${@'bt' if 'bigendian' in TUNE_FEATURES.split() else 'lt'}"
  81. LDEMULATION_BITS = "${@'64' if 'n64' in TUNE_FEATURES.split() else '32'}"
  82. LDEMULATION_mips64 = "elf${LDEMULATION_BITS}${LDEMULATION_ENDIAN}smip${@bb.utils.contains('TUNE_FEATURES', 'n32', 'n32', '', d)}"
  83. TUNE_LDARGS += "${@'-m ${LDEMULATION}' if LDEMULATION else ''}"
  84. # Ensure that the licensing variables are available to the toolchain.
  85. export MGLS_LICENSE_FILE
  86. export LM_LICENSE_FILE
  87. python toolchain_metadata_setup () {
  88. import subprocess
  89. import tempfile
  90. d = e.data
  91. # Ensure that changes to toolchain licensing don't affect checksums
  92. d.appendVar('BB_HASHBASE_WHITELIST', ' MGLS_LICENSE_FILE LM_LICENSE_FILE')
  93. l = d.createCopy()
  94. l.finalize()
  95. systems = l.getVarFlag('EXTERNAL_TARGET_SYSTEMS', l.getVar('TARGET_ARCH', True), True)
  96. if systems:
  97. d.setVar('EXTERNAL_TARGET_SYSTEMS', systems)
  98. # Remove already-added toolchain install paths from the PATH, as they can
  99. # break the build (in particular, the ia32 toolchain, as it provdes
  100. # non-prefixed binaries).
  101. install_prefix_default = bb.data.expand('${HOME}/CodeSourcery/', l)
  102. path = d.getVar('PATH', False).split(':')
  103. path = filter(lambda p: not p.startswith(install_prefix_default), path)
  104. d.setVar('PATH', ':'.join(path))
  105. # The external toolchain may not have been built with the yocto preferred
  106. # gnu hash setting, so ensure that the corresponding sanity check is a
  107. # warning, not an error.
  108. error_qa = (l.getVar('ERROR_QA', True) or '').split()
  109. if 'ldflags' in error_qa:
  110. error_qa.remove('ldflags')
  111. d.setVar('ERROR_QA', ' '.join(error_qa))
  112. d.appendVar('WARN_QA', ' ldflags')
  113. # Determine if '-msgxx-glibc' is a valid toolchain option.
  114. # If so then we need to use it to ensure that the libraries included with
  115. # the toolchain are used rather than the build host native libraries.
  116. with tempfile.NamedTemporaryFile(suffix='.c') as f:
  117. try:
  118. subprocess.check_output([d.expand('${EXTERNAL_TOOLCHAIN}/bin/${EXTERNAL_TARGET_SYS}-gcc'), '-msgxx-glibc', '-E', f.name], cwd=d.getVar('TOPDIR', True), stderr=subprocess.STDOUT)
  119. except (OSError, subprocess.CalledProcessError):
  120. return
  121. else:
  122. d.appendVar('TUNE_CCARGS', ' -msgxx-glibc')
  123. }
  124. toolchain_metadata_setup[eventmask] = "bb.event.ConfigParsed"
  125. addhandler toolchain_metadata_setup
  126. python toolchain_sanity_check () {
  127. external_toolchain = e.data.getVar('EXTERNAL_TOOLCHAIN', True)
  128. if not external_toolchain or external_toolchain == 'UNDEFINED':
  129. bb.fatal("Error: EXTERNAL_TOOLCHAIN must be set to the path to your sourcery toolchain")
  130. if not os.path.exists(external_toolchain):
  131. bb.fatal("Error: EXTERNAL_TOOLCHAIN path '%s' does not exist" % external_toolchain)
  132. }
  133. toolchain_sanity_check[eventmask] = "bb.event.BuildStarted"
  134. addhandler toolchain_sanity_check
  135. require conf/distro/include/external-run.inc
  136. GCC_VERSION = "${@external_run(d, 'gcc', '-dumpversion').rstrip()}"
  137. GCC_VERSION_allarch = ""
  138. GCC_VERSION[vardepvalue] = "${GCC_VERSION}"
  139. def sourcery_version(d):
  140. version = external_run(d, 'gcc', '-v').splitlines()[-1]
  141. if version != 'UNKNOWN':
  142. main_version = version.split()[-1].rstrip(')')
  143. if main_version == 'Preview':
  144. main_version = version.split()[-3]
  145. return main_version
  146. else:
  147. return version
  148. SOURCERY_VERSION = "${@sourcery_version(d)}"
  149. SOURCERY_VERSION_allarch = ""
  150. # Add sourcery toolchain version to external recipe versions
  151. EXTERNAL_PV_SUFFIX ?= "-${SOURCERY_VERSION}"
  152. EXTERNAL_PV_SUFFIX_allarch = ""
  153. BUILDCFG_VARS += "SOURCERY_VERSION GCC_VERSION EXTERNAL_TOOLCHAIN"
  154. # Adjust tunings to ensure we're using Sourcery G++ multilibs
  155. require conf/distro/include/sourcery-tuning.inc