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, 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 # * Xilinx toolchains for the Microblaze architecture
20 # * Synopsys DesignWare toolchains for ARC cores
22 # The basic principle is the following
24 # 1. If the toolchain is not pre-installed, download and extract it
25 # in $(TOOLCHAIN_EXTERNAL_INSTALL_DIR). Otherwise,
26 # $(TOOLCHAIN_EXTERNAL_INSTALL_DIR) points to were the toolchain has
27 # already been installed by the user.
29 # 2. For all external toolchains, perform some checks on the
30 # conformity between the toolchain configuration described in the
31 # Buildroot menuconfig system, and the real configuration of the
32 # external toolchain. This is for example important to make sure that
33 # the Buildroot configuration system knows whether the toolchain
34 # supports RPC, IPv6, locales, large files, etc. Unfortunately, these
35 # things cannot be detected automatically, since the value of these
36 # options (such as BR2_TOOLCHAIN_HAS_NATIVE_RPC) are needed at
37 # configuration time because these options are used as dependencies
38 # for other options. And at configuration time, we are not able to
39 # retrieve the external toolchain configuration.
41 # 3. Copy the libraries needed at runtime to the target directory,
42 # $(TARGET_DIR). Obviously, things such as the C library, the dynamic
43 # loader and a few other utility libraries are needed if dynamic
44 # applications are to be executed on the target system.
46 # 4. Copy the libraries and headers to the staging directory. This
47 # will allow all further calls to gcc to be made using --sysroot
48 # $(STAGING_DIR), which greatly simplifies the compilation of the
49 # packages when using external toolchains. So in the end, only the
50 # cross-compiler binaries remains external, all libraries and headers
51 # are imported into the Buildroot tree.
53 # 5. Build a toolchain wrapper which executes the external toolchain
54 # with a number of arguments (sysroot/march/mtune/..) hardcoded,
55 # so we're sure the correct configuration is always used and the
56 # toolchain behaves similar to an internal toolchain.
57 # This toolchain wrapper and symlinks are installed into
58 # $(HOST_DIR)/usr/bin like for the internal toolchains, and the rest
59 # of Buildroot is handled identical for the 2 toolchain types.
60 ################################################################################
63 # Definitions of where the toolchain can be found
66 TOOLCHAIN_EXTERNAL_PREFIX
= $(call qstrip
,$(BR2_TOOLCHAIN_EXTERNAL_PREFIX
))
67 TOOLCHAIN_EXTERNAL_DOWNLOAD_INSTALL_DIR
= $(HOST_DIR
)/opt
/ext-toolchain
69 ifeq ($(BR2_TOOLCHAIN_EXTERNAL_DOWNLOAD
),y
)
70 TOOLCHAIN_EXTERNAL_INSTALL_DIR
= $(TOOLCHAIN_EXTERNAL_DOWNLOAD_INSTALL_DIR
)
72 TOOLCHAIN_EXTERNAL_INSTALL_DIR
= $(call qstrip
,$(BR2_TOOLCHAIN_EXTERNAL_PATH
))
75 ifeq ($(TOOLCHAIN_EXTERNAL_INSTALL_DIR
),)
76 ifneq ($(TOOLCHAIN_EXTERNAL_PREFIX
),)
77 # if no path set, figure it out from path
78 TOOLCHAIN_EXTERNAL_BIN
:= $(shell dirname
$(shell which
$(TOOLCHAIN_EXTERNAL_PREFIX
)-gcc
))
81 TOOLCHAIN_EXTERNAL_BIN
:= $(TOOLCHAIN_EXTERNAL_INSTALL_DIR
)/bin
84 # If this is a buildroot toolchain, it already has a wrapper which we want to
85 # bypass. Since this is only evaluated after it has been extracted, we can use
86 # $(wildcard ...) here.
87 TOOLCHAIN_EXTERNAL_SUFFIX
= \
88 $(if
$(wildcard $(TOOLCHAIN_EXTERNAL_BIN
)/*.br_real
),.br_real
)
90 TOOLCHAIN_EXTERNAL_CROSS
= $(TOOLCHAIN_EXTERNAL_BIN
)/$(TOOLCHAIN_EXTERNAL_PREFIX
)-
91 TOOLCHAIN_EXTERNAL_CC
= $(TOOLCHAIN_EXTERNAL_CROSS
)gcc
$(TOOLCHAIN_EXTERNAL_SUFFIX
)
92 TOOLCHAIN_EXTERNAL_CXX
= $(TOOLCHAIN_EXTERNAL_CROSS
)g
++$(TOOLCHAIN_EXTERNAL_SUFFIX
)
93 TOOLCHAIN_EXTERNAL_FC
= $(TOOLCHAIN_EXTERNAL_CROSS
)gfortran
$(TOOLCHAIN_EXTERNAL_SUFFIX
)
94 TOOLCHAIN_EXTERNAL_READELF
= $(TOOLCHAIN_EXTERNAL_CROSS
)readelf
$(TOOLCHAIN_EXTERNAL_SUFFIX
)
96 # Normal handling of downloaded toolchain tarball extraction.
97 ifeq ($(BR2_TOOLCHAIN_EXTERNAL_DOWNLOAD
),y
)
98 # As a regular package, the toolchain gets extracted in $(@D), but
99 # since it's actually a fairly special package, we need it to be moved
100 # into TOOLCHAIN_EXTERNAL_DOWNLOAD_INSTALL_DIR.
101 define TOOLCHAIN_EXTERNAL_MOVE
102 rm -rf
$(TOOLCHAIN_EXTERNAL_DOWNLOAD_INSTALL_DIR
)
103 mkdir
-p
$(TOOLCHAIN_EXTERNAL_DOWNLOAD_INSTALL_DIR
)
104 mv
$(@D
)/* $(TOOLCHAIN_EXTERNAL_DOWNLOAD_INSTALL_DIR
)/
109 # Definitions of the list of libraries that should be copied to the target.
111 ifeq ($(BR2_TOOLCHAIN_EXTERNAL_GLIBC
)$(BR2_TOOLCHAIN_EXTERNAL_UCLIBC
),y
)
112 TOOLCHAIN_EXTERNAL_LIBS
+= libatomic.so.
* libc.so.
* libcrypt.so.
* libdl.so.
* libgcc_s.so.
* libm.so.
* libnsl.so.
* libresolv.so.
* librt.so.
* libutil.so.
*
113 ifeq ($(BR2_TOOLCHAIN_EXTERNAL_GLIBC
)$(BR2_ARM_EABIHF
),yy
)
114 TOOLCHAIN_EXTERNAL_LIBS
+= ld-linux-armhf.so.
*
116 TOOLCHAIN_EXTERNAL_LIBS
+= ld*.so.
*
118 ifeq ($(BR2_TOOLCHAIN_HAS_THREADS
),y
)
119 TOOLCHAIN_EXTERNAL_LIBS
+= libpthread.so.
*
120 ifneq ($(BR2_PACKAGE_GDB
)$(BR2_TOOLCHAIN_EXTERNAL_GDB_SERVER_COPY
),)
121 TOOLCHAIN_EXTERNAL_LIBS
+= libthread_db.so.
*
126 ifeq ($(BR2_TOOLCHAIN_EXTERNAL_GLIBC
),y
)
127 TOOLCHAIN_EXTERNAL_LIBS
+= libnss_files.so.
* libnss_dns.so.
* libmvec.so.
* libanl.so.
*
130 ifeq ($(BR2_TOOLCHAIN_EXTERNAL_MUSL
),y
)
131 TOOLCHAIN_EXTERNAL_LIBS
+= libc.so libgcc_s.so.
*
134 ifeq ($(BR2_INSTALL_LIBSTDCPP
),y
)
135 TOOLCHAIN_EXTERNAL_LIBS
+= libstdc
++.so.
*
138 ifeq ($(BR2_TOOLCHAIN_HAS_FORTRAN
),y
)
139 TOOLCHAIN_EXTERNAL_LIBS
+= libgfortran.so.
*
140 # fortran needs quadmath on x86 and x86_64
141 ifeq ($(BR2_TOOLCHAIN_HAS_LIBQUADMATH
),y
)
142 TOOLCHAIN_EXTERNAL_LIBS
+= libquadmath.so
*
146 TOOLCHAIN_EXTERNAL_LIBS
+= $(call qstrip
,$(BR2_TOOLCHAIN_EXTRA_EXTERNAL_LIBS
))
150 # Definition of the CFLAGS to use with the external toolchain, as well as the
151 # common toolchain wrapper build arguments
153 ifeq ($(call qstrip
,$(BR2_GCC_TARGET_CPU_REVISION
)),)
154 CC_TARGET_CPU_
:= $(call qstrip
,$(BR2_GCC_TARGET_CPU
))
156 CC_TARGET_CPU_
:= $(call qstrip
,$(BR2_GCC_TARGET_CPU
)-$(BR2_GCC_TARGET_CPU_REVISION
))
158 CC_TARGET_ARCH_
:= $(call qstrip
,$(BR2_GCC_TARGET_ARCH
))
159 CC_TARGET_ABI_
:= $(call qstrip
,$(BR2_GCC_TARGET_ABI
))
160 CC_TARGET_FPU_
:= $(call qstrip
,$(BR2_GCC_TARGET_FPU
))
161 CC_TARGET_FLOAT_ABI_
:= $(call qstrip
,$(BR2_GCC_TARGET_FLOAT_ABI
))
162 CC_TARGET_MODE_
:= $(call qstrip
,$(BR2_GCC_TARGET_MODE
))
164 # march/mtune/floating point mode needs to be passed to the external toolchain
165 # to select the right multilib variant
166 ifeq ($(BR2_x86_64
),y
)
167 TOOLCHAIN_EXTERNAL_CFLAGS
+= -m64
168 TOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS
+= -DBR_64
170 ifneq ($(CC_TARGET_ARCH_
),)
171 TOOLCHAIN_EXTERNAL_CFLAGS
+= -march
=$(CC_TARGET_ARCH_
)
172 TOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS
+= -DBR_ARCH
='"$(CC_TARGET_ARCH_)"'
174 ifneq ($(CC_TARGET_CPU_
),)
175 TOOLCHAIN_EXTERNAL_CFLAGS
+= -mcpu
=$(CC_TARGET_CPU_
)
176 TOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS
+= -DBR_CPU
='"$(CC_TARGET_CPU_)"'
178 ifneq ($(CC_TARGET_ABI_
),)
179 TOOLCHAIN_EXTERNAL_CFLAGS
+= -mabi
=$(CC_TARGET_ABI_
)
180 TOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS
+= -DBR_ABI
='"$(CC_TARGET_ABI_)"'
182 ifneq ($(CC_TARGET_FPU_
),)
183 TOOLCHAIN_EXTERNAL_CFLAGS
+= -mfpu
=$(CC_TARGET_FPU_
)
184 TOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS
+= -DBR_FPU
='"$(CC_TARGET_FPU_)"'
186 ifneq ($(CC_TARGET_FLOAT_ABI_
),)
187 TOOLCHAIN_EXTERNAL_CFLAGS
+= -mfloat-abi
=$(CC_TARGET_FLOAT_ABI_
)
188 TOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS
+= -DBR_FLOAT_ABI
='"$(CC_TARGET_FLOAT_ABI_)"'
190 ifneq ($(CC_TARGET_MODE_
),)
191 TOOLCHAIN_EXTERNAL_CFLAGS
+= -m
$(CC_TARGET_MODE_
)
192 TOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS
+= -DBR_MODE
='"$(CC_TARGET_MODE_)"'
194 ifeq ($(BR2_BINFMT_FLAT
),y
)
195 TOOLCHAIN_EXTERNAL_CFLAGS
+= -Wl
,-elf2flt
196 TOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS
+= -DBR_BINFMT_FLAT
198 ifeq ($(BR2_mipsel
)$(BR2_mips64el
),y
)
199 TOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS
+= -DBR_MIPS_TARGET_LITTLE_ENDIAN
200 TOOLCHAIN_EXTERNAL_CFLAGS
+= -EL
202 ifeq ($(BR2_mips
)$(BR2_mips64
),y
)
203 TOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS
+= -DBR_MIPS_TARGET_BIG_ENDIAN
204 TOOLCHAIN_EXTERNAL_CFLAGS
+= -EB
206 ifeq ($(BR2_arceb
),y
)
207 TOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS
+= -DBR_ARC_TARGET_BIG_ENDIAN
208 TOOLCHAIN_EXTERNAL_CFLAGS
+= -EB
211 TOOLCHAIN_EXTERNAL_CFLAGS
+= $(call qstrip
,$(BR2_TARGET_OPTIMIZATION
))
213 ifeq ($(BR2_SOFT_FLOAT
),y
)
214 TOOLCHAIN_EXTERNAL_CFLAGS
+= -msoft-float
215 TOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS
+= -DBR_SOFTFLOAT
=1
218 TOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS
+= \
219 -DBR_CROSS_PATH_SUFFIX
='"$(TOOLCHAIN_EXTERNAL_SUFFIX)"'
221 ifeq ($(filter $(HOST_DIR
)/%,$(TOOLCHAIN_EXTERNAL_BIN
)),)
222 # TOOLCHAIN_EXTERNAL_BIN points outside HOST_DIR => absolute path
223 TOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS
+= \
224 -DBR_CROSS_PATH_ABS
='"$(TOOLCHAIN_EXTERNAL_BIN)"'
226 # TOOLCHAIN_EXTERNAL_BIN points inside HOST_DIR => relative path
227 TOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS
+= \
228 -DBR_CROSS_PATH_REL
='"$(TOOLCHAIN_EXTERNAL_BIN:$(HOST_DIR)/%=%)"'
233 # The following functions creates the symbolic links needed to get the
234 # cross-compilation tools visible in $(HOST_DIR)/usr/bin. Some of
235 # links are done directly to the corresponding tool in the external
236 # toolchain installation directory, while some other links are done to
237 # the toolchain wrapper (preprocessor, C, C++ and Fortran compiler)
239 # We skip gdb symlink when we are building our own gdb to prevent two
240 # gdb's in $(HOST_DIR)/usr/bin.
242 # The LTO support in gcc creates wrappers for ar, ranlib and nm which load
243 # the lto plugin. These wrappers are called *-gcc-ar, *-gcc-ranlib, and
244 # *-gcc-nm and should be used instead of the real programs when -flto is
245 # used. However, we should not add the toolchain wrapper for them, and they
246 # match the *cc-* pattern. Therefore, an additional case is added for *-ar,
248 define TOOLCHAIN_EXTERNAL_INSTALL_WRAPPER
249 $(Q
)cd
$(HOST_DIR
)/usr
/bin
; \
250 for i in
$(TOOLCHAIN_EXTERNAL_CROSS
)*; do \
253 *-ar|
*-ranlib|
*-nm
) \
254 ln
-sf
$$(echo
$$i | sed
's%^$(HOST_DIR)%../..%') .
; \
256 *cc|
*cc-
*|
*++|
*++-*|
*cpp|
*-gfortran
) \
257 ln
-sf toolchain-wrapper
$$base; \
260 if
test "$(BR2_PACKAGE_HOST_GDB)" != "y"; then \
261 ln
-sf
$$(echo
$$i | sed
's%^$(HOST_DIR)%../..%') .
; \
265 ln
-sf
$$(echo
$$i | sed
's%^$(HOST_DIR)%../..%') .
; \
272 # Various utility functions used by the external toolchain package
273 # infrastructure. Those functions are mainly responsible for:
275 # - installation the toolchain libraries to $(TARGET_DIR)
276 # - copying the toolchain sysroot to $(STAGING_DIR)
277 # - installing a gdbinit file
279 # Details about sysroot directory selection.
281 # To find the sysroot directory, we use the trick of looking for the
282 # 'libc.a' file with the -print-file-name gcc option, and then
283 # mangling the path to find the base directory of the sysroot.
285 # Note that we do not use the -print-sysroot option, because it is
286 # only available since gcc 4.4.x, and we only recently dropped support
287 # for 4.2.x and 4.3.x.
289 # When doing this, we don't pass any option to gcc that could select a
290 # multilib variant (such as -march) as we want the "main" sysroot,
291 # which contains all variants of the C library in the case of multilib
292 # toolchains. We use the TARGET_CC_NO_SYSROOT variable, which is the
293 # path of the cross-compiler, without the --sysroot=$(STAGING_DIR),
294 # since what we want to find is the location of the original toolchain
295 # sysroot. This "main" sysroot directory is stored in SYSROOT_DIR.
297 # Then, multilib toolchains are a little bit more complicated, since
298 # they in fact have multiple sysroots, one for each variant supported
299 # by the toolchain. So we need to find the particular sysroot we're
302 # To do so, we ask the compiler where its sysroot is by passing all
303 # flags (including -march and al.), except the --sysroot flag since we
304 # want to the compiler to tell us where its original sysroot
305 # is. ARCH_SUBDIR will contain the subdirectory, in the main
306 # SYSROOT_DIR, that corresponds to the selected architecture
307 # variant. ARCH_SYSROOT_DIR will contain the full path to this
310 # One might wonder why we don't just bother with ARCH_SYSROOT_DIR. The
311 # fact is that in multilib toolchains, the header files are often only
312 # present in the main sysroot, and only the libraries are available in
313 # each variant-specific sysroot directory.
316 # toolchain_find_sysroot returns the sysroot location for the given
317 # compiler + flags. We need to handle cases where libc.a is in:
323 # - lib32-fp/ (Cavium toolchain)
324 # - lib64-fp/ (Cavium toolchain)
325 # - usr/lib/<tuple>/ (Linaro toolchain)
327 # And variations on these.
328 define toolchain_find_sysroot
329 $$(printf
$(call toolchain_find_libc_a
,$(1)) | sed
-r
-e
's:(usr/)?lib(32|64)?([^/]*)?/([^/]*/)?libc\.a::')
332 # Returns the lib subdirectory for the given compiler + flags (i.e
333 # typically lib32 or lib64 for some toolchains)
334 define toolchain_find_libdir
335 $$(printf
$(call toolchain_find_libc_a
,$(1)) | sed
-r
-e
's:.*/(usr/)?(lib(32|64)?([^/]*)?)/([^/]*/)?libc.a:\2:')
338 # Returns the location of the libc.a file for the given compiler + flags
339 define toolchain_find_libc_a
340 $$(readlink
-f
$$(LANG
=C
$(1) -print-file-name
=libc.a
))
343 # Integration of the toolchain into Buildroot: find the main sysroot
344 # and the variant-specific sysroot, then copy the needed libraries to
345 # the $(TARGET_DIR) and copy the whole sysroot (libraries and headers)
348 # Variables are defined as follows:
350 # SYSROOT_DIR: the main sysroot directory, deduced from the location of
351 # the libc.a file in the default multilib variant, by
352 # removing the usr/lib[32|64]/libc.a part of the path.
353 # Ex: /x-tools/mips-2011.03/mips-linux-gnu/libc/
355 # ARCH_SYSROOT_DIR: the sysroot of the selected multilib variant,
356 # deduced from the location of the libc.a file in the
357 # selected multilib variant (taking into account the
358 # CFLAGS), by removing usr/lib[32|64]/libc.a at the end
360 # Ex: /x-tools/mips-2011.03/mips-linux-gnu/libc/mips16/soft-float/el/
362 # ARCH_LIB_DIR: 'lib', 'lib32' or 'lib64' depending on where libraries
363 # are stored. Deduced from the location of the libc.a file
364 # in the selected multilib variant, by looking at
368 # ARCH_SUBDIR: the relative location of the sysroot of the selected
369 # multilib variant compared to the main sysroot.
370 # Ex: mips16/soft-float/el
372 # SUPPORT_LIB_DIR: some toolchains, such as recent Linaro toolchains,
373 # store GCC support libraries (libstdc++,
374 # libgcc_s, etc.) outside of the sysroot. In
375 # this case, SUPPORT_LIB_DIR is set to a
376 # non-empty value, and points to the directory
377 # where these support libraries are
378 # available. Those libraries will be copied to
379 # our sysroot, and the directory will also be
380 # considered when searching libraries for copy
381 # to the target filesystem.
383 # Please be very careful to check the major toolchain sources:
384 # Buildroot, Crosstool-NG, CodeSourcery and Linaro
385 # before doing any modification on the below logic.
387 ifeq ($(BR2_STATIC_LIBS
),)
388 define TOOLCHAIN_EXTERNAL_INSTALL_TARGET_LIBS
389 $(Q
)$(call MESSAGE
,"Copying external toolchain libraries to target...")
390 $(Q
)for libs in
$(TOOLCHAIN_EXTERNAL_LIBS
); do \
391 $(call copy_toolchain_lib_root
,$$libs); \
396 ifeq ($(BR2_TOOLCHAIN_EXTERNAL_GDB_SERVER_COPY
),y
)
397 define TOOLCHAIN_EXTERNAL_INSTALL_TARGET_GDBSERVER
398 $(Q
)$(call MESSAGE
,"Copying gdbserver")
399 $(Q
)ARCH_SYSROOT_DIR
="$(call toolchain_find_sysroot,$(TOOLCHAIN_EXTERNAL_CC) $(TOOLCHAIN_EXTERNAL_CFLAGS))" ; \
400 ARCH_LIB_DIR
="$(call toolchain_find_libdir,$(TOOLCHAIN_EXTERNAL_CC) $(TOOLCHAIN_EXTERNAL_CFLAGS))" ; \
401 gdbserver_found
=0 ; \
402 for d in
$${ARCH_SYSROOT_DIR}/usr \
403 $${ARCH_SYSROOT_DIR}/..
/debug-root
/usr \
404 $${ARCH_SYSROOT_DIR}/usr
/$${ARCH_LIB_DIR} \
405 $(TOOLCHAIN_EXTERNAL_INSTALL_DIR
); do \
406 if
test -f
$${d}/bin
/gdbserver
; then \
407 install -m
0755 -D
$${d}/bin
/gdbserver
$(TARGET_DIR
)/usr
/bin
/gdbserver
; \
408 gdbserver_found
=1 ; \
412 if
[ $${gdbserver_found} -eq
0 ] ; then \
413 echo
"Could not find gdbserver in external toolchain" ; \
419 define TOOLCHAIN_EXTERNAL_INSTALL_SYSROOT_LIBS
420 $(Q
)SYSROOT_DIR
="$(call toolchain_find_sysroot,$(TOOLCHAIN_EXTERNAL_CC))" ; \
421 ARCH_SYSROOT_DIR
="$(call toolchain_find_sysroot,$(TOOLCHAIN_EXTERNAL_CC) $(TOOLCHAIN_EXTERNAL_CFLAGS))" ; \
422 ARCH_LIB_DIR
="$(call toolchain_find_libdir,$(TOOLCHAIN_EXTERNAL_CC) $(TOOLCHAIN_EXTERNAL_CFLAGS))" ; \
423 SUPPORT_LIB_DIR
="" ; \
424 if
test `find $${ARCH_SYSROOT_DIR} -name 'libstdc++.a' | wc -l` -eq
0 ; then \
425 LIBSTDCPP_A_LOCATION
=$$(LANG
=C
$(TOOLCHAIN_EXTERNAL_CC
) $(TOOLCHAIN_EXTERNAL_CFLAGS
) -print-file-name
=libstdc
++.a
) ; \
426 if
[ -e
"$${LIBSTDCPP_A_LOCATION}" ]; then \
427 SUPPORT_LIB_DIR
=`readlink -f $${LIBSTDCPP_A_LOCATION} | sed -r -e 's:libstdc\+\+\.a::'` ; \
430 if
[ "$${SYSROOT_DIR}" == "$${ARCH_SYSROOT_DIR}" ] ; then \
432 elif
[ "`dirname $${ARCH_SYSROOT_DIR}`" = "`dirname $${SYSROOT_DIR}`" ] ; then \
433 SYSROOT_DIR_DIRNAME
=`dirname $${SYSROOT_DIR}`/ ; \
434 ARCH_SUBDIR
=`echo $${ARCH_SYSROOT_DIR} | sed -r -e "s:^$${SYSROOT_DIR_DIRNAME}(.*)/$$:\1:"` ; \
436 ARCH_SUBDIR
=`echo $${ARCH_SYSROOT_DIR} | sed -r -e "s:^$${SYSROOT_DIR}(.*)/$$:\1:"` ; \
438 $(call MESSAGE
,"Copying external toolchain sysroot to staging...") ; \
439 $(call copy_toolchain_sysroot
,$${SYSROOT_DIR},$${ARCH_SYSROOT_DIR},$${ARCH_SUBDIR},$${ARCH_LIB_DIR},$${SUPPORT_LIB_DIR})
442 # Create a symlink from (usr/)$(ARCH_LIB_DIR) to lib.
443 # Note: the skeleton package additionally creates lib32->lib or lib64->lib
446 # $1: destination directory (TARGET_DIR / STAGING_DIR)
447 create_lib_symlinks
= \
448 $(Q
)DESTDIR
="$(strip $1)" ; \
449 ARCH_LIB_DIR
="$(call toolchain_find_libdir,$(TOOLCHAIN_EXTERNAL_CC) $(TOOLCHAIN_EXTERNAL_CFLAGS))" ; \
450 if
[ ! -e
"$${DESTDIR}/$${ARCH_LIB_DIR}" -a
! -e
"$${DESTDIR}/usr/$${ARCH_LIB_DIR}" ]; then \
451 ln
-snf lib
"$${DESTDIR}/$${ARCH_LIB_DIR}" ; \
452 ln
-snf lib
"$${DESTDIR}/usr/$${ARCH_LIB_DIR}" ; \
455 define TOOLCHAIN_EXTERNAL_CREATE_STAGING_LIB_SYMLINK
456 $(call create_lib_symlinks
,$(STAGING_DIR
))
459 define TOOLCHAIN_EXTERNAL_CREATE_TARGET_LIB_SYMLINK
460 $(call create_lib_symlinks
,$(TARGET_DIR
))
464 # Generate gdbinit file for use with Buildroot
466 define TOOLCHAIN_EXTERNAL_INSTALL_GDBINIT
467 $(Q
)if
test -f
$(TARGET_CROSS
)gdb
; then \
468 $(call MESSAGE
,"Installing gdbinit"); \
469 $(gen_gdbinit_file
); \
473 # Various utility functions used by the external toolchain based on musl.
475 # With the musl C library, the libc.so library directly plays the role
476 # of the dynamic library loader. We just need to create a symbolic
477 # link to libc.so with the appropriate name.
478 ifeq ($(BR2_TOOLCHAIN_EXTERNAL_MUSL
),y
)
481 else ifeq ($(BR2_ARM_EABIHF
),y
)
483 else ifeq ($(BR2_mipsel
):$(BR2_SOFT_FLOAT
),y
:y
)
484 MUSL_ARCH
= mipsel-sf
485 else ifeq ($(BR2_sh
),y
)
490 define TOOLCHAIN_EXTERNAL_MUSL_LD_LINK
491 ln
-sf libc.so
$(TARGET_DIR
)/lib
/ld-musl-
$(MUSL_ARCH
).so
.1
495 # uClibc-ng dynamic loader is called ld-uClibc.so.1, but gcc is not
496 # patched specifically for uClibc-ng, so it continues to generate
497 # binaries that expect the dynamic loader to be named ld-uClibc.so.0,
498 # like with the original uClibc. Therefore, we create an additional
499 # symbolic link to make uClibc-ng systems work properly.
500 define TOOLCHAIN_EXTERNAL_FIXUP_UCLIBCNG_LDSO
501 $(Q
)if
test -e
$(TARGET_DIR
)/lib
/ld-uClibc.so
.1; then \
502 ln
-sf ld-uClibc.so
.1 $(TARGET_DIR
)/lib
/ld-uClibc.so
.0 ; \
504 $(Q
)if
test -e
$(TARGET_DIR
)/lib
/ld64-uClibc.so
.1; then \
505 ln
-sf ld64-uClibc.so
.1 $(TARGET_DIR
)/lib
/ld64-uClibc.so
.0 ; \
510 ################################################################################
511 # inner-toolchain-external-package -- defines the generic installation rules
512 # for external toolchain packages
514 # argument 1 is the lowercase package name
515 # argument 2 is the uppercase package name, including a HOST_ prefix
517 # argument 3 is the uppercase package name, without the HOST_ prefix
519 # argument 4 is the type (target or host)
520 ################################################################################
521 define inner-toolchain-external-package
523 $(2)_INSTALL_STAGING
= YES
524 $(2)_ADD_TOOLCHAIN_DEPENDENCY
= NO
526 # In fact, we don't need to download the toolchain, since it is already
527 # available on the system, so force the site and source to be empty so
528 # that nothing will be downloaded/extracted.
529 ifeq ($$(BR2_TOOLCHAIN_EXTERNAL_PREINSTALLED
),y
)
534 ifeq ($$(BR2_TOOLCHAIN_EXTERNAL_DOWNLOAD
),y
)
535 $(2)_EXCLUDES
= usr
/lib
/locale
/*
537 $(2)_POST_EXTRACT_HOOKS
+= \
538 TOOLCHAIN_EXTERNAL_MOVE
541 # Checks for an already installed toolchain: check the toolchain
542 # location, check that it is usable, and then verify that it
543 # matches the configuration provided in Buildroot: ABI, C++ support,
544 # kernel headers version, type of C library and all C library features.
545 define $(2)_CONFIGURE_CMDS
546 $$(Q
)$$(call check_cross_compiler_exists
,$$(TOOLCHAIN_EXTERNAL_CC
))
547 $$(Q
)$$(call check_unusable_toolchain
,$$(TOOLCHAIN_EXTERNAL_CC
))
548 $$(Q
)SYSROOT_DIR
="$$(call toolchain_find_sysroot,$$(TOOLCHAIN_EXTERNAL_CC))" ; \
549 $$(call check_kernel_headers_version
,\
550 $$(call toolchain_find_sysroot
,$$(TOOLCHAIN_EXTERNAL_CC
)),\
551 $$(call qstrip
,$$(BR2_TOOLCHAIN_HEADERS_AT_LEAST
))); \
552 $$(call check_gcc_version
,$$(TOOLCHAIN_EXTERNAL_CC
),\
553 $$(call qstrip
,$$(BR2_TOOLCHAIN_GCC_AT_LEAST
))); \
554 if
test "$$(BR2_arm)" = "y" ; then \
555 $$(call check_arm_abi
,\
556 "$$(TOOLCHAIN_EXTERNAL_CC) $$(TOOLCHAIN_EXTERNAL_CFLAGS)",\
557 $$(TOOLCHAIN_EXTERNAL_READELF
)) ; \
559 if
test "$$(BR2_INSTALL_LIBSTDCPP)" = "y" ; then \
560 $$(call check_cplusplus
,$$(TOOLCHAIN_EXTERNAL_CXX
)) ; \
562 if
test "$$(BR2_TOOLCHAIN_HAS_FORTRAN)" = "y" ; then \
563 $$(call check_fortran
,$$(TOOLCHAIN_EXTERNAL_FC
)) ; \
565 if
test "$$(BR2_TOOLCHAIN_EXTERNAL_UCLIBC)" = "y" ; then \
566 $$(call check_uclibc
,$$$${SYSROOT_DIR}) ; \
567 elif
test "$$(BR2_TOOLCHAIN_EXTERNAL_MUSL)" = "y" ; then \
568 $$(call check_musl
,$$$${SYSROOT_DIR}) ; \
570 $$(call check_glibc
,$$$${SYSROOT_DIR}) ; \
572 $$(Q
)$$(call check_toolchain_ssp
,$$(TOOLCHAIN_EXTERNAL_CC
))
575 $(2)_TOOLCHAIN_WRAPPER_ARGS
+= $$(TOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS
)
577 $(2)_BUILD_CMDS
= $$(TOOLCHAIN_WRAPPER_BUILD
)
579 define $(2)_INSTALL_STAGING_CMDS
580 $$(TOOLCHAIN_WRAPPER_INSTALL
)
581 $$(TOOLCHAIN_EXTERNAL_CREATE_STAGING_LIB_SYMLINK
)
582 $$(TOOLCHAIN_EXTERNAL_INSTALL_SYSROOT_LIBS
)
583 $$(TOOLCHAIN_EXTERNAL_INSTALL_WRAPPER
)
584 $$(TOOLCHAIN_EXTERNAL_INSTALL_GDBINIT
)
587 ifeq ($$(BR2_TOOLCHAIN_EXTERNAL_MUSL
),y
)
588 $(2)_POST_INSTALL_STAGING_HOOKS
+= TOOLCHAIN_EXTERNAL_MUSL_LD_LINK
591 # Even though we're installing things in both the staging, the host
592 # and the target directory, we do everything within the
593 # install-staging step, arbitrarily.
594 define $(2)_INSTALL_TARGET_CMDS
595 $$(TOOLCHAIN_EXTERNAL_CREATE_TARGET_LIB_SYMLINK
)
596 $$(TOOLCHAIN_EXTERNAL_INSTALL_TARGET_LIBS
)
597 $$(TOOLCHAIN_EXTERNAL_INSTALL_TARGET_GDBSERVER
)
598 $$(TOOLCHAIN_EXTERNAL_FIXUP_UCLIBCNG_LDSO
)
601 # Call the generic package infrastructure to generate the necessary
603 $(call inner-generic-package
,$(1),$(2),$(3),$(4))
607 toolchain-external-package
= $(call inner-toolchain-external-package
,$(pkgname
),$(call UPPERCASE
,$(pkgname
)),$(call UPPERCASE
,$(pkgname
)),target
)