1 ################################################################################
2 # External toolchain package infrastructure
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
11 # * Toolchains generated by Crosstool-NG
12 # * Toolchains generated by Buildroot
13 # * Toolchains provided by Linaro for the ARM and AArch64
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
21 # The basic principle is the following
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.
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.
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.
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.
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 ################################################################################
62 # Definitions of where the toolchain can be found
65 TOOLCHAIN_EXTERNAL_PREFIX = $(call qstrip,$(BR2_TOOLCHAIN_EXTERNAL_PREFIX))
66 TOOLCHAIN_EXTERNAL_DOWNLOAD_INSTALL_DIR = $(HOST_DIR)/opt/ext-toolchain
68 ifeq ($(BR2_TOOLCHAIN_EXTERNAL_DOWNLOAD),y)
69 TOOLCHAIN_EXTERNAL_INSTALL_DIR = $(TOOLCHAIN_EXTERNAL_DOWNLOAD_INSTALL_DIR)
71 TOOLCHAIN_EXTERNAL_INSTALL_DIR = $(call qstrip,$(BR2_TOOLCHAIN_EXTERNAL_PATH))
74 ifeq ($(TOOLCHAIN_EXTERNAL_INSTALL_DIR),)
75 ifneq ($(TOOLCHAIN_EXTERNAL_PREFIX),)
76 # if no path set, figure it out from path
77 TOOLCHAIN_EXTERNAL_BIN := $(dir $(shell which $(TOOLCHAIN_EXTERNAL_PREFIX)-gcc))
80 TOOLCHAIN_EXTERNAL_REL_BIN_PATH = $(call qstrip,$(BR2_TOOLCHAIN_EXTERNAL_REL_BIN_PATH))
81 ifeq ($(TOOLCHAIN_EXTERNAL_REL_BIN_PATH),)
82 TOOLCHAIN_EXTERNAL_REL_BIN_PATH = bin
84 TOOLCHAIN_EXTERNAL_BIN = $(TOOLCHAIN_EXTERNAL_INSTALL_DIR)/$(TOOLCHAIN_EXTERNAL_REL_BIN_PATH)
87 # If this is a buildroot toolchain, it already has a wrapper which we want to
88 # bypass. Since this is only evaluated after it has been extracted, we can use
89 # $(wildcard ...) here.
90 TOOLCHAIN_EXTERNAL_SUFFIX = \
91 $(if $(wildcard $(TOOLCHAIN_EXTERNAL_BIN)/*.br_real),.br_real)
93 TOOLCHAIN_EXTERNAL_CROSS = $(TOOLCHAIN_EXTERNAL_BIN)/$(TOOLCHAIN_EXTERNAL_PREFIX)-
94 TOOLCHAIN_EXTERNAL_CC = $(TOOLCHAIN_EXTERNAL_CROSS)gcc$(TOOLCHAIN_EXTERNAL_SUFFIX)
95 TOOLCHAIN_EXTERNAL_CXX = $(TOOLCHAIN_EXTERNAL_CROSS)g++$(TOOLCHAIN_EXTERNAL_SUFFIX)
96 TOOLCHAIN_EXTERNAL_GDC = $(TOOLCHAIN_EXTERNAL_CROSS)gdc$(TOOLCHAIN_EXTERNAL_SUFFIX)
97 TOOLCHAIN_EXTERNAL_FC = $(TOOLCHAIN_EXTERNAL_CROSS)gfortran$(TOOLCHAIN_EXTERNAL_SUFFIX)
98 TOOLCHAIN_EXTERNAL_READELF = $(TOOLCHAIN_EXTERNAL_CROSS)readelf
100 # Normal handling of downloaded toolchain tarball extraction.
101 ifeq ($(BR2_TOOLCHAIN_EXTERNAL_DOWNLOAD),y)
102 # As a regular package, the toolchain gets extracted in $(@D), but
103 # since it's actually a fairly special package, we need it to be moved
104 # into TOOLCHAIN_EXTERNAL_DOWNLOAD_INSTALL_DIR.
105 define TOOLCHAIN_EXTERNAL_MOVE
106 rm -rf $(TOOLCHAIN_EXTERNAL_DOWNLOAD_INSTALL_DIR)
107 mkdir -p $(TOOLCHAIN_EXTERNAL_DOWNLOAD_INSTALL_DIR)
108 mv $(@D)/* $(TOOLCHAIN_EXTERNAL_DOWNLOAD_INSTALL_DIR)/
113 # Definitions of the list of libraries that should be copied to the target.
116 TOOLCHAIN_EXTERNAL_LIBS += ld*.so.* libgcc_s.so.* libatomic.so.*
118 ifneq ($(BR2_SSP_NONE),y)
119 TOOLCHAIN_EXTERNAL_LIBS += libssp.so.*
122 ifeq ($(BR2_TOOLCHAIN_EXTERNAL_GLIBC)$(BR2_TOOLCHAIN_EXTERNAL_UCLIBC),y)
123 TOOLCHAIN_EXTERNAL_LIBS += libc.so.* libcrypt.so.* libdl.so.* libm.so.* libnsl.so.* libresolv.so.* librt.so.* libutil.so.*
124 ifeq ($(BR2_TOOLCHAIN_HAS_THREADS),y)
125 TOOLCHAIN_EXTERNAL_LIBS += libpthread.so.*
126 ifneq ($(BR2_PACKAGE_GDB)$(BR2_TOOLCHAIN_EXTERNAL_GDB_SERVER_COPY),)
127 TOOLCHAIN_EXTERNAL_LIBS += libthread_db.so.*
132 ifeq ($(BR2_TOOLCHAIN_EXTERNAL_GLIBC),y)
133 TOOLCHAIN_EXTERNAL_LIBS += libnss_files.so.* libnss_dns.so.* libmvec.so.* libanl.so.*
136 ifeq ($(BR2_TOOLCHAIN_EXTERNAL_MUSL),y)
137 TOOLCHAIN_EXTERNAL_LIBS += libc.so
140 ifeq ($(BR2_INSTALL_LIBSTDCPP),y)
141 TOOLCHAIN_EXTERNAL_LIBS += libstdc++.so.*
144 ifeq ($(BR2_TOOLCHAIN_HAS_FORTRAN),y)
145 TOOLCHAIN_EXTERNAL_LIBS += libgfortran.so.*
146 # fortran needs quadmath on x86 and x86_64
147 ifeq ($(BR2_TOOLCHAIN_HAS_LIBQUADMATH),y)
148 TOOLCHAIN_EXTERNAL_LIBS += libquadmath.so*
152 ifeq ($(BR2_TOOLCHAIN_HAS_OPENMP),y)
153 TOOLCHAIN_EXTERNAL_LIBS += libgomp.so.*
156 ifeq ($(BR2_TOOLCHAIN_HAS_DLANG),y)
157 TOOLCHAIN_EXTERNAL_LIBS += libgdruntime.so* libgphobos.so*
160 TOOLCHAIN_EXTERNAL_LIBS += $(addsuffix .so*,$(call qstrip,$(BR2_TOOLCHAIN_EXTRA_LIBS)))
164 # Definition of the CFLAGS to use with the external toolchain, as well as the
165 # common toolchain wrapper build arguments
168 # march/mtune/floating point mode needs to be passed to the external toolchain
169 # to select the right multilib variant
170 ifeq ($(BR2_x86_64),y)
171 TOOLCHAIN_EXTERNAL_CFLAGS += -m64
172 TOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS += -DBR_64
174 ifneq ($(GCC_TARGET_ARCH),)
175 TOOLCHAIN_EXTERNAL_CFLAGS += -march=$(GCC_TARGET_ARCH)
176 TOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS += -DBR_ARCH='"$(GCC_TARGET_ARCH)"'
178 ifneq ($(GCC_TARGET_CPU),)
179 TOOLCHAIN_EXTERNAL_CFLAGS += -mcpu=$(GCC_TARGET_CPU)
180 TOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS += -DBR_CPU='"$(GCC_TARGET_CPU)"'
182 ifneq ($(GCC_TARGET_ABI),)
183 TOOLCHAIN_EXTERNAL_CFLAGS += -mabi=$(GCC_TARGET_ABI)
184 TOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS += -DBR_ABI='"$(GCC_TARGET_ABI)"'
186 ifeq ($(BR2_TOOLCHAIN_HAS_MNAN_OPTION),y)
187 ifneq ($(GCC_TARGET_NAN),)
188 TOOLCHAIN_EXTERNAL_CFLAGS += -mnan=$(GCC_TARGET_NAN)
189 TOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS += -DBR_NAN='"$(GCC_TARGET_NAN)"'
192 ifneq ($(GCC_TARGET_FP32_MODE),)
193 TOOLCHAIN_EXTERNAL_CFLAGS += -mfp$(GCC_TARGET_FP32_MODE)
194 TOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS += -DBR_FP32_MODE='"$(GCC_TARGET_FP32_MODE)"'
196 ifneq ($(GCC_TARGET_FPU),)
197 TOOLCHAIN_EXTERNAL_CFLAGS += -mfpu=$(GCC_TARGET_FPU)
198 TOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS += -DBR_FPU='"$(GCC_TARGET_FPU)"'
200 ifneq ($(GCC_TARGET_FLOAT_ABI),)
201 TOOLCHAIN_EXTERNAL_CFLAGS += -mfloat-abi=$(GCC_TARGET_FLOAT_ABI)
202 TOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS += -DBR_FLOAT_ABI='"$(GCC_TARGET_FLOAT_ABI)"'
204 ifneq ($(GCC_TARGET_MODE),)
205 TOOLCHAIN_EXTERNAL_CFLAGS += -m$(GCC_TARGET_MODE)
206 TOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS += -DBR_MODE='"$(GCC_TARGET_MODE)"'
208 ifeq ($(BR2_BINFMT_FLAT),y)
209 TOOLCHAIN_EXTERNAL_CFLAGS += -Wl,-elf2flt
210 TOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS += -DBR_BINFMT_FLAT
212 ifeq ($(BR2_mipsel)$(BR2_mips64el),y)
213 TOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS += -DBR_MIPS_TARGET_LITTLE_ENDIAN
214 TOOLCHAIN_EXTERNAL_CFLAGS += -EL
216 ifeq ($(BR2_mips)$(BR2_mips64),y)
217 TOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS += -DBR_MIPS_TARGET_BIG_ENDIAN
218 TOOLCHAIN_EXTERNAL_CFLAGS += -EB
220 ifeq ($(BR2_arceb),y)
221 TOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS += -DBR_ARC_TARGET_BIG_ENDIAN
222 TOOLCHAIN_EXTERNAL_CFLAGS += -EB
225 TOOLCHAIN_EXTERNAL_CFLAGS += $(call qstrip,$(BR2_TARGET_OPTIMIZATION))
227 ifeq ($(BR2_SOFT_FLOAT),y)
228 TOOLCHAIN_EXTERNAL_CFLAGS += -msoft-float
229 TOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS += -DBR_SOFTFLOAT=1
232 TOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS += \
233 -DBR_CROSS_PATH_SUFFIX='"$(TOOLCHAIN_EXTERNAL_SUFFIX)"'
235 ifeq ($(filter $(HOST_DIR)/%,$(TOOLCHAIN_EXTERNAL_BIN)),)
236 # TOOLCHAIN_EXTERNAL_BIN points outside HOST_DIR => absolute path
237 TOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS += \
238 -DBR_CROSS_PATH_ABS='"$(TOOLCHAIN_EXTERNAL_BIN)"'
240 # TOOLCHAIN_EXTERNAL_BIN points inside HOST_DIR => relative path
241 TOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS += \
242 -DBR_CROSS_PATH_REL='"$(TOOLCHAIN_EXTERNAL_BIN:$(HOST_DIR)/%=%)"'
247 # The following functions creates the symbolic links needed to get the
248 # cross-compilation tools visible in $(HOST_DIR)/bin. Some of
249 # links are done directly to the corresponding tool in the external
250 # toolchain installation directory, while some other links are done to
251 # the toolchain wrapper (preprocessor, C, C++ and Fortran compiler)
253 # We skip gdb symlink when we are building our own gdb to prevent two
254 # gdb's in $(HOST_DIR)/bin.
256 # The LTO support in gcc creates wrappers for ar, ranlib and nm which load
257 # the lto plugin. These wrappers are called *-gcc-ar, *-gcc-ranlib, and
258 # *-gcc-nm and should be used instead of the real programs when -flto is
259 # used. However, we should not add the toolchain wrapper for them, and they
260 # match the *cc-* pattern. Therefore, an additional case is added for *-ar,
262 define TOOLCHAIN_EXTERNAL_INSTALL_WRAPPER
263 $(Q)cd $(HOST_DIR)/bin; \
264 for i in $(TOOLCHAIN_EXTERNAL_CROSS)*; do \
267 *-ar|*-ranlib|*-nm) \
268 ln -sf $$(echo $$i | sed 's%^$(HOST_DIR)%..%') .; \
270 *cc|*cc-*|*++|*++-*|*cpp|*-gfortran|*-gdc) \
271 ln -sf toolchain-wrapper $$base; \
274 if test "$(BR2_PACKAGE_HOST_GDB)" != "y"; then \
275 ln -sf $$(echo $$i | sed 's%^$(HOST_DIR)%..%') .; \
279 ln -sf $$(echo $$i | sed 's%^$(HOST_DIR)%..%') .; \
286 # Various utility functions used by the external toolchain package
287 # infrastructure. Those functions are mainly responsible for:
289 # - installation the toolchain libraries to $(TARGET_DIR)
290 # - copying the toolchain sysroot to $(STAGING_DIR)
291 # - installing a gdbinit file
293 # Details about sysroot directory selection.
295 # To find the sysroot directory, we use the trick of looking for the
296 # 'libc.a' file with the -print-file-name gcc option, and then
297 # mangling the path to find the base directory of the sysroot.
299 # Note that we do not use the -print-sysroot option, because it is
300 # only available since gcc 4.4.x, and we only recently dropped support
301 # for 4.2.x and 4.3.x.
303 # When doing this, we don't pass any option to gcc that could select a
304 # multilib variant (such as -march) as we want the "main" sysroot,
305 # which contains all variants of the C library in the case of multilib
306 # toolchains. We use the TARGET_CC_NO_SYSROOT variable, which is the
307 # path of the cross-compiler, without the --sysroot=$(STAGING_DIR),
308 # since what we want to find is the location of the original toolchain
309 # sysroot. This "main" sysroot directory is stored in SYSROOT_DIR.
311 # Then, multilib toolchains are a little bit more complicated, since
312 # they in fact have multiple sysroots, one for each variant supported
313 # by the toolchain. So we need to find the particular sysroot we're
316 # To do so, we ask the compiler where its sysroot is by passing all
317 # flags (including -march and al.), except the --sysroot flag since we
318 # want to the compiler to tell us where its original sysroot
319 # is. ARCH_SUBDIR will contain the subdirectory, in the main
320 # SYSROOT_DIR, that corresponds to the selected architecture
321 # variant. ARCH_SYSROOT_DIR will contain the full path to this
324 # One might wonder why we don't just bother with ARCH_SYSROOT_DIR. The
325 # fact is that in multilib toolchains, the header files are often only
326 # present in the main sysroot, and only the libraries are available in
327 # each variant-specific sysroot directory.
330 # toolchain_find_sysroot returns the sysroot location for the given
331 # compiler + flags. We need to handle cases where libc.a is in:
337 # - lib32-fp/ (Cavium toolchain)
338 # - lib64-fp/ (Cavium toolchain)
339 # - usr/lib/<tuple>/ (Linaro toolchain)
341 # And variations on these.
342 define toolchain_find_sysroot
343 $$(printf $(call toolchain_find_libc_a,$(1)) | sed -r -e 's:/(usr/)?lib(32|64)?([^/]*)?/([^/]*/)?libc\.a:/:')
346 # Returns the lib subdirectory for the given compiler + flags (i.e
347 # typically lib32 or lib64 for some toolchains)
348 define toolchain_find_libdir
349 $$(printf $(call toolchain_find_libc_a,$(1)) | sed -r -e 's:.*/(usr/)?(lib(32|64)?([^/]*)?(/[^/]*)?)/libc.a:\2:')
352 # Returns the location of the libc.a file for the given compiler + flags
353 define toolchain_find_libc_a
354 $$(readlink -f $$(LANG=C $(1) -print-file-name=libc.a))
357 # Integration of the toolchain into Buildroot: find the main sysroot
358 # and the variant-specific sysroot, then copy the needed libraries to
359 # the $(TARGET_DIR) and copy the whole sysroot (libraries and headers)
362 # Variables are defined as follows:
364 # SYSROOT_DIR: the main sysroot directory, deduced from the location of
365 # the libc.a file in the default multilib variant, by
366 # removing the usr/lib[32|64]/libc.a part of the path.
367 # Ex: /x-tools/mips-2011.03/mips-linux-gnu/libc/
369 # ARCH_SYSROOT_DIR: the sysroot of the selected multilib variant,
370 # deduced from the location of the libc.a file in the
371 # selected multilib variant (taking into account the
372 # CFLAGS), by removing usr/lib[32|64]/libc.a at the end
374 # Ex: /x-tools/mips-2011.03/mips-linux-gnu/libc/mips16/soft-float/el/
376 # ARCH_LIB_DIR: 'lib', 'lib32' or 'lib64' depending on where libraries
377 # are stored. Deduced from the location of the libc.a file
378 # in the selected multilib variant, by looking at
382 # ARCH_SUBDIR: the relative location of the sysroot of the selected
383 # multilib variant compared to the main sysroot.
384 # Ex: mips16/soft-float/el
386 # SUPPORT_LIB_DIR: some toolchains, such as recent Linaro toolchains,
387 # store GCC support libraries (libstdc++,
388 # libgcc_s, etc.) outside of the sysroot. In
389 # this case, SUPPORT_LIB_DIR is set to a
390 # non-empty value, and points to the directory
391 # where these support libraries are
392 # available. Those libraries will be copied to
393 # our sysroot, and the directory will also be
394 # considered when searching libraries for copy
395 # to the target filesystem.
397 # Please be very careful to check the major toolchain sources:
398 # Buildroot, Crosstool-NG, CodeSourcery and Linaro
399 # before doing any modification on the below logic.
401 ifeq ($(BR2_STATIC_LIBS),)
402 define TOOLCHAIN_EXTERNAL_INSTALL_TARGET_LIBS
403 $(Q)$(call MESSAGE,"Copying external toolchain libraries to target...")
404 $(Q)for libpattern in $(TOOLCHAIN_EXTERNAL_LIBS); do \
405 $(call copy_toolchain_lib_root,$$libpattern); \
410 ifeq ($(BR2_TOOLCHAIN_EXTERNAL_GDB_SERVER_COPY),y)
411 define TOOLCHAIN_EXTERNAL_INSTALL_TARGET_GDBSERVER
412 $(Q)$(call MESSAGE,"Copying gdbserver")
413 $(Q)ARCH_SYSROOT_DIR="$(call toolchain_find_sysroot,$(TOOLCHAIN_EXTERNAL_CC) $(TOOLCHAIN_EXTERNAL_CFLAGS))" ; \
414 ARCH_LIB_DIR="$(call toolchain_find_libdir,$(TOOLCHAIN_EXTERNAL_CC) $(TOOLCHAIN_EXTERNAL_CFLAGS))" ; \
415 gdbserver_found=0 ; \
416 for d in $${ARCH_SYSROOT_DIR}/usr \
417 $${ARCH_SYSROOT_DIR}/../debug-root/usr \
418 $${ARCH_SYSROOT_DIR}/usr/$${ARCH_LIB_DIR} \
419 $(TOOLCHAIN_EXTERNAL_INSTALL_DIR); do \
420 if test -f $${d}/bin/gdbserver ; then \
421 install -m 0755 -D $${d}/bin/gdbserver $(TARGET_DIR)/usr/bin/gdbserver ; \
422 gdbserver_found=1 ; \
426 if [ $${gdbserver_found} -eq 0 ] ; then \
427 echo "Could not find gdbserver in external toolchain" ; \
433 define TOOLCHAIN_EXTERNAL_INSTALL_SYSROOT_LIBS
434 $(Q)SYSROOT_DIR="$(call toolchain_find_sysroot,$(TOOLCHAIN_EXTERNAL_CC))" ; \
435 ARCH_SYSROOT_DIR="$(call toolchain_find_sysroot,$(TOOLCHAIN_EXTERNAL_CC) $(TOOLCHAIN_EXTERNAL_CFLAGS))" ; \
436 ARCH_LIB_DIR="$(call toolchain_find_libdir,$(TOOLCHAIN_EXTERNAL_CC) $(TOOLCHAIN_EXTERNAL_CFLAGS))" ; \
437 SUPPORT_LIB_DIR="" ; \
438 if test `find $${ARCH_SYSROOT_DIR} -name 'libstdc++.a' | wc -l` -eq 0 ; then \
439 LIBSTDCPP_A_LOCATION=$$(LANG=C $(TOOLCHAIN_EXTERNAL_CC) $(TOOLCHAIN_EXTERNAL_CFLAGS) -print-file-name=libstdc++.a) ; \
440 if [ -e "$${LIBSTDCPP_A_LOCATION}" ]; then \
441 SUPPORT_LIB_DIR=`readlink -f $${LIBSTDCPP_A_LOCATION} | sed -r -e 's:libstdc\+\+\.a::'` ; \
444 if [ "$${SYSROOT_DIR}" == "$${ARCH_SYSROOT_DIR}" ] ; then \
446 elif [ "`dirname $${ARCH_SYSROOT_DIR}`" = "`dirname $${SYSROOT_DIR}`" ] ; then \
447 SYSROOT_DIR_DIRNAME=`dirname $${SYSROOT_DIR}`/ ; \
448 ARCH_SUBDIR=`echo $${ARCH_SYSROOT_DIR} | sed -r -e "s:^$${SYSROOT_DIR_DIRNAME}(.*)/$$:\1:"` ; \
450 ARCH_SUBDIR=`echo $${ARCH_SYSROOT_DIR} | sed -r -e "s:^$${SYSROOT_DIR}(.*)/$$:\1:"` ; \
452 $(call MESSAGE,"Copying external toolchain sysroot to staging...") ; \
453 $(call copy_toolchain_sysroot,$${SYSROOT_DIR},$${ARCH_SYSROOT_DIR},$${ARCH_SUBDIR},$${ARCH_LIB_DIR},$${SUPPORT_LIB_DIR})
456 # Create a symlink from (usr/)$(ARCH_LIB_DIR) to lib.
457 # Note: the skeleton package additionally creates lib32->lib or lib64->lib
460 # $1: destination directory (TARGET_DIR / STAGING_DIR)
461 create_lib_symlinks = \
462 $(Q)DESTDIR="$(strip $1)" ; \
463 ARCH_LIB_DIR="$(call toolchain_find_libdir,$(TOOLCHAIN_EXTERNAL_CC) $(TOOLCHAIN_EXTERNAL_CFLAGS))" ; \
464 if [ ! -e "$${DESTDIR}/$${ARCH_LIB_DIR}" -a ! -e "$${DESTDIR}/usr/$${ARCH_LIB_DIR}" ]; then \
465 relpath="$(call relpath_prefix,$${ARCH_LIB_DIR})" ; \
466 ln -snf $${relpath}lib "$${DESTDIR}/$${ARCH_LIB_DIR}" ; \
467 ln -snf $${relpath}lib "$${DESTDIR}/usr/$${ARCH_LIB_DIR}" ; \
470 define TOOLCHAIN_EXTERNAL_CREATE_STAGING_LIB_SYMLINK
471 $(call create_lib_symlinks,$(STAGING_DIR))
474 define TOOLCHAIN_EXTERNAL_CREATE_TARGET_LIB_SYMLINK
475 $(call create_lib_symlinks,$(TARGET_DIR))
479 # Generate gdbinit file for use with Buildroot
481 define TOOLCHAIN_EXTERNAL_INSTALL_GDBINIT
482 $(Q)if test -f $(TARGET_CROSS)gdb ; then \
483 $(call MESSAGE,"Installing gdbinit"); \
484 $(gen_gdbinit_file); \
488 # GCC installs a libstdcxx-...so-gdb.py file that gdb will load automatically,
489 # but it contains hardcoded paths referring to the location where the (external)
490 # toolchain was built. Fix up these paths so that the pretty printers can be
491 # loaded automatically.
492 # By default, the pretty printers are installed in
493 # $(datadir)/gcc-$(gcc_version)/python but this could have been overwritten with
494 # the gcc configure option: --with-python-dir. We thus have to search the
495 # correct path first.
496 define TOOLCHAIN_EXTERNAL_FIXUP_PRETTY_PRINTER_LOADER
497 $(Q)loadfiles=$$(find $(STAGING_DIR) -name 'libstdc++.so*-gdb.py' 2>/dev/null); \
498 pythondir=$$(find $(TOOLCHAIN_EXTERNAL_DOWNLOAD_INSTALL_DIR) -path '*/libstdcxx/__init__.py' 2>/dev/null | sed 's%/libstdcxx/__init__.py%%' | head -n1); \
499 if [ -n "$$loadfiles" ] && [ -n "$$pythondir" ]; then \
500 echo "Fixing up hardcoded paths in GDB pretty-printer auto-load file(s) for libstdcxx: $$loadfiles"; \
502 -e 's%^libdir\s*=.*%libdir = "$(STAGING_DIR)/lib"%' \
503 -e "s%^pythondir\s*=.*%pythondir = '$$pythondir'%" \
508 # uClibc-ng dynamic loader is called ld-uClibc.so.1, but gcc is not
509 # patched specifically for uClibc-ng, so it continues to generate
510 # binaries that expect the dynamic loader to be named ld-uClibc.so.0,
511 # like with the original uClibc. Therefore, we create an additional
512 # symbolic link to make uClibc-ng systems work properly.
513 define TOOLCHAIN_EXTERNAL_FIXUP_UCLIBCNG_LDSO
514 $(Q)if test -e $(TARGET_DIR)/lib/ld-uClibc.so.1; then \
515 ln -sf ld-uClibc.so.1 $(TARGET_DIR)/lib/ld-uClibc.so.0 ; \
517 $(Q)if test -e $(TARGET_DIR)/lib/ld64-uClibc.so.1; then \
518 ln -sf ld64-uClibc.so.1 $(TARGET_DIR)/lib/ld64-uClibc.so.0 ; \
522 define TOOLCHAIN_EXTERNAL_INSTALL_TARGET_LDD
523 $(Q)if test -f $(STAGING_DIR)/usr/bin/ldd ; then \
524 $(INSTALL) -D $(STAGING_DIR)/usr/bin/ldd $(TARGET_DIR)/usr/bin/ldd ; \
525 $(SED) 's:.*/bin/bash:#!/bin/sh:' $(TARGET_DIR)/usr/bin/ldd ; \
529 ################################################################################
530 # inner-toolchain-external-package -- defines the generic installation rules
531 # for external toolchain packages
533 # argument 1 is the lowercase package name
534 # argument 2 is the uppercase package name, including a HOST_ prefix
536 # argument 3 is the uppercase package name, without the HOST_ prefix
538 # argument 4 is the type (target or host)
539 ################################################################################
540 define inner-toolchain-external-package
542 $(2)_INSTALL_STAGING = YES
543 $(2)_ADD_TOOLCHAIN_DEPENDENCY = NO
545 # In fact, we don't need to download the toolchain, since it is already
546 # available on the system, so force the site and source to be empty so
547 # that nothing will be downloaded/extracted.
548 ifeq ($$(BR2_TOOLCHAIN_EXTERNAL_PREINSTALLED),y)
553 ifeq ($$(BR2_TOOLCHAIN_EXTERNAL_DOWNLOAD),y)
554 $(2)_EXCLUDES = usr/lib/locale/*
556 $(2)_POST_EXTRACT_HOOKS += \
557 TOOLCHAIN_EXTERNAL_MOVE
560 # Checks for an already installed toolchain: check the toolchain
561 # location, check that it is usable, and then verify that it
562 # matches the configuration provided in Buildroot: ABI, C++ support,
563 # kernel headers version, type of C library and all C library features.
564 define $(2)_CONFIGURE_CMDS
565 $$(Q)$$(call check_cross_compiler_exists,$$(TOOLCHAIN_EXTERNAL_CC))
566 $$(Q)$$(call check_unusable_toolchain,$$(TOOLCHAIN_EXTERNAL_CC))
567 $$(Q)SYSROOT_DIR="$$(call toolchain_find_sysroot,$$(TOOLCHAIN_EXTERNAL_CC))" ; \
568 $$(call check_kernel_headers_version,\
570 $$(call toolchain_find_sysroot,$$(TOOLCHAIN_EXTERNAL_CC)),\
571 $$(call qstrip,$$(BR2_TOOLCHAIN_HEADERS_AT_LEAST)),\
572 $$(if $$(BR2_TOOLCHAIN_EXTERNAL_CUSTOM),loose,strict)); \
573 $$(call check_gcc_version,$$(TOOLCHAIN_EXTERNAL_CC),\
574 $$(call qstrip,$$(BR2_TOOLCHAIN_GCC_AT_LEAST))); \
575 if test "$$(BR2_arm)" = "y" ; then \
576 $$(call check_arm_abi,\
577 "$$(TOOLCHAIN_EXTERNAL_CC) $$(TOOLCHAIN_EXTERNAL_CFLAGS)") ; \
579 if test "$$(BR2_INSTALL_LIBSTDCPP)" = "y" ; then \
580 $$(call check_cplusplus,$$(TOOLCHAIN_EXTERNAL_CXX)) ; \
582 if test "$$(BR2_TOOLCHAIN_HAS_DLANG)" = "y" ; then \
583 $$(call check_dlang,$$(TOOLCHAIN_EXTERNAL_GDC)) ; \
585 if test "$$(BR2_TOOLCHAIN_HAS_FORTRAN)" = "y" ; then \
586 $$(call check_fortran,$$(TOOLCHAIN_EXTERNAL_FC)) ; \
588 if test "$$(BR2_TOOLCHAIN_HAS_OPENMP)" = "y" ; then \
589 $$(call check_openmp,$$(TOOLCHAIN_EXTERNAL_CC)) ; \
591 if test "$$(BR2_TOOLCHAIN_EXTERNAL_UCLIBC)" = "y" ; then \
592 $$(call check_uclibc,$$$${SYSROOT_DIR}) ; \
593 elif test "$$(BR2_TOOLCHAIN_EXTERNAL_MUSL)" = "y" ; then \
595 "$$(TOOLCHAIN_EXTERNAL_CC) $$(TOOLCHAIN_EXTERNAL_CFLAGS)") ; \
597 $$(call check_glibc,$$$${SYSROOT_DIR}) ; \
599 $$(Q)$$(call check_toolchain_ssp,$$(TOOLCHAIN_EXTERNAL_CC),$(BR2_SSP_OPTION))
602 $(2)_TOOLCHAIN_WRAPPER_ARGS += $$(TOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS)
604 $(2)_BUILD_CMDS = $$(TOOLCHAIN_WRAPPER_BUILD)
606 define $(2)_INSTALL_STAGING_CMDS
607 $$(TOOLCHAIN_WRAPPER_INSTALL)
608 $$(TOOLCHAIN_EXTERNAL_CREATE_STAGING_LIB_SYMLINK)
609 $$(TOOLCHAIN_EXTERNAL_INSTALL_SYSROOT_LIBS)
610 $$(TOOLCHAIN_EXTERNAL_INSTALL_WRAPPER)
611 $$(TOOLCHAIN_EXTERNAL_INSTALL_GDBINIT)
612 $$(TOOLCHAIN_EXTERNAL_FIXUP_PRETTY_PRINTER_LOADER)
615 # Even though we're installing things in both the staging, the host
616 # and the target directory, we do everything within the
617 # install-staging step, arbitrarily.
618 define $(2)_INSTALL_TARGET_CMDS
619 $$(TOOLCHAIN_EXTERNAL_CREATE_TARGET_LIB_SYMLINK)
620 $$(TOOLCHAIN_EXTERNAL_INSTALL_TARGET_LIBS)
621 $$(TOOLCHAIN_EXTERNAL_INSTALL_TARGET_GDBSERVER)
622 $$(TOOLCHAIN_EXTERNAL_FIXUP_UCLIBCNG_LDSO)
623 $$(TOOLCHAIN_EXTERNAL_INSTALL_TARGET_LDD)
626 # Call the generic package infrastructure to generate the necessary
628 $(call inner-generic-package,$(1),$(2),$(3),$(4))
632 toolchain-external-package = $(call inner-toolchain-external-package,$(pkgname),$(call UPPERCASE,$(pkgname)),$(call UPPERCASE,$(pkgname)),target)