pkg-toolchain-external.mk 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611
  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_GDC = $(TOOLCHAIN_EXTERNAL_CROSS)gdc$(TOOLCHAIN_EXTERNAL_SUFFIX)
  91. TOOLCHAIN_EXTERNAL_FC = $(TOOLCHAIN_EXTERNAL_CROSS)gfortran$(TOOLCHAIN_EXTERNAL_SUFFIX)
  92. TOOLCHAIN_EXTERNAL_READELF = $(TOOLCHAIN_EXTERNAL_CROSS)readelf
  93. # Normal handling of downloaded toolchain tarball extraction.
  94. ifeq ($(BR2_TOOLCHAIN_EXTERNAL_DOWNLOAD),y)
  95. # As a regular package, the toolchain gets extracted in $(@D), but
  96. # since it's actually a fairly special package, we need it to be moved
  97. # into TOOLCHAIN_EXTERNAL_DOWNLOAD_INSTALL_DIR.
  98. define TOOLCHAIN_EXTERNAL_MOVE
  99. rm -rf $(TOOLCHAIN_EXTERNAL_DOWNLOAD_INSTALL_DIR)
  100. mkdir -p $(TOOLCHAIN_EXTERNAL_DOWNLOAD_INSTALL_DIR)
  101. mv $(@D)/* $(TOOLCHAIN_EXTERNAL_DOWNLOAD_INSTALL_DIR)/
  102. endef
  103. endif
  104. #
  105. # Definitions of the list of libraries that should be copied to the target.
  106. #
  107. TOOLCHAIN_EXTERNAL_LIBS += ld*.so.* libgcc_s.so.* libatomic.so.*
  108. ifneq ($(BR2_SSP_NONE),y)
  109. TOOLCHAIN_EXTERNAL_LIBS += libssp.so.*
  110. endif
  111. ifeq ($(BR2_TOOLCHAIN_EXTERNAL_GLIBC)$(BR2_TOOLCHAIN_EXTERNAL_UCLIBC),y)
  112. TOOLCHAIN_EXTERNAL_LIBS += libc.so.* libcrypt.so.* libdl.so.* libm.so.* libnsl.so.* libresolv.so.* librt.so.* libutil.so.*
  113. ifeq ($(BR2_TOOLCHAIN_HAS_THREADS),y)
  114. TOOLCHAIN_EXTERNAL_LIBS += libpthread.so.*
  115. ifneq ($(BR2_PACKAGE_GDB)$(BR2_TOOLCHAIN_EXTERNAL_GDB_SERVER_COPY),)
  116. TOOLCHAIN_EXTERNAL_LIBS += libthread_db.so.*
  117. endif # gdbserver
  118. endif # ! no threads
  119. endif
  120. ifeq ($(BR2_TOOLCHAIN_EXTERNAL_GLIBC),y)
  121. TOOLCHAIN_EXTERNAL_LIBS += libnss_files.so.* libnss_dns.so.* libmvec.so.* libanl.so.*
  122. endif
  123. ifeq ($(BR2_TOOLCHAIN_EXTERNAL_MUSL),y)
  124. TOOLCHAIN_EXTERNAL_LIBS += libc.so
  125. endif
  126. ifeq ($(BR2_INSTALL_LIBSTDCPP),y)
  127. TOOLCHAIN_EXTERNAL_LIBS += libstdc++.so.*
  128. endif
  129. ifeq ($(BR2_TOOLCHAIN_HAS_FORTRAN),y)
  130. TOOLCHAIN_EXTERNAL_LIBS += libgfortran.so.*
  131. # fortran needs quadmath on x86 and x86_64
  132. ifeq ($(BR2_TOOLCHAIN_HAS_LIBQUADMATH),y)
  133. TOOLCHAIN_EXTERNAL_LIBS += libquadmath.so*
  134. endif
  135. endif
  136. ifeq ($(BR2_TOOLCHAIN_HAS_OPENMP),y)
  137. TOOLCHAIN_EXTERNAL_LIBS += libgomp.so.*
  138. endif
  139. ifeq ($(BR2_TOOLCHAIN_HAS_DLANG),y)
  140. TOOLCHAIN_EXTERNAL_LIBS += libgdruntime.so* libgphobos.so*
  141. endif
  142. TOOLCHAIN_EXTERNAL_LIBS += $(addsuffix .so*,$(call qstrip,$(BR2_TOOLCHAIN_EXTRA_LIBS)))
  143. #
  144. # Definition of the CFLAGS to use with the external toolchain, as well as the
  145. # common toolchain wrapper build arguments
  146. #
  147. # march/mtune/floating point mode needs to be passed to the external toolchain
  148. # to select the right multilib variant
  149. ifeq ($(BR2_x86_64),y)
  150. TOOLCHAIN_EXTERNAL_CFLAGS += -m64
  151. TOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS += -DBR_64
  152. endif
  153. ifneq ($(GCC_TARGET_ARCH),)
  154. TOOLCHAIN_EXTERNAL_CFLAGS += -march=$(GCC_TARGET_ARCH)
  155. TOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS += -DBR_ARCH='"$(GCC_TARGET_ARCH)"'
  156. endif
  157. #ifneq ($(GCC_TARGET_CPU),)
  158. #TOOLCHAIN_EXTERNAL_CFLAGS += -mcpu=$(GCC_TARGET_CPU)
  159. #TOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS += -DBR_CPU='"$(GCC_TARGET_CPU)"'
  160. #endif
  161. ifneq ($(GCC_TARGET_ABI),)
  162. TOOLCHAIN_EXTERNAL_CFLAGS += -mabi=$(GCC_TARGET_ABI)
  163. TOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS += -DBR_ABI='"$(GCC_TARGET_ABI)"'
  164. endif
  165. ifeq ($(BR2_TOOLCHAIN_HAS_MNAN_OPTION),y)
  166. ifneq ($(GCC_TARGET_NAN),)
  167. TOOLCHAIN_EXTERNAL_CFLAGS += -mnan=$(GCC_TARGET_NAN)
  168. TOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS += -DBR_NAN='"$(GCC_TARGET_NAN)"'
  169. endif
  170. endif
  171. ifneq ($(GCC_TARGET_FP32_MODE),)
  172. TOOLCHAIN_EXTERNAL_CFLAGS += -mfp$(GCC_TARGET_FP32_MODE)
  173. TOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS += -DBR_FP32_MODE='"$(GCC_TARGET_FP32_MODE)"'
  174. endif
  175. ifneq ($(GCC_TARGET_FPU),)
  176. TOOLCHAIN_EXTERNAL_CFLAGS += -mfpu=$(GCC_TARGET_FPU)
  177. TOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS += -DBR_FPU='"$(GCC_TARGET_FPU)"'
  178. endif
  179. ifneq ($(GCC_TARGET_FLOAT_ABI),)
  180. TOOLCHAIN_EXTERNAL_CFLAGS += -mfloat-abi=$(GCC_TARGET_FLOAT_ABI)
  181. TOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS += -DBR_FLOAT_ABI='"$(GCC_TARGET_FLOAT_ABI)"'
  182. endif
  183. ifneq ($(GCC_TARGET_MODE),)
  184. TOOLCHAIN_EXTERNAL_CFLAGS += -m$(GCC_TARGET_MODE)
  185. TOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS += -DBR_MODE='"$(GCC_TARGET_MODE)"'
  186. endif
  187. ifeq ($(BR2_BINFMT_FLAT),y)
  188. TOOLCHAIN_EXTERNAL_CFLAGS += -Wl,-elf2flt
  189. TOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS += -DBR_BINFMT_FLAT
  190. endif
  191. ifeq ($(BR2_mipsel)$(BR2_mips64el),y)
  192. TOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS += -DBR_MIPS_TARGET_LITTLE_ENDIAN
  193. TOOLCHAIN_EXTERNAL_CFLAGS += -EL
  194. endif
  195. ifeq ($(BR2_mips)$(BR2_mips64),y)
  196. TOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS += -DBR_MIPS_TARGET_BIG_ENDIAN
  197. TOOLCHAIN_EXTERNAL_CFLAGS += -EB
  198. endif
  199. ifeq ($(BR2_arceb),y)
  200. TOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS += -DBR_ARC_TARGET_BIG_ENDIAN
  201. TOOLCHAIN_EXTERNAL_CFLAGS += -EB
  202. endif
  203. TOOLCHAIN_EXTERNAL_CFLAGS += $(call qstrip,$(BR2_TARGET_OPTIMIZATION))
  204. ifeq ($(BR2_SOFT_FLOAT),y)
  205. TOOLCHAIN_EXTERNAL_CFLAGS += -msoft-float
  206. TOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS += -DBR_SOFTFLOAT=1
  207. endif
  208. TOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS += \
  209. -DBR_CROSS_PATH_SUFFIX='"$(TOOLCHAIN_EXTERNAL_SUFFIX)"'
  210. ifeq ($(filter $(HOST_DIR)/%,$(TOOLCHAIN_EXTERNAL_BIN)),)
  211. # TOOLCHAIN_EXTERNAL_BIN points outside HOST_DIR => absolute path
  212. TOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS += \
  213. -DBR_CROSS_PATH_ABS='"$(TOOLCHAIN_EXTERNAL_BIN)"'
  214. else
  215. # TOOLCHAIN_EXTERNAL_BIN points inside HOST_DIR => relative path
  216. TOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS += \
  217. -DBR_CROSS_PATH_REL='"$(TOOLCHAIN_EXTERNAL_BIN:$(HOST_DIR)/%=%)"'
  218. endif
  219. #
  220. # The following functions creates the symbolic links needed to get the
  221. # cross-compilation tools visible in $(HOST_DIR)/bin. Some of
  222. # links are done directly to the corresponding tool in the external
  223. # toolchain installation directory, while some other links are done to
  224. # the toolchain wrapper (preprocessor, C, C++ and Fortran compiler)
  225. #
  226. # We skip gdb symlink when we are building our own gdb to prevent two
  227. # gdb's in $(HOST_DIR)/bin.
  228. #
  229. # The LTO support in gcc creates wrappers for ar, ranlib and nm which load
  230. # the lto plugin. These wrappers are called *-gcc-ar, *-gcc-ranlib, and
  231. # *-gcc-nm and should be used instead of the real programs when -flto is
  232. # used. However, we should not add the toolchain wrapper for them, and they
  233. # match the *cc-* pattern. Therefore, an additional case is added for *-ar,
  234. # *-ranlib and *-nm.
  235. define TOOLCHAIN_EXTERNAL_INSTALL_WRAPPER
  236. $(Q)cd $(HOST_DIR)/bin; \
  237. for i in $(TOOLCHAIN_EXTERNAL_CROSS)*; do \
  238. base=$${i##*/}; \
  239. case "$$base" in \
  240. *-ar|*-ranlib|*-nm) \
  241. ln -sf $$(echo $$i | sed 's%^$(HOST_DIR)%..%') .; \
  242. ;; \
  243. *cc|*cc-*|*++|*++-*|*cpp|*-gfortran|*-gdc) \
  244. ln -sf toolchain-wrapper $$base; \
  245. ;; \
  246. *gdb|*gdbtui) \
  247. if test "$(BR2_PACKAGE_HOST_GDB)" != "y"; then \
  248. ln -sf $$(echo $$i | sed 's%^$(HOST_DIR)%..%') .; \
  249. fi \
  250. ;; \
  251. *) \
  252. ln -sf $$(echo $$i | sed 's%^$(HOST_DIR)%..%') .; \
  253. ;; \
  254. esac; \
  255. done
  256. endef
  257. # Various utility functions used by the external toolchain package
  258. # infrastructure. Those functions are mainly responsible for:
  259. #
  260. # - installation the toolchain libraries to $(TARGET_DIR)
  261. # - copying the toolchain sysroot to $(STAGING_DIR)
  262. # - installing a gdbinit file
  263. #
  264. # Details about sysroot directory selection.
  265. #
  266. # To find the sysroot directory, we use the trick of looking for the
  267. # 'libc.a' file with the -print-file-name gcc option, and then
  268. # mangling the path to find the base directory of the sysroot.
  269. #
  270. # Note that we do not use the -print-sysroot option, because it is
  271. # only available since gcc 4.4.x, and we only recently dropped support
  272. # for 4.2.x and 4.3.x.
  273. #
  274. # When doing this, we don't pass any option to gcc that could select a
  275. # multilib variant (such as -march) as we want the "main" sysroot,
  276. # which contains all variants of the C library in the case of multilib
  277. # toolchains. We use the TARGET_CC_NO_SYSROOT variable, which is the
  278. # path of the cross-compiler, without the --sysroot=$(STAGING_DIR),
  279. # since what we want to find is the location of the original toolchain
  280. # sysroot. This "main" sysroot directory is stored in SYSROOT_DIR.
  281. #
  282. # Then, multilib toolchains are a little bit more complicated, since
  283. # they in fact have multiple sysroots, one for each variant supported
  284. # by the toolchain. So we need to find the particular sysroot we're
  285. # interested in.
  286. #
  287. # To do so, we ask the compiler where its sysroot is by passing all
  288. # flags (including -march and al.), except the --sysroot flag since we
  289. # want to the compiler to tell us where its original sysroot
  290. # is. ARCH_SUBDIR will contain the subdirectory, in the main
  291. # SYSROOT_DIR, that corresponds to the selected architecture
  292. # variant. ARCH_SYSROOT_DIR will contain the full path to this
  293. # location.
  294. #
  295. # One might wonder why we don't just bother with ARCH_SYSROOT_DIR. The
  296. # fact is that in multilib toolchains, the header files are often only
  297. # present in the main sysroot, and only the libraries are available in
  298. # each variant-specific sysroot directory.
  299. # toolchain_find_sysroot returns the sysroot location for the given
  300. # compiler + flags. We need to handle cases where libc.a is in:
  301. #
  302. # - lib/
  303. # - usr/lib/
  304. # - lib32/
  305. # - lib64/
  306. # - lib32-fp/ (Cavium toolchain)
  307. # - lib64-fp/ (Cavium toolchain)
  308. # - usr/lib/<tuple>/ (Linaro toolchain)
  309. #
  310. # And variations on these.
  311. define toolchain_find_sysroot
  312. $$(printf $(call toolchain_find_libc_a,$(1)) | sed -r -e 's:/(usr/)?lib(32|64)?([^/]*)?/([^/]*/)?libc\.a:/:')
  313. endef
  314. # Returns the lib subdirectory for the given compiler + flags (i.e
  315. # typically lib32 or lib64 for some toolchains)
  316. define toolchain_find_libdir
  317. $$(printf $(call toolchain_find_libc_a,$(1)) | sed -r -e 's:.*/(usr/)?(lib(32|64)?([^/]*)?(/[^/]*)?)/libc.a:\2:')
  318. endef
  319. # Returns the location of the libc.a file for the given compiler + flags
  320. define toolchain_find_libc_a
  321. $$(readlink -f $$(LANG=C $(1) -print-file-name=libc.a))
  322. endef
  323. # Integration of the toolchain into Buildroot: find the main sysroot
  324. # and the variant-specific sysroot, then copy the needed libraries to
  325. # the $(TARGET_DIR) and copy the whole sysroot (libraries and headers)
  326. # to $(STAGING_DIR).
  327. #
  328. # Variables are defined as follows:
  329. #
  330. # SYSROOT_DIR: the main sysroot directory, deduced from the location of
  331. # the libc.a file in the default multilib variant, by
  332. # removing the usr/lib[32|64]/libc.a part of the path.
  333. # Ex: /x-tools/mips-2011.03/mips-linux-gnu/libc/
  334. #
  335. # ARCH_SYSROOT_DIR: the sysroot of the selected multilib variant,
  336. # deduced from the location of the libc.a file in the
  337. # selected multilib variant (taking into account the
  338. # CFLAGS), by removing usr/lib[32|64]/libc.a at the end
  339. # of the path.
  340. # Ex: /x-tools/mips-2011.03/mips-linux-gnu/libc/mips16/soft-float/el/
  341. #
  342. # ARCH_LIB_DIR: 'lib', 'lib32' or 'lib64' depending on where libraries
  343. # are stored. Deduced from the location of the libc.a file
  344. # in the selected multilib variant, by looking at
  345. # usr/lib??/libc.a.
  346. # Ex: lib
  347. #
  348. # ARCH_SUBDIR: the relative location of the sysroot of the selected
  349. # multilib variant compared to the main sysroot.
  350. # Ex: mips16/soft-float/el
  351. #
  352. # SUPPORT_LIB_DIR: some toolchains, such as recent Linaro toolchains,
  353. # store GCC support libraries (libstdc++,
  354. # libgcc_s, etc.) outside of the sysroot. In
  355. # this case, SUPPORT_LIB_DIR is set to a
  356. # non-empty value, and points to the directory
  357. # where these support libraries are
  358. # available. Those libraries will be copied to
  359. # our sysroot, and the directory will also be
  360. # considered when searching libraries for copy
  361. # to the target filesystem.
  362. #
  363. # Please be very careful to check the major toolchain sources:
  364. # Buildroot, Crosstool-NG, CodeSourcery and Linaro
  365. # before doing any modification on the below logic.
  366. ifeq ($(BR2_STATIC_LIBS),)
  367. define TOOLCHAIN_EXTERNAL_INSTALL_TARGET_LIBS
  368. $(Q)$(call MESSAGE,"Copying external toolchain libraries to target...")
  369. $(Q)for libpattern in $(TOOLCHAIN_EXTERNAL_LIBS); do \
  370. $(call copy_toolchain_lib_root,$$libpattern); \
  371. done
  372. endef
  373. endif
  374. ifeq ($(BR2_TOOLCHAIN_EXTERNAL_GDB_SERVER_COPY),y)
  375. define TOOLCHAIN_EXTERNAL_INSTALL_TARGET_GDBSERVER
  376. $(Q)$(call MESSAGE,"Copying gdbserver")
  377. $(Q)ARCH_SYSROOT_DIR="$(call toolchain_find_sysroot,$(TOOLCHAIN_EXTERNAL_CC) $(TOOLCHAIN_EXTERNAL_CFLAGS))" ; \
  378. ARCH_LIB_DIR="$(call toolchain_find_libdir,$(TOOLCHAIN_EXTERNAL_CC) $(TOOLCHAIN_EXTERNAL_CFLAGS))" ; \
  379. gdbserver_found=0 ; \
  380. for d in $${ARCH_SYSROOT_DIR}/usr \
  381. $${ARCH_SYSROOT_DIR}/../debug-root/usr \
  382. $${ARCH_SYSROOT_DIR}/usr/$${ARCH_LIB_DIR} \
  383. $(TOOLCHAIN_EXTERNAL_INSTALL_DIR); do \
  384. if test -f $${d}/bin/gdbserver ; then \
  385. install -m 0755 -D $${d}/bin/gdbserver $(TARGET_DIR)/usr/bin/gdbserver ; \
  386. gdbserver_found=1 ; \
  387. break ; \
  388. fi ; \
  389. done ; \
  390. if [ $${gdbserver_found} -eq 0 ] ; then \
  391. echo "Could not find gdbserver in external toolchain" ; \
  392. exit 1 ; \
  393. fi
  394. endef
  395. endif
  396. define TOOLCHAIN_EXTERNAL_INSTALL_SYSROOT_LIBS
  397. $(Q)SYSROOT_DIR="$(call toolchain_find_sysroot,$(TOOLCHAIN_EXTERNAL_CC))" ; \
  398. ARCH_SYSROOT_DIR="$(call toolchain_find_sysroot,$(TOOLCHAIN_EXTERNAL_CC) $(TOOLCHAIN_EXTERNAL_CFLAGS))" ; \
  399. ARCH_LIB_DIR="$(call toolchain_find_libdir,$(TOOLCHAIN_EXTERNAL_CC) $(TOOLCHAIN_EXTERNAL_CFLAGS))" ; \
  400. SUPPORT_LIB_DIR="" ; \
  401. if test `find $${ARCH_SYSROOT_DIR} -name 'libstdc++.a' | wc -l` -eq 0 ; then \
  402. LIBSTDCPP_A_LOCATION=$$(LANG=C $(TOOLCHAIN_EXTERNAL_CC) $(TOOLCHAIN_EXTERNAL_CFLAGS) -print-file-name=libstdc++.a) ; \
  403. if [ -e "$${LIBSTDCPP_A_LOCATION}" ]; then \
  404. SUPPORT_LIB_DIR=`readlink -f $${LIBSTDCPP_A_LOCATION} | sed -r -e 's:libstdc\+\+\.a::'` ; \
  405. fi ; \
  406. fi ; \
  407. if [ "$${SYSROOT_DIR}" == "$${ARCH_SYSROOT_DIR}" ] ; then \
  408. ARCH_SUBDIR="" ; \
  409. elif [ "`dirname $${ARCH_SYSROOT_DIR}`" = "`dirname $${SYSROOT_DIR}`" ] ; then \
  410. SYSROOT_DIR_DIRNAME=`dirname $${SYSROOT_DIR}`/ ; \
  411. ARCH_SUBDIR=`echo $${ARCH_SYSROOT_DIR} | sed -r -e "s:^$${SYSROOT_DIR_DIRNAME}(.*)/$$:\1:"` ; \
  412. else \
  413. ARCH_SUBDIR=`echo $${ARCH_SYSROOT_DIR} | sed -r -e "s:^$${SYSROOT_DIR}(.*)/$$:\1:"` ; \
  414. fi ; \
  415. $(call MESSAGE,"Copying external toolchain sysroot to staging...") ; \
  416. $(call copy_toolchain_sysroot,$${SYSROOT_DIR},$${ARCH_SYSROOT_DIR},$${ARCH_SUBDIR},$${ARCH_LIB_DIR},$${SUPPORT_LIB_DIR})
  417. endef
  418. # Create a symlink from (usr/)$(ARCH_LIB_DIR) to lib.
  419. # Note: the skeleton package additionally creates lib32->lib or lib64->lib
  420. # (as appropriate)
  421. #
  422. # $1: destination directory (TARGET_DIR / STAGING_DIR)
  423. create_lib_symlinks = \
  424. $(Q)DESTDIR="$(strip $1)" ; \
  425. ARCH_LIB_DIR="$(call toolchain_find_libdir,$(TOOLCHAIN_EXTERNAL_CC) $(TOOLCHAIN_EXTERNAL_CFLAGS))" ; \
  426. if [ ! -e "$${DESTDIR}/$${ARCH_LIB_DIR}" -a ! -e "$${DESTDIR}/usr/$${ARCH_LIB_DIR}" ]; then \
  427. relpath="$(call relpath_prefix,$${ARCH_LIB_DIR})" ; \
  428. ln -snf $${relpath}lib "$${DESTDIR}/$${ARCH_LIB_DIR}" ; \
  429. ln -snf $${relpath}lib "$${DESTDIR}/usr/$${ARCH_LIB_DIR}" ; \
  430. fi
  431. define TOOLCHAIN_EXTERNAL_CREATE_STAGING_LIB_SYMLINK
  432. $(call create_lib_symlinks,$(STAGING_DIR))
  433. endef
  434. define TOOLCHAIN_EXTERNAL_CREATE_TARGET_LIB_SYMLINK
  435. $(call create_lib_symlinks,$(TARGET_DIR))
  436. endef
  437. #
  438. # Generate gdbinit file for use with Buildroot
  439. #
  440. define TOOLCHAIN_EXTERNAL_INSTALL_GDBINIT
  441. $(Q)if test -f $(TARGET_CROSS)gdb ; then \
  442. $(call MESSAGE,"Installing gdbinit"); \
  443. $(gen_gdbinit_file); \
  444. fi
  445. endef
  446. # uClibc-ng dynamic loader is called ld-uClibc.so.1, but gcc is not
  447. # patched specifically for uClibc-ng, so it continues to generate
  448. # binaries that expect the dynamic loader to be named ld-uClibc.so.0,
  449. # like with the original uClibc. Therefore, we create an additional
  450. # symbolic link to make uClibc-ng systems work properly.
  451. define TOOLCHAIN_EXTERNAL_FIXUP_UCLIBCNG_LDSO
  452. $(Q)if test -e $(TARGET_DIR)/lib/ld-uClibc.so.1; then \
  453. ln -sf ld-uClibc.so.1 $(TARGET_DIR)/lib/ld-uClibc.so.0 ; \
  454. fi
  455. $(Q)if test -e $(TARGET_DIR)/lib/ld64-uClibc.so.1; then \
  456. ln -sf ld64-uClibc.so.1 $(TARGET_DIR)/lib/ld64-uClibc.so.0 ; \
  457. fi
  458. endef
  459. define TOOLCHAIN_EXTERNAL_INSTALL_TARGET_LDD
  460. $(Q)if test -f $(STAGING_DIR)/usr/bin/ldd ; then \
  461. $(INSTALL) -D $(STAGING_DIR)/usr/bin/ldd $(TARGET_DIR)/usr/bin/ldd ; \
  462. $(SED) 's:.*/bin/bash:#!/bin/sh:' $(TARGET_DIR)/usr/bin/ldd ; \
  463. fi
  464. endef
  465. ################################################################################
  466. # inner-toolchain-external-package -- defines the generic installation rules
  467. # for external toolchain packages
  468. #
  469. # argument 1 is the lowercase package name
  470. # argument 2 is the uppercase package name, including a HOST_ prefix
  471. # for host packages
  472. # argument 3 is the uppercase package name, without the HOST_ prefix
  473. # for host packages
  474. # argument 4 is the type (target or host)
  475. ################################################################################
  476. define inner-toolchain-external-package
  477. $(2)_INSTALL_STAGING = YES
  478. $(2)_ADD_TOOLCHAIN_DEPENDENCY = NO
  479. # In fact, we don't need to download the toolchain, since it is already
  480. # available on the system, so force the site and source to be empty so
  481. # that nothing will be downloaded/extracted.
  482. ifeq ($$(BR2_TOOLCHAIN_EXTERNAL_PREINSTALLED),y)
  483. $(2)_SITE =
  484. $(2)_SOURCE =
  485. endif
  486. ifeq ($$(BR2_TOOLCHAIN_EXTERNAL_DOWNLOAD),y)
  487. $(2)_EXCLUDES = usr/lib/locale/*
  488. $(2)_POST_EXTRACT_HOOKS += \
  489. TOOLCHAIN_EXTERNAL_MOVE
  490. endif
  491. # Checks for an already installed toolchain: check the toolchain
  492. # location, check that it is usable, and then verify that it
  493. # matches the configuration provided in Buildroot: ABI, C++ support,
  494. # kernel headers version, type of C library and all C library features.
  495. define $(2)_CONFIGURE_CMDS
  496. $$(Q)$$(call check_cross_compiler_exists,$$(TOOLCHAIN_EXTERNAL_CC))
  497. $$(Q)$$(call check_unusable_toolchain,$$(TOOLCHAIN_EXTERNAL_CC))
  498. $$(Q)SYSROOT_DIR="$$(call toolchain_find_sysroot,$$(TOOLCHAIN_EXTERNAL_CC))" ; \
  499. $$(call check_kernel_headers_version,\
  500. $$(BUILD_DIR),\
  501. $$(call toolchain_find_sysroot,$$(TOOLCHAIN_EXTERNAL_CC)),\
  502. $$(call qstrip,$$(BR2_TOOLCHAIN_HEADERS_AT_LEAST)),\
  503. $$(if $$(BR2_TOOLCHAIN_EXTERNAL_CUSTOM),loose,strict)); \
  504. $$(call check_gcc_version,$$(TOOLCHAIN_EXTERNAL_CC),\
  505. $$(call qstrip,$$(BR2_TOOLCHAIN_GCC_AT_LEAST))); \
  506. if test "$$(BR2_arm)" = "y" ; then \
  507. $$(call check_arm_abi,\
  508. "$$(TOOLCHAIN_EXTERNAL_CC) $$(TOOLCHAIN_EXTERNAL_CFLAGS)") ; \
  509. fi ; \
  510. if test "$$(BR2_INSTALL_LIBSTDCPP)" = "y" ; then \
  511. $$(call check_cplusplus,$$(TOOLCHAIN_EXTERNAL_CXX)) ; \
  512. fi ; \
  513. if test "$$(BR2_TOOLCHAIN_HAS_DLANG)" = "y" ; then \
  514. $$(call check_dlang,$$(TOOLCHAIN_EXTERNAL_GDC)) ; \
  515. fi ; \
  516. if test "$$(BR2_TOOLCHAIN_HAS_FORTRAN)" = "y" ; then \
  517. $$(call check_fortran,$$(TOOLCHAIN_EXTERNAL_FC)) ; \
  518. fi ; \
  519. if test "$$(BR2_TOOLCHAIN_HAS_OPENMP)" = "y" ; then \
  520. $$(call check_openmp,$$(TOOLCHAIN_EXTERNAL_CC)) ; \
  521. fi ; \
  522. if test "$$(BR2_TOOLCHAIN_EXTERNAL_UCLIBC)" = "y" ; then \
  523. $$(call check_uclibc,$$$${SYSROOT_DIR}) ; \
  524. elif test "$$(BR2_TOOLCHAIN_EXTERNAL_MUSL)" = "y" ; then \
  525. $$(call check_musl,\
  526. "$$(TOOLCHAIN_EXTERNAL_CC) $$(TOOLCHAIN_EXTERNAL_CFLAGS)") ; \
  527. else \
  528. $$(call check_glibc,$$$${SYSROOT_DIR}) ; \
  529. fi
  530. $$(Q)$$(call check_toolchain_ssp,$$(TOOLCHAIN_EXTERNAL_CC),$(BR2_SSP_OPTION))
  531. endef
  532. $(2)_TOOLCHAIN_WRAPPER_ARGS += $$(TOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS)
  533. $(2)_BUILD_CMDS = $$(TOOLCHAIN_WRAPPER_BUILD)
  534. define $(2)_INSTALL_STAGING_CMDS
  535. $$(TOOLCHAIN_WRAPPER_INSTALL)
  536. $$(TOOLCHAIN_EXTERNAL_CREATE_STAGING_LIB_SYMLINK)
  537. $$(TOOLCHAIN_EXTERNAL_INSTALL_SYSROOT_LIBS)
  538. $$(TOOLCHAIN_EXTERNAL_INSTALL_WRAPPER)
  539. $$(TOOLCHAIN_EXTERNAL_INSTALL_GDBINIT)
  540. endef
  541. # Even though we're installing things in both the staging, the host
  542. # and the target directory, we do everything within the
  543. # install-staging step, arbitrarily.
  544. define $(2)_INSTALL_TARGET_CMDS
  545. $$(TOOLCHAIN_EXTERNAL_CREATE_TARGET_LIB_SYMLINK)
  546. $$(TOOLCHAIN_EXTERNAL_INSTALL_TARGET_LIBS)
  547. $$(TOOLCHAIN_EXTERNAL_INSTALL_TARGET_GDBSERVER)
  548. $$(TOOLCHAIN_EXTERNAL_FIXUP_UCLIBCNG_LDSO)
  549. $$(TOOLCHAIN_EXTERNAL_INSTALL_TARGET_LDD)
  550. endef
  551. # Call the generic package infrastructure to generate the necessary
  552. # make targets
  553. $(call inner-generic-package,$(1),$(2),$(3),$(4))
  554. endef
  555. toolchain-external-package = $(call inner-toolchain-external-package,$(pkgname),$(call UPPERCASE,$(pkgname)),$(call UPPERCASE,$(pkgname)),target)