toolchain: bump Codescape IMG MIPS version to 2016.05-06
[buildroot-gz.git] / toolchain / toolchain-external / pkg-toolchain-external.mk
blobe0a8b410c04c0636e57e14d6de1e5b931b39de88
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
9 # tested this with:
11 # * Toolchains generated by Crosstool-NG
12 # * Toolchains generated by Buildroot
13 # * Toolchains provided by Linaro for the ARM and AArch64
14 # architectures
15 # * Sourcery CodeBench toolchains (from Mentor Graphics) for the ARM,
16 # MIPS, PowerPC, x86, 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)
71 else
72 TOOLCHAIN_EXTERNAL_INSTALL_DIR = $(call qstrip,$(BR2_TOOLCHAIN_EXTERNAL_PATH))
73 endif
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))
79 endif
80 else
81 TOOLCHAIN_EXTERNAL_BIN := $(TOOLCHAIN_EXTERNAL_INSTALL_DIR)/bin
82 endif
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)/
105 endef
106 endif
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.*
115 else
116 TOOLCHAIN_EXTERNAL_LIBS += ld*.so.*
117 endif
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.*
122 endif # gdbserver
123 endif # ! no threads
124 endif
126 ifeq ($(BR2_TOOLCHAIN_EXTERNAL_GLIBC),y)
127 TOOLCHAIN_EXTERNAL_LIBS += libnss_files.so.* libnss_dns.so.* libmvec.so.*
128 endif
130 ifeq ($(BR2_TOOLCHAIN_EXTERNAL_MUSL),y)
131 TOOLCHAIN_EXTERNAL_LIBS += libc.so libgcc_s.so.*
132 endif
134 ifeq ($(BR2_INSTALL_LIBSTDCPP),y)
135 TOOLCHAIN_EXTERNAL_LIBS += libstdc++.so.*
136 endif
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*
143 endif
144 endif
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))
155 else
156 CC_TARGET_CPU_ := $(call qstrip,$(BR2_GCC_TARGET_CPU)-$(BR2_GCC_TARGET_CPU_REVISION))
157 endif
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
169 endif
170 ifneq ($(CC_TARGET_ARCH_),)
171 TOOLCHAIN_EXTERNAL_CFLAGS += -march=$(CC_TARGET_ARCH_)
172 TOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS += -DBR_ARCH='"$(CC_TARGET_ARCH_)"'
173 endif
174 ifneq ($(CC_TARGET_CPU_),)
175 TOOLCHAIN_EXTERNAL_CFLAGS += -mcpu=$(CC_TARGET_CPU_)
176 TOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS += -DBR_CPU='"$(CC_TARGET_CPU_)"'
177 endif
178 ifneq ($(CC_TARGET_ABI_),)
179 TOOLCHAIN_EXTERNAL_CFLAGS += -mabi=$(CC_TARGET_ABI_)
180 TOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS += -DBR_ABI='"$(CC_TARGET_ABI_)"'
181 endif
182 ifneq ($(CC_TARGET_FPU_),)
183 TOOLCHAIN_EXTERNAL_CFLAGS += -mfpu=$(CC_TARGET_FPU_)
184 TOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS += -DBR_FPU='"$(CC_TARGET_FPU_)"'
185 endif
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_)"'
189 endif
190 ifneq ($(CC_TARGET_MODE_),)
191 TOOLCHAIN_EXTERNAL_CFLAGS += -m$(CC_TARGET_MODE_)
192 TOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS += -DBR_MODE='"$(CC_TARGET_MODE_)"'
193 endif
194 ifeq ($(BR2_BINFMT_FLAT),y)
195 TOOLCHAIN_EXTERNAL_CFLAGS += -Wl,-elf2flt
196 TOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS += -DBR_BINFMT_FLAT
197 endif
198 ifeq ($(BR2_mipsel)$(BR2_mips64el),y)
199 TOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS += -DBR_MIPS_TARGET_LITTLE_ENDIAN
200 TOOLCHAIN_EXTERNAL_CFLAGS += -EL
201 endif
202 ifeq ($(BR2_mips)$(BR2_mips64),y)
203 TOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS += -DBR_MIPS_TARGET_BIG_ENDIAN
204 TOOLCHAIN_EXTERNAL_CFLAGS += -EB
205 endif
206 ifeq ($(BR2_arceb),y)
207 TOOLCHAIN_EXTERNAL_TOOLCHAIN_WRAPPER_ARGS += -DBR_ARC_TARGET_BIG_ENDIAN
208 TOOLCHAIN_EXTERNAL_CFLAGS += -EB
209 endif
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
216 endif
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)"'
225 else
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)/%=%)"'
229 endif
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,
247 # *-ranlib and *-nm.
248 define TOOLCHAIN_EXTERNAL_INSTALL_WRAPPER
249 $(Q)cd $(HOST_DIR)/usr/bin; \
250 for i in $(TOOLCHAIN_EXTERNAL_CROSS)*; do \
251 base=$${i##*/}; \
252 case "$$base" in \
253 *-ar|*-ranlib|*-nm) \
254 ln -sf $$(echo $$i | sed 's%^$(HOST_DIR)%../..%') .; \
255 ;; \
256 *cc|*cc-*|*++|*++-*|*cpp|*-gfortran) \
257 ln -sf toolchain-wrapper $$base; \
258 ;; \
259 *gdb|*gdbtui) \
260 if test "$(BR2_PACKAGE_HOST_GDB)" != "y"; then \
261 ln -sf $$(echo $$i | sed 's%^$(HOST_DIR)%../..%') .; \
262 fi \
263 ;; \
264 *) \
265 ln -sf $$(echo $$i | sed 's%^$(HOST_DIR)%../..%') .; \
266 ;; \
267 esac; \
268 done
269 endef
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
300 # interested in.
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
308 # location.
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:
319 # - lib/
320 # - usr/lib/
321 # - lib32/
322 # - lib64/
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::')
330 endef
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:')
336 endef
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))
341 endef
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)
346 # to $(STAGING_DIR).
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
352 # sysroot directory)
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.
374 # Ex: lib
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); \
400 done
401 endef
402 endif
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 ; \
417 break ; \
418 fi ; \
419 done ; \
420 if [ $${gdbserver_found} -eq 0 ] ; then \
421 echo "Could not find gdbserver in external toolchain" ; \
422 exit 1 ; \
424 endef
425 endif
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::'` ; \
436 fi ; \
437 fi ; \
438 if [ "$${SYSROOT_DIR}" == "$${ARCH_SYSROOT_DIR}" ] ; then \
439 ARCH_SUBDIR="" ; \
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:"` ; \
443 else \
444 ARCH_SUBDIR=`echo $${ARCH_SYSROOT_DIR} | sed -r -e "s:^$${SYSROOT_DIR}(.*)/$$:\1:"` ; \
445 fi ; \
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})
448 endef
450 # Create a symlink from (usr/)$(ARCH_LIB_DIR) to lib.
451 # Note: the skeleton package additionally creates lib32->lib or lib64->lib
452 # (as appropriate)
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))
465 endef
467 define TOOLCHAIN_EXTERNAL_CREATE_TARGET_LIB_SYMLINK
468 $(call create_lib_symlinks,$(TARGET_DIR))
469 endef
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); \
479 endef
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)
487 ifeq ($(BR2_i386),y)
488 MUSL_ARCH = i386
489 else ifeq ($(BR2_ARM_EABIHF),y)
490 MUSL_ARCH = armhf
491 else ifeq ($(BR2_mipsel):$(BR2_SOFT_FLOAT),y:y)
492 MUSL_ARCH = mipsel-sf
493 else ifeq ($(BR2_sh),y)
494 MUSL_ARCH = sh
495 else
496 MUSL_ARCH = $(ARCH)
497 endif
498 define TOOLCHAIN_EXTERNAL_MUSL_LD_LINK
499 ln -sf libc.so $(TARGET_DIR)/lib/ld-musl-$(MUSL_ARCH).so.1
500 endef
501 endif
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 ; \
515 endef
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
524 # for host packages
525 # argument 3 is the uppercase package name, without the HOST_ prefix
526 # for host packages
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)
538 $(2)_SITE =
539 $(2)_SOURCE =
540 endif
542 ifeq ($$(BR2_TOOLCHAIN_EXTERNAL_DOWNLOAD),y)
543 $(2)_EXCLUDES = usr/lib/locale/*
545 $(2)_POST_EXTRACT_HOOKS += \
546 TOOLCHAIN_EXTERNAL_MOVE
547 endif
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)) ; \
566 fi ; \
567 if test "$$(BR2_INSTALL_LIBSTDCPP)" = "y" ; then \
568 $$(call check_cplusplus,$$(TOOLCHAIN_EXTERNAL_CXX)) ; \
569 fi ; \
570 if test "$$(BR2_TOOLCHAIN_HAS_FORTRAN)" = "y" ; then \
571 $$(call check_fortran,$$(TOOLCHAIN_EXTERNAL_FC)) ; \
572 fi ; \
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}) ; \
577 else \
578 $$(call check_glibc,$$$${SYSROOT_DIR}) ; \
580 $$(Q)$$(call check_toolchain_ssp,$$(TOOLCHAIN_EXTERNAL_CC))
581 endef
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)
593 endef
595 ifeq ($$(BR2_TOOLCHAIN_EXTERNAL_MUSL),y)
596 $(2)_POST_INSTALL_STAGING_HOOKS += TOOLCHAIN_EXTERNAL_MUSL_LD_LINK
597 endif
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)
607 endef
609 # Call the generic package infrastructure to generate the necessary
610 # make targets
611 $(call inner-generic-package,$(1),$(2),$(3),$(4))
613 endef
615 toolchain-external-package = $(call inner-toolchain-external-package,$(pkgname),$(call UPPERCASE,$(pkgname)),$(call UPPERCASE,$(pkgname)),target)