toolchain-external.mk 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754
  1. ################################################################################
  2. #
  3. # toolchain-external
  4. #
  5. ################################################################################
  6. #
  7. # This package implements the support for external toolchains, i.e
  8. # toolchains that are available pre-built, ready to use. Such toolchain
  9. # may either be readily available on the Web (Linaro, Sourcery
  10. # CodeBench, from processor vendors) or may be built with tools like
  11. # Crosstool-NG or Buildroot itself. So far, we have tested this
  12. # with:
  13. #
  14. # * Toolchains generated by Crosstool-NG
  15. # * Toolchains generated by Buildroot
  16. # * Toolchains provided by Linaro for the ARM and AArch64
  17. # architectures
  18. # * Sourcery CodeBench toolchains (from Mentor Graphics) for the ARM,
  19. # MIPS, PowerPC, x86, x86_64 and NIOS 2 architectures. For the MIPS
  20. # toolchain, the -muclibc variant isn't supported yet, only the
  21. # default glibc-based variant is.
  22. # * Analog Devices toolchains for the Blackfin architecture
  23. # * Xilinx toolchains for the Microblaze architecture
  24. # * Synopsys DesignWare toolchains for ARC cores
  25. #
  26. # The basic principle is the following
  27. #
  28. # 1. If the toolchain is not pre-installed, download and extract it
  29. # in $(TOOLCHAIN_EXTERNAL_INSTALL_DIR). Otherwise,
  30. # $(TOOLCHAIN_EXTERNAL_INSTALL_DIR) points to were the toolchain has
  31. # already been installed by the user.
  32. #
  33. # 2. For all external toolchains, perform some checks on the
  34. # conformity between the toolchain configuration described in the
  35. # Buildroot menuconfig system, and the real configuration of the
  36. # external toolchain. This is for example important to make sure that
  37. # the Buildroot configuration system knows whether the toolchain
  38. # supports RPC, IPv6, locales, large files, etc. Unfortunately, these
  39. # things cannot be detected automatically, since the value of these
  40. # options (such as BR2_TOOLCHAIN_HAS_NATIVE_RPC) are needed at
  41. # configuration time because these options are used as dependencies
  42. # for other options. And at configuration time, we are not able to
  43. # retrieve the external toolchain configuration.
  44. #
  45. # 3. Copy the libraries needed at runtime to the target directory,
  46. # $(TARGET_DIR). Obviously, things such as the C library, the dynamic
  47. # loader and a few other utility libraries are needed if dynamic
  48. # applications are to be executed on the target system.
  49. #
  50. # 4. Copy the libraries and headers to the staging directory. This
  51. # will allow all further calls to gcc to be made using --sysroot
  52. # $(STAGING_DIR), which greatly simplifies the compilation of the
  53. # packages when using external toolchains. So in the end, only the
  54. # cross-compiler binaries remains external, all libraries and headers
  55. # are imported into the Buildroot tree.
  56. #
  57. # 5. Build a toolchain wrapper which executes the external toolchain
  58. # with a number of arguments (sysroot/march/mtune/..) hardcoded,
  59. # so we're sure the correct configuration is always used and the
  60. # toolchain behaves similar to an internal toolchain.
  61. # This toolchain wrapper and symlinks are installed into
  62. # $(HOST_DIR)/usr/bin like for the internal toolchains, and the rest
  63. # of Buildroot is handled identical for the 2 toolchain types.
  64. ifeq ($(BR2_TOOLCHAIN_EXTERNAL_GLIBC)$(BR2_TOOLCHAIN_EXTERNAL_UCLIBC),y)
  65. LIB_EXTERNAL_LIBS += libatomic.so.* libc.so.* libcrypt.so.* libdl.so.* libgcc_s.so.* libm.so.* libnsl.so.* libresolv.so.* librt.so.* libutil.so.*
  66. ifeq ($(BR2_TOOLCHAIN_EXTERNAL_GLIBC)$(BR2_ARM_EABIHF),yy)
  67. LIB_EXTERNAL_LIBS += ld-linux-armhf.so.*
  68. else
  69. LIB_EXTERNAL_LIBS += ld*.so.*
  70. endif
  71. ifeq ($(BR2_TOOLCHAIN_HAS_THREADS),y)
  72. LIB_EXTERNAL_LIBS += libpthread.so.*
  73. ifneq ($(BR2_PACKAGE_GDB)$(BR2_TOOLCHAIN_EXTERNAL_GDB_SERVER_COPY),)
  74. LIB_EXTERNAL_LIBS += libthread_db.so.*
  75. endif # gdbserver
  76. endif # ! no threads
  77. endif
  78. ifeq ($(BR2_TOOLCHAIN_EXTERNAL_GLIBC),y)
  79. LIB_EXTERNAL_LIBS += libnss_files.so.* libnss_dns.so.*
  80. endif
  81. ifeq ($(BR2_TOOLCHAIN_EXTERNAL_MUSL),y)
  82. LIB_EXTERNAL_LIBS += libc.so libgcc_s.so.*
  83. endif
  84. ifeq ($(BR2_INSTALL_LIBSTDCPP),y)
  85. USR_LIB_EXTERNAL_LIBS += libstdc++.so.*
  86. endif
  87. LIB_EXTERNAL_LIBS += $(call qstrip,$(BR2_TOOLCHAIN_EXTRA_EXTERNAL_LIBS))
  88. # Details about sysroot directory selection.
  89. #
  90. # To find the sysroot directory, we use the trick of looking for the
  91. # 'libc.a' file with the -print-file-name gcc option, and then
  92. # mangling the path to find the base directory of the sysroot.
  93. #
  94. # Note that we do not use the -print-sysroot option, because it is
  95. # only available since gcc 4.4.x, and we only recently dropped support
  96. # for 4.2.x and 4.3.x.
  97. #
  98. # When doing this, we don't pass any option to gcc that could select a
  99. # multilib variant (such as -march) as we want the "main" sysroot,
  100. # which contains all variants of the C library in the case of multilib
  101. # toolchains. We use the TARGET_CC_NO_SYSROOT variable, which is the
  102. # path of the cross-compiler, without the --sysroot=$(STAGING_DIR),
  103. # since what we want to find is the location of the original toolchain
  104. # sysroot. This "main" sysroot directory is stored in SYSROOT_DIR.
  105. #
  106. # Then, multilib toolchains are a little bit more complicated, since
  107. # they in fact have multiple sysroots, one for each variant supported
  108. # by the toolchain. So we need to find the particular sysroot we're
  109. # interested in.
  110. #
  111. # To do so, we ask the compiler where its sysroot is by passing all
  112. # flags (including -march and al.), except the --sysroot flag since we
  113. # want to the compiler to tell us where its original sysroot
  114. # is. ARCH_SUBDIR will contain the subdirectory, in the main
  115. # SYSROOT_DIR, that corresponds to the selected architecture
  116. # variant. ARCH_SYSROOT_DIR will contain the full path to this
  117. # location.
  118. #
  119. # One might wonder why we don't just bother with ARCH_SYSROOT_DIR. The
  120. # fact is that in multilib toolchains, the header files are often only
  121. # present in the main sysroot, and only the libraries are available in
  122. # each variant-specific sysroot directory.
  123. TOOLCHAIN_EXTERNAL_PREFIX = $(call qstrip,$(BR2_TOOLCHAIN_EXTERNAL_PREFIX))
  124. ifeq ($(BR2_TOOLCHAIN_EXTERNAL_DOWNLOAD),y)
  125. TOOLCHAIN_EXTERNAL_INSTALL_DIR = $(HOST_DIR)/opt/ext-toolchain
  126. else
  127. TOOLCHAIN_EXTERNAL_INSTALL_DIR = $(call qstrip,$(BR2_TOOLCHAIN_EXTERNAL_PATH))
  128. endif
  129. ifeq ($(TOOLCHAIN_EXTERNAL_INSTALL_DIR),)
  130. ifneq ($(TOOLCHAIN_EXTERNAL_PREFIX),)
  131. # if no path set, figure it out from path
  132. TOOLCHAIN_EXTERNAL_BIN := $(shell dirname $(shell which $(TOOLCHAIN_EXTERNAL_PREFIX)-gcc))
  133. endif
  134. else
  135. ifeq ($(BR2_TOOLCHAIN_EXTERNAL_BLACKFIN_UCLINUX_2014R1)$(BR2_TOOLCHAIN_EXTERNAL_BLACKFIN_UCLINUX_2013R1)$(BR2_TOOLCHAIN_EXTERNAL_BLACKFIN_UCLINUX_2012R2),y)
  136. TOOLCHAIN_EXTERNAL_BIN := $(TOOLCHAIN_EXTERNAL_INSTALL_DIR)/$(TOOLCHAIN_EXTERNAL_PREFIX)/bin
  137. else
  138. TOOLCHAIN_EXTERNAL_BIN := $(TOOLCHAIN_EXTERNAL_INSTALL_DIR)/bin
  139. endif
  140. endif
  141. TOOLCHAIN_EXTERNAL_CROSS = $(TOOLCHAIN_EXTERNAL_BIN)/$(TOOLCHAIN_EXTERNAL_PREFIX)-
  142. TOOLCHAIN_EXTERNAL_CC = $(TOOLCHAIN_EXTERNAL_CROSS)gcc
  143. TOOLCHAIN_EXTERNAL_CXX = $(TOOLCHAIN_EXTERNAL_CROSS)g++
  144. TOOLCHAIN_EXTERNAL_READELF = $(TOOLCHAIN_EXTERNAL_CROSS)readelf
  145. TOOLCHAIN_EXTERNAL_WRAPPER_ARGS = -DBR_SYSROOT='"$(STAGING_SUBDIR)"'
  146. ifeq ($(filter $(HOST_DIR)/%,$(TOOLCHAIN_EXTERNAL_BIN)),)
  147. # TOOLCHAIN_EXTERNAL_BIN points outside HOST_DIR => absolute path
  148. TOOLCHAIN_EXTERNAL_WRAPPER_ARGS += \
  149. -DBR_CROSS_PATH_ABS='"$(TOOLCHAIN_EXTERNAL_BIN)"'
  150. else
  151. # TOOLCHAIN_EXTERNAL_BIN points inside HOST_DIR => relative path
  152. TOOLCHAIN_EXTERNAL_WRAPPER_ARGS += \
  153. -DBR_CROSS_PATH_REL='"$(TOOLCHAIN_EXTERNAL_BIN:$(HOST_DIR)/%=%)"'
  154. endif
  155. ifeq ($(call qstrip,$(BR2_GCC_TARGET_CPU_REVISION)),)
  156. CC_TARGET_CPU_ := $(call qstrip,$(BR2_GCC_TARGET_CPU))
  157. else
  158. CC_TARGET_CPU_ := $(call qstrip,$(BR2_GCC_TARGET_CPU)-$(BR2_GCC_TARGET_CPU_REVISION))
  159. endif
  160. CC_TARGET_ARCH_ := $(call qstrip,$(BR2_GCC_TARGET_ARCH))
  161. CC_TARGET_ABI_ := $(call qstrip,$(BR2_GCC_TARGET_ABI))
  162. CC_TARGET_FPU_ := $(call qstrip,$(BR2_GCC_TARGET_FPU))
  163. CC_TARGET_FLOAT_ABI_ := $(call qstrip,$(BR2_GCC_TARGET_FLOAT_ABI))
  164. CC_TARGET_MODE_ := $(call qstrip,$(BR2_GCC_TARGET_MODE))
  165. # march/mtune/floating point mode needs to be passed to the external toolchain
  166. # to select the right multilib variant
  167. ifeq ($(BR2_x86_64),y)
  168. TOOLCHAIN_EXTERNAL_CFLAGS += -m64
  169. TOOLCHAIN_EXTERNAL_WRAPPER_ARGS += -DBR_64
  170. endif
  171. ifneq ($(CC_TARGET_ARCH_),)
  172. TOOLCHAIN_EXTERNAL_CFLAGS += -march=$(CC_TARGET_ARCH_)
  173. TOOLCHAIN_EXTERNAL_WRAPPER_ARGS += -DBR_ARCH='"$(CC_TARGET_ARCH_)"'
  174. endif
  175. ifneq ($(CC_TARGET_CPU_),)
  176. TOOLCHAIN_EXTERNAL_CFLAGS += -mcpu=$(CC_TARGET_CPU_)
  177. TOOLCHAIN_EXTERNAL_WRAPPER_ARGS += -DBR_CPU='"$(CC_TARGET_CPU_)"'
  178. endif
  179. ifneq ($(CC_TARGET_ABI_),)
  180. TOOLCHAIN_EXTERNAL_CFLAGS += -mabi=$(CC_TARGET_ABI_)
  181. TOOLCHAIN_EXTERNAL_WRAPPER_ARGS += -DBR_ABI='"$(CC_TARGET_ABI_)"'
  182. endif
  183. ifneq ($(CC_TARGET_FPU_),)
  184. TOOLCHAIN_EXTERNAL_CFLAGS += -mfpu=$(CC_TARGET_FPU_)
  185. TOOLCHAIN_EXTERNAL_WRAPPER_ARGS += -DBR_FPU='"$(CC_TARGET_FPU_)"'
  186. endif
  187. ifneq ($(CC_TARGET_FLOAT_ABI_),)
  188. TOOLCHAIN_EXTERNAL_CFLAGS += -mfloat-abi=$(CC_TARGET_FLOAT_ABI_)
  189. TOOLCHAIN_EXTERNAL_WRAPPER_ARGS += -DBR_FLOAT_ABI='"$(CC_TARGET_FLOAT_ABI_)"'
  190. endif
  191. ifneq ($(CC_TARGET_MODE_),)
  192. TOOLCHAIN_EXTERNAL_CFLAGS += -m$(CC_TARGET_MODE_)
  193. TOOLCHAIN_EXTERNAL_WRAPPER_ARGS += -DBR_MODE='"$(CC_TARGET_MODE_)"'
  194. endif
  195. ifeq ($(BR2_BINFMT_FLAT),y)
  196. TOOLCHAIN_EXTERNAL_CFLAGS += -Wl,-elf2flt
  197. TOOLCHAIN_EXTERNAL_WRAPPER_ARGS += -DBR_BINFMT_FLAT
  198. endif
  199. ifeq ($(BR2_mipsel)$(BR2_mips64el),y)
  200. TOOLCHAIN_EXTERNAL_WRAPPER_ARGS += -DBR_MIPS_TARGET_LITTLE_ENDIAN
  201. TOOLCHAIN_EXTERNAL_CFLAGS += -EL
  202. endif
  203. ifeq ($(BR2_mips)$(BR2_mips64),y)
  204. TOOLCHAIN_EXTERNAL_WRAPPER_ARGS += -DBR_MIPS_TARGET_BIG_ENDIAN
  205. TOOLCHAIN_EXTERNAL_CFLAGS += -EB
  206. endif
  207. ifeq ($(BR2_arceb),y)
  208. TOOLCHAIN_EXTERNAL_WRAPPER_ARGS += -DBR_ARC_TARGET_BIG_ENDIAN
  209. TOOLCHAIN_EXTERNAL_CFLAGS += -EB
  210. endif
  211. ifneq ($(BR2_TARGET_OPTIMIZATION),)
  212. TOOLCHAIN_EXTERNAL_CFLAGS += $(call qstrip,$(BR2_TARGET_OPTIMIZATION))
  213. # We create a list like '"-mfoo", "-mbar", "-mbarfoo"' so that each
  214. # flag is a separate argument when used in execv() by the external
  215. # toolchain wrapper.
  216. TOOLCHAIN_EXTERNAL_WRAPPER_ARGS += -DBR_ADDITIONAL_CFLAGS='$(foreach f,$(call qstrip,$(BR2_TARGET_OPTIMIZATION)),"$(f)",)'
  217. endif
  218. ifeq ($(BR2_SOFT_FLOAT),y)
  219. TOOLCHAIN_EXTERNAL_CFLAGS += -msoft-float
  220. TOOLCHAIN_EXTERNAL_WRAPPER_ARGS += -DBR_SOFTFLOAT=1
  221. endif
  222. # The Linaro ARMhf toolchain expects the libraries in
  223. # {/usr,}/lib/arm-linux-gnueabihf, but Buildroot copies them to
  224. # {/usr,}/lib, so we need to create a symbolic link.
  225. define TOOLCHAIN_EXTERNAL_LINARO_ARMHF_SYMLINK
  226. ln -snf . $(TARGET_DIR)/lib/arm-linux-gnueabihf
  227. ln -snf . $(TARGET_DIR)/usr/lib/arm-linux-gnueabihf
  228. endef
  229. define TOOLCHAIN_EXTERNAL_LINARO_ARMEBHF_SYMLINK
  230. ln -snf . $(TARGET_DIR)/lib/armeb-linux-gnueabihf
  231. ln -snf . $(TARGET_DIR)/usr/lib/armeb-linux-gnueabihf
  232. endef
  233. define TOOLCHAIN_EXTERNAL_LINARO_AARCH64_SYMLINK
  234. ln -snf . $(TARGET_DIR)/lib/aarch64-linux-gnu
  235. ln -snf . $(TARGET_DIR)/usr/lib/aarch64-linux-gnu
  236. endef
  237. ifeq ($(BR2_TOOLCHAIN_EXTERNAL_CODESOURCERY_ARM201305),y)
  238. TOOLCHAIN_EXTERNAL_SITE = http://sourcery.mentor.com/public/gnu_toolchain/arm-none-linux-gnueabi
  239. TOOLCHAIN_EXTERNAL_SOURCE = arm-2013.05-24-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2
  240. else ifeq ($(BR2_TOOLCHAIN_EXTERNAL_CODESOURCERY_ARM201311),y)
  241. TOOLCHAIN_EXTERNAL_SITE = http://sourcery.mentor.com/public/gnu_toolchain/arm-none-linux-gnueabi
  242. TOOLCHAIN_EXTERNAL_SOURCE = arm-2013.11-33-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2
  243. else ifeq ($(BR2_TOOLCHAIN_EXTERNAL_CODESOURCERY_ARM201405),y)
  244. TOOLCHAIN_EXTERNAL_SITE = http://sourcery.mentor.com/public/gnu_toolchain/arm-none-linux-gnueabi
  245. TOOLCHAIN_EXTERNAL_SOURCE = arm-2014.05-29-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2
  246. else ifeq ($(BR2_TOOLCHAIN_EXTERNAL_ARAGO_ARMV7A_201109),y)
  247. TOOLCHAIN_EXTERNAL_SITE = http://software-dl.ti.com/sdoemb/sdoemb_public_sw/arago_toolchain/2011_09/exports
  248. TOOLCHAIN_EXTERNAL_SOURCE = arago-2011.09-armv7a-linux-gnueabi-sdk.tar.bz2
  249. define TOOLCHAIN_EXTERNAL_FIXUP_CMDS
  250. mv $(TOOLCHAIN_EXTERNAL_INSTALL_DIR)/arago-2011.09/armv7a/* $(TOOLCHAIN_EXTERNAL_INSTALL_DIR)/
  251. rm -rf $(TOOLCHAIN_EXTERNAL_INSTALL_DIR)/arago-2011.09/
  252. endef
  253. else ifeq ($(BR2_TOOLCHAIN_EXTERNAL_ARAGO_ARMV5TE_201109),y)
  254. TOOLCHAIN_EXTERNAL_SITE = http://software-dl.ti.com/sdoemb/sdoemb_public_sw/arago_toolchain/2011_09/exports
  255. TOOLCHAIN_EXTERNAL_SOURCE = arago-2011.09-armv5te-linux-gnueabi-sdk.tar.bz2
  256. define TOOLCHAIN_EXTERNAL_FIXUP_CMDS
  257. mv $(TOOLCHAIN_EXTERNAL_INSTALL_DIR)/arago-2011.09/armv5te/* $(TOOLCHAIN_EXTERNAL_INSTALL_DIR)/
  258. rm -rf $(TOOLCHAIN_EXTERNAL_INSTALL_DIR)/arago-2011.09/
  259. endef
  260. else ifeq ($(BR2_TOOLCHAIN_EXTERNAL_LINARO_ARM),y)
  261. TOOLCHAIN_EXTERNAL_SITE = http://releases.linaro.org/14.09/components/toolchain/binaries
  262. TOOLCHAIN_EXTERNAL_SOURCE = gcc-linaro-arm-linux-gnueabihf-4.9-2014.09_linux.tar.xz
  263. TOOLCHAIN_EXTERNAL_POST_INSTALL_STAGING_HOOKS += TOOLCHAIN_EXTERNAL_LINARO_ARMHF_SYMLINK
  264. else ifeq ($(BR2_TOOLCHAIN_EXTERNAL_LINARO_ARMEB),y)
  265. TOOLCHAIN_EXTERNAL_SITE = http://releases.linaro.org/14.09/components/toolchain/binaries
  266. TOOLCHAIN_EXTERNAL_SOURCE = gcc-linaro-armeb-linux-gnueabihf-4.9-2014.09_linux.tar.xz
  267. TOOLCHAIN_EXTERNAL_POST_INSTALL_STAGING_HOOKS += TOOLCHAIN_EXTERNAL_LINARO_ARMEBHF_SYMLINK
  268. else ifeq ($(BR2_TOOLCHAIN_EXTERNAL_CODESOURCERY_MIPS201405),y)
  269. TOOLCHAIN_EXTERNAL_SITE = http://sourcery.mentor.com/public/gnu_toolchain/mips-linux-gnu
  270. TOOLCHAIN_EXTERNAL_SOURCE = mips-2014.05-27-mips-linux-gnu-i686-pc-linux-gnu.tar.bz2
  271. else ifeq ($(BR2_TOOLCHAIN_EXTERNAL_CODESOURCERY_MIPS201411),y)
  272. TOOLCHAIN_EXTERNAL_SITE = http://sourcery.mentor.com/public/gnu_toolchain/mips-linux-gnu
  273. TOOLCHAIN_EXTERNAL_SOURCE = mips-2014.11-22-mips-linux-gnu-i686-pc-linux-gnu.tar.bz2
  274. else ifeq ($(BR2_TOOLCHAIN_EXTERNAL_CODESOURCERY_MIPS201505),y)
  275. TOOLCHAIN_EXTERNAL_SITE = http://sourcery.mentor.com/public/gnu_toolchain/mips-linux-gnu
  276. TOOLCHAIN_EXTERNAL_SOURCE = mips-2015.05-18-mips-linux-gnu-i686-pc-linux-gnu.tar.bz2
  277. else ifeq ($(BR2_TOOLCHAIN_EXTERNAL_CODESOURCERY_NIOSII201305),y)
  278. TOOLCHAIN_EXTERNAL_SITE = http://sourcery.mentor.com/public/gnu_toolchain/nios2-linux-gnu
  279. TOOLCHAIN_EXTERNAL_SOURCE = sourceryg++-2013.05-43-nios2-linux-gnu-i686-pc-linux-gnu.tar.bz2
  280. TOOLCHAIN_EXTERNAL_POST_INSTALL_STAGING_HOOKS += TOOLCHAIN_EXTERNAL_SANITIZE_KERNEL_HEADERS
  281. else ifeq ($(BR2_TOOLCHAIN_EXTERNAL_CODESOURCERY_NIOSII201405),y)
  282. TOOLCHAIN_EXTERNAL_SITE = http://sourcery.mentor.com/public/gnu_toolchain/nios2-linux-gnu
  283. TOOLCHAIN_EXTERNAL_SOURCE = sourceryg++-2014.05-47-nios2-linux-gnu-i686-pc-linux-gnu.tar.bz2
  284. else ifeq ($(BR2_TOOLCHAIN_EXTERNAL_CODESOURCERY_POWERPC201009),y)
  285. TOOLCHAIN_EXTERNAL_SITE = http://sourcery.mentor.com/public/gnu_toolchain/powerpc-linux-gnu
  286. TOOLCHAIN_EXTERNAL_SOURCE = freescale-2010.09-55-powerpc-linux-gnu-i686-pc-linux-gnu.tar.bz2
  287. else ifeq ($(BR2_TOOLCHAIN_EXTERNAL_CODESOURCERY_POWERPC201103),y)
  288. TOOLCHAIN_EXTERNAL_SITE = http://sourcery.mentor.com/public/gnu_toolchain/powerpc-linux-gnu
  289. TOOLCHAIN_EXTERNAL_SOURCE = freescale-2011.03-38-powerpc-linux-gnu-i686-pc-linux-gnu.tar.bz2
  290. else ifeq ($(BR2_TOOLCHAIN_EXTERNAL_CODESOURCERY_POWERPC201203),y)
  291. TOOLCHAIN_EXTERNAL_SITE = http://sourcery.mentor.com/public/gnu_toolchain/powerpc-mentor-linux-gnu
  292. TOOLCHAIN_EXTERNAL_SOURCE = mentor-2012.03-71-powerpc-mentor-linux-gnu-i686-pc-linux-gnu.tar.bz2
  293. else ifeq ($(BR2_TOOLCHAIN_EXTERNAL_CODESOURCERY_SH201103),y)
  294. TOOLCHAIN_EXTERNAL_SITE = http://sourcery.mentor.com/public/gnu_toolchain/sh-linux-gnu
  295. TOOLCHAIN_EXTERNAL_SOURCE = renesas-2011.03-37-sh-linux-gnu-i686-pc-linux-gnu.tar.bz2
  296. else ifeq ($(BR2_TOOLCHAIN_EXTERNAL_CODESOURCERY_SH201203),y)
  297. TOOLCHAIN_EXTERNAL_SITE = http://sourcery.mentor.com/public/gnu_toolchain/sh-linux-gnu
  298. TOOLCHAIN_EXTERNAL_SOURCE = renesas-2012.03-35-sh-linux-gnu-i686-pc-linux-gnu.tar.bz2
  299. else ifeq ($(BR2_TOOLCHAIN_EXTERNAL_CODESOURCERY_SH201209),y)
  300. TOOLCHAIN_EXTERNAL_SITE = https://sourcery.mentor.com/public/gnu_toolchain/sh-linux-gnu
  301. TOOLCHAIN_EXTERNAL_SOURCE = renesas-2012.09-61-sh-linux-gnu-i686-pc-linux-gnu.tar.bz2
  302. else ifeq ($(BR2_TOOLCHAIN_EXTERNAL_CODESOURCERY_SH2A_201009),y)
  303. TOOLCHAIN_EXTERNAL_SITE = http://sourcery.mentor.com/public/gnu_toolchain/sh-uclinux
  304. TOOLCHAIN_EXTERNAL_SOURCE = renesas-2010.09-60-sh-uclinux-i686-pc-linux-gnu.tar.bz2
  305. else ifeq ($(BR2_TOOLCHAIN_EXTERNAL_CODESOURCERY_SH2A_201103),y)
  306. TOOLCHAIN_EXTERNAL_SITE = http://sourcery.mentor.com/public/gnu_toolchain/sh-uclinux
  307. TOOLCHAIN_EXTERNAL_SOURCE = renesas-2011.03-36-sh-uclinux-i686-pc-linux-gnu.tar.bz2
  308. else ifeq ($(BR2_TOOLCHAIN_EXTERNAL_CODESOURCERY_X86_201109),y)
  309. TOOLCHAIN_EXTERNAL_SITE = https://sourcery.mentor.com/public/gnu_toolchain/i686-pc-linux-gnu
  310. TOOLCHAIN_EXTERNAL_SOURCE = ia32-2011.09-24-i686-pc-linux-gnu-i386-linux.tar.bz2
  311. else ifeq ($(BR2_TOOLCHAIN_EXTERNAL_CODESOURCERY_X86_201203),y)
  312. TOOLCHAIN_EXTERNAL_SITE = http://sourcery.mentor.com/public/gnu_toolchain/i686-pc-linux-gnu
  313. TOOLCHAIN_EXTERNAL_SOURCE = ia32-2012.03-27-i686-pc-linux-gnu-i386-linux.tar.bz2
  314. else ifeq ($(BR2_TOOLCHAIN_EXTERNAL_CODESOURCERY_X86_201209),y)
  315. TOOLCHAIN_EXTERNAL_SITE = https://sourcery.mentor.com/public/gnu_toolchain/i686-pc-linux-gnu
  316. TOOLCHAIN_EXTERNAL_SOURCE = ia32-2012.09-62-i686-pc-linux-gnu-i386-linux.tar.bz2
  317. else ifeq ($(BR2_TOOLCHAIN_EXTERNAL_CODESOURCERY_AMD64_201405),y)
  318. TOOLCHAIN_EXTERNAL_SITE = https://sourcery.mentor.com/public/gnu_toolchain/x86_64-amd-linux-gnu
  319. TOOLCHAIN_EXTERNAL_SOURCE = amd-2014.05-25-x86_64-amd-linux-gnu-i686-pc-linux-gnu.tar.bz2
  320. else ifeq ($(BR2_TOOLCHAIN_EXTERNAL_BLACKFIN_UCLINUX_2012R2),y)
  321. TOOLCHAIN_EXTERNAL_SITE = http://downloads.sourceforge.net/project/adi-toolchain/2012R2/2012R2-RC2/i386
  322. TOOLCHAIN_EXTERNAL_SOURCE = blackfin-toolchain-2012R2-RC2.i386.tar.bz2
  323. TOOLCHAIN_EXTERNAL_EXTRA_DOWNLOADS = blackfin-toolchain-uclibc-full-2012R2-RC2.i386.tar.bz2
  324. else ifeq ($(BR2_TOOLCHAIN_EXTERNAL_BLACKFIN_UCLINUX_2013R1),y)
  325. TOOLCHAIN_EXTERNAL_SITE = http://downloads.sourceforge.net/project/adi-toolchain/2013R1/2013R1-RC1/i386
  326. TOOLCHAIN_EXTERNAL_SOURCE = blackfin-toolchain-2013R1-RC1.i386.tar.bz2
  327. TOOLCHAIN_EXTERNAL_EXTRA_DOWNLOADS = blackfin-toolchain-uclibc-full-2013R1-RC1.i386.tar.bz2
  328. else ifeq ($(BR2_TOOLCHAIN_EXTERNAL_BLACKFIN_UCLINUX_2014R1),y)
  329. TOOLCHAIN_EXTERNAL_SITE = http://downloads.sourceforge.net/project/adi-toolchain/2014R1/2014R1-RC2/i386
  330. TOOLCHAIN_EXTERNAL_SOURCE = blackfin-toolchain-2014R1-RC2.i386.tar.bz2
  331. TOOLCHAIN_EXTERNAL_EXTRA_DOWNLOADS = blackfin-toolchain-uclibc-full-2014R1-RC2.i386.tar.bz2
  332. else ifeq ($(BR2_TOOLCHAIN_EXTERNAL_LINARO_AARCH64),y)
  333. TOOLCHAIN_EXTERNAL_SITE = http://releases.linaro.org/14.09/components/toolchain/binaries
  334. TOOLCHAIN_EXTERNAL_SOURCE = gcc-linaro-aarch64-linux-gnu-4.9-2014.09_linux.tar.xz
  335. TOOLCHAIN_EXTERNAL_POST_INSTALL_STAGING_HOOKS += TOOLCHAIN_EXTERNAL_LINARO_AARCH64_SYMLINK
  336. else ifeq ($(BR2_TOOLCHAIN_EXTERNAL_CODESOURCERY_AARCH64),y)
  337. TOOLCHAIN_EXTERNAL_SITE = http://sourcery.mentor.com/public/gnu_toolchain/aarch64-linux-gnu
  338. TOOLCHAIN_EXTERNAL_SOURCE = aarch64-2014.05-30-aarch64-linux-gnu-i686-pc-linux-gnu.tar.bz2
  339. else ifeq ($(BR2_TOOLCHAIN_EXTERNAL_MUSL_CROSS),y)
  340. TOOLCHAIN_EXTERNAL_VERSION = 1.1.6
  341. TOOLCHAIN_EXTERNAL_SITE = https://googledrive.com/host/0BwnS5DMB0YQ6bDhPZkpOYVFhbk0/musl-$(TOOLCHAIN_EXTERNAL_VERSION)
  342. ifeq ($(BR2_arm),y)
  343. TOOLCHAIN_EXTERNAL_SOURCE = crossx86-arm-linux-musleabi-$(TOOLCHAIN_EXTERNAL_VERSION).tar.xz
  344. else ifeq ($(BR2_armeb),y)
  345. TOOLCHAIN_EXTERNAL_SOURCE = crossx86-armeb-linux-musleabi-$(TOOLCHAIN_EXTERNAL_VERSION).tar.xz
  346. else ifeq ($(BR2_i386),y)
  347. TOOLCHAIN_EXTERNAL_SOURCE = crossx86-i486-linux-musl-$(TOOLCHAIN_EXTERNAL_VERSION).tar.xz
  348. else ifeq ($(BR2_microblazebe),y)
  349. TOOLCHAIN_EXTERNAL_SOURCE = crossx86-microblaze-linux-musl-$(TOOLCHAIN_EXTERNAL_VERSION).tar.xz
  350. else ifeq ($(BR2_mips),y)
  351. TOOLCHAIN_EXTERNAL_SOURCE = crossx86-mips-linux-musl-$(TOOLCHAIN_EXTERNAL_VERSION).tar.xz
  352. else ifeq ($(BR2_mipsel),y)
  353. TOOLCHAIN_EXTERNAL_SOURCE = crossx86-mipsel-linux-musl-$(TOOLCHAIN_EXTERNAL_VERSION).tar.xz
  354. else ifeq ($(BR2_powerpc),y)
  355. TOOLCHAIN_EXTERNAL_SOURCE = crossx86-powerpc-linux-musl-$(TOOLCHAIN_EXTERNAL_VERSION).tar.xz
  356. else ifeq ($(BR2_x86_64),y)
  357. TOOLCHAIN_EXTERNAL_SOURCE = crossx86-x86_64-linux-musl-$(TOOLCHAIN_EXTERNAL_VERSION).tar.xz
  358. endif
  359. else ifeq ($(BR2_TOOLCHAIN_EXTERNAL_SYNOPSYS_ARC_2014_12),y)
  360. TOOLCHAIN_EXTERNAL_SITE = https://github.com/foss-for-synopsys-dwc-arc-processors/toolchain/releases/download/arc-2014.12
  361. ifeq ($(BR2_arc750d)$(BR2_arc770d),y)
  362. TOOLCHAIN_EXTERNAL_SYNOPSYS_CORE = arc700
  363. else
  364. TOOLCHAIN_EXTERNAL_SYNOPSYS_CORE = archs
  365. endif
  366. ifeq ($(BR2_arcle),y)
  367. TOOLCHAIN_EXTERNAL_SYNOPSYS_ENDIANESS = le
  368. else
  369. TOOLCHAIN_EXTERNAL_SYNOPSYS_ENDIANESS = be
  370. endif
  371. TOOLCHAIN_EXTERNAL_SOURCE = arc_gnu_2014.12_prebuilt_uclibc_$(TOOLCHAIN_EXTERNAL_SYNOPSYS_ENDIANESS)_$(TOOLCHAIN_EXTERNAL_SYNOPSYS_CORE)_linux_install.tar.gz
  372. else
  373. # Custom toolchain
  374. TOOLCHAIN_EXTERNAL_SITE = $(dir $(call qstrip,$(BR2_TOOLCHAIN_EXTERNAL_URL)))
  375. TOOLCHAIN_EXTERNAL_SOURCE = $(notdir $(call qstrip,$(BR2_TOOLCHAIN_EXTERNAL_URL)))
  376. # We can't check hashes for custom downloaded toolchains
  377. BR_NO_CHECK_HASH_FOR += $(TOOLCHAIN_EXTERNAL_SOURCE)
  378. endif
  379. # In fact, we don't need to download the toolchain, since it is already
  380. # available on the system, so force the site and source to be empty so
  381. # that nothing will be downloaded/extracted.
  382. ifeq ($(BR2_TOOLCHAIN_EXTERNAL_PREINSTALLED),y)
  383. TOOLCHAIN_EXTERNAL_SITE =
  384. TOOLCHAIN_EXTERNAL_SOURCE =
  385. endif
  386. TOOLCHAIN_EXTERNAL_ADD_TOOLCHAIN_DEPENDENCY = NO
  387. TOOLCHAIN_EXTERNAL_INSTALL_STAGING = YES
  388. ifeq ($(BR2_TOOLCHAIN_EXTERNAL_BLACKFIN_UCLINUX_2012R2)$(BR2_TOOLCHAIN_EXTERNAL_BLACKFIN_UCLINUX_2013R1)$(BR2_TOOLCHAIN_EXTERNAL_BLACKFIN_UCLINUX_2014R1),y)
  389. # Special handling for Blackfin toolchain, because of the split in two
  390. # tarballs, and the organization of tarball contents. The tarballs
  391. # contain ./opt/uClinux/{bfin-uclinux,bfin-linux-uclibc} directories,
  392. # which themselves contain the toolchain. This is why we strip more
  393. # components than usual.
  394. define TOOLCHAIN_EXTERNAL_EXTRACT_CMDS
  395. mkdir -p $(TOOLCHAIN_EXTERNAL_INSTALL_DIR)
  396. $(call suitable-extractor,$(TOOLCHAIN_EXTERNAL_SOURCE)) $(DL_DIR)/$(TOOLCHAIN_EXTERNAL_SOURCE) | \
  397. $(TAR) --strip-components=3 --hard-dereference -C $(TOOLCHAIN_EXTERNAL_INSTALL_DIR) $(TAR_OPTIONS) -
  398. $(call suitable-extractor,$(TOOLCHAIN_EXTERNAL_EXTRA_DOWNLOADS)) $(DL_DIR)/$(TOOLCHAIN_EXTERNAL_EXTRA_DOWNLOADS) | \
  399. $(TAR) --strip-components=3 --hard-dereference -C $(TOOLCHAIN_EXTERNAL_INSTALL_DIR) $(TAR_OPTIONS) -
  400. endef
  401. else ifneq ($(TOOLCHAIN_EXTERNAL_SOURCE),)
  402. # Normal handling of toolchain tarball extraction.
  403. define TOOLCHAIN_EXTERNAL_EXTRACT_CMDS
  404. mkdir -p $(TOOLCHAIN_EXTERNAL_INSTALL_DIR)
  405. $(call suitable-extractor,$(TOOLCHAIN_EXTERNAL_SOURCE)) $(DL_DIR)/$(TOOLCHAIN_EXTERNAL_SOURCE) | \
  406. $(TAR) --strip-components=1 --exclude='usr/lib/locale/*' -C $(TOOLCHAIN_EXTERNAL_INSTALL_DIR) $(TAR_OPTIONS) -
  407. $(TOOLCHAIN_EXTERNAL_FIXUP_CMDS)
  408. endef
  409. endif
  410. # Returns the location of the libc.a file for the given compiler + flags
  411. define toolchain_find_libc_a
  412. $$(readlink -f $$(LANG=C $(1) -print-file-name=libc.a))
  413. endef
  414. # Returns the sysroot location for the given compiler + flags. We need
  415. # to handle cases where libc.a is in:
  416. #
  417. # - lib/
  418. # - usr/lib/
  419. # - lib32/
  420. # - lib64/
  421. # - lib32-fp/ (Cavium toolchain)
  422. # - lib64-fp/ (Cavium toolchain)
  423. # - usr/lib/<tuple>/ (Linaro toolchain)
  424. #
  425. # And variations on these.
  426. define toolchain_find_sysroot
  427. $$(echo -n $(call toolchain_find_libc_a,$(1)) | sed -r -e 's:(usr/)?lib(32|64)?([^/]*)?/([^/]*/)?libc\.a::')
  428. endef
  429. # Returns the lib subdirectory for the given compiler + flags (i.e
  430. # typically lib32 or lib64 for some toolchains)
  431. define toolchain_find_libdir
  432. $$(echo -n $(call toolchain_find_libc_a,$(1)) | sed -r -e 's:.*/(usr/)?(lib(32|64)?([^/]*)?)/([^/]*/)?libc.a:\2:')
  433. endef
  434. # Checks for an already installed toolchain: check the toolchain
  435. # location, check that it supports sysroot, and then verify that it
  436. # matches the configuration provided in Buildroot: ABI, C++ support,
  437. # kernel headers version, type of C library and all C library features.
  438. define TOOLCHAIN_EXTERNAL_CONFIGURE_CMDS
  439. $(Q)$(call check_cross_compiler_exists,$(TOOLCHAIN_EXTERNAL_CC))
  440. $(Q)$(call check_unusable_toolchain,$(TOOLCHAIN_EXTERNAL_CC))
  441. $(Q)SYSROOT_DIR="$(call toolchain_find_sysroot,$(TOOLCHAIN_EXTERNAL_CC))" ; \
  442. if test -z "$${SYSROOT_DIR}" ; then \
  443. @echo "External toolchain doesn't support --sysroot. Cannot use." ; \
  444. exit 1 ; \
  445. fi ; \
  446. $(call check_kernel_headers_version,\
  447. $(call toolchain_find_sysroot,$(TOOLCHAIN_EXTERNAL_CC)),\
  448. $(call qstrip,$(BR2_TOOLCHAIN_HEADERS_AT_LEAST))); \
  449. if test "$(BR2_arm)" = "y" ; then \
  450. $(call check_arm_abi,\
  451. "$(TOOLCHAIN_EXTERNAL_CC) $(TOOLCHAIN_EXTERNAL_CFLAGS)",\
  452. $(TOOLCHAIN_EXTERNAL_READELF)) ; \
  453. fi ; \
  454. if test "$(BR2_INSTALL_LIBSTDCPP)" = "y" ; then \
  455. $(call check_cplusplus,$(TOOLCHAIN_EXTERNAL_CXX)) ; \
  456. fi ; \
  457. if test "$(BR2_TOOLCHAIN_EXTERNAL_UCLIBC)" = "y" ; then \
  458. $(call check_uclibc,$${SYSROOT_DIR}) ; \
  459. elif test "$(BR2_TOOLCHAIN_EXTERNAL_MUSL)" = "y" ; then \
  460. $(call check_musl,$${SYSROOT_DIR}) ; \
  461. else \
  462. $(call check_glibc,$${SYSROOT_DIR}) ; \
  463. fi
  464. endef
  465. # With the musl C library, the libc.so library directly plays the role
  466. # of the dynamic library loader. We just need to create a symbolic
  467. # link to libc.so with the appropriate name.
  468. ifeq ($(BR2_TOOLCHAIN_EXTERNAL_MUSL),y)
  469. ifeq ($(BR2_i386),y)
  470. MUSL_ARCH = i386
  471. else
  472. MUSL_ARCH = $(ARCH)
  473. endif
  474. define TOOLCHAIN_EXTERNAL_MUSL_LD_LINK
  475. ln -sf libc.so $(TARGET_DIR)/lib/ld-musl-$(MUSL_ARCH).so.1
  476. endef
  477. TOOLCHAIN_EXTERNAL_POST_INSTALL_STAGING_HOOKS += TOOLCHAIN_EXTERNAL_MUSL_LD_LINK
  478. endif
  479. # Integration of the toolchain into Buildroot: find the main sysroot
  480. # and the variant-specific sysroot, then copy the needed libraries to
  481. # the $(TARGET_DIR) and copy the whole sysroot (libraries and headers)
  482. # to $(STAGING_DIR).
  483. #
  484. # Variables are defined as follows:
  485. #
  486. # LIBC_A_LOCATION: location of the libc.a file in the default
  487. # multilib variant (allows to find the main
  488. # sysroot directory)
  489. # Ex: /x-tools/mips-2011.03/mips-linux-gnu/libc/usr/lib/libc.a
  490. #
  491. # SYSROOT_DIR: the main sysroot directory, deduced from
  492. # LIBC_A_LOCATION by removing the
  493. # usr/lib[32|64]/libc.a part of the path.
  494. # Ex: /x-tools/mips-2011.03/mips-linux-gnu/libc/
  495. #
  496. # ARCH_LIBC_A_LOCATION: location of the libc.a file in the selected
  497. # multilib variant (taking into account the
  498. # CFLAGS). Allows to find the sysroot of the
  499. # selected multilib variant.
  500. # Ex: /x-tools/mips-2011.03/mips-linux-gnu/libc/mips16/soft-float/el/usr/lib/libc.a
  501. #
  502. # ARCH_SYSROOT_DIR: the sysroot of the selected multilib variant,
  503. # deduced from ARCH_LIBC_A_LOCATION by removing
  504. # usr/lib[32|64]/libc.a at the end of the path.
  505. # Ex: /x-tools/mips-2011.03/mips-linux-gnu/libc/mips16/soft-float/el/
  506. #
  507. # ARCH_LIB_DIR: 'lib', 'lib32' or 'lib64' depending on where libraries
  508. # are stored. Deduced from ARCH_LIBC_A_LOCATION by
  509. # looking at usr/lib??/libc.a.
  510. # Ex: lib
  511. #
  512. # ARCH_SUBDIR: the relative location of the sysroot of the selected
  513. # multilib variant compared to the main sysroot.
  514. # Ex: mips16/soft-float/el
  515. #
  516. # SUPPORT_LIB_DIR: some toolchains, such as recent Linaro toolchains,
  517. # store GCC support libraries (libstdc++,
  518. # libgcc_s, etc.) outside of the sysroot. In
  519. # this case, SUPPORT_LIB_DIR is set to a
  520. # non-empty value, and points to the directory
  521. # where these support libraries are
  522. # available. Those libraries will be copied to
  523. # our sysroot, and the directory will also be
  524. # considered when searching libraries for copy
  525. # to the target filesystem.
  526. define TOOLCHAIN_EXTERNAL_INSTALL_TARGET_LIBS
  527. $(Q)SYSROOT_DIR="$(call toolchain_find_sysroot,$(TOOLCHAIN_EXTERNAL_CC))" ; \
  528. if test -z "$${SYSROOT_DIR}" ; then \
  529. @echo "External toolchain doesn't support --sysroot. Cannot use." ; \
  530. exit 1 ; \
  531. fi ; \
  532. ARCH_SYSROOT_DIR="$(call toolchain_find_sysroot,$(TOOLCHAIN_EXTERNAL_CC) $(TOOLCHAIN_EXTERNAL_CFLAGS))" ; \
  533. ARCH_LIB_DIR="$(call toolchain_find_libdir,$(TOOLCHAIN_EXTERNAL_CC) $(TOOLCHAIN_EXTERNAL_CFLAGS))" ; \
  534. SUPPORT_LIB_DIR="" ; \
  535. if test `find $${ARCH_SYSROOT_DIR} -name 'libstdc++.a' | wc -l` -eq 0 ; then \
  536. LIBSTDCPP_A_LOCATION=$$(LANG=C $(TOOLCHAIN_EXTERNAL_CC) $(TOOLCHAIN_EXTERNAL_CFLAGS) -print-file-name=libstdc++.a) ; \
  537. if [ -e "$${LIBSTDCPP_A_LOCATION}" ]; then \
  538. SUPPORT_LIB_DIR=`readlink -f $${LIBSTDCPP_A_LOCATION} | sed -r -e 's:libstdc\+\+\.a::'` ; \
  539. fi ; \
  540. fi ; \
  541. ARCH_SUBDIR=`echo $${ARCH_SYSROOT_DIR} | sed -r -e "s:^$${SYSROOT_DIR}(.*)/$$:\1:"` ; \
  542. if test -z "$(BR2_STATIC_LIBS)" ; then \
  543. $(call MESSAGE,"Copying external toolchain libraries to target...") ; \
  544. for libs in $(LIB_EXTERNAL_LIBS); do \
  545. $(call copy_toolchain_lib_root,$${ARCH_SYSROOT_DIR},$${SUPPORT_LIB_DIR},$${ARCH_LIB_DIR},$$libs,/lib); \
  546. done ; \
  547. for libs in $(USR_LIB_EXTERNAL_LIBS); do \
  548. $(call copy_toolchain_lib_root,$${ARCH_SYSROOT_DIR},$${SUPPORT_LIB_DIR},$${ARCH_LIB_DIR},$$libs,/usr/lib); \
  549. done ; \
  550. fi ; \
  551. if test "$(BR2_TOOLCHAIN_EXTERNAL_GDB_SERVER_COPY)" = "y"; then \
  552. $(call MESSAGE,"Copying gdbserver") ; \
  553. gdbserver_found=0 ; \
  554. for d in $${ARCH_SYSROOT_DIR}/usr $${ARCH_SYSROOT_DIR}/../debug-root/usr $${ARCH_SYSROOT_DIR}/usr/$${ARCH_LIB_DIR} ; do \
  555. if test -f $${d}/bin/gdbserver ; then \
  556. install -m 0755 -D $${d}/bin/gdbserver $(TARGET_DIR)/usr/bin/gdbserver ; \
  557. gdbserver_found=1 ; \
  558. break ; \
  559. fi ; \
  560. done ; \
  561. if [ $${gdbserver_found} -eq 0 ] ; then \
  562. echo "Could not find gdbserver in external toolchain" ; \
  563. exit 1 ; \
  564. fi ; \
  565. fi
  566. endef
  567. define TOOLCHAIN_EXTERNAL_INSTALL_SYSROOT_LIBS
  568. $(Q)SYSROOT_DIR="$(call toolchain_find_sysroot,$(TOOLCHAIN_EXTERNAL_CC))" ; \
  569. if test -z "$${SYSROOT_DIR}" ; then \
  570. @echo "External toolchain doesn't support --sysroot. Cannot use." ; \
  571. exit 1 ; \
  572. fi ; \
  573. ARCH_SYSROOT_DIR="$(call toolchain_find_sysroot,$(TOOLCHAIN_EXTERNAL_CC) $(TOOLCHAIN_EXTERNAL_CFLAGS))" ; \
  574. ARCH_LIB_DIR="$(call toolchain_find_libdir,$(TOOLCHAIN_EXTERNAL_CC) $(TOOLCHAIN_EXTERNAL_CFLAGS))" ; \
  575. SUPPORT_LIB_DIR="" ; \
  576. if test `find $${ARCH_SYSROOT_DIR} -name 'libstdc++.a' | wc -l` -eq 0 ; then \
  577. LIBSTDCPP_A_LOCATION=$$(LANG=C $(TOOLCHAIN_EXTERNAL_CC) $(TOOLCHAIN_EXTERNAL_CFLAGS) -print-file-name=libstdc++.a) ; \
  578. if [ -e "$${LIBSTDCPP_A_LOCATION}" ]; then \
  579. SUPPORT_LIB_DIR=`readlink -f $${LIBSTDCPP_A_LOCATION} | sed -r -e 's:libstdc\+\+\.a::'` ; \
  580. fi ; \
  581. fi ; \
  582. ARCH_SUBDIR=`echo $${ARCH_SYSROOT_DIR} | sed -r -e "s:^$${SYSROOT_DIR}(.*)/$$:\1:"` ; \
  583. $(call MESSAGE,"Copying external toolchain sysroot to staging...") ; \
  584. $(call copy_toolchain_sysroot,$${SYSROOT_DIR},$${ARCH_SYSROOT_DIR},$${ARCH_SUBDIR},$${ARCH_LIB_DIR},$${SUPPORT_LIB_DIR})
  585. endef
  586. # Special installation target used on the Blackfin architecture when
  587. # FDPIC is not the primary binary format being used, but the user has
  588. # nonetheless requested the installation of the FDPIC libraries to the
  589. # target filesystem.
  590. ifeq ($(BR2_BFIN_INSTALL_FDPIC_SHARED),y)
  591. define TOOLCHAIN_EXTERNAL_INSTALL_BFIN_FDPIC
  592. $(Q)$(call MESSAGE,"Install external toolchain FDPIC libraries to target...") ; \
  593. FDPIC_EXTERNAL_CC=$(dir $(TOOLCHAIN_EXTERNAL_CC))/../../bfin-linux-uclibc/bin/bfin-linux-uclibc-gcc ; \
  594. FDPIC_SYSROOT_DIR="$(call toolchain_find_sysroot,$${FDPIC_EXTERNAL_CC} $(TOOLCHAIN_EXTERNAL_CFLAGS))" ; \
  595. FDPIC_LIB_DIR="$(call toolchain_find_libdir,$${FDPIC_EXTERNAL_CC} $(TOOLCHAIN_EXTERNAL_CFLAGS))" ; \
  596. FDPIC_SUPPORT_LIB_DIR="" ; \
  597. if test `find $${FDPIC_SYSROOT_DIR} -name 'libstdc++.a' | wc -l` -eq 0 ; then \
  598. FDPIC_LIBSTDCPP_A_LOCATION=$$(LANG=C $${FDPIC_EXTERNAL_CC} $(TOOLCHAIN_EXTERNAL_CFLAGS) -print-file-name=libstdc++.a) ; \
  599. if [ -e "$${FDPIC_LIBSTDCPP_A_LOCATION}" ]; then \
  600. FDPIC_SUPPORT_LIB_DIR=`readlink -f $${FDPIC_LIBSTDCPP_A_LOCATION} | sed -r -e 's:libstdc\+\+\.a::'` ; \
  601. fi ; \
  602. fi ; \
  603. for libs in $(LIB_EXTERNAL_LIBS); do \
  604. $(call copy_toolchain_lib_root,$${FDPIC_SYSROOT_DIR},$${FDPIC_SUPPORT_LIB_DIR},$${FDPIC_LIB_DIR},$$libs,/lib); \
  605. done ; \
  606. for libs in $(USR_LIB_EXTERNAL_LIBS); do \
  607. $(call copy_toolchain_lib_root,$${FDPIC_SYSROOT_DIR},$${FDPIC_SUPPORT_LIB_DIR},$${FDPIC_LIB_DIR},$$libs,/usr/lib); \
  608. done
  609. endef
  610. endif
  611. # Special installation target used on the Blackfin architecture when
  612. # shared FLAT is not the primary format being used, but the user has
  613. # nonetheless requested the installation of the shared FLAT libraries
  614. # to the target filesystem. The flat libraries are found and linked
  615. # according to the index in name "libN.so". Index 1 is reserved for
  616. # the standard C library. Customer libraries can use 4 and above.
  617. ifeq ($(BR2_BFIN_INSTALL_FLAT_SHARED),y)
  618. define TOOLCHAIN_EXTERNAL_INSTALL_BFIN_FLAT
  619. $(Q)$(call MESSAGE,"Install external toolchain FLAT libraries to target...") ; \
  620. FLAT_EXTERNAL_CC=$(dir $(TOOLCHAIN_EXTERNAL_CC))../../bfin-uclinux/bin/bfin-uclinux-gcc ; \
  621. FLAT_LIBC_A_LOCATION=`$${FLAT_EXTERNAL_CC} $(TOOLCHAIN_EXTERNAL_CFLAGS) -mid-shared-library -print-file-name=libc`; \
  622. if [ -f $${FLAT_LIBC_A_LOCATION} -a ! -h $${FLAT_LIBC_A_LOCATION} ] ; then \
  623. $(INSTALL) -D $${FLAT_LIBC_A_LOCATION} $(TARGET_DIR)/lib/lib1.so; \
  624. fi
  625. endef
  626. endif
  627. # We use --hash-style=both to increase the compatibility of
  628. # the generated binary with older platforms, except for MIPS,
  629. # where the only acceptable hash style is 'sysv'
  630. ifeq ($(findstring mips,$(HOSTARCH)),mips)
  631. TOOLCHAIN_EXTERNAL_WRAPPER_HASH_STYLE = sysv
  632. else
  633. TOOLCHAIN_EXTERNAL_WRAPPER_HASH_STYLE = both
  634. endif
  635. # Build toolchain wrapper for preprocessor, C and C++ compiler and setup
  636. # symlinks for everything else. Skip gdb symlink when we are building our
  637. # own gdb to prevent two gdb's in output/host/usr/bin.
  638. # When the link-time-optimization flag '-flto' is used, then the compiler
  639. # and binutils have to support lto. ar/ranlib need to be called with the
  640. # lto plugin. The wrappers *-gcc-ar and *-gcc-ranlib provided by GCC could
  641. # be used as drop-ins for ar/runlib when Makefiles are used which do not
  642. # pass the lto arguments.
  643. define TOOLCHAIN_EXTERNAL_INSTALL_WRAPPER
  644. $(Q)$(call MESSAGE,"Building ext-toolchain wrapper")
  645. mkdir -p $(HOST_DIR)/usr/bin; cd $(HOST_DIR)/usr/bin; \
  646. for i in $(TOOLCHAIN_EXTERNAL_CROSS)*; do \
  647. base=$${i##*/}; \
  648. case "$$base" in \
  649. *-ar|*-ranlib|*-nm) \
  650. ln -sf $$(echo $$i | sed 's%^$(HOST_DIR)%../..%') .; \
  651. ;; \
  652. *cc|*cc-*|*++|*++-*|*cpp) \
  653. ln -sf ext-toolchain-wrapper $$base; \
  654. ;; \
  655. *gdb|*gdbtui) \
  656. if test "$(BR2_PACKAGE_HOST_GDB)" != "y"; then \
  657. ln -sf $$(echo $$i | sed 's%^$(HOST_DIR)%../..%') .; \
  658. fi \
  659. ;; \
  660. *) \
  661. ln -sf $$(echo $$i | sed 's%^$(HOST_DIR)%../..%') .; \
  662. ;; \
  663. esac; \
  664. done ;
  665. $(HOSTCC) $(HOST_CFLAGS) $(TOOLCHAIN_EXTERNAL_WRAPPER_ARGS) \
  666. -s -Wl,--hash-style=$(TOOLCHAIN_EXTERNAL_WRAPPER_HASH_STYLE) \
  667. toolchain/toolchain-external/ext-toolchain-wrapper.c \
  668. -o $(HOST_DIR)/usr/bin/ext-toolchain-wrapper
  669. endef
  670. # This sed magic is taken from Linux headers_install.sh script.
  671. define TOOLCHAIN_EXTERNAL_SANITIZE_KERNEL_HEADERS
  672. $(Q)$(call MESSAGE,"Sanitizing kernel headers");
  673. find $(STAGING_DIR)/usr/include/linux/ -name "*.h" | xargs sed -r -i \
  674. -e 's/([ \t(])(__user|__force|__iomem)[ \t]/\1/g' \
  675. -e 's/__attribute_const__([ \t]|$$)/\1/g' \
  676. -e 's@^#include <linux/compiler.h>@@' \
  677. -e 's/(^|[^a-zA-Z0-9])__packed([^a-zA-Z0-9_]|$$)/\1__attribute__((packed))\2/g' \
  678. -e 's/(^|[ \t(])(inline|asm|volatile)([ \t(]|$$)/\1__\2__\3/g' \
  679. -e 's@#(ifndef|define|endif[ \t]*/[*])[ \t]*_UAPI@#\1 @'
  680. endef
  681. define TOOLCHAIN_EXTERNAL_INSTALL_GDBINIT
  682. if test -f $(TARGET_CROSS)gdb ; then \
  683. $(call gen_gdbinit_file) ; \
  684. fi
  685. endef
  686. # uClibc-ng dynamic loader is called ld-uClibc.so.1, but gcc is not
  687. # patched specifically for uClibc-ng, so it continues to generate
  688. # binaries that expect the dynamic loader to be named ld-uClibc.so.0,
  689. # like with the original uClibc. Therefore, we create an additional
  690. # symbolic link to make uClibc-ng systems work properly.
  691. define TOOLCHAIN_EXTERNAL_FIXUP_UCLIBCNG_LDSO
  692. if test -e $(TARGET_DIR)/lib/ld-uClibc.so.1; then \
  693. ln -sf ld-uClibc.so.1 $(TARGET_DIR)/lib/ld-uClibc.so.0 ; \
  694. fi
  695. if test -e $(TARGET_DIR)/lib/ld64-uClibc.so.1; then \
  696. ln -sf ld64-uClibc.so.1 $(TARGET_DIR)/lib/ld64-uClibc.so.0 ; \
  697. fi
  698. endef
  699. define TOOLCHAIN_EXTERNAL_INSTALL_STAGING_CMDS
  700. $(TOOLCHAIN_EXTERNAL_INSTALL_SYSROOT_LIBS)
  701. $(TOOLCHAIN_EXTERNAL_INSTALL_WRAPPER)
  702. $(TOOLCHAIN_EXTERNAL_INSTALL_GDBINIT)
  703. endef
  704. # Even though we're installing things in both the staging, the host
  705. # and the target directory, we do everything within the
  706. # install-staging step, arbitrarily.
  707. define TOOLCHAIN_EXTERNAL_INSTALL_TARGET_CMDS
  708. $(TOOLCHAIN_EXTERNAL_INSTALL_TARGET_LIBS)
  709. $(TOOLCHAIN_EXTERNAL_INSTALL_BFIN_FDPIC)
  710. $(TOOLCHAIN_EXTERNAL_INSTALL_BFIN_FLAT)
  711. $(TOOLCHAIN_EXTERNAL_FIXUP_UCLIBCNG_LDSO)
  712. endef
  713. $(eval $(generic-package))