3 # This file implements the support for external toolchains, i.e
4 # toolchains that have not been produced by Buildroot itself and that
5 # Buildroot can download from the Web or that are already available on
6 # the system on which Buildroot runs. So far, we have tested this
9 # * Toolchains generated by Crosstool-NG
10 # * Toolchains generated by Buildroot
11 # * ARM, MIPS and PowerPC toolchains made available by
12 # Codesourcery. For the MIPS toolchain, the -muclibc variant isn't
13 # supported yet, only the default glibc-based variant is.
15 # The basic principle is the following
17 # 1. a. For toolchains downloaded from the Web, Buildroot already
18 # knows their configuration, so it just downloads them and extract
19 # them in $(TOOLCHAIN_EXTERNAL_DIR).
21 # 1. b. For pre-installed toolchains, perform some checks on the
22 # conformity between the toolchain configuration described in the
23 # Buildroot menuconfig system, and the real configuration of the
24 # external toolchain. This is for example important to make sure that
25 # the Buildroot configuration system knows whether the toolchain
26 # supports RPC, IPv6, locales, large files, etc. Unfortunately, these
27 # things cannot be detected automatically, since the value of these
28 # options (such as BR2_INET_RPC) are needed at configuration time
29 # because these options are used as dependencies for other
30 # options. And at configuration time, we are not able to retrieve the
31 # external toolchain configuration.
33 # 2. Copy the libraries needed at runtime to the target directory,
34 # $(TARGET_DIR). Obviously, things such as the C library, the dynamic
35 # loader and a few other utility libraries are needed if dynamic
36 # applications are to be executed on the target system.
38 # 3. Copy the libraries and headers to the staging directory. This
39 # will allow all further calls to gcc to be made using --sysroot
40 # $(STAGING_DIR), which greatly simplifies the compilation of the
41 # packages when using external toolchains. So in the end, only the
42 # cross-compiler binaries remains external, all libraries and headers
43 # are imported into the Buildroot tree.
45 # 4. Build a toolchain wrapper which executes the external toolchain
46 # with a number of arguments (sysroot/march/mtune/..) hardcoded,
47 # so we're sure the correct configuration is always used and the
48 # toolchain behaves similar to an internal toolchain.
49 # This toolchain wrapper and symlinks are installed into
50 # $(HOST_DIR)/usr/bin like for the internal toolchains, and the rest
51 # of Buildroot is handled identical for the 2 toolchain types.
53 uclibc: dependencies $(HOST_DIR)/usr/bin/ext-toolchain-wrapper
55 LIB_EXTERNAL_LIBS=ld*.so libc.so libcrypt.so libdl.so libgcc_s.so libm.so libnsl.so libresolv.so librt.so libutil.so
56 ifeq ($(BR2_TOOLCHAIN_EXTERNAL_GLIBC),y)
57 LIB_EXTERNAL_LIBS+=libnss_files.so libnss_dns.so
60 ifeq ($(BR2_INSTALL_LIBSTDCPP),y)
61 USR_LIB_EXTERNAL_LIBS+=libstdc++.so
64 ifeq ($(BR2_TOOLCHAIN_HAS_THREADS),y)
65 LIB_EXTERNAL_LIBS+=libpthread.so
66 ifeq ($(BR2_PACKAGE_GDB_SERVER),y)
67 LIB_EXTERNAL_LIBS+=libthread_db.so
71 # Details about sysroot directory selection.
73 # To find the sysroot directory:
75 # * We first try the -print-sysroot option, available in gcc 4.4.x
76 # and in some Codesourcery toolchains.
78 # * If this option is not available, we fallback to the value of
79 # --with-sysroot as visible in CROSS-gcc -v.
81 # When doing those tests, we don't pass any option to gcc that could
82 # select a multilib variant (such as -march) as we want the "main"
83 # sysroot, which contains all variants of the C library in the case of
84 # multilib toolchains. We use the TARGET_CC_NO_SYSROOT variable, which
85 # is the path of the cross-compiler, without the
86 # --sysroot=$(STAGING_DIR), since what we want to find is the location
87 # of the original toolchain sysroot. This "main" sysroot directory is
88 # stored in SYSROOT_DIR.
90 # Then, multilib toolchains are a little bit more complicated, since
91 # they in fact have multiple sysroots, one for each variant supported
92 # by the toolchain. So we need to find the particular sysroot we're
95 # To do so, we ask the compiler where its sysroot is by passing all
96 # flags (including -march and al.), except the --sysroot flag since we
97 # want to the compiler to tell us where its original sysroot
98 # is. ARCH_SUBDIR will contain the subdirectory, in the main
99 # SYSROOT_DIR, that corresponds to the selected architecture
100 # variant. ARCH_SYSROOT_DIR will contain the full path to this
103 # One might wonder why we don't just bother with ARCH_SYSROOT_DIR. The
104 # fact is that in multilib toolchains, the header files are often only
105 # present in the main sysroot, and only the libraries are available in
106 # each variant-specific sysroot directory.
109 TOOLCHAIN_EXTERNAL_PREFIX=$(call qstrip,$(BR2_TOOLCHAIN_EXTERNAL_PREFIX))
110 ifeq ($(BR2_TOOLCHAIN_EXTERNAL_DOWNLOAD),y)
111 TOOLCHAIN_EXTERNAL_DIR=$(HOST_DIR)/opt/ext-toolchain
113 TOOLCHAIN_EXTERNAL_DIR=$(call qstrip,$(BR2_TOOLCHAIN_EXTERNAL_PATH))
116 ifeq ($(TOOLCHAIN_EXTERNAL_DIR),)
117 # if no path set, figure it out from path
118 TOOLCHAIN_EXTERNAL_BIN:=$(shell dirname $(shell which $(TOOLCHAIN_EXTERNAL_PREFIX)-gcc))
120 TOOLCHAIN_EXTERNAL_BIN:=$(TOOLCHAIN_EXTERNAL_DIR)/bin
123 TOOLCHAIN_EXTERNAL_CROSS=$(TOOLCHAIN_EXTERNAL_BIN)/$(TOOLCHAIN_EXTERNAL_PREFIX)-
124 TOOLCHAIN_EXTERNAL_CC=$(TOOLCHAIN_EXTERNAL_CROSS)gcc
125 TOOLCHAIN_EXTERNAL_WRAPPER_ARGS = \
126 -DBR_CROSS_PATH='"$(TOOLCHAIN_EXTERNAL_BIN)/"' \
127 -DBR_SYSROOT='"$(STAGING_DIR)"'
129 # march/mtune/floating point mode needs to be passed to the external toolchain
130 # to select the right multilib variant
131 ifneq ($(CC_TARGET_TUNE_),)
132 TOOLCHAIN_EXTERNAL_CFLAGS += -mtune=$(CC_TARGET_TUNE_)
133 TOOLCHAIN_EXTERNAL_WRAPPER_ARGS += -DBR_TUNE='"$(CC_TARGET_TUNE_)"'
135 ifneq ($(CC_TARGET_ARCH_),)
136 TOOLCHAIN_EXTERNAL_CFLAGS += -march=$(CC_TARGET_ARCH_)
137 TOOLCHAIN_EXTERNAL_WRAPPER_ARGS += -DBR_ARCH='"$(CC_TARGET_ARCH_)"'
139 ifneq ($(CC_TARGET_ABI_),)
140 TOOLCHAIN_EXTERNAL_CFLAGS += -mabi=$(CC_TARGET_ABI_)
141 TOOLCHAIN_EXTERNAL_WRAPPER_ARGS += -DBR_ABI='"$(CC_TARGET_ABI_)"'
144 ifeq ($(BR2_SOFT_FLOAT),y)
145 TOOLCHAIN_EXTERNAL_CFLAGS += -msoft-float
146 TOOLCHAIN_EXTERNAL_WRAPPER_ARGS += -DBR_SOFTFLOAT=1
149 ifeq ($(BR2_VFP_FLOAT),y)
150 TOOLCHAIN_EXTERNAL_CFLAGS += -mfpu=vfp
151 TOOLCHAIN_EXTERNAL_WRAPPER_ARGS += -DBR_VFPFLOAT=1
154 ifeq ($(BR2_TOOLCHAIN_EXTERNAL_DOWNLOAD),y)
155 TOOLCHAIN_EXTERNAL_DEPENDENCIES = $(TOOLCHAIN_EXTERNAL_DIR)/.extracted
157 TOOLCHAIN_EXTERNAL_DEPENDENCIES = $(STAMP_DIR)/ext-toolchain-checked
160 ifeq ($(BR2_TOOLCHAIN_EXTERNAL_CODESOURCERY_ARM2009Q1),y)
161 TOOLCHAIN_EXTERNAL_SITE=http://www.codesourcery.com/sgpp/lite/arm/portal/package5383/public/arm-none-linux-gnueabi/
162 TOOLCHAIN_EXTERNAL_SOURCE=arm-2009q3-67-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2
163 else ifeq ($(BR2_TOOLCHAIN_EXTERNAL_CODESOURCERY_ARM2010Q1),y)
164 TOOLCHAIN_EXTERNAL_SITE=http://www.codesourcery.com/sgpp/lite/arm/portal/package6488/public/arm-none-linux-gnueabi/
165 TOOLCHAIN_EXTERNAL_SOURCE=arm-2010q1-202-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2
166 else ifeq ($(BR2_TOOLCHAIN_EXTERNAL_CODESOURCERY_ARM201009),y)
167 TOOLCHAIN_EXTERNAL_SITE=http://www.codesourcery.com/sgpp/lite/arm/portal/package7851/public/arm-none-linux-gnueabi/
168 TOOLCHAIN_EXTERNAL_SOURCE=arm-2010.09-50-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2
169 else ifeq ($(BR2_TOOLCHAIN_EXTERNAL_CODESOURCERY_MIPS44),y)
170 TOOLCHAIN_EXTERNAL_SITE=http://www.codesourcery.com/sgpp/lite/mips/portal/package7401/public/mips-linux-gnu/
171 TOOLCHAIN_EXTERNAL_SOURCE=mips-4.4-303-mips-linux-gnu-i686-pc-linux-gnu.tar.bz2
172 else ifeq ($(BR2_TOOLCHAIN_EXTERNAL_CODESOURCERY_POWERPC201009),y)
173 TOOLCHAIN_EXTERNAL_SITE=http://www.codesourcery.com/sgpp/lite/power/portal/package7703/public/powerpc-linux-gnu/
174 TOOLCHAIN_EXTERNAL_SOURCE=freescale-2010.09-55-powerpc-linux-gnu-i686-pc-linux-gnu.tar.bz2
175 else ifeq ($(BR2_TOOLCHAIN_EXTERNAL_CODESOURCERY_SH201009),y)
176 TOOLCHAIN_EXTERNAL_SITE=http://www.codesourcery.com/sgpp/lite/superh/portal/package7783/public/sh-linux-gnu/
177 TOOLCHAIN_EXTERNAL_SOURCE=renesas-2010.09-45-sh-linux-gnu-i686-pc-linux-gnu.tar.bz2
179 # A value must be set (even if unused), otherwise the
180 # $(DL_DIR)/$(TOOLCHAIN_EXTERNAL_SOURCE) rule would override the main
182 TOOLCHAIN_EXTERNAL_SOURCE=none
185 # Download and extraction of a toolchain
186 $(DL_DIR)/$(TOOLCHAIN_EXTERNAL_SOURCE):
187 $(call DOWNLOAD,$(TOOLCHAIN_EXTERNAL_SITE),$(TOOLCHAIN_EXTERNAL_SOURCE))
189 $(TOOLCHAIN_EXTERNAL_DIR)/.extracted: $(DL_DIR)/$(TOOLCHAIN_EXTERNAL_SOURCE)
191 $(INFLATE$(suffix $(TOOLCHAIN_EXTERNAL_SOURCE))) $^ | $(TAR) $(TAR_STRIP_COMPONENTS)=1 -C $(@D) $(TAR_OPTIONS) -
194 # Checks for an already installed toolchain: check the toolchain
195 # location, check that it supports sysroot, and then verify that it
196 # matches the configuration provided in Buildroot: ABI, C++ support,
197 # type of C library and all C library features.
198 $(STAMP_DIR)/ext-toolchain-checked:
199 @echo "Checking external toolchain settings"
200 $(Q)$(call check_cross_compiler_exists)
201 $(Q)SYSROOT_DIR=`$(TOOLCHAIN_EXTERNAL_CC) -print-sysroot 2>/dev/null` ; \
202 if test -z "$${SYSROOT_DIR}" ; then \
203 SYSROOT_DIR=`readlink -f $$(LANG=C $(TOOLCHAIN_EXTERNAL_CC) -print-file-name=libc.a) |sed -r -e 's:usr/lib/libc\.a::;'` ; \
205 if test -z "$${SYSROOT_DIR}" ; then \
206 @echo "External toolchain doesn't support --sysroot. Cannot use." ; \
209 if test x$(BR2_arm) == x"y" ; then \
210 $(call check_arm_abi) ; \
212 if test x$(BR2_INSTALL_LIBSTDCPP) == x"y" ; then \
213 $(call check_cplusplus) ; \
215 if test x$(BR2_TOOLCHAIN_EXTERNAL_UCLIBC) == x"y" ; then \
216 $(call check_uclibc,$${SYSROOT_DIR}) ; \
218 $(call check_glibc,$${SYSROOT_DIR}) ; \
222 # Integration of the toolchain into Buildroot: find the main sysroot
223 # and the variant-specific sysroot, then copy the needed libraries to
224 # the $(TARGET_DIR) and copy the whole sysroot (libraries and headers)
226 $(STAMP_DIR)/ext-toolchain-installed: $(TOOLCHAIN_EXTERNAL_DEPENDENCIES)
227 $(Q)SYSROOT_DIR=`$(TOOLCHAIN_EXTERNAL_CC) -print-sysroot 2>/dev/null` ; \
228 if test -z "$${SYSROOT_DIR}" ; then \
229 SYSROOT_DIR=`readlink -f $$(LANG=C $(TOOLCHAIN_EXTERNAL_CC) -print-file-name=libc.a) |sed -r -e 's:usr/lib/libc\.a::;'` ; \
231 if test -z "$${SYSROOT_DIR}" ; then \
232 @echo "External toolchain doesn't support --sysroot. Cannot use." ; \
235 ARCH_SUBDIR=`$(TOOLCHAIN_EXTERNAL_CC) $(TOOLCHAIN_EXTERNAL_CFLAGS) -print-multi-directory` ; \
236 ARCH_SYSROOT_DIR=$${SYSROOT_DIR}/$${ARCH_SUBDIR} ; \
237 mkdir -p $(TARGET_DIR)/lib ; \
238 echo "Copy external toolchain libraries to target..." ; \
239 for libs in $(LIB_EXTERNAL_LIBS); do \
240 $(call copy_toolchain_lib_root,$${ARCH_SYSROOT_DIR},$$libs,/lib); \
242 for libs in $(USR_LIB_EXTERNAL_LIBS); do \
243 $(call copy_toolchain_lib_root,$${ARCH_SYSROOT_DIR},$$libs,/usr/lib); \
245 echo "Copy external toolchain sysroot to staging..." ; \
246 $(call copy_toolchain_sysroot,$${SYSROOT_DIR},$${ARCH_SYSROOT_DIR},$${ARCH_SUBDIR}) ; \
247 if [ -L $${ARCH_SYSROOT_DIR}/lib64 ] ; then \
248 $(call create_lib64_symlinks) ; \
252 # Build toolchain wrapper for preprocessor, C and C++ compiler, and setup
253 # symlinks for everything else
254 $(HOST_DIR)/usr/bin/ext-toolchain-wrapper: $(STAMP_DIR)/ext-toolchain-installed
255 mkdir -p $(HOST_DIR)/usr/bin; cd $(HOST_DIR)/usr/bin; \
256 for i in $(TOOLCHAIN_EXTERNAL_CROSS)*; do \
258 *cc|*cc-*|*++|*++-*|*cpp) \
260 ln -sf $(@F) $$base; \
267 $(HOSTCC) $(HOST_CFLAGS) $(TOOLCHAIN_EXTERNAL_WRAPPER_ARGS) -s \
268 toolchain/toolchain-external/ext-toolchain-wrapper.c -o $@