pkg-toolchain-external.mk 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591
  1. ################################################################################
  2. # External toolchain package infrastructure
  3. #
  4. # This package infrastructure implements the support for external
  5. # toolchains, i.e toolchains that are available pre-built, ready to
  6. # use. Such toolchain may either be readily available on the Web
  7. # (Linaro, Sourcery CodeBench, from processor vendors) or may be built
  8. # with tools like Crosstool-NG or Buildroot itself. So far, we have
  9. # tested this with:
  10. #
  11. # * Toolchains generated by Crosstool-NG
  12. # * Toolchains generated by Buildroot
  13. # * Toolchains provided by Linaro for the ARM and AArch64
  14. # architectures
  15. # * Sourcery CodeBench toolchains (from Mentor Graphics) for the ARM,
  16. # MIPS, PowerPC, x86_64 and NIOS 2 architectures. For the MIPS
  17. # toolchain, the -muclibc variant isn't supported yet, only the
  18. # default glibc-based variant is.
  19. # * Synopsys DesignWare toolchains for ARC cores
  20. #
  21. # The basic principle is the following
  22. #
  23. # 1. If the toolchain is not pre-installed, download and extract it
  24. # in $(TOOLCHAIN_EXTERNAL_INSTALL_DIR). Otherwise,
  25. # $(TOOLCHAIN_EXTERNAL_INSTALL_DIR) points to were the toolchain has
  26. # already been installed by the user.
  27. #
  28. # 2. For all external toolchains, perform some checks on the
  29. # conformity between the toolchain configuration described in the
  30. # Buildroot menuconfig system, and the real configuration of the
  31. # external toolchain. This is for example important to make sure that
  32. # the Buildroot configuration system knows whether the toolchain
  33. # supports RPC, IPv6, locales, large files, etc. Unfortunately, these
  34. # things cannot be detected automatically, since the value of these
  35. # options (such as BR2_TOOLCHAIN_HAS_NATIVE_RPC) are needed at
  36. # configuration time because these options are used as dependencies
  37. # for other options. And at configuration time, we are not able to
  38. # retrieve the external toolchain configuration.
  39. #
  40. # 3. Copy the libraries needed at runtime to the target directory,
  41. # $(TARGET_DIR). Obviously, things such as the C library, the dynamic
  42. # loader and a few other utility libraries are needed if dynamic
  43. # applications are to be executed on the target system.
  44. #
  45. # 4. Copy the libraries and headers to the staging directory. This
  46. # will allow all further calls to gcc to be made using --sysroot
  47. # $(STAGING_DIR), which greatly simplifies the compilation of the
  48. # packages when using external toolchains. So in the end, only the
  49. # cross-compiler binaries remains external, all libraries and headers
  50. # are imported into the Buildroot tree.
  51. #
  52. # 5. Build a toolchain wrapper which executes the external toolchain
  53. # with a number of arguments (sysroot/march/mtune/..) hardcoded,
  54. # so we're sure the correct configuration is always used and the
  55. # toolchain behaves similar to an internal toolchain.
  56. # This toolchain wrapper and symlinks are installed into
  57. # $(HOST_DIR)/bin like for the internal toolchains, and the rest
  58. # of Buildroot is handled identical for the 2 toolchain types.
  59. ################################################################################
  60. #
  61. # Definitions of where the toolchain can be found
  62. #
  63. TOOLCHAIN_EXTERNAL_PREFIX = $(call qstrip,$(BR2_TOOLCHAIN_EXTERNAL_PREFIX))
  64. TOOLCHAIN_EXTERNAL_DOWNLOAD_INSTALL_DIR = $(HOST_DIR)/opt/ext-toolchain
  65. ifeq ($(BR2_TOOLCHAIN_EXTERNAL_DOWNLOAD),y)
  66. TOOLCHAIN_EXTERNAL_INSTALL_DIR = $(TOOLCHAIN_EXTERNAL_DOWNLOAD_INSTALL_DIR)
  67. else
  68. TOOLCHAIN_EXTERNAL_INSTALL_DIR = $(call qstrip,$(BR2_TOOLCHAIN_EXTERNAL_PATH))
  69. endif
  70. ifeq ($(TOOLCHAIN_EXTERNAL_INSTALL_DIR),)
  71. ifneq ($(TOOLCHAIN_EXTERNAL_PREFIX),)
  72. # if no path set, figure it out from path
  73. TOOLCHAIN_EXTERNAL_BIN := $(dir $(shell which $(TOOLCHAIN_EXTERNAL_PREFIX)-gcc))
  74. endif
  75. else
  76. TOOLCHAIN_EXTERNAL_REL_BIN_PATH = $(call qstrip,$(BR2_TOOLCHAIN_EXTERNAL_REL_BIN_PATH))
  77. ifeq ($(TOOLCHAIN_EXTERNAL_REL_BIN_PATH),)
  78. TOOLCHAIN_EXTERNAL_REL_BIN_PATH = bin
  79. endif
  80. TOOLCHAIN_EXTERNAL_BIN = $(TOOLCHAIN_EXTERNAL_INSTALL_DIR)/$(TOOLCHAIN_EXTERNAL_REL_BIN_PATH)
  81. endif
  82. # If this is a buildroot toolchain, it already has a wrapper which we want to
  83. # bypass. Since this is only evaluated after it has been extracted, we can use
  84. # $(wildcard ...) here.
  85. TOOLCHAIN_EXTERNAL_SUFFIX = \
  86. $(if $(wildcard $(TOOLCHAIN_EXTERNAL_BIN)/*.br_real),.br_real)
  87. TOOLCHAIN_EXTERNAL_CROSS = $(TOOLCHAIN_EXTERNAL_BIN)/$(TOOLCHAIN_EXTERNAL_PREFIX)-
  88. TOOLCHAIN_EXTERNAL_CC = $(TOOLCHAIN_EXTERNAL_CROSS)gcc$(TOOLCHAIN_EXTERNAL_SUFFIX)
  89. TOOLCHAIN_EXTERNAL_CXX = $(TOOLCHAIN_EXTERNAL_CROSS)g++$(TOOLCHAIN_EXTERNAL_SUFFIX)
  90. TOOLCHAIN_EXTERNAL_FC = $(TOOLCHAIN_EXTERNAL_CROSS)gfortran$(TOOLCHAIN_EXTERNAL_SUFFIX)
  91. TOOLCHAIN_EXTERNAL_READELF = $(TOOLCHAIN_EXTERNAL_CROSS)readelf
  92. # Normal handling of downloaded toolchain tarball extraction.
  93. ifeq ($(BR2_TOOLCHAIN_EXTERNAL_DOWNLOAD),y)
  94. # As a regular package, the toolchain gets extracted in $(@D), but
  95. # since it's actually a fairly special package, we need it to be moved
  96. # into TOOLCHAIN_EXTERNAL_DOWNLOAD_INSTALL_DIR.
  97. define TOOLCHAIN_EXTERNAL_MOVE
  98. rm -rf $(TOOLCHAIN_EXTERNAL_DOWNLOAD_INSTALL_DIR)
  99. mkdir -p $(TOOLCHAIN_EXTERNAL_DOWNLOAD_INSTALL_DIR)
  100. mv $(@D)/* $(TOOLCHAIN_EXTERNAL_DOWNLOAD_INSTALL_DIR)/
  101. endef
  102. endif
  103. #
  104. # Definitions of the list of libraries that should be copied to the target.
  105. #
  106. TOOLCHAIN_EXTERNAL_LIBS += ld*.so* libgcc_s.so.* libatomic.so.*
  107. ifeq ($(BR2_TOOLCHAIN_EXTERNAL_GLIBC)$(BR2_TOOLCHAIN_EXTERNAL_UCLIBC),y)
  108. TOOLCHAIN_EXTERNAL_LIBS += libc.so.* libcrypt.so.* libdl.so.* libm.so.* libnsl.so.* libresolv.so.* librt.so.* libutil.so.*
  109. ifeq ($(BR2_TOOLCHAIN_HAS_THREADS),y)
  110. TOOLCHAIN_EXTERNAL_LIBS += libpthread.so.*
  111. ifneq ($(BR2_PACKAGE_GDB)$(BR2_TOOLCHAIN_EXTERNAL_GDB_SERVER_COPY),)
  112. TOOLCHAIN_EXTERNAL_LIBS += libthread_db.so.*
  113. endif # gdbserver
  114. endif # ! no threads
  115. endif
  116. ifeq ($(BR2_TOOLCHAIN_EXTERNAL_GLIBC),y)
  117. TOOLCHAIN_EXTERNAL_LIBS += libnss_files.so.* libnss_dns.so.* libmvec.so.* libanl.so.*
  118. endif
  119. ifeq ($(BR2_TOOLCHAIN_EXTERNAL_MUSL),y)
  120. TOOLCHAIN_EXTERNAL_LIBS += libc.so
  121. endif
  122. ifeq ($(BR2_INSTALL_LIBSTDCPP),y)
  123. TOOLCHAIN_EXTERNAL_LIBS += libstdc++.so.*
  124. endif
  125. ifeq ($(BR2_TOOLCHAIN_HAS_FORTRAN),y)
  126. TOOLCHAIN_EXTERNAL_LIBS += libgfortran.so.*
  127. # fortran needs quadmath on x86 and x86_64
  128. ifeq ($(BR2_TOOLCHAIN_HAS_LIBQUADMATH),y)
  129. TOOLCHAIN_EXTERNAL_LIBS += libquadmath.so*
  130. endif
  131. endif
  132. TOOLCHAIN_EXTERNAL_LIBS += $(call qstrip,$(BR2_TOOLCHAIN_EXTRA_EXTERNAL_LIBS))
  133. #
  134. # Definition of the CFLAGS to use with the external toolchain, as well as the
  135. # common toolchain wrapper build arguments
  136. #
  137. CC_TARGET_CPU_ := $(GCC_TARGET_CPU)
  138. CC_TARGET_ARCH_ := $(GCC_TARGET_ARCH)
  139. CC_TARGET_ABI_ := $(GCC_TARGET_ABI)
  140. CC_TARGET_NAN_ := $(GCC_TARGET_NAN)
  141. CC_TARGET_FP32_MODE_ := $(GCC_TARGET_FP32_MODE)
  142. CC_TARGET_FPU_ := $(GCC_TARGET_FPU)
  143. CC_TARGET_FLOAT_ABI_ := $(GCC_TARGET_FLOAT_ABI)
  144. CC_TARGET_MODE_ := $(GCC_TARGET_MODE)
  145. # march/mtune/floating point mode needs to be passed to the external toolchain
  146. # to select the right multilib variant
  147. ifeq ($(BR2_x86_64),y)
  148. TOOLCHAIN_EXTERNAL_CFLAGS += -m64
  149. TOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS += -DBR_64
  150. endif
  151. ifneq ($(CC_TARGET_ARCH_),)
  152. TOOLCHAIN_EXTERNAL_CFLAGS += -march=$(CC_TARGET_ARCH_)
  153. TOOLCHAIN_EXTERNAL_TOOLCHAIN_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_TOOLCHAIN_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_TOOLCHAIN_WRAPPER_ARGS += -DBR_ABI='"$(CC_TARGET_ABI_)"'
  162. endif
  163. ifeq ($(BR2_TOOLCHAIN_HAS_MNAN_OPTION),y)
  164. ifneq ($(CC_TARGET_NAN_),)
  165. TOOLCHAIN_EXTERNAL_CFLAGS += -mnan=$(CC_TARGET_NAN_)
  166. TOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS += -DBR_NAN='"$(CC_TARGET_NAN_)"'
  167. endif
  168. endif
  169. ifneq ($(CC_TARGET_FP32_MODE_),)
  170. TOOLCHAIN_EXTERNAL_CFLAGS += -mfp$(CC_TARGET_FP32_MODE_)
  171. TOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS += -DBR_FP32_MODE='"$(CC_TARGET_FP32_MODE_)"'
  172. endif
  173. ifneq ($(CC_TARGET_FPU_),)
  174. TOOLCHAIN_EXTERNAL_CFLAGS += -mfpu=$(CC_TARGET_FPU_)
  175. TOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS += -DBR_FPU='"$(CC_TARGET_FPU_)"'
  176. endif
  177. ifneq ($(CC_TARGET_FLOAT_ABI_),)
  178. TOOLCHAIN_EXTERNAL_CFLAGS += -mfloat-abi=$(CC_TARGET_FLOAT_ABI_)
  179. TOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS += -DBR_FLOAT_ABI='"$(CC_TARGET_FLOAT_ABI_)"'
  180. endif
  181. ifneq ($(CC_TARGET_MODE_),)
  182. TOOLCHAIN_EXTERNAL_CFLAGS += -m$(CC_TARGET_MODE_)
  183. TOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS += -DBR_MODE='"$(CC_TARGET_MODE_)"'
  184. endif
  185. ifeq ($(BR2_BINFMT_FLAT),y)
  186. TOOLCHAIN_EXTERNAL_CFLAGS += -Wl,-elf2flt
  187. TOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS += -DBR_BINFMT_FLAT
  188. endif
  189. ifeq ($(BR2_mipsel)$(BR2_mips64el),y)
  190. TOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS += -DBR_MIPS_TARGET_LITTLE_ENDIAN
  191. TOOLCHAIN_EXTERNAL_CFLAGS += -EL
  192. endif
  193. ifeq ($(BR2_mips)$(BR2_mips64),y)
  194. TOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS += -DBR_MIPS_TARGET_BIG_ENDIAN
  195. TOOLCHAIN_EXTERNAL_CFLAGS += -EB
  196. endif
  197. ifeq ($(BR2_arceb),y)
  198. TOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS += -DBR_ARC_TARGET_BIG_ENDIAN
  199. TOOLCHAIN_EXTERNAL_CFLAGS += -EB
  200. endif
  201. TOOLCHAIN_EXTERNAL_CFLAGS += $(call qstrip,$(BR2_TARGET_OPTIMIZATION))
  202. ifeq ($(BR2_SOFT_FLOAT),y)
  203. TOOLCHAIN_EXTERNAL_CFLAGS += -msoft-float
  204. TOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS += -DBR_SOFTFLOAT=1
  205. endif
  206. TOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS += \
  207. -DBR_CROSS_PATH_SUFFIX='"$(TOOLCHAIN_EXTERNAL_SUFFIX)"'
  208. ifeq ($(filter $(HOST_DIR)/%,$(TOOLCHAIN_EXTERNAL_BIN)),)
  209. # TOOLCHAIN_EXTERNAL_BIN points outside HOST_DIR => absolute path
  210. TOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS += \
  211. -DBR_CROSS_PATH_ABS='"$(TOOLCHAIN_EXTERNAL_BIN)"'
  212. else
  213. # TOOLCHAIN_EXTERNAL_BIN points inside HOST_DIR => relative path
  214. TOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS += \
  215. -DBR_CROSS_PATH_REL='"$(TOOLCHAIN_EXTERNAL_BIN:$(HOST_DIR)/%=%)"'
  216. endif
  217. #
  218. # The following functions creates the symbolic links needed to get the
  219. # cross-compilation tools visible in $(HOST_DIR)/bin. Some of
  220. # links are done directly to the corresponding tool in the external
  221. # toolchain installation directory, while some other links are done to
  222. # the toolchain wrapper (preprocessor, C, C++ and Fortran compiler)
  223. #
  224. # We skip gdb symlink when we are building our own gdb to prevent two
  225. # gdb's in $(HOST_DIR)/bin.
  226. #
  227. # The LTO support in gcc creates wrappers for ar, ranlib and nm which load
  228. # the lto plugin. These wrappers are called *-gcc-ar, *-gcc-ranlib, and
  229. # *-gcc-nm and should be used instead of the real programs when -flto is
  230. # used. However, we should not add the toolchain wrapper for them, and they
  231. # match the *cc-* pattern. Therefore, an additional case is added for *-ar,
  232. # *-ranlib and *-nm.
  233. define TOOLCHAIN_EXTERNAL_INSTALL_WRAPPER
  234. $(Q)cd $(HOST_DIR)/bin; \
  235. for i in $(TOOLCHAIN_EXTERNAL_CROSS)*; do \
  236. base=$${i##*/}; \
  237. case "$$base" in \
  238. *-ar|*-ranlib|*-nm) \
  239. ln -sf $$(echo $$i | sed 's%^$(HOST_DIR)%..%') .; \
  240. ;; \
  241. *cc|*cc-*|*++|*++-*|*cpp|*-gfortran) \
  242. ln -sf toolchain-wrapper $$base; \
  243. ;; \
  244. *gdb|*gdbtui) \
  245. if test "$(BR2_PACKAGE_HOST_GDB)" != "y"; then \
  246. ln -sf $$(echo $$i | sed 's%^$(HOST_DIR)%..%') .; \
  247. fi \
  248. ;; \
  249. *) \
  250. ln -sf $$(echo $$i | sed 's%^$(HOST_DIR)%..%') .; \
  251. ;; \
  252. esac; \
  253. done
  254. endef
  255. # Various utility functions used by the external toolchain package
  256. # infrastructure. Those functions are mainly responsible for:
  257. #
  258. # - installation the toolchain libraries to $(TARGET_DIR)
  259. # - copying the toolchain sysroot to $(STAGING_DIR)
  260. # - installing a gdbinit file
  261. #
  262. # Details about sysroot directory selection.
  263. #
  264. # To find the sysroot directory, we use the trick of looking for the
  265. # 'libc.a' file with the -print-file-name gcc option, and then
  266. # mangling the path to find the base directory of the sysroot.
  267. #
  268. # Note that we do not use the -print-sysroot option, because it is
  269. # only available since gcc 4.4.x, and we only recently dropped support
  270. # for 4.2.x and 4.3.x.
  271. #
  272. # When doing this, we don't pass any option to gcc that could select a
  273. # multilib variant (such as -march) as we want the "main" sysroot,
  274. # which contains all variants of the C library in the case of multilib
  275. # toolchains. We use the TARGET_CC_NO_SYSROOT variable, which is the
  276. # path of the cross-compiler, without the --sysroot=$(STAGING_DIR),
  277. # since what we want to find is the location of the original toolchain
  278. # sysroot. This "main" sysroot directory is stored in SYSROOT_DIR.
  279. #
  280. # Then, multilib toolchains are a little bit more complicated, since
  281. # they in fact have multiple sysroots, one for each variant supported
  282. # by the toolchain. So we need to find the particular sysroot we're
  283. # interested in.
  284. #
  285. # To do so, we ask the compiler where its sysroot is by passing all
  286. # flags (including -march and al.), except the --sysroot flag since we
  287. # want to the compiler to tell us where its original sysroot
  288. # is. ARCH_SUBDIR will contain the subdirectory, in the main
  289. # SYSROOT_DIR, that corresponds to the selected architecture
  290. # variant. ARCH_SYSROOT_DIR will contain the full path to this
  291. # location.
  292. #
  293. # One might wonder why we don't just bother with ARCH_SYSROOT_DIR. The
  294. # fact is that in multilib toolchains, the header files are often only
  295. # present in the main sysroot, and only the libraries are available in
  296. # each variant-specific sysroot directory.
  297. # toolchain_find_sysroot returns the sysroot location for the given
  298. # compiler + flags. We need to handle cases where libc.a is in:
  299. #
  300. # - lib/
  301. # - usr/lib/
  302. # - lib32/
  303. # - lib64/
  304. # - lib32-fp/ (Cavium toolchain)
  305. # - lib64-fp/ (Cavium toolchain)
  306. # - usr/lib/<tuple>/ (Linaro toolchain)
  307. #
  308. # And variations on these.
  309. define toolchain_find_sysroot
  310. $$(printf $(call toolchain_find_libc_a,$(1)) | sed -r -e 's:(usr/)?lib(32|64)?([^/]*)?/([^/]*/)?libc\.a::')
  311. endef
  312. # Returns the lib subdirectory for the given compiler + flags (i.e
  313. # typically lib32 or lib64 for some toolchains)
  314. define toolchain_find_libdir
  315. $$(printf $(call toolchain_find_libc_a,$(1)) | sed -r -e 's:.*/(usr/)?(lib(32|64)?([^/]*)?(/[^/]*)?)/libc.a:\2:')
  316. endef
  317. # Returns the location of the libc.a file for the given compiler + flags
  318. define toolchain_find_libc_a
  319. $$(readlink -f $$(LANG=C $(1) -print-file-name=libc.a))
  320. endef
  321. # Integration of the toolchain into Buildroot: find the main sysroot
  322. # and the variant-specific sysroot, then copy the needed libraries to
  323. # the $(TARGET_DIR) and copy the whole sysroot (libraries and headers)
  324. # to $(STAGING_DIR).
  325. #
  326. # Variables are defined as follows:
  327. #
  328. # SYSROOT_DIR: the main sysroot directory, deduced from the location of
  329. # the libc.a file in the default multilib variant, by
  330. # removing the usr/lib[32|64]/libc.a part of the path.
  331. # Ex: /x-tools/mips-2011.03/mips-linux-gnu/libc/
  332. #
  333. # ARCH_SYSROOT_DIR: the sysroot of the selected multilib variant,
  334. # deduced from the location of the libc.a file in the
  335. # selected multilib variant (taking into account the
  336. # CFLAGS), by removing usr/lib[32|64]/libc.a at the end
  337. # of the path.
  338. # Ex: /x-tools/mips-2011.03/mips-linux-gnu/libc/mips16/soft-float/el/
  339. #
  340. # ARCH_LIB_DIR: 'lib', 'lib32' or 'lib64' depending on where libraries
  341. # are stored. Deduced from the location of the libc.a file
  342. # in the selected multilib variant, by looking at
  343. # usr/lib??/libc.a.
  344. # Ex: lib
  345. #
  346. # ARCH_SUBDIR: the relative location of the sysroot of the selected
  347. # multilib variant compared to the main sysroot.
  348. # Ex: mips16/soft-float/el
  349. #
  350. # SUPPORT_LIB_DIR: some toolchains, such as recent Linaro toolchains,
  351. # store GCC support libraries (libstdc++,
  352. # libgcc_s, etc.) outside of the sysroot. In
  353. # this case, SUPPORT_LIB_DIR is set to a
  354. # non-empty value, and points to the directory
  355. # where these support libraries are
  356. # available. Those libraries will be copied to
  357. # our sysroot, and the directory will also be
  358. # considered when searching libraries for copy
  359. # to the target filesystem.
  360. #
  361. # Please be very careful to check the major toolchain sources:
  362. # Buildroot, Crosstool-NG, CodeSourcery and Linaro
  363. # before doing any modification on the below logic.
  364. ifeq ($(BR2_STATIC_LIBS),)
  365. define TOOLCHAIN_EXTERNAL_INSTALL_TARGET_LIBS
  366. $(Q)$(call MESSAGE,"Copying external toolchain libraries to target...")
  367. $(Q)for libpattern in $(TOOLCHAIN_EXTERNAL_LIBS); do \
  368. $(call copy_toolchain_lib_root,$$libpattern); \
  369. done
  370. endef
  371. endif
  372. ifeq ($(BR2_TOOLCHAIN_EXTERNAL_GDB_SERVER_COPY),y)
  373. define TOOLCHAIN_EXTERNAL_INSTALL_TARGET_GDBSERVER
  374. $(Q)$(call MESSAGE,"Copying gdbserver")
  375. $(Q)ARCH_SYSROOT_DIR="$(call toolchain_find_sysroot,$(TOOLCHAIN_EXTERNAL_CC) $(TOOLCHAIN_EXTERNAL_CFLAGS))" ; \
  376. ARCH_LIB_DIR="$(call toolchain_find_libdir,$(TOOLCHAIN_EXTERNAL_CC) $(TOOLCHAIN_EXTERNAL_CFLAGS))" ; \
  377. gdbserver_found=0 ; \
  378. for d in $${ARCH_SYSROOT_DIR}/usr \
  379. $${ARCH_SYSROOT_DIR}/../debug-root/usr \
  380. $${ARCH_SYSROOT_DIR}/usr/$${ARCH_LIB_DIR} \
  381. $(TOOLCHAIN_EXTERNAL_INSTALL_DIR); do \
  382. if test -f $${d}/bin/gdbserver ; then \
  383. install -m 0755 -D $${d}/bin/gdbserver $(TARGET_DIR)/usr/bin/gdbserver ; \
  384. gdbserver_found=1 ; \
  385. break ; \
  386. fi ; \
  387. done ; \
  388. if [ $${gdbserver_found} -eq 0 ] ; then \
  389. echo "Could not find gdbserver in external toolchain" ; \
  390. exit 1 ; \
  391. fi
  392. endef
  393. endif
  394. define TOOLCHAIN_EXTERNAL_INSTALL_SYSROOT_LIBS
  395. $(Q)SYSROOT_DIR="$(call toolchain_find_sysroot,$(TOOLCHAIN_EXTERNAL_CC))" ; \
  396. ARCH_SYSROOT_DIR="$(call toolchain_find_sysroot,$(TOOLCHAIN_EXTERNAL_CC) $(TOOLCHAIN_EXTERNAL_CFLAGS))" ; \
  397. ARCH_LIB_DIR="$(call toolchain_find_libdir,$(TOOLCHAIN_EXTERNAL_CC) $(TOOLCHAIN_EXTERNAL_CFLAGS))" ; \
  398. SUPPORT_LIB_DIR="" ; \
  399. if test `find $${ARCH_SYSROOT_DIR} -name 'libstdc++.a' | wc -l` -eq 0 ; then \
  400. LIBSTDCPP_A_LOCATION=$$(LANG=C $(TOOLCHAIN_EXTERNAL_CC) $(TOOLCHAIN_EXTERNAL_CFLAGS) -print-file-name=libstdc++.a) ; \
  401. if [ -e "$${LIBSTDCPP_A_LOCATION}" ]; then \
  402. SUPPORT_LIB_DIR=`readlink -f $${LIBSTDCPP_A_LOCATION} | sed -r -e 's:libstdc\+\+\.a::'` ; \
  403. fi ; \
  404. fi ; \
  405. if [ "$${SYSROOT_DIR}" == "$${ARCH_SYSROOT_DIR}" ] ; then \
  406. ARCH_SUBDIR="" ; \
  407. elif [ "`dirname $${ARCH_SYSROOT_DIR}`" = "`dirname $${SYSROOT_DIR}`" ] ; then \
  408. SYSROOT_DIR_DIRNAME=`dirname $${SYSROOT_DIR}`/ ; \
  409. ARCH_SUBDIR=`echo $${ARCH_SYSROOT_DIR} | sed -r -e "s:^$${SYSROOT_DIR_DIRNAME}(.*)/$$:\1:"` ; \
  410. else \
  411. ARCH_SUBDIR=`echo $${ARCH_SYSROOT_DIR} | sed -r -e "s:^$${SYSROOT_DIR}(.*)/$$:\1:"` ; \
  412. fi ; \
  413. $(call MESSAGE,"Copying external toolchain sysroot to staging...") ; \
  414. $(call copy_toolchain_sysroot,$${SYSROOT_DIR},$${ARCH_SYSROOT_DIR},$${ARCH_SUBDIR},$${ARCH_LIB_DIR},$${SUPPORT_LIB_DIR})
  415. endef
  416. # Create a symlink from (usr/)$(ARCH_LIB_DIR) to lib.
  417. # Note: the skeleton package additionally creates lib32->lib or lib64->lib
  418. # (as appropriate)
  419. #
  420. # $1: destination directory (TARGET_DIR / STAGING_DIR)
  421. create_lib_symlinks = \
  422. $(Q)DESTDIR="$(strip $1)" ; \
  423. ARCH_LIB_DIR="$(call toolchain_find_libdir,$(TOOLCHAIN_EXTERNAL_CC) $(TOOLCHAIN_EXTERNAL_CFLAGS))" ; \
  424. if [ ! -e "$${DESTDIR}/$${ARCH_LIB_DIR}" -a ! -e "$${DESTDIR}/usr/$${ARCH_LIB_DIR}" ]; then \
  425. relpath="$(call relpath_prefix,$${ARCH_LIB_DIR})" ; \
  426. ln -snf $${relpath}lib "$${DESTDIR}/$${ARCH_LIB_DIR}" ; \
  427. ln -snf $${relpath}lib "$${DESTDIR}/usr/$${ARCH_LIB_DIR}" ; \
  428. fi
  429. define TOOLCHAIN_EXTERNAL_CREATE_STAGING_LIB_SYMLINK
  430. $(call create_lib_symlinks,$(STAGING_DIR))
  431. endef
  432. define TOOLCHAIN_EXTERNAL_CREATE_TARGET_LIB_SYMLINK
  433. $(call create_lib_symlinks,$(TARGET_DIR))
  434. endef
  435. #
  436. # Generate gdbinit file for use with Buildroot
  437. #
  438. define TOOLCHAIN_EXTERNAL_INSTALL_GDBINIT
  439. $(Q)if test -f $(TARGET_CROSS)gdb ; then \
  440. $(call MESSAGE,"Installing gdbinit"); \
  441. $(gen_gdbinit_file); \
  442. fi
  443. endef
  444. # uClibc-ng dynamic loader is called ld-uClibc.so.1, but gcc is not
  445. # patched specifically for uClibc-ng, so it continues to generate
  446. # binaries that expect the dynamic loader to be named ld-uClibc.so.0,
  447. # like with the original uClibc. Therefore, we create an additional
  448. # symbolic link to make uClibc-ng systems work properly.
  449. define TOOLCHAIN_EXTERNAL_FIXUP_UCLIBCNG_LDSO
  450. $(Q)if test -e $(TARGET_DIR)/lib/ld-uClibc.so.1; then \
  451. ln -sf ld-uClibc.so.1 $(TARGET_DIR)/lib/ld-uClibc.so.0 ; \
  452. fi
  453. $(Q)if test -e $(TARGET_DIR)/lib/ld64-uClibc.so.1; then \
  454. ln -sf ld64-uClibc.so.1 $(TARGET_DIR)/lib/ld64-uClibc.so.0 ; \
  455. fi
  456. endef
  457. ################################################################################
  458. # inner-toolchain-external-package -- defines the generic installation rules
  459. # for external toolchain packages
  460. #
  461. # argument 1 is the lowercase package name
  462. # argument 2 is the uppercase package name, including a HOST_ prefix
  463. # for host packages
  464. # argument 3 is the uppercase package name, without the HOST_ prefix
  465. # for host packages
  466. # argument 4 is the type (target or host)
  467. ################################################################################
  468. define inner-toolchain-external-package
  469. $(2)_INSTALL_STAGING = YES
  470. $(2)_ADD_TOOLCHAIN_DEPENDENCY = NO
  471. # In fact, we don't need to download the toolchain, since it is already
  472. # available on the system, so force the site and source to be empty so
  473. # that nothing will be downloaded/extracted.
  474. ifeq ($$(BR2_TOOLCHAIN_EXTERNAL_PREINSTALLED),y)
  475. $(2)_SITE =
  476. $(2)_SOURCE =
  477. endif
  478. ifeq ($$(BR2_TOOLCHAIN_EXTERNAL_DOWNLOAD),y)
  479. $(2)_EXCLUDES = usr/lib/locale/*
  480. $(2)_POST_EXTRACT_HOOKS += \
  481. TOOLCHAIN_EXTERNAL_MOVE
  482. endif
  483. # Checks for an already installed toolchain: check the toolchain
  484. # location, check that it is usable, and then verify that it
  485. # matches the configuration provided in Buildroot: ABI, C++ support,
  486. # kernel headers version, type of C library and all C library features.
  487. define $(2)_CONFIGURE_CMDS
  488. $$(Q)$$(call check_cross_compiler_exists,$$(TOOLCHAIN_EXTERNAL_CC))
  489. $$(Q)$$(call check_unusable_toolchain,$$(TOOLCHAIN_EXTERNAL_CC))
  490. $$(Q)SYSROOT_DIR="$$(call toolchain_find_sysroot,$$(TOOLCHAIN_EXTERNAL_CC))" ; \
  491. $$(call check_kernel_headers_version,\
  492. $$(call toolchain_find_sysroot,$$(TOOLCHAIN_EXTERNAL_CC)),\
  493. $$(call qstrip,$$(BR2_TOOLCHAIN_HEADERS_AT_LEAST))); \
  494. $$(call check_gcc_version,$$(TOOLCHAIN_EXTERNAL_CC),\
  495. $$(call qstrip,$$(BR2_TOOLCHAIN_GCC_AT_LEAST))); \
  496. if test "$$(BR2_arm)" = "y" ; then \
  497. $$(call check_arm_abi,\
  498. "$$(TOOLCHAIN_EXTERNAL_CC) $$(TOOLCHAIN_EXTERNAL_CFLAGS)") ; \
  499. fi ; \
  500. if test "$$(BR2_INSTALL_LIBSTDCPP)" = "y" ; then \
  501. $$(call check_cplusplus,$$(TOOLCHAIN_EXTERNAL_CXX)) ; \
  502. fi ; \
  503. if test "$$(BR2_TOOLCHAIN_HAS_FORTRAN)" = "y" ; then \
  504. $$(call check_fortran,$$(TOOLCHAIN_EXTERNAL_FC)) ; \
  505. fi ; \
  506. if test "$$(BR2_TOOLCHAIN_EXTERNAL_UCLIBC)" = "y" ; then \
  507. $$(call check_uclibc,$$$${SYSROOT_DIR}) ; \
  508. elif test "$$(BR2_TOOLCHAIN_EXTERNAL_MUSL)" = "y" ; then \
  509. $$(call check_musl,\
  510. "$$(TOOLCHAIN_EXTERNAL_CC) $$(TOOLCHAIN_EXTERNAL_CFLAGS)") ; \
  511. else \
  512. $$(call check_glibc,$$$${SYSROOT_DIR}) ; \
  513. fi
  514. $$(Q)$$(call check_toolchain_ssp,$$(TOOLCHAIN_EXTERNAL_CC))
  515. endef
  516. $(2)_TOOLCHAIN_WRAPPER_ARGS += $$(TOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS)
  517. $(2)_BUILD_CMDS = $$(TOOLCHAIN_WRAPPER_BUILD)
  518. define $(2)_INSTALL_STAGING_CMDS
  519. $$(TOOLCHAIN_WRAPPER_INSTALL)
  520. $$(TOOLCHAIN_EXTERNAL_CREATE_STAGING_LIB_SYMLINK)
  521. $$(TOOLCHAIN_EXTERNAL_INSTALL_SYSROOT_LIBS)
  522. $$(TOOLCHAIN_EXTERNAL_INSTALL_WRAPPER)
  523. $$(TOOLCHAIN_EXTERNAL_INSTALL_GDBINIT)
  524. endef
  525. # Even though we're installing things in both the staging, the host
  526. # and the target directory, we do everything within the
  527. # install-staging step, arbitrarily.
  528. define $(2)_INSTALL_TARGET_CMDS
  529. $$(TOOLCHAIN_EXTERNAL_CREATE_TARGET_LIB_SYMLINK)
  530. $$(TOOLCHAIN_EXTERNAL_INSTALL_TARGET_LIBS)
  531. $$(TOOLCHAIN_EXTERNAL_INSTALL_TARGET_GDBSERVER)
  532. $$(TOOLCHAIN_EXTERNAL_FIXUP_UCLIBCNG_LDSO)
  533. endef
  534. # Call the generic package infrastructure to generate the necessary
  535. # make targets
  536. $(call inner-generic-package,$(1),$(2),$(3),$(4))
  537. endef
  538. toolchain-external-package = $(call inner-toolchain-external-package,$(pkgname),$(call UPPERCASE,$(pkgname)),$(call UPPERCASE,$(pkgname)),target)