ext-tool.mk 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562
  1. #
  2. # This file implements the support for external toolchains, i.e
  3. # toolchains that have not been produced by Buildroot itself and that
  4. # Buildroot can download from the Web or that are already available on
  5. # the system on which Buildroot runs. So far, we have tested this
  6. # with:
  7. #
  8. # * Toolchains generated by Crosstool-NG
  9. # * Toolchains generated by Buildroot
  10. # * ARM, MIPS and PowerPC toolchains made available by
  11. # Codesourcery. For the MIPS toolchain, the -muclibc variant isn't
  12. # supported yet, only the default glibc-based variant is.
  13. #
  14. # The basic principle is the following
  15. #
  16. # 1. If the toolchain is not pre-installed, download and extract it
  17. # in $(TOOLCHAIN_EXTERNAL_DIR).
  18. #
  19. # 2. For all external toolchains, perform some checks on the
  20. # conformity between the toolchain configuration described in the
  21. # Buildroot menuconfig system, and the real configuration of the
  22. # external toolchain. This is for example important to make sure that
  23. # the Buildroot configuration system knows whether the toolchain
  24. # supports RPC, IPv6, locales, large files, etc. Unfortunately, these
  25. # things cannot be detected automatically, since the value of these
  26. # options (such as BR2_TOOLCHAIN_HAS_NATIVE_RPC) are needed at
  27. # configuration time because these options are used as dependencies
  28. # for other options. And at configuration time, we are not able to
  29. # retrieve the external toolchain configuration.
  30. #
  31. # 3. Copy the libraries needed at runtime to the target directory,
  32. # $(TARGET_DIR). Obviously, things such as the C library, the dynamic
  33. # loader and a few other utility libraries are needed if dynamic
  34. # applications are to be executed on the target system.
  35. #
  36. # 4. Copy the libraries and headers to the staging directory. This
  37. # will allow all further calls to gcc to be made using --sysroot
  38. # $(STAGING_DIR), which greatly simplifies the compilation of the
  39. # packages when using external toolchains. So in the end, only the
  40. # cross-compiler binaries remains external, all libraries and headers
  41. # are imported into the Buildroot tree.
  42. #
  43. # 5. Build a toolchain wrapper which executes the external toolchain
  44. # with a number of arguments (sysroot/march/mtune/..) hardcoded,
  45. # so we're sure the correct configuration is always used and the
  46. # toolchain behaves similar to an internal toolchain.
  47. # This toolchain wrapper and symlinks are installed into
  48. # $(HOST_DIR)/usr/bin like for the internal toolchains, and the rest
  49. # of Buildroot is handled identical for the 2 toolchain types.
  50. LIB_EXTERNAL_LIBS=ld*.so libc.so libcrypt.so libdl.so libgcc_s.so libm.so libnsl.so libresolv.so librt.so libutil.so
  51. LIB_EXTERNAL_LIBS+=$(call qstrip,$(BR2_TOOLCHAIN_EXTRA_EXTERNAL_LIBS))
  52. ifeq ($(BR2_TOOLCHAIN_EXTERNAL_GLIBC),y)
  53. LIB_EXTERNAL_LIBS+=libnss_files.so libnss_dns.so
  54. endif
  55. ifeq ($(BR2_INSTALL_LIBSTDCPP),y)
  56. USR_LIB_EXTERNAL_LIBS+=libstdc++.so
  57. endif
  58. ifeq ($(BR2_TOOLCHAIN_HAS_THREADS),y)
  59. LIB_EXTERNAL_LIBS+=libpthread.so
  60. ifneq ($(BR2_PACKAGE_GDB_SERVER)$(BR2_TOOLCHAIN_EXTERNAL_GDB_SERVER_COPY),)
  61. LIB_EXTERNAL_LIBS+=libthread_db.so
  62. endif # gdbserver
  63. endif # ! no threads
  64. # Details about sysroot directory selection.
  65. #
  66. # To find the sysroot directory:
  67. #
  68. # * We first try the -print-sysroot option, available in gcc 4.4.x
  69. # and in some Codesourcery toolchains.
  70. #
  71. # * If this option is not available, we fallback to the value of
  72. # --with-sysroot as visible in CROSS-gcc -v.
  73. #
  74. # When doing those tests, we don't pass any option to gcc that could
  75. # select a multilib variant (such as -march) as we want the "main"
  76. # sysroot, which contains all variants of the C library in the case of
  77. # multilib toolchains. We use the TARGET_CC_NO_SYSROOT variable, which
  78. # is the path of the cross-compiler, without the
  79. # --sysroot=$(STAGING_DIR), since what we want to find is the location
  80. # of the original toolchain sysroot. This "main" sysroot directory is
  81. # stored in SYSROOT_DIR.
  82. #
  83. # Then, multilib toolchains are a little bit more complicated, since
  84. # they in fact have multiple sysroots, one for each variant supported
  85. # by the toolchain. So we need to find the particular sysroot we're
  86. # interested in.
  87. #
  88. # To do so, we ask the compiler where its sysroot is by passing all
  89. # flags (including -march and al.), except the --sysroot flag since we
  90. # want to the compiler to tell us where its original sysroot
  91. # is. ARCH_SUBDIR will contain the subdirectory, in the main
  92. # SYSROOT_DIR, that corresponds to the selected architecture
  93. # variant. ARCH_SYSROOT_DIR will contain the full path to this
  94. # location.
  95. #
  96. # One might wonder why we don't just bother with ARCH_SYSROOT_DIR. The
  97. # fact is that in multilib toolchains, the header files are often only
  98. # present in the main sysroot, and only the libraries are available in
  99. # each variant-specific sysroot directory.
  100. TOOLCHAIN_EXTERNAL_PREFIX=$(call qstrip,$(BR2_TOOLCHAIN_EXTERNAL_PREFIX))
  101. ifeq ($(BR2_TOOLCHAIN_EXTERNAL_DOWNLOAD),y)
  102. TOOLCHAIN_EXTERNAL_DIR=$(HOST_DIR)/opt/ext-toolchain
  103. else
  104. TOOLCHAIN_EXTERNAL_DIR=$(call qstrip,$(BR2_TOOLCHAIN_EXTERNAL_PATH))
  105. endif
  106. ifeq ($(TOOLCHAIN_EXTERNAL_DIR),)
  107. # if no path set, figure it out from path
  108. TOOLCHAIN_EXTERNAL_BIN := $(shell dirname $(shell which $(TOOLCHAIN_EXTERNAL_PREFIX)-gcc))
  109. else
  110. ifeq ($(BR2_bfin),y)
  111. TOOLCHAIN_EXTERNAL_BIN := $(TOOLCHAIN_EXTERNAL_DIR)/$(TOOLCHAIN_EXTERNAL_PREFIX)/bin
  112. else
  113. TOOLCHAIN_EXTERNAL_BIN := $(TOOLCHAIN_EXTERNAL_DIR)/bin
  114. endif
  115. endif
  116. TOOLCHAIN_EXTERNAL_CROSS=$(TOOLCHAIN_EXTERNAL_BIN)/$(TOOLCHAIN_EXTERNAL_PREFIX)-
  117. TOOLCHAIN_EXTERNAL_CC=$(TOOLCHAIN_EXTERNAL_CROSS)gcc
  118. TOOLCHAIN_EXTERNAL_CXX=$(TOOLCHAIN_EXTERNAL_CROSS)g++
  119. TOOLCHAIN_EXTERNAL_READELF=$(TOOLCHAIN_EXTERNAL_CROSS)readelf
  120. TOOLCHAIN_EXTERNAL_WRAPPER_ARGS = -DBR_SYSROOT='"$(STAGING_SUBDIR)"'
  121. ifeq ($(filter $(HOST_DIR)/%,$(TOOLCHAIN_EXTERNAL_BIN)),)
  122. # TOOLCHAIN_EXTERNAL_BIN points outside HOST_DIR => absolute path
  123. TOOLCHAIN_EXTERNAL_WRAPPER_ARGS += \
  124. -DBR_CROSS_PATH_ABS='"$(TOOLCHAIN_EXTERNAL_BIN)"'
  125. else
  126. # TOOLCHAIN_EXTERNAL_BIN points inside HOST_DIR => relative path
  127. TOOLCHAIN_EXTERNAL_WRAPPER_ARGS += \
  128. -DBR_CROSS_PATH_REL='"$(TOOLCHAIN_EXTERNAL_BIN:$(HOST_DIR)/%=%)"'
  129. endif
  130. CC_TARGET_TUNE_:=$(call qstrip,$(BR2_GCC_TARGET_TUNE))
  131. ifeq ($(call qstrip,$(BR2_GCC_TARGET_CPU_REVISION)),)
  132. CC_TARGET_CPU_:=$(call qstrip,$(BR2_GCC_TARGET_CPU))
  133. else
  134. CC_TARGET_CPU_:=$(call qstrip,$(BR2_GCC_TARGET_CPU)-$(BR2_GCC_TARGET_CPU_REVISION))
  135. endif
  136. CC_TARGET_ARCH_:=$(call qstrip,$(BR2_GCC_TARGET_ARCH))
  137. CC_TARGET_ABI_:=$(call qstrip,$(BR2_GCC_TARGET_ABI))
  138. CC_TARGET_FPU_:=$(call qstrip,$(BR2_GCC_TARGET_FPU))
  139. CC_TARGET_FLOAT_ABI_:=$(call qstrip,$(BR2_GCC_TARGET_FLOAT_ABI))
  140. CC_TARGET_MODE_:=$(call qstrip,$(BR2_GCC_TARGET_MODE))
  141. # march/mtune/floating point mode needs to be passed to the external toolchain
  142. # to select the right multilib variant
  143. ifeq ($(BR2_x86_64),y)
  144. TOOLCHAIN_EXTERNAL_CFLAGS += -m64
  145. TOOLCHAIN_EXTERNAL_WRAPPER_ARGS += -DBR_64
  146. endif
  147. ifneq ($(CC_TARGET_TUNE_),)
  148. TOOLCHAIN_EXTERNAL_CFLAGS += -mtune=$(CC_TARGET_TUNE_)
  149. TOOLCHAIN_EXTERNAL_WRAPPER_ARGS += -DBR_TUNE='"$(CC_TARGET_TUNE_)"'
  150. endif
  151. ifneq ($(CC_TARGET_ARCH_),)
  152. TOOLCHAIN_EXTERNAL_CFLAGS += -march=$(CC_TARGET_ARCH_)
  153. TOOLCHAIN_EXTERNAL_WRAPPER_ARGS += -DBR_ARCH='"$(CC_TARGET_ARCH_)"'
  154. endif
  155. ifneq ($(CC_TARGET_CPU_),)
  156. TOOLCHAIN_EXTERNAL_CFLAGS += -mcpu=$(CC_TARGET_CPU_)
  157. TOOLCHAIN_EXTERNAL_WRAPPER_ARGS += -DBR_CPU='"$(CC_TARGET_CPU_)"'
  158. endif
  159. ifneq ($(CC_TARGET_ABI_),)
  160. TOOLCHAIN_EXTERNAL_CFLAGS += -mabi=$(CC_TARGET_ABI_)
  161. TOOLCHAIN_EXTERNAL_WRAPPER_ARGS += -DBR_ABI='"$(CC_TARGET_ABI_)"'
  162. endif
  163. ifneq ($(CC_TARGET_FPU_),)
  164. TOOLCHAIN_EXTERNAL_CFLAGS += -mfpu=$(CC_TARGET_FPU_)
  165. TOOLCHAIN_EXTERNAL_WRAPPER_ARGS += -DBR_FPU='"$(CC_TARGET_FPU_)"'
  166. endif
  167. ifneq ($(CC_TARGET_FLOAT_ABI_),)
  168. TOOLCHAIN_EXTERNAL_CFLAGS += -mfloat-abi=$(CC_TARGET_FLOAT_ABI_)
  169. TOOLCHAIN_EXTERNAL_WRAPPER_ARGS += -DBR_FLOAT_ABI='"$(CC_TARGET_FLOAT_ABI_)"'
  170. endif
  171. ifneq ($(CC_TARGET_MODE_),)
  172. TOOLCHAIN_EXTERNAL_CFLAGS += -m$(CC_TARGET_MODE_)
  173. TOOLCHAIN_EXTERNAL_WRAPPER_ARGS += -DBR_MODE='"$(CC_TARGET_MODE_)"'
  174. endif
  175. ifeq ($(BR2_BINFMT_FLAT),y)
  176. TOOLCHAIN_EXTERNAL_CFLAGS += -Wl,-elf2flt
  177. TOOLCHAIN_EXTERNAL_WRAPPER_ARGS += -DBR_BINFMT_FLAT
  178. endif
  179. ifneq ($(BR2_TARGET_OPTIMIZATION),)
  180. TOOLCHAIN_EXTERNAL_CFLAGS += $(call qstrip,$(BR2_TARGET_OPTIMIZATION))
  181. # We create a list like '"-mfoo", "-mbar", "-mbarfoo"' so that each
  182. # flag is a separate argument when used in execv() by the external
  183. # toolchain wrapper.
  184. TOOLCHAIN_EXTERNAL_WRAPPER_ARGS += -DBR_ADDITIONAL_CFLAGS='$(foreach f,$(call qstrip,$(BR2_TARGET_OPTIMIZATION)),"$(f)",)'
  185. endif
  186. ifeq ($(BR2_SOFT_FLOAT),y)
  187. TOOLCHAIN_EXTERNAL_CFLAGS += -msoft-float
  188. TOOLCHAIN_EXTERNAL_WRAPPER_ARGS += -DBR_SOFTFLOAT=1
  189. endif
  190. ifeq ($(BR2_TOOLCHAIN_EXTERNAL_DOWNLOAD),y)
  191. TOOLCHAIN_EXTERNAL_DEPENDENCIES = $(TOOLCHAIN_EXTERNAL_DIR)/.extracted
  192. endif
  193. ifeq ($(BR2_TOOLCHAIN_EXTERNAL_CODESOURCERY_ARM201109),y)
  194. TOOLCHAIN_EXTERNAL_SITE = http://sourcery.mentor.com/public/gnu_toolchain/arm-none-linux-gnueabi/
  195. TOOLCHAIN_EXTERNAL_SOURCE = arm-2011.09-70-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2
  196. else ifeq ($(BR2_TOOLCHAIN_EXTERNAL_CODESOURCERY_ARM201203),y)
  197. TOOLCHAIN_EXTERNAL_SITE = http://sourcery.mentor.com/public/gnu_toolchain/arm-none-linux-gnueabi/
  198. TOOLCHAIN_EXTERNAL_SOURCE = arm-2012.03-57-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2
  199. else ifeq ($(BR2_TOOLCHAIN_EXTERNAL_CODESOURCERY_ARM201305),y)
  200. TOOLCHAIN_EXTERNAL_SITE = http://sourcery.mentor.com/public/gnu_toolchain/arm-none-linux-gnueabi/
  201. TOOLCHAIN_EXTERNAL_SOURCE = arm-2013.05-24-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2
  202. else ifeq ($(BR2_TOOLCHAIN_EXTERNAL_ARAGO_ARMV7A_201109),y)
  203. TOOLCHAIN_EXTERNAL_SITE = http://software-dl.ti.com/sdoemb/sdoemb_public_sw/arago_toolchain/2011_09/exports/
  204. TOOLCHAIN_EXTERNAL_SOURCE = arago-2011.09-armv7a-linux-gnueabi-sdk.tar.bz2
  205. define TOOLCHAIN_EXTERNAL_FIXUP_CMDS
  206. mv $(@D)/arago-2011.09/armv7a/* $(@D)/
  207. rm -rf $(@D)/arago-2011.09/
  208. endef
  209. else ifeq ($(BR2_TOOLCHAIN_EXTERNAL_ARAGO_ARMV5TE_201109),y)
  210. TOOLCHAIN_EXTERNAL_SITE = http://software-dl.ti.com/sdoemb/sdoemb_public_sw/arago_toolchain/2011_09/exports/
  211. TOOLCHAIN_EXTERNAL_SOURCE = arago-2011.09-armv5te-linux-gnueabi-sdk.tar.bz2
  212. define TOOLCHAIN_EXTERNAL_FIXUP_CMDS
  213. mv $(@D)/arago-2011.09/armv5te/* $(@D)/
  214. rm -rf $(@D)/arago-2011.09/
  215. endef
  216. else ifeq ($(BR2_TOOLCHAIN_EXTERNAL_LINARO_2013_04),y)
  217. TOOLCHAIN_EXTERNAL_SITE = https://releases.linaro.org/13.04/components/toolchain/binaries/
  218. TOOLCHAIN_EXTERNAL_SOURCE = gcc-linaro-arm-linux-gnueabihf-4.7-2013.04-20130415_linux.tar.xz
  219. else ifeq ($(BR2_TOOLCHAIN_EXTERNAL_LINARO_2013_05),y)
  220. TOOLCHAIN_EXTERNAL_SITE = https://releases.linaro.org/13.05/components/toolchain/binaries/
  221. TOOLCHAIN_EXTERNAL_SOURCE = gcc-linaro-arm-linux-gnueabihf-4.8-2013.05_linux.tar.xz
  222. else ifeq ($(BR2_TOOLCHAIN_EXTERNAL_LINARO_2013_06),y)
  223. TOOLCHAIN_EXTERNAL_SITE = https://releases.linaro.org/13.06/components/toolchain/binaries/
  224. TOOLCHAIN_EXTERNAL_SOURCE = gcc-linaro-arm-linux-gnueabihf-4.8-2013.06_linux.tar.xz
  225. else ifeq ($(BR2_TOOLCHAIN_EXTERNAL_CODESOURCERY_MIPS201203),y)
  226. TOOLCHAIN_EXTERNAL_SITE = http://sourcery.mentor.com/public/gnu_toolchain/mips-linux-gnu/
  227. TOOLCHAIN_EXTERNAL_SOURCE = mips-2012.03-63-mips-linux-gnu-i686-pc-linux-gnu.tar.bz2
  228. else ifeq ($(BR2_TOOLCHAIN_EXTERNAL_CODESOURCERY_MIPS201209),y)
  229. TOOLCHAIN_EXTERNAL_SITE = http://sourcery.mentor.com/public/gnu_toolchain/mips-linux-gnu/
  230. TOOLCHAIN_EXTERNAL_SOURCE = mips-2012.09-99-mips-linux-gnu-i686-pc-linux-gnu.tar.bz2
  231. else ifeq ($(BR2_TOOLCHAIN_EXTERNAL_CODESOURCERY_MIPS201305),y)
  232. TOOLCHAIN_EXTERNAL_SITE = http://sourcery.mentor.com/public/gnu_toolchain/mips-linux-gnu/
  233. TOOLCHAIN_EXTERNAL_SOURCE = mips-2013.05-36-mips-linux-gnu-i686-pc-linux-gnu.tar.bz2
  234. else ifeq ($(BR2_TOOLCHAIN_EXTERNAL_CODESOURCERY_POWERPC201009),y)
  235. TOOLCHAIN_EXTERNAL_SITE = http://sourcery.mentor.com/public/gnu_toolchain/powerpc-linux-gnu/
  236. TOOLCHAIN_EXTERNAL_SOURCE = freescale-2010.09-55-powerpc-linux-gnu-i686-pc-linux-gnu.tar.bz2
  237. else ifeq ($(BR2_TOOLCHAIN_EXTERNAL_CODESOURCERY_POWERPC201103),y)
  238. TOOLCHAIN_EXTERNAL_SITE = http://sourcery.mentor.com/public/gnu_toolchain/powerpc-linux-gnu/
  239. TOOLCHAIN_EXTERNAL_SOURCE = freescale-2011.03-38-powerpc-linux-gnu-i686-pc-linux-gnu.tar.bz2
  240. else ifeq ($(BR2_TOOLCHAIN_EXTERNAL_CODESOURCERY_SH201103),y)
  241. TOOLCHAIN_EXTERNAL_SITE = http://sourcery.mentor.com/public/gnu_toolchain/sh-linux-gnu/
  242. TOOLCHAIN_EXTERNAL_SOURCE = renesas-2011.03-37-sh-linux-gnu-i686-pc-linux-gnu.tar.bz2
  243. else ifeq ($(BR2_TOOLCHAIN_EXTERNAL_CODESOURCERY_SH201203),y)
  244. TOOLCHAIN_EXTERNAL_SITE = http://sourcery.mentor.com/public/gnu_toolchain/sh-linux-gnu/
  245. TOOLCHAIN_EXTERNAL_SOURCE = renesas-2012.03-35-sh-linux-gnu-i686-pc-linux-gnu.tar.bz2
  246. else ifeq ($(BR2_TOOLCHAIN_EXTERNAL_CODESOURCERY_SH201209),y)
  247. TOOLCHAIN_EXTERNAL_SITE = https://sourcery.mentor.com/public/gnu_toolchain/sh-linux-gnu/
  248. TOOLCHAIN_EXTERNAL_SOURCE = renesas-2012.09-61-sh-linux-gnu-i686-pc-linux-gnu.tar.bz2
  249. else ifeq ($(BR2_TOOLCHAIN_EXTERNAL_CODESOURCERY_SH2A_201009),y)
  250. TOOLCHAIN_EXTERNAL_SITE = http://sourcery.mentor.com/public/gnu_toolchain/sh-uclinux/
  251. TOOLCHAIN_EXTERNAL_SOURCE = renesas-2010.09-60-sh-uclinux-i686-pc-linux-gnu.tar.bz2
  252. else ifeq ($(BR2_TOOLCHAIN_EXTERNAL_CODESOURCERY_SH2A_201103),y)
  253. TOOLCHAIN_EXTERNAL_SITE = http://sourcery.mentor.com/public/gnu_toolchain/sh-uclinux/
  254. TOOLCHAIN_EXTERNAL_SOURCE = renesas-2011.03-36-sh-uclinux-i686-pc-linux-gnu.tar.bz2
  255. else ifeq ($(BR2_TOOLCHAIN_EXTERNAL_CODESOURCERY_X86_201109),y)
  256. TOOLCHAIN_EXTERNAL_SITE = https://sourcery.mentor.com/public/gnu_toolchain/i686-pc-linux-gnu/
  257. TOOLCHAIN_EXTERNAL_SOURCE = ia32-2011.09-24-i686-pc-linux-gnu-i386-linux.tar.bz2
  258. else ifeq ($(BR2_TOOLCHAIN_EXTERNAL_CODESOURCERY_X86_201203),y)
  259. TOOLCHAIN_EXTERNAL_SITE = http://sourcery.mentor.com/public/gnu_toolchain/i686-pc-linux-gnu/
  260. TOOLCHAIN_EXTERNAL_SOURCE = ia32-2012.03-27-i686-pc-linux-gnu-i386-linux.tar.bz2
  261. else ifeq ($(BR2_TOOLCHAIN_EXTERNAL_CODESOURCERY_X86_201209),y)
  262. TOOLCHAIN_EXTERNAL_SITE = https://sourcery.mentor.com/public/gnu_toolchain/i686-pc-linux-gnu/
  263. TOOLCHAIN_EXTERNAL_SOURCE = ia32-2012.09-62-i686-pc-linux-gnu-i386-linux.tar.bz2
  264. else ifeq ($(BR2_TOOLCHAIN_EXTERNAL_BLACKFIN_UCLINUX_2012R1),y)
  265. TOOLCHAIN_EXTERNAL_SITE_1 = http://blackfin.uclinux.org/gf/download/frsrelease/559/9858/
  266. TOOLCHAIN_EXTERNAL_SOURCE_1 = blackfin-toolchain-2012R1-RC2.i386.tar.bz2
  267. TOOLCHAIN_EXTERNAL_SITE_2 = http://blackfin.uclinux.org/gf/download/frsrelease/559/9866/
  268. TOOLCHAIN_EXTERNAL_SOURCE_2 = blackfin-toolchain-uclibc-full-2012R1-RC2.i386.tar.bz2
  269. TOOLCHAIN_EXTERNAL_SOURCE = $(TOOLCHAIN_EXTERNAL_SOURCE_1) $(TOOLCHAIN_EXTERNAL_SOURCE_2)
  270. else ifeq ($(BR2_TOOLCHAIN_EXTERNAL_BLACKFIN_UCLINUX_2012R2),y)
  271. TOOLCHAIN_EXTERNAL_SITE_1 = http://blackfin.uclinux.org/gf/download/frsrelease/588/10139/
  272. TOOLCHAIN_EXTERNAL_SOURCE_1 = blackfin-toolchain-2012R2-RC2.i386.tar.bz2
  273. TOOLCHAIN_EXTERNAL_SITE_2 = http://blackfin.uclinux.org/gf/download/frsrelease/588/10147/
  274. TOOLCHAIN_EXTERNAL_SOURCE_2 = blackfin-toolchain-uclibc-full-2012R2-RC2.i386.tar.bz2
  275. TOOLCHAIN_EXTERNAL_SOURCE = $(TOOLCHAIN_EXTERNAL_SOURCE_1) $(TOOLCHAIN_EXTERNAL_SOURCE_2)
  276. else ifeq ($(BR2_TOOLCHAIN_EXTERNAL_XILINX_MICROBLAZEEL_14_3),y)
  277. TOOLCHAIN_EXTERNAL_SITE = http://sources.buildroot.net/
  278. TOOLCHAIN_EXTERNAL_SOURCE = lin32-microblazeel-unknown-linux-gnu_14.3_early.tar.xz
  279. else ifeq ($(BR2_TOOLCHAIN_EXTERNAL_XILINX_MICROBLAZEEL_V2),y)
  280. TOOLCHAIN_EXTERNAL_SITE = http://sources.buildroot.net/
  281. TOOLCHAIN_EXTERNAL_SOURCE = microblazeel-unknown-linux-gnu.tgz
  282. else ifeq ($(BR2_TOOLCHAIN_EXTERNAL_XILINX_MICROBLAZEBE_14_3),y)
  283. TOOLCHAIN_EXTERNAL_SITE = http://sources.buildroot.net/
  284. TOOLCHAIN_EXTERNAL_SOURCE = lin32-microblaze-unknown-linux-gnu_14.3_early.tar.xz
  285. else ifeq ($(BR2_TOOLCHAIN_EXTERNAL_XILINX_MICROBLAZEBE_V2),y)
  286. TOOLCHAIN_EXTERNAL_SITE = http://sources.buildroot.net/
  287. TOOLCHAIN_EXTERNAL_SOURCE = microblaze-unknown-linux-gnu.tgz
  288. else ifeq ($(BR2_TOOLCHAIN_EXTERNAL_LINARO_AARCH64_13_04),y)
  289. TOOLCHAIN_EXTERNAL_SITE = https://releases.linaro.org/13.04/components/toolchain/binaries/
  290. TOOLCHAIN_EXTERNAL_SOURCE = gcc-linaro-aarch64-linux-gnu-4.7-2013.04-20130415_linux.tar.xz
  291. else ifeq ($(BR2_TOOLCHAIN_EXTERNAL_LINARO_AARCH64_13_05),y)
  292. TOOLCHAIN_EXTERNAL_SITE = https://releases.linaro.org/13.05/components/toolchain/binaries/
  293. TOOLCHAIN_EXTERNAL_SOURCE = gcc-linaro-aarch64-linux-gnu-4.8-2013.05_linux.tar.xz
  294. else ifeq ($(BR2_TOOLCHAIN_EXTERNAL_LINARO_AARCH64_13_06),y)
  295. TOOLCHAIN_EXTERNAL_SITE = https://releases.linaro.org/13.06/components/toolchain/binaries/
  296. TOOLCHAIN_EXTERNAL_SOURCE = gcc-linaro-aarch64-linux-gnu-4.8-2013.06_linux.tar.xz
  297. else
  298. # Custom toolchain
  299. TOOLCHAIN_EXTERNAL_SITE = $(dir $(call qstrip,$(BR2_TOOLCHAIN_EXTERNAL_URL)))
  300. TOOLCHAIN_EXTERNAL_SOURCE = $(notdir $(call qstrip,$(BR2_TOOLCHAIN_EXTERNAL_URL)))
  301. # A value must be set (even if unused), otherwise the
  302. # $(DL_DIR)/$(TOOLCHAIN_EXTERNAL_SOURCE) rule would override the main
  303. # $(DL_DIR) rule
  304. ifeq (,$(TOOLCHAIN_EXTERNAL_SOURCE))
  305. TOOLCHAIN_EXTERNAL_SOURCE = none
  306. endif
  307. endif
  308. # Special handling for Blackfin toolchain, because of the split in two
  309. # tarballs, and the organization of tarball contents. The tarballs
  310. # contain ./opt/uClinux/{bfin-uclinux,bfin-linux-uclibc} directories,
  311. # which themselves contain the toolchain. This is why we strip more
  312. # components than usual.
  313. ifeq ($(BR2_TOOLCHAIN_EXTERNAL_BLACKFIN_UCLINUX_2012R1)$(BR2_TOOLCHAIN_EXTERNAL_BLACKFIN_UCLINUX_2012R2),y)
  314. $(DL_DIR)/$(TOOLCHAIN_EXTERNAL_SOURCE_1):
  315. $(call DOWNLOAD,$(TOOLCHAIN_EXTERNAL_SITE_1:/=)/$(TOOLCHAIN_EXTERNAL_SOURCE_1))
  316. $(DL_DIR)/$(TOOLCHAIN_EXTERNAL_SOURCE_2):
  317. $(call DOWNLOAD,$(TOOLCHAIN_EXTERNAL_SITE_2:/=)/$(TOOLCHAIN_EXTERNAL_SOURCE_2))
  318. $(TOOLCHAIN_EXTERNAL_DIR)/.extracted: $(DL_DIR)/$(TOOLCHAIN_EXTERNAL_SOURCE_1) $(DL_DIR)/$(TOOLCHAIN_EXTERNAL_SOURCE_2)
  319. mkdir -p $(@D)
  320. $(INFLATE$(suffix $(TOOLCHAIN_EXTERNAL_SOURCE_1))) $(DL_DIR)/$(TOOLCHAIN_EXTERNAL_SOURCE_1) | \
  321. $(TAR) $(TAR_STRIP_COMPONENTS)=3 --hard-dereference -C $(@D) $(TAR_OPTIONS) -
  322. $(INFLATE$(suffix $(TOOLCHAIN_EXTERNAL_SOURCE_2))) $(DL_DIR)/$(TOOLCHAIN_EXTERNAL_SOURCE_2) | \
  323. $(TAR) $(TAR_STRIP_COMPONENTS)=3 --hard-dereference -C $(@D) $(TAR_OPTIONS) -
  324. $(Q)touch $@
  325. else
  326. # Download and extraction of a toolchain
  327. $(DL_DIR)/$(TOOLCHAIN_EXTERNAL_SOURCE):
  328. $(call DOWNLOAD,$(TOOLCHAIN_EXTERNAL_SITE)$(TOOLCHAIN_EXTERNAL_SOURCE),$(TOOLCHAIN_EXTERNAL_SOURCE))
  329. $(TOOLCHAIN_EXTERNAL_DIR)/.extracted: $(DL_DIR)/$(TOOLCHAIN_EXTERNAL_SOURCE)
  330. mkdir -p $(@D)
  331. $(INFLATE$(suffix $(TOOLCHAIN_EXTERNAL_SOURCE))) $^ | \
  332. $(TAR) $(TAR_STRIP_COMPONENTS)=1 --exclude='usr/lib/locale/*' -C $(@D) $(TAR_OPTIONS) -
  333. $(TOOLCHAIN_EXTERNAL_FIXUP_CMDS)
  334. $(Q)touch $@
  335. endif
  336. # Checks for an already installed toolchain: check the toolchain
  337. # location, check that it supports sysroot, and then verify that it
  338. # matches the configuration provided in Buildroot: ABI, C++ support,
  339. # type of C library and all C library features.
  340. $(STAMP_DIR)/ext-toolchain-checked: $(TOOLCHAIN_EXTERNAL_DEPENDENCIES)
  341. @$(call MESSAGE,"Checking external toolchain settings")
  342. $(Q)$(call check_cross_compiler_exists,$(TOOLCHAIN_EXTERNAL_CC))
  343. $(Q)LIBC_A_LOCATION=`readlink -f $$(LANG=C $(TOOLCHAIN_EXTERNAL_CC) -print-file-name=libc.a)` ; \
  344. SYSROOT_DIR=`echo $${LIBC_A_LOCATION} | sed -r -e 's:usr/lib(32|64)?/(.*/)?libc\.a::'` ; \
  345. if test -z "$${SYSROOT_DIR}" ; then \
  346. @echo "External toolchain doesn't support --sysroot. Cannot use." ; \
  347. exit 1 ; \
  348. fi ; \
  349. if test "$(BR2_arm)" = "y" ; then \
  350. $(call check_arm_abi,\
  351. "$(TOOLCHAIN_EXTERNAL_CC) $(TOOLCHAIN_EXTERNAL_CFLAGS)",\
  352. $(TOOLCHAIN_EXTERNAL_READELF)) ; \
  353. fi ; \
  354. if test "$(BR2_INSTALL_LIBSTDCPP)" = "y" ; then \
  355. $(call check_cplusplus,$(TOOLCHAIN_EXTERNAL_CXX)) ; \
  356. fi ; \
  357. if test "$(BR2_TOOLCHAIN_EXTERNAL_UCLIBC)" = "y" ; then \
  358. $(call check_uclibc,$${SYSROOT_DIR}) ; \
  359. else \
  360. $(call check_glibc,$${SYSROOT_DIR}) ; \
  361. fi
  362. $(Q)touch $@
  363. # Integration of the toolchain into Buildroot: find the main sysroot
  364. # and the variant-specific sysroot, then copy the needed libraries to
  365. # the $(TARGET_DIR) and copy the whole sysroot (libraries and headers)
  366. # to $(STAGING_DIR).
  367. #
  368. # Variables are defined as follows:
  369. #
  370. # LIBC_A_LOCATION: location of the libc.a file in the default
  371. # multilib variant (allows to find the main
  372. # sysroot directory)
  373. # Ex: /x-tools/mips-2011.03/mips-linux-gnu/libc/usr/lib/libc.a
  374. #
  375. # SYSROOT_DIR: the main sysroot directory, deduced from
  376. # LIBC_A_LOCATION by removing the
  377. # usr/lib[32|64]/libc.a part of the path.
  378. # Ex: /x-tools/mips-2011.03/mips-linux-gnu/libc/
  379. #
  380. # ARCH_LIBC_A_LOCATION: location of the libc.a file in the selected
  381. # multilib variant (taking into account the
  382. # CFLAGS). Allows to find the sysroot of the
  383. # selected multilib variant.
  384. # Ex: /x-tools/mips-2011.03/mips-linux-gnu/libc/mips16/soft-float/el/usr/lib/libc.a
  385. #
  386. # ARCH_SYSROOT_DIR: the sysroot of the selected multilib variant,
  387. # deduced from ARCH_LIBC_A_LOCATION by removing
  388. # usr/lib[32|64]/libc.a at the end of the path.
  389. # Ex: /x-tools/mips-2011.03/mips-linux-gnu/libc/mips16/soft-float/el/
  390. #
  391. # ARCH_LIB_DIR: 'lib', 'lib32' or 'lib64' depending on where libraries
  392. # are stored. Deduced from ARCH_LIBC_A_LOCATION by
  393. # looking at usr/lib??/libc.a.
  394. # Ex: lib
  395. #
  396. # ARCH_SUBDIR: the relative location of the sysroot of the selected
  397. # multilib variant compared to the main sysroot.
  398. # Ex: mips16/soft-float/el
  399. #
  400. # SUPPORT_LIB_DIR: some toolchains, such as recent Linaro toolchains,
  401. # store GCC support libraries (libstdc++,
  402. # libgcc_s, etc.) outside of the sysroot. In
  403. # this case, SUPPORT_LIB_DIR is set to a
  404. # non-empty value, and points to the directory
  405. # where these support libraries are
  406. # available. Those libraries will be copied to
  407. # our sysroot, and the directory will also be
  408. # considered when searching libraries for copy
  409. # to the target filesystem.
  410. $(STAMP_DIR)/ext-toolchain-installed: $(STAMP_DIR)/ext-toolchain-checked
  411. $(Q)LIBC_A_LOCATION=`readlink -f $$(LANG=C $(TOOLCHAIN_EXTERNAL_CC) -print-file-name=libc.a)` ; \
  412. SYSROOT_DIR=`echo $${LIBC_A_LOCATION} | sed -r -e 's:usr/lib(32|64)?/(.*/)?libc\.a::'` ; \
  413. if test -z "$${SYSROOT_DIR}" ; then \
  414. @echo "External toolchain doesn't support --sysroot. Cannot use." ; \
  415. exit 1 ; \
  416. fi ; \
  417. ARCH_LIBC_A_LOCATION=`readlink -f $$(LANG=C $(TOOLCHAIN_EXTERNAL_CC) $(TOOLCHAIN_EXTERNAL_CFLAGS) -print-file-name=libc.a)` ; \
  418. ARCH_SYSROOT_DIR=`echo $${ARCH_LIBC_A_LOCATION} | sed -r -e 's:usr/lib(32|64)?/(.*/)?libc\.a::'` ; \
  419. ARCH_LIB_DIR=`echo $${ARCH_LIBC_A_LOCATION} | sed -r -e 's:.*/usr/(lib(32|64)?)/(.*/)?libc.a:\1:'` ; \
  420. SUPPORT_LIB_DIR="" ; \
  421. if test `find $${ARCH_SYSROOT_DIR} -name 'libstdc++.a' | wc -l` -eq 0 ; then \
  422. LIBSTDCPP_A_LOCATION=$$(LANG=C $(TOOLCHAIN_EXTERNAL_CC) $(TOOLCHAIN_EXTERNAL_CFLAGS) -print-file-name=libstdc++.a) ; \
  423. if [ -e "$${LIBSTDCPP_A_LOCATION}" ]; then \
  424. SUPPORT_LIB_DIR=`readlink -f $${LIBSTDCPP_A_LOCATION} | sed -r -e 's:libstdc\+\+\.a::'` ; \
  425. fi ; \
  426. fi ; \
  427. ARCH_SUBDIR=`echo $${ARCH_SYSROOT_DIR} | sed -r -e "s:^$${SYSROOT_DIR}(.*)/$$:\1:"` ; \
  428. if test -z "$(BR2_PREFER_STATIC_LIB)" ; then \
  429. $(call MESSAGE,"Copying external toolchain libraries to target...") ; \
  430. for libs in $(LIB_EXTERNAL_LIBS); do \
  431. $(call copy_toolchain_lib_root,$${ARCH_SYSROOT_DIR},$${SUPPORT_LIB_DIR},$${ARCH_LIB_DIR},$$libs,/lib); \
  432. done ; \
  433. for libs in $(USR_LIB_EXTERNAL_LIBS); do \
  434. $(call copy_toolchain_lib_root,$${ARCH_SYSROOT_DIR},$${SUPPORT_LIB_DIR},$${ARCH_LIB_DIR},$$libs,/usr/lib); \
  435. done ; \
  436. fi ; \
  437. $(call MESSAGE,"Copying external toolchain sysroot to staging...") ; \
  438. $(call copy_toolchain_sysroot,$${SYSROOT_DIR},$${ARCH_SYSROOT_DIR},$${ARCH_SUBDIR},$${ARCH_LIB_DIR},$${SUPPORT_LIB_DIR}) ; \
  439. if test "$(BR2_TOOLCHAIN_EXTERNAL_GDB_SERVER_COPY)" = "y"; then \
  440. $(call MESSAGE,"Copying gdbserver") ; \
  441. gdbserver_found=0 ; \
  442. for d in $${ARCH_SYSROOT_DIR}/usr $${ARCH_SYSROOT_DIR}/../debug-root/usr $${ARCH_SYSROOT_DIR}/usr/$${ARCH_LIB_DIR} ; do \
  443. if test -f $${d}/bin/gdbserver ; then \
  444. install -m 0755 -D $${d}/bin/gdbserver $(TARGET_DIR)/usr/bin/gdbserver ; \
  445. gdbserver_found=1 ; \
  446. break ; \
  447. fi ; \
  448. done ; \
  449. if [ $${gdbserver_found} -eq 0 ] ; then \
  450. echo "Could not find gdbserver in external toolchain" ; \
  451. exit 1 ; \
  452. fi ; \
  453. fi ; \
  454. touch $@
  455. # Special installation target used on the Blackfin architecture when
  456. # FDPIC is not the primary binary format being used, but the user has
  457. # nonetheless requested the installation of the FDPIC libraries to the
  458. # target filesystem.
  459. $(STAMP_DIR)/ext-toolchain-bfin-fdpic-shared-installed: $(STAMP_DIR)/ext-toolchain-checked
  460. $(Q)$(call MESSAGE,"Install external toolchain FDPIC libraries to target...") ; \
  461. FDPIC_EXTERNAL_CC=$(dir $(TOOLCHAIN_EXTERNAL_CC))/../../bfin-linux-uclibc/bin/bfin-linux-uclibc-gcc ; \
  462. FDPIC_LIBC_A_LOCATION=`readlink -f $$(LANG=C $${FDPIC_EXTERNAL_CC} $(TOOLCHAIN_EXTERNAL_CFLAGS) -print-file-name=libc.a)` ; \
  463. FDPIC_SYSROOT_DIR=`echo $${FDPIC_LIBC_A_LOCATION} | sed -r -e 's:usr/lib(32|64)?/(.*/)?libc\.a::'` ; \
  464. FDPIC_LIB_DIR=`echo $${FDPIC_LIBC_A_LOCATION} | sed -r -e 's:.*/usr/(lib(32|64)?)/(.*/)?libc.a:\1:'` ; \
  465. FDPIC_SUPPORT_LIB_DIR="" ; \
  466. if test `find $${FDPIC_SYSROOT_DIR} -name 'libstdc++.a' | wc -l` -eq 0 ; then \
  467. FDPIC_LIBSTDCPP_A_LOCATION=$$(LANG=C $${FDPIC_EXTERNAL_CC} $(TOOLCHAIN_EXTERNAL_CFLAGS) -print-file-name=libstdc++.a) ; \
  468. if [ -e "$${FDPIC_LIBSTDCPP_A_LOCATION}" ]; then \
  469. FDPIC_SUPPORT_LIB_DIR=`readlink -f $${FDPIC_LIBSTDCPP_A_LOCATION} | sed -r -e 's:libstdc\+\+\.a::'` ; \
  470. fi ; \
  471. fi ; \
  472. for libs in $(LIB_EXTERNAL_LIBS); do \
  473. $(call copy_toolchain_lib_root,$${FDPIC_SYSROOT_DIR},$${FDPIC_SUPPORT_LIB_DIR},$${FDPIC_LIB_DIR},$$libs,/lib); \
  474. done ; \
  475. for libs in $(USR_LIB_EXTERNAL_LIBS); do \
  476. $(call copy_toolchain_lib_root,$${FDPIC_SYSROOT_DIR},$${FDPIC_SUPPORT_LIB_DIR},$${FDPIC_LIB_DIR},$$libs,/usr/lib); \
  477. done ; \
  478. touch $@
  479. # Special installation target used on the Blackfin architecture when
  480. # shared FLAT is not the primary format being used, but the user has
  481. # nonetheless requested the installation of the shared FLAT libraries
  482. # to the target filesystem. The flat libraries are found and linked
  483. # according to the index in name "libN.so". Index 1 is reserved for
  484. # the standard C library. Customer libraries can use 4 and above.
  485. $(STAMP_DIR)/ext-toolchain-bfin-shared-flat-installed: $(STAMP_DIR)/ext-toolchain-checked
  486. $(Q)$(call MESSAGE,"Install external toolchain FLAT libraries to target...") ; \
  487. FLAT_EXTERNAL_CC=$(dir $(TOOLCHAIN_EXTERNAL_CC))../../bfin-uclinux/bin/bfin-uclinux-gcc ; \
  488. FLAT_LIBC_A_LOCATION=`$${FLAT_EXTERNAL_CC} $(TOOLCHAIN_EXTERNAL_CFLAGS) -mid-shared-library -print-file-name=libc`; \
  489. if [ -f $${FLAT_LIBC_A_LOCATION} -a ! -h $${FLAT_LIBC_A_LOCATION} ] ; then \
  490. $(INSTALL) -D $${FLAT_LIBC_A_LOCATION} $(TARGET_DIR)/lib/lib1.so; \
  491. fi ; \
  492. touch $@
  493. TOOLCHAIN_EXTERNAL_INSTALL = $(STAMP_DIR)/ext-toolchain-installed
  494. ifeq ($(BR2_BFIN_INSTALL_FDPIC_SHARED),y)
  495. TOOLCHAIN_EXTERNAL_INSTALL += $(STAMP_DIR)/ext-toolchain-bfin-fdpic-shared-installed
  496. endif
  497. ifeq ($(BR2_BFIN_INSTALL_FLAT_SHARED),y)
  498. TOOLCHAIN_EXTERNAL_INSTALL += $(STAMP_DIR)/ext-toolchain-bfin-shared-flat-installed
  499. endif
  500. # Build toolchain wrapper for preprocessor, C and C++ compiler and setup
  501. # symlinks for everything else. Skip gdb symlink when we are building our
  502. # own gdb to prevent two gdb's in output/host/usr/bin.
  503. $(HOST_DIR)/usr/bin/ext-toolchain-wrapper: $(TOOLCHAIN_EXTERNAL_INSTALL)
  504. $(Q)$(call MESSAGE,"Building ext-toolchain wrapper")
  505. mkdir -p $(HOST_DIR)/usr/bin; cd $(HOST_DIR)/usr/bin; \
  506. for i in $(TOOLCHAIN_EXTERNAL_CROSS)*; do \
  507. base=$${i##*/}; \
  508. case "$$base" in \
  509. *cc|*cc-*|*++|*++-*|*cpp) \
  510. ln -sf $(@F) $$base; \
  511. ;; \
  512. *gdb|*gdbtui) \
  513. if test "$(BR2_PACKAGE_HOST_GDB)" != "y"; then \
  514. ln -sf $$(echo $$i | sed 's%^$(HOST_DIR)%../..%') .; \
  515. fi \
  516. ;; \
  517. *) \
  518. ln -sf $$(echo $$i | sed 's%^$(HOST_DIR)%../..%') .; \
  519. ;; \
  520. esac; \
  521. done ;
  522. # We use --hash-style=both to increase the compatibility of
  523. # the generated binary with older platforms
  524. $(HOSTCC) $(HOST_CFLAGS) $(TOOLCHAIN_EXTERNAL_WRAPPER_ARGS) -s -Wl,--hash-style=both \
  525. toolchain/toolchain-external/ext-toolchain-wrapper.c -o $@
  526. toolchain-external: dependencies $(HOST_DIR)/usr/bin/ext-toolchain-wrapper
  527. ifeq ($(BR2_TOOLCHAIN_EXTERNAL_DOWNLOAD),y)
  528. # download ext toolchain if so configured
  529. toolchain-external-source: $(addprefix $(DL_DIR)/,$(TOOLCHAIN_EXTERNAL_SOURCE))
  530. endif