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_BIN := $(TOOLCHAIN_EXTERNAL_INSTALL_DIR)/bin
83 # If this is a buildroot toolchain, it already has a wrapper which we want to
84 # bypass. Since this is only evaluated after it has been extracted, we can use
85 # $(wildcard ...) here.
86 TOOLCHAIN_EXTERNAL_SUFFIX = \
87 $(if $(wildcard $(TOOLCHAIN_EXTERNAL_BIN)/*.br_real),.br_real)
89 TOOLCHAIN_EXTERNAL_CROSS = $(TOOLCHAIN_EXTERNAL_BIN)/$(TOOLCHAIN_EXTERNAL_PREFIX)-
90 TOOLCHAIN_EXTERNAL_CC = $(TOOLCHAIN_EXTERNAL_CROSS)gcc$(TOOLCHAIN_EXTERNAL_SUFFIX)
91 TOOLCHAIN_EXTERNAL_CXX = $(TOOLCHAIN_EXTERNAL_CROSS)g++$(TOOLCHAIN_EXTERNAL_SUFFIX)
92 TOOLCHAIN_EXTERNAL_FC = $(TOOLCHAIN_EXTERNAL_CROSS)gfortran$(TOOLCHAIN_EXTERNAL_SUFFIX)
93 TOOLCHAIN_EXTERNAL_READELF = $(TOOLCHAIN_EXTERNAL_CROSS)readelf
95 # Normal handling of downloaded toolchain tarball extraction.
96 ifeq ($(BR2_TOOLCHAIN_EXTERNAL_DOWNLOAD),y)
97 # As a regular package, the toolchain gets extracted in $(@D), but
98 # since it's actually a fairly special package, we need it to be moved
99 # into TOOLCHAIN_EXTERNAL_DOWNLOAD_INSTALL_DIR.
100 define TOOLCHAIN_EXTERNAL_MOVE
101 rm -rf $(TOOLCHAIN_EXTERNAL_DOWNLOAD_INSTALL_DIR)
102 mkdir -p $(TOOLCHAIN_EXTERNAL_DOWNLOAD_INSTALL_DIR)
103 mv $(@D)/* $(TOOLCHAIN_EXTERNAL_DOWNLOAD_INSTALL_DIR)/
108 # Definitions of the list of libraries that should be copied to the target.
111 TOOLCHAIN_EXTERNAL_LIBS += ld*.so* libgcc_s.so.* libatomic.so.*
113 ifeq ($(BR2_TOOLCHAIN_EXTERNAL_GLIBC)$(BR2_TOOLCHAIN_EXTERNAL_UCLIBC),y)
114 TOOLCHAIN_EXTERNAL_LIBS += libc.so.* libcrypt.so.* libdl.so.* libm.so.* libnsl.so.* libresolv.so.* librt.so.* libutil.so.*
115 ifeq ($(BR2_TOOLCHAIN_HAS_THREADS),y)
116 TOOLCHAIN_EXTERNAL_LIBS += libpthread.so.*
117 ifneq ($(BR2_PACKAGE_GDB)$(BR2_TOOLCHAIN_EXTERNAL_GDB_SERVER_COPY),)
118 TOOLCHAIN_EXTERNAL_LIBS += libthread_db.so.*
123 ifeq ($(BR2_TOOLCHAIN_EXTERNAL_GLIBC),y)
124 TOOLCHAIN_EXTERNAL_LIBS += libnss_files.so.* libnss_dns.so.* libmvec.so.* libanl.so.*
127 ifeq ($(BR2_TOOLCHAIN_EXTERNAL_MUSL),y)
128 TOOLCHAIN_EXTERNAL_LIBS += libc.so
131 ifeq ($(BR2_INSTALL_LIBSTDCPP),y)
132 TOOLCHAIN_EXTERNAL_LIBS += libstdc++.so.*
135 ifeq ($(BR2_TOOLCHAIN_HAS_FORTRAN),y)
136 TOOLCHAIN_EXTERNAL_LIBS += libgfortran.so.*
137 # fortran needs quadmath on x86 and x86_64
138 ifeq ($(BR2_TOOLCHAIN_HAS_LIBQUADMATH),y)
139 TOOLCHAIN_EXTERNAL_LIBS += libquadmath.so*
143 TOOLCHAIN_EXTERNAL_LIBS += $(call qstrip,$(BR2_TOOLCHAIN_EXTRA_EXTERNAL_LIBS))
147 # Definition of the CFLAGS to use with the external toolchain, as well as the
148 # common toolchain wrapper build arguments
150 ifeq ($(call qstrip,$(BR2_GCC_TARGET_CPU_REVISION)),)
151 CC_TARGET_CPU_ := $(call qstrip,$(BR2_GCC_TARGET_CPU))
153 CC_TARGET_CPU_ := $(call qstrip,$(BR2_GCC_TARGET_CPU)-$(BR2_GCC_TARGET_CPU_REVISION))
155 CC_TARGET_ARCH_ := $(call qstrip,$(BR2_GCC_TARGET_ARCH))
156 CC_TARGET_ABI_ := $(call qstrip,$(BR2_GCC_TARGET_ABI))
157 CC_TARGET_NAN_ := $(call qstrip,$(BR2_GCC_TARGET_NAN))
158 CC_TARGET_FP32_MODE_ := $(call qstrip,$(BR2_GCC_TARGET_FP32_MODE))
159 CC_TARGET_FPU_ := $(call qstrip,$(BR2_GCC_TARGET_FPU))
160 CC_TARGET_FLOAT_ABI_ := $(call qstrip,$(BR2_GCC_TARGET_FLOAT_ABI))
161 CC_TARGET_MODE_ := $(call qstrip,$(BR2_GCC_TARGET_MODE))
163 # march/mtune/floating point mode needs to be passed to the external toolchain
164 # to select the right multilib variant
165 ifeq ($(BR2_x86_64),y)
166 TOOLCHAIN_EXTERNAL_CFLAGS += -m64
167 TOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS += -DBR_64
169 ifneq ($(CC_TARGET_ARCH_),)
170 TOOLCHAIN_EXTERNAL_CFLAGS += -march=$(CC_TARGET_ARCH_)
171 TOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS += -DBR_ARCH='"$(CC_TARGET_ARCH_)"'
173 ifneq ($(CC_TARGET_CPU_),)
174 TOOLCHAIN_EXTERNAL_CFLAGS += -mcpu=$(CC_TARGET_CPU_)
175 TOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS += -DBR_CPU='"$(CC_TARGET_CPU_)"'
177 ifneq ($(CC_TARGET_ABI_),)
178 TOOLCHAIN_EXTERNAL_CFLAGS += -mabi=$(CC_TARGET_ABI_)
179 TOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS += -DBR_ABI='"$(CC_TARGET_ABI_)"'
181 ifeq ($(BR2_TOOLCHAIN_HAS_MNAN_OPTION),y)
182 ifneq ($(CC_TARGET_NAN_),)
183 TOOLCHAIN_EXTERNAL_CFLAGS += -mnan=$(CC_TARGET_NAN_)
184 TOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS += -DBR_NAN='"$(CC_TARGET_NAN_)"'
187 ifneq ($(CC_TARGET_FP32_MODE_),)
188 TOOLCHAIN_EXTERNAL_CFLAGS += -mfp$(CC_TARGET_FP32_MODE_)
189 TOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS += -DBR_FP32_MODE='"$(CC_TARGET_FP32_MODE_)"'
191 ifneq ($(CC_TARGET_FPU_),)
192 TOOLCHAIN_EXTERNAL_CFLAGS += -mfpu=$(CC_TARGET_FPU_)
193 TOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS += -DBR_FPU='"$(CC_TARGET_FPU_)"'
195 ifneq ($(CC_TARGET_FLOAT_ABI_),)
196 TOOLCHAIN_EXTERNAL_CFLAGS += -mfloat-abi=$(CC_TARGET_FLOAT_ABI_)
197 TOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS += -DBR_FLOAT_ABI='"$(CC_TARGET_FLOAT_ABI_)"'
199 ifneq ($(CC_TARGET_MODE_),)
200 TOOLCHAIN_EXTERNAL_CFLAGS += -m$(CC_TARGET_MODE_)
201 TOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS += -DBR_MODE='"$(CC_TARGET_MODE_)"'
203 ifeq ($(BR2_BINFMT_FLAT),y)
204 TOOLCHAIN_EXTERNAL_CFLAGS += -Wl,-elf2flt
205 TOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS += -DBR_BINFMT_FLAT
207 ifeq ($(BR2_mipsel)$(BR2_mips64el),y)
208 TOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS += -DBR_MIPS_TARGET_LITTLE_ENDIAN
209 TOOLCHAIN_EXTERNAL_CFLAGS += -EL
211 ifeq ($(BR2_mips)$(BR2_mips64),y)
212 TOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS += -DBR_MIPS_TARGET_BIG_ENDIAN
213 TOOLCHAIN_EXTERNAL_CFLAGS += -EB
215 ifeq ($(BR2_arceb),y)
216 TOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS += -DBR_ARC_TARGET_BIG_ENDIAN
217 TOOLCHAIN_EXTERNAL_CFLAGS += -EB
220 TOOLCHAIN_EXTERNAL_CFLAGS += $(call qstrip,$(BR2_TARGET_OPTIMIZATION))
222 ifeq ($(BR2_SOFT_FLOAT),y)
223 TOOLCHAIN_EXTERNAL_CFLAGS += -msoft-float
224 TOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS += -DBR_SOFTFLOAT=1
227 TOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS += \
228 -DBR_CROSS_PATH_SUFFIX='"$(TOOLCHAIN_EXTERNAL_SUFFIX)"'
230 ifeq ($(filter $(HOST_DIR)/%,$(TOOLCHAIN_EXTERNAL_BIN)),)
231 # TOOLCHAIN_EXTERNAL_BIN points outside HOST_DIR => absolute path
232 TOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS += \
233 -DBR_CROSS_PATH_ABS='"$(TOOLCHAIN_EXTERNAL_BIN)"'
235 # TOOLCHAIN_EXTERNAL_BIN points inside HOST_DIR => relative path
236 TOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS += \
237 -DBR_CROSS_PATH_REL='"$(TOOLCHAIN_EXTERNAL_BIN:$(HOST_DIR)/%=%)"'
242 # The following functions creates the symbolic links needed to get the
243 # cross-compilation tools visible in $(HOST_DIR)/bin. Some of
244 # links are done directly to the corresponding tool in the external
245 # toolchain installation directory, while some other links are done to
246 # the toolchain wrapper (preprocessor, C, C++ and Fortran compiler)
248 # We skip gdb symlink when we are building our own gdb to prevent two
249 # gdb's in $(HOST_DIR)/bin.
251 # The LTO support in gcc creates wrappers for ar, ranlib and nm which load
252 # the lto plugin. These wrappers are called *-gcc-ar, *-gcc-ranlib, and
253 # *-gcc-nm and should be used instead of the real programs when -flto is
254 # used. However, we should not add the toolchain wrapper for them, and they
255 # match the *cc-* pattern. Therefore, an additional case is added for *-ar,
257 define TOOLCHAIN_EXTERNAL_INSTALL_WRAPPER
258 $(Q)cd $(HOST_DIR)/bin; \
259 for i in $(TOOLCHAIN_EXTERNAL_CROSS)*; do \
262 *-ar|*-ranlib|*-nm) \
263 ln -sf $$(echo $$i | sed 's%^$(HOST_DIR)%..%') .; \
265 *cc|*cc-*|*++|*++-*|*cpp|*-gfortran) \
266 ln -sf toolchain-wrapper $$base; \
269 if test "$(BR2_PACKAGE_HOST_GDB)" != "y"; then \
270 ln -sf $$(echo $$i | sed 's%^$(HOST_DIR)%..%') .; \
274 ln -sf $$(echo $$i | sed 's%^$(HOST_DIR)%..%') .; \
281 # Various utility functions used by the external toolchain package
282 # infrastructure. Those functions are mainly responsible for:
284 # - installation the toolchain libraries to $(TARGET_DIR)
285 # - copying the toolchain sysroot to $(STAGING_DIR)
286 # - installing a gdbinit file
288 # Details about sysroot directory selection.
290 # To find the sysroot directory, we use the trick of looking for the
291 # 'libc.a' file with the -print-file-name gcc option, and then
292 # mangling the path to find the base directory of the sysroot.
294 # Note that we do not use the -print-sysroot option, because it is
295 # only available since gcc 4.4.x, and we only recently dropped support
296 # for 4.2.x and 4.3.x.
298 # When doing this, we don't pass any option to gcc that could select a
299 # multilib variant (such as -march) as we want the "main" sysroot,
300 # which contains all variants of the C library in the case of multilib
301 # toolchains. We use the TARGET_CC_NO_SYSROOT variable, which is the
302 # path of the cross-compiler, without the --sysroot=$(STAGING_DIR),
303 # since what we want to find is the location of the original toolchain
304 # sysroot. This "main" sysroot directory is stored in SYSROOT_DIR.
306 # Then, multilib toolchains are a little bit more complicated, since
307 # they in fact have multiple sysroots, one for each variant supported
308 # by the toolchain. So we need to find the particular sysroot we're
311 # To do so, we ask the compiler where its sysroot is by passing all
312 # flags (including -march and al.), except the --sysroot flag since we
313 # want to the compiler to tell us where its original sysroot
314 # is. ARCH_SUBDIR will contain the subdirectory, in the main
315 # SYSROOT_DIR, that corresponds to the selected architecture
316 # variant. ARCH_SYSROOT_DIR will contain the full path to this
319 # One might wonder why we don't just bother with ARCH_SYSROOT_DIR. The
320 # fact is that in multilib toolchains, the header files are often only
321 # present in the main sysroot, and only the libraries are available in
322 # each variant-specific sysroot directory.
325 # toolchain_find_sysroot returns the sysroot location for the given
326 # compiler + flags. We need to handle cases where libc.a is in:
332 # - lib32-fp/ (Cavium toolchain)
333 # - lib64-fp/ (Cavium toolchain)
334 # - usr/lib/<tuple>/ (Linaro toolchain)
336 # And variations on these.
337 define toolchain_find_sysroot
338 $$(printf $(call toolchain_find_libc_a,$(1)) | sed -r -e 's:(usr/)?lib(32|64)?([^/]*)?/([^/]*/)?libc\.a::')
341 # Returns the lib subdirectory for the given compiler + flags (i.e
342 # typically lib32 or lib64 for some toolchains)
343 define toolchain_find_libdir
344 $$(printf $(call toolchain_find_libc_a,$(1)) | sed -r -e 's:.*/(usr/)?(lib(32|64)?([^/]*)?(/[^/]*)?)/libc.a:\2:')
347 # Returns the location of the libc.a file for the given compiler + flags
348 define toolchain_find_libc_a
349 $$(readlink -f $$(LANG=C $(1) -print-file-name=libc.a))
352 # Integration of the toolchain into Buildroot: find the main sysroot
353 # and the variant-specific sysroot, then copy the needed libraries to
354 # the $(TARGET_DIR) and copy the whole sysroot (libraries and headers)
357 # Variables are defined as follows:
359 # SYSROOT_DIR: the main sysroot directory, deduced from the location of
360 # the libc.a file in the default multilib variant, by
361 # removing the usr/lib[32|64]/libc.a part of the path.
362 # Ex: /x-tools/mips-2011.03/mips-linux-gnu/libc/
364 # ARCH_SYSROOT_DIR: the sysroot of the selected multilib variant,
365 # deduced from the location of the libc.a file in the
366 # selected multilib variant (taking into account the
367 # CFLAGS), by removing usr/lib[32|64]/libc.a at the end
369 # Ex: /x-tools/mips-2011.03/mips-linux-gnu/libc/mips16/soft-float/el/
371 # ARCH_LIB_DIR: 'lib', 'lib32' or 'lib64' depending on where libraries
372 # are stored. Deduced from the location of the libc.a file
373 # in the selected multilib variant, by looking at
377 # ARCH_SUBDIR: the relative location of the sysroot of the selected
378 # multilib variant compared to the main sysroot.
379 # Ex: mips16/soft-float/el
381 # SUPPORT_LIB_DIR: some toolchains, such as recent Linaro toolchains,
382 # store GCC support libraries (libstdc++,
383 # libgcc_s, etc.) outside of the sysroot. In
384 # this case, SUPPORT_LIB_DIR is set to a
385 # non-empty value, and points to the directory
386 # where these support libraries are
387 # available. Those libraries will be copied to
388 # our sysroot, and the directory will also be
389 # considered when searching libraries for copy
390 # to the target filesystem.
392 # Please be very careful to check the major toolchain sources:
393 # Buildroot, Crosstool-NG, CodeSourcery and Linaro
394 # before doing any modification on the below logic.
396 ifeq ($(BR2_STATIC_LIBS),)
397 define TOOLCHAIN_EXTERNAL_INSTALL_TARGET_LIBS
398 $(Q)$(call MESSAGE,"Copying external toolchain libraries to target...")
399 $(Q)for libpattern in $(TOOLCHAIN_EXTERNAL_LIBS); do \
400 $(call copy_toolchain_lib_root,$$libpattern); \
405 ifeq ($(BR2_TOOLCHAIN_EXTERNAL_GDB_SERVER_COPY),y)
406 define TOOLCHAIN_EXTERNAL_INSTALL_TARGET_GDBSERVER
407 $(Q)$(call MESSAGE,"Copying gdbserver")
408 $(Q)ARCH_SYSROOT_DIR="$(call toolchain_find_sysroot,$(TOOLCHAIN_EXTERNAL_CC) $(TOOLCHAIN_EXTERNAL_CFLAGS))" ; \
409 ARCH_LIB_DIR="$(call toolchain_find_libdir,$(TOOLCHAIN_EXTERNAL_CC) $(TOOLCHAIN_EXTERNAL_CFLAGS))" ; \
410 gdbserver_found=0 ; \
411 for d in $${ARCH_SYSROOT_DIR}/usr \
412 $${ARCH_SYSROOT_DIR}/../debug-root/usr \
413 $${ARCH_SYSROOT_DIR}/usr/$${ARCH_LIB_DIR} \
414 $(TOOLCHAIN_EXTERNAL_INSTALL_DIR); do \
415 if test -f $${d}/bin/gdbserver ; then \
416 install -m 0755 -D $${d}/bin/gdbserver $(TARGET_DIR)/usr/bin/gdbserver ; \
417 gdbserver_found=1 ; \
421 if [ $${gdbserver_found} -eq 0 ] ; then \
422 echo "Could not find gdbserver in external toolchain" ; \
428 define TOOLCHAIN_EXTERNAL_INSTALL_SYSROOT_LIBS
429 $(Q)SYSROOT_DIR="$(call toolchain_find_sysroot,$(TOOLCHAIN_EXTERNAL_CC))" ; \
430 ARCH_SYSROOT_DIR="$(call toolchain_find_sysroot,$(TOOLCHAIN_EXTERNAL_CC) $(TOOLCHAIN_EXTERNAL_CFLAGS))" ; \
431 ARCH_LIB_DIR="$(call toolchain_find_libdir,$(TOOLCHAIN_EXTERNAL_CC) $(TOOLCHAIN_EXTERNAL_CFLAGS))" ; \
432 SUPPORT_LIB_DIR="" ; \
433 if test `find $${ARCH_SYSROOT_DIR} -name 'libstdc++.a' | wc -l` -eq 0 ; then \
434 LIBSTDCPP_A_LOCATION=$$(LANG=C $(TOOLCHAIN_EXTERNAL_CC) $(TOOLCHAIN_EXTERNAL_CFLAGS) -print-file-name=libstdc++.a) ; \
435 if [ -e "$${LIBSTDCPP_A_LOCATION}" ]; then \
436 SUPPORT_LIB_DIR=`readlink -f $${LIBSTDCPP_A_LOCATION} | sed -r -e 's:libstdc\+\+\.a::'` ; \
439 if [ "$${SYSROOT_DIR}" == "$${ARCH_SYSROOT_DIR}" ] ; then \
441 elif [ "`dirname $${ARCH_SYSROOT_DIR}`" = "`dirname $${SYSROOT_DIR}`" ] ; then \
442 SYSROOT_DIR_DIRNAME=`dirname $${SYSROOT_DIR}`/ ; \
443 ARCH_SUBDIR=`echo $${ARCH_SYSROOT_DIR} | sed -r -e "s:^$${SYSROOT_DIR_DIRNAME}(.*)/$$:\1:"` ; \
445 ARCH_SUBDIR=`echo $${ARCH_SYSROOT_DIR} | sed -r -e "s:^$${SYSROOT_DIR}(.*)/$$:\1:"` ; \
447 $(call MESSAGE,"Copying external toolchain sysroot to staging...") ; \
448 $(call copy_toolchain_sysroot,$${SYSROOT_DIR},$${ARCH_SYSROOT_DIR},$${ARCH_SUBDIR},$${ARCH_LIB_DIR},$${SUPPORT_LIB_DIR})
451 # Create a symlink from (usr/)$(ARCH_LIB_DIR) to lib.
452 # Note: the skeleton package additionally creates lib32->lib or lib64->lib
455 # $1: destination directory (TARGET_DIR / STAGING_DIR)
456 create_lib_symlinks = \
457 $(Q)DESTDIR="$(strip $1)" ; \
458 ARCH_LIB_DIR="$(call toolchain_find_libdir,$(TOOLCHAIN_EXTERNAL_CC) $(TOOLCHAIN_EXTERNAL_CFLAGS))" ; \
459 if [ ! -e "$${DESTDIR}/$${ARCH_LIB_DIR}" -a ! -e "$${DESTDIR}/usr/$${ARCH_LIB_DIR}" ]; then \
460 relpath="$(call relpath_prefix,$${ARCH_LIB_DIR})" ; \
461 ln -snf $${relpath}lib "$${DESTDIR}/$${ARCH_LIB_DIR}" ; \
462 ln -snf $${relpath}lib "$${DESTDIR}/usr/$${ARCH_LIB_DIR}" ; \
465 define TOOLCHAIN_EXTERNAL_CREATE_STAGING_LIB_SYMLINK
466 $(call create_lib_symlinks,$(STAGING_DIR))
469 define TOOLCHAIN_EXTERNAL_CREATE_TARGET_LIB_SYMLINK
470 $(call create_lib_symlinks,$(TARGET_DIR))
474 # Generate gdbinit file for use with Buildroot
476 define TOOLCHAIN_EXTERNAL_INSTALL_GDBINIT
477 $(Q)if test -f $(TARGET_CROSS)gdb ; then \
478 $(call MESSAGE,"Installing gdbinit"); \
479 $(gen_gdbinit_file); \
483 # uClibc-ng dynamic loader is called ld-uClibc.so.1, but gcc is not
484 # patched specifically for uClibc-ng, so it continues to generate
485 # binaries that expect the dynamic loader to be named ld-uClibc.so.0,
486 # like with the original uClibc. Therefore, we create an additional
487 # symbolic link to make uClibc-ng systems work properly.
488 define TOOLCHAIN_EXTERNAL_FIXUP_UCLIBCNG_LDSO
489 $(Q)if test -e $(TARGET_DIR)/lib/ld-uClibc.so.1; then \
490 ln -sf ld-uClibc.so.1 $(TARGET_DIR)/lib/ld-uClibc.so.0 ; \
492 $(Q)if test -e $(TARGET_DIR)/lib/ld64-uClibc.so.1; then \
493 ln -sf ld64-uClibc.so.1 $(TARGET_DIR)/lib/ld64-uClibc.so.0 ; \
498 ################################################################################
499 # inner-toolchain-external-package -- defines the generic installation rules
500 # for external toolchain packages
502 # argument 1 is the lowercase package name
503 # argument 2 is the uppercase package name, including a HOST_ prefix
505 # argument 3 is the uppercase package name, without the HOST_ prefix
507 # argument 4 is the type (target or host)
508 ################################################################################
509 define inner-toolchain-external-package
511 $(2)_INSTALL_STAGING = YES
512 $(2)_ADD_TOOLCHAIN_DEPENDENCY = NO
514 # In fact, we don't need to download the toolchain, since it is already
515 # available on the system, so force the site and source to be empty so
516 # that nothing will be downloaded/extracted.
517 ifeq ($$(BR2_TOOLCHAIN_EXTERNAL_PREINSTALLED),y)
522 ifeq ($$(BR2_TOOLCHAIN_EXTERNAL_DOWNLOAD),y)
523 $(2)_EXCLUDES = usr/lib/locale/*
525 $(2)_POST_EXTRACT_HOOKS += \
526 TOOLCHAIN_EXTERNAL_MOVE
529 # Checks for an already installed toolchain: check the toolchain
530 # location, check that it is usable, and then verify that it
531 # matches the configuration provided in Buildroot: ABI, C++ support,
532 # kernel headers version, type of C library and all C library features.
533 define $(2)_CONFIGURE_CMDS
534 $$(Q)$$(call check_cross_compiler_exists,$$(TOOLCHAIN_EXTERNAL_CC))
535 $$(Q)$$(call check_unusable_toolchain,$$(TOOLCHAIN_EXTERNAL_CC))
536 $$(Q)SYSROOT_DIR="$$(call toolchain_find_sysroot,$$(TOOLCHAIN_EXTERNAL_CC))" ; \
537 $$(call check_kernel_headers_version,\
538 $$(call toolchain_find_sysroot,$$(TOOLCHAIN_EXTERNAL_CC)),\
539 $$(call qstrip,$$(BR2_TOOLCHAIN_HEADERS_AT_LEAST))); \
540 $$(call check_gcc_version,$$(TOOLCHAIN_EXTERNAL_CC),\
541 $$(call qstrip,$$(BR2_TOOLCHAIN_GCC_AT_LEAST))); \
542 if test "$$(BR2_arm)" = "y" ; then \
543 $$(call check_arm_abi,\
544 "$$(TOOLCHAIN_EXTERNAL_CC) $$(TOOLCHAIN_EXTERNAL_CFLAGS)") ; \
546 if test "$$(BR2_INSTALL_LIBSTDCPP)" = "y" ; then \
547 $$(call check_cplusplus,$$(TOOLCHAIN_EXTERNAL_CXX)) ; \
549 if test "$$(BR2_TOOLCHAIN_HAS_FORTRAN)" = "y" ; then \
550 $$(call check_fortran,$$(TOOLCHAIN_EXTERNAL_FC)) ; \
552 if test "$$(BR2_TOOLCHAIN_EXTERNAL_UCLIBC)" = "y" ; then \
553 $$(call check_uclibc,$$$${SYSROOT_DIR}) ; \
554 elif test "$$(BR2_TOOLCHAIN_EXTERNAL_MUSL)" = "y" ; then \
556 "$$(TOOLCHAIN_EXTERNAL_CC) $$(TOOLCHAIN_EXTERNAL_CFLAGS)",\
557 $$(TOOLCHAIN_EXTERNAL_READELF)) ; \
559 $$(call check_glibc,$$$${SYSROOT_DIR}) ; \
561 $$(Q)$$(call check_toolchain_ssp,$$(TOOLCHAIN_EXTERNAL_CC))
564 $(2)_TOOLCHAIN_WRAPPER_ARGS += $$(TOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS)
566 $(2)_BUILD_CMDS = $$(TOOLCHAIN_WRAPPER_BUILD)
568 define $(2)_INSTALL_STAGING_CMDS
569 $$(TOOLCHAIN_WRAPPER_INSTALL)
570 $$(TOOLCHAIN_EXTERNAL_CREATE_STAGING_LIB_SYMLINK)
571 $$(TOOLCHAIN_EXTERNAL_INSTALL_SYSROOT_LIBS)
572 $$(TOOLCHAIN_EXTERNAL_INSTALL_WRAPPER)
573 $$(TOOLCHAIN_EXTERNAL_INSTALL_GDBINIT)
576 # Even though we're installing things in both the staging, the host
577 # and the target directory, we do everything within the
578 # install-staging step, arbitrarily.
579 define $(2)_INSTALL_TARGET_CMDS
580 $$(TOOLCHAIN_EXTERNAL_CREATE_TARGET_LIB_SYMLINK)
581 $$(TOOLCHAIN_EXTERNAL_INSTALL_TARGET_LIBS)
582 $$(TOOLCHAIN_EXTERNAL_INSTALL_TARGET_GDBSERVER)
583 $$(TOOLCHAIN_EXTERNAL_FIXUP_UCLIBCNG_LDSO)
586 # Call the generic package infrastructure to generate the necessary
588 $(call inner-generic-package,$(1),$(2),$(3),$(4))
592 toolchain-external-package = $(call inner-toolchain-external-package,$(pkgname),$(call UPPERCASE,$(pkgname)),$(call UPPERCASE,$(pkgname)),target)