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.
*
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 # LIBC_A_LOCATION: location of the libc.a file in the default
351 # multilib variant (allows to find the main
353 # Ex: /x-tools/mips-2011.03/mips-linux-gnu/libc/usr/lib/libc.a
355 # SYSROOT_DIR: the main sysroot directory, deduced from
356 # LIBC_A_LOCATION by removing the
357 # usr/lib[32|64]/libc.a part of the path.
358 # Ex: /x-tools/mips-2011.03/mips-linux-gnu/libc/
360 # ARCH_LIBC_A_LOCATION: location of the libc.a file in the selected
361 # multilib variant (taking into account the
362 # CFLAGS). Allows to find the sysroot of the
363 # selected multilib variant.
364 # Ex: /x-tools/mips-2011.03/mips-linux-gnu/libc/mips16/soft-float/el/usr/lib/libc.a
366 # ARCH_SYSROOT_DIR: the sysroot of the selected multilib variant,
367 # deduced from ARCH_LIBC_A_LOCATION by removing
368 # usr/lib[32|64]/libc.a at the end of the path.
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 ARCH_LIBC_A_LOCATION by
373 # looking at usr/lib??/libc.a.
376 # ARCH_SUBDIR: the relative location of the sysroot of the selected
377 # multilib variant compared to the main sysroot.
378 # Ex: mips16/soft-float/el
380 # SUPPORT_LIB_DIR: some toolchains, such as recent Linaro toolchains,
381 # store GCC support libraries (libstdc++,
382 # libgcc_s, etc.) outside of the sysroot. In
383 # this case, SUPPORT_LIB_DIR is set to a
384 # non-empty value, and points to the directory
385 # where these support libraries are
386 # available. Those libraries will be copied to
387 # our sysroot, and the directory will also be
388 # considered when searching libraries for copy
389 # to the target filesystem.
391 # Please be very careful to check the major toolchain sources:
392 # Buildroot, Crosstool-NG, CodeSourcery and Linaro
393 # before doing any modification on the below logic.
395 ifeq ($(BR2_STATIC_LIBS
),)
396 define TOOLCHAIN_EXTERNAL_INSTALL_TARGET_LIBS
397 $(Q
)$(call MESSAGE
,"Copying external toolchain libraries to target...")
398 $(Q
)for libs in
$(TOOLCHAIN_EXTERNAL_LIBS
); do \
399 $(call copy_toolchain_lib_root
,$$libs); \
404 ifeq ($(BR2_TOOLCHAIN_EXTERNAL_GDB_SERVER_COPY
),y
)
405 define TOOLCHAIN_EXTERNAL_INSTALL_TARGET_GDBSERVER
406 $(Q
)$(call MESSAGE
,"Copying gdbserver")
407 $(Q
)ARCH_SYSROOT_DIR
="$(call toolchain_find_sysroot,$(TOOLCHAIN_EXTERNAL_CC) $(TOOLCHAIN_EXTERNAL_CFLAGS))" ; \
408 ARCH_LIB_DIR
="$(call toolchain_find_libdir,$(TOOLCHAIN_EXTERNAL_CC) $(TOOLCHAIN_EXTERNAL_CFLAGS))" ; \
409 gdbserver_found
=0 ; \
410 for d in
$${ARCH_SYSROOT_DIR}/usr \
411 $${ARCH_SYSROOT_DIR}/..
/debug-root
/usr \
412 $${ARCH_SYSROOT_DIR}/usr
/$${ARCH_LIB_DIR} \
413 $(TOOLCHAIN_EXTERNAL_INSTALL_DIR
); do \
414 if
test -f
$${d}/bin
/gdbserver
; then \
415 install -m
0755 -D
$${d}/bin
/gdbserver
$(TARGET_DIR
)/usr
/bin
/gdbserver
; \
416 gdbserver_found
=1 ; \
420 if
[ $${gdbserver_found} -eq
0 ] ; then \
421 echo
"Could not find gdbserver in external toolchain" ; \
427 define TOOLCHAIN_EXTERNAL_INSTALL_SYSROOT_LIBS
428 $(Q
)SYSROOT_DIR
="$(call toolchain_find_sysroot,$(TOOLCHAIN_EXTERNAL_CC))" ; \
429 ARCH_SYSROOT_DIR
="$(call toolchain_find_sysroot,$(TOOLCHAIN_EXTERNAL_CC) $(TOOLCHAIN_EXTERNAL_CFLAGS))" ; \
430 ARCH_LIB_DIR
="$(call toolchain_find_libdir,$(TOOLCHAIN_EXTERNAL_CC) $(TOOLCHAIN_EXTERNAL_CFLAGS))" ; \
431 SUPPORT_LIB_DIR
="" ; \
432 if
test `find $${ARCH_SYSROOT_DIR} -name 'libstdc++.a' | wc -l` -eq
0 ; then \
433 LIBSTDCPP_A_LOCATION
=$$(LANG
=C
$(TOOLCHAIN_EXTERNAL_CC
) $(TOOLCHAIN_EXTERNAL_CFLAGS
) -print-file-name
=libstdc
++.a
) ; \
434 if
[ -e
"$${LIBSTDCPP_A_LOCATION}" ]; then \
435 SUPPORT_LIB_DIR
=`readlink -f $${LIBSTDCPP_A_LOCATION} | sed -r -e 's:libstdc\+\+\.a::'` ; \
438 if
[ "$${SYSROOT_DIR}" == "$${ARCH_SYSROOT_DIR}" ] ; then \
440 elif
[ "`dirname $${ARCH_SYSROOT_DIR}`" = "`dirname $${SYSROOT_DIR}`" ] ; then \
441 SYSROOT_DIR_DIRNAME
=`dirname $${SYSROOT_DIR}`/ ; \
442 ARCH_SUBDIR
=`echo $${ARCH_SYSROOT_DIR} | sed -r -e "s:^$${SYSROOT_DIR_DIRNAME}(.*)/$$:\1:"` ; \
444 ARCH_SUBDIR
=`echo $${ARCH_SYSROOT_DIR} | sed -r -e "s:^$${SYSROOT_DIR}(.*)/$$:\1:"` ; \
446 $(call MESSAGE
,"Copying external toolchain sysroot to staging...") ; \
447 $(call copy_toolchain_sysroot
,$${SYSROOT_DIR},$${ARCH_SYSROOT_DIR},$${ARCH_SUBDIR},$${ARCH_LIB_DIR},$${SUPPORT_LIB_DIR})
450 # Create a symlink from (usr/)$(ARCH_LIB_DIR) to lib.
451 # Note: the skeleton package additionally creates lib32->lib or lib64->lib
454 # $1: destination directory (TARGET_DIR / STAGING_DIR)
455 create_lib_symlinks
= \
456 $(Q
)DESTDIR
="$(strip $1)" ; \
457 ARCH_LIB_DIR
="$(call toolchain_find_libdir,$(TOOLCHAIN_EXTERNAL_CC) $(TOOLCHAIN_EXTERNAL_CFLAGS))" ; \
458 if
[ ! -e
"$${DESTDIR}/$${ARCH_LIB_DIR}" -a
! -e
"$${DESTDIR}/usr/$${ARCH_LIB_DIR}" ]; then \
459 ln
-snf lib
"$${DESTDIR}/$${ARCH_LIB_DIR}" ; \
460 ln
-snf lib
"$${DESTDIR}/usr/$${ARCH_LIB_DIR}" ; \
463 define TOOLCHAIN_EXTERNAL_CREATE_STAGING_LIB_SYMLINK
464 $(call create_lib_symlinks
,$(STAGING_DIR
))
467 define TOOLCHAIN_EXTERNAL_CREATE_TARGET_LIB_SYMLINK
468 $(call create_lib_symlinks
,$(TARGET_DIR
))
472 # Generate gdbinit file for use with Buildroot
474 define TOOLCHAIN_EXTERNAL_INSTALL_GDBINIT
475 $(Q
)if
test -f
$(TARGET_CROSS
)gdb
; then \
476 $(call MESSAGE
,"Installing gdbinit"); \
477 $(gen_gdbinit_file
); \
481 # Various utility functions used by the external toolchain based on musl.
483 # With the musl C library, the libc.so library directly plays the role
484 # of the dynamic library loader. We just need to create a symbolic
485 # link to libc.so with the appropriate name.
486 ifeq ($(BR2_TOOLCHAIN_EXTERNAL_MUSL
),y
)
489 else ifeq ($(BR2_ARM_EABIHF
),y
)
491 else ifeq ($(BR2_mipsel
):$(BR2_SOFT_FLOAT
),y
:y
)
492 MUSL_ARCH
= mipsel-sf
493 else ifeq ($(BR2_sh
),y
)
498 define TOOLCHAIN_EXTERNAL_MUSL_LD_LINK
499 ln
-sf libc.so
$(TARGET_DIR
)/lib
/ld-musl-
$(MUSL_ARCH
).so
.1
503 # uClibc-ng dynamic loader is called ld-uClibc.so.1, but gcc is not
504 # patched specifically for uClibc-ng, so it continues to generate
505 # binaries that expect the dynamic loader to be named ld-uClibc.so.0,
506 # like with the original uClibc. Therefore, we create an additional
507 # symbolic link to make uClibc-ng systems work properly.
508 define TOOLCHAIN_EXTERNAL_FIXUP_UCLIBCNG_LDSO
509 $(Q
)if
test -e
$(TARGET_DIR
)/lib
/ld-uClibc.so
.1; then \
510 ln
-sf ld-uClibc.so
.1 $(TARGET_DIR
)/lib
/ld-uClibc.so
.0 ; \
512 $(Q
)if
test -e
$(TARGET_DIR
)/lib
/ld64-uClibc.so
.1; then \
513 ln
-sf ld64-uClibc.so
.1 $(TARGET_DIR
)/lib
/ld64-uClibc.so
.0 ; \
518 ################################################################################
519 # inner-toolchain-external-package -- defines the generic installation rules
520 # for external toolchain packages
522 # argument 1 is the lowercase package name
523 # argument 2 is the uppercase package name, including a HOST_ prefix
525 # argument 3 is the uppercase package name, without the HOST_ prefix
527 # argument 4 is the type (target or host)
528 ################################################################################
529 define inner-toolchain-external-package
531 $(2)_INSTALL_STAGING
= YES
532 $(2)_ADD_TOOLCHAIN_DEPENDENCY
= NO
534 # In fact, we don't need to download the toolchain, since it is already
535 # available on the system, so force the site and source to be empty so
536 # that nothing will be downloaded/extracted.
537 ifeq ($$(BR2_TOOLCHAIN_EXTERNAL_PREINSTALLED
),y
)
542 ifeq ($$(BR2_TOOLCHAIN_EXTERNAL_DOWNLOAD
),y
)
543 $(2)_EXCLUDES
= usr
/lib
/locale
/*
545 $(2)_POST_EXTRACT_HOOKS
+= \
546 TOOLCHAIN_EXTERNAL_MOVE
549 # Checks for an already installed toolchain: check the toolchain
550 # location, check that it is usable, and then verify that it
551 # matches the configuration provided in Buildroot: ABI, C++ support,
552 # kernel headers version, type of C library and all C library features.
553 define $(2)_CONFIGURE_CMDS
554 $$(Q
)$$(call check_cross_compiler_exists
,$$(TOOLCHAIN_EXTERNAL_CC
))
555 $$(Q
)$$(call check_unusable_toolchain
,$$(TOOLCHAIN_EXTERNAL_CC
))
556 $$(Q
)SYSROOT_DIR
="$$(call toolchain_find_sysroot,$$(TOOLCHAIN_EXTERNAL_CC))" ; \
557 $$(call check_kernel_headers_version
,\
558 $$(call toolchain_find_sysroot
,$$(TOOLCHAIN_EXTERNAL_CC
)),\
559 $$(call qstrip
,$$(BR2_TOOLCHAIN_HEADERS_AT_LEAST
))); \
560 $$(call check_gcc_version
,$$(TOOLCHAIN_EXTERNAL_CC
),\
561 $$(call qstrip
,$$(BR2_TOOLCHAIN_GCC_AT_LEAST
))); \
562 if
test "$$(BR2_arm)" = "y" ; then \
563 $$(call check_arm_abi
,\
564 "$$(TOOLCHAIN_EXTERNAL_CC) $$(TOOLCHAIN_EXTERNAL_CFLAGS)",\
565 $$(TOOLCHAIN_EXTERNAL_READELF
)) ; \
567 if
test "$$(BR2_INSTALL_LIBSTDCPP)" = "y" ; then \
568 $$(call check_cplusplus
,$$(TOOLCHAIN_EXTERNAL_CXX
)) ; \
570 if
test "$$(BR2_TOOLCHAIN_HAS_FORTRAN)" = "y" ; then \
571 $$(call check_fortran
,$$(TOOLCHAIN_EXTERNAL_FC
)) ; \
573 if
test "$$(BR2_TOOLCHAIN_EXTERNAL_UCLIBC)" = "y" ; then \
574 $$(call check_uclibc
,$$$${SYSROOT_DIR}) ; \
575 elif
test "$$(BR2_TOOLCHAIN_EXTERNAL_MUSL)" = "y" ; then \
576 $$(call check_musl
,$$$${SYSROOT_DIR}) ; \
578 $$(call check_glibc
,$$$${SYSROOT_DIR}) ; \
580 $$(Q
)$$(call check_toolchain_ssp
,$$(TOOLCHAIN_EXTERNAL_CC
))
583 $(2)_TOOLCHAIN_WRAPPER_ARGS
+= $$(TOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS
)
585 $(2)_BUILD_CMDS
= $$(TOOLCHAIN_WRAPPER_BUILD
)
587 define $(2)_INSTALL_STAGING_CMDS
588 $$(TOOLCHAIN_WRAPPER_INSTALL
)
589 $$(TOOLCHAIN_EXTERNAL_CREATE_STAGING_LIB_SYMLINK
)
590 $$(TOOLCHAIN_EXTERNAL_INSTALL_SYSROOT_LIBS
)
591 $$(TOOLCHAIN_EXTERNAL_INSTALL_WRAPPER
)
592 $$(TOOLCHAIN_EXTERNAL_INSTALL_GDBINIT
)
595 ifeq ($$(BR2_TOOLCHAIN_EXTERNAL_MUSL
),y
)
596 $(2)_POST_INSTALL_STAGING_HOOKS
+= TOOLCHAIN_EXTERNAL_MUSL_LD_LINK
599 # Even though we're installing things in both the staging, the host
600 # and the target directory, we do everything within the
601 # install-staging step, arbitrarily.
602 define $(2)_INSTALL_TARGET_CMDS
603 $$(TOOLCHAIN_EXTERNAL_CREATE_TARGET_LIB_SYMLINK
)
604 $$(TOOLCHAIN_EXTERNAL_INSTALL_TARGET_LIBS
)
605 $$(TOOLCHAIN_EXTERNAL_INSTALL_TARGET_GDBSERVER
)
606 $$(TOOLCHAIN_EXTERNAL_FIXUP_UCLIBCNG_LDSO
)
609 # Call the generic package infrastructure to generate the necessary
611 $(call inner-generic-package
,$(1),$(2),$(3),$(4))
615 toolchain-external-package
= $(call inner-toolchain-external-package
,$(pkgname
),$(call UPPERCASE
,$(pkgname
)),$(call UPPERCASE
,$(pkgname
)),target
)