b293ba9efb24810495df6473840a4cd99ebed146
[packages/trusty/cirros-testvm.git] / cirros-testvm / src-cirros / buildroot-2015.05 / toolchain / toolchain-external / toolchain-external.mk
1 ################################################################################
2 #
3 # toolchain-external
4 #
5 ################################################################################
6
7 #
8 # This package implements the support for external toolchains, i.e
9 # toolchains that are available pre-built, ready to use. Such toolchain
10 # may either be readily available on the Web (Linaro, Sourcery
11 # CodeBench, from processor vendors) or may be built with tools like
12 # Crosstool-NG or Buildroot itself. So far, we have tested this
13 # with:
14 #
15 #  * Toolchains generated by Crosstool-NG
16 #  * Toolchains generated by Buildroot
17 #  * Toolchains provided by Linaro for the ARM and AArch64
18 #    architectures
19 #  * Sourcery CodeBench toolchains (from Mentor Graphics) for the ARM,
20 #    MIPS, PowerPC, x86, x86_64 and NIOS 2 architectures. For the MIPS
21 #    toolchain, the -muclibc variant isn't supported yet, only the
22 #    default glibc-based variant is.
23 #  * Analog Devices toolchains for the Blackfin architecture
24 #  * Xilinx toolchains for the Microblaze architecture
25 #  * Synopsys DesignWare toolchains for ARC cores
26 #
27 # The basic principle is the following
28 #
29 #  1. If the toolchain is not pre-installed, download and extract it
30 #  in $(TOOLCHAIN_EXTERNAL_INSTALL_DIR). Otherwise,
31 #  $(TOOLCHAIN_EXTERNAL_INSTALL_DIR) points to were the toolchain has
32 #  already been installed by the user.
33 #
34 #  2. For all external toolchains, perform some checks on the
35 #  conformity between the toolchain configuration described in the
36 #  Buildroot menuconfig system, and the real configuration of the
37 #  external toolchain. This is for example important to make sure that
38 #  the Buildroot configuration system knows whether the toolchain
39 #  supports RPC, IPv6, locales, large files, etc. Unfortunately, these
40 #  things cannot be detected automatically, since the value of these
41 #  options (such as BR2_TOOLCHAIN_HAS_NATIVE_RPC) are needed at
42 #  configuration time because these options are used as dependencies
43 #  for other options. And at configuration time, we are not able to
44 #  retrieve the external toolchain configuration.
45 #
46 #  3. Copy the libraries needed at runtime to the target directory,
47 #  $(TARGET_DIR). Obviously, things such as the C library, the dynamic
48 #  loader and a few other utility libraries are needed if dynamic
49 #  applications are to be executed on the target system.
50 #
51 #  4. Copy the libraries and headers to the staging directory. This
52 #  will allow all further calls to gcc to be made using --sysroot
53 #  $(STAGING_DIR), which greatly simplifies the compilation of the
54 #  packages when using external toolchains. So in the end, only the
55 #  cross-compiler binaries remains external, all libraries and headers
56 #  are imported into the Buildroot tree.
57 #
58 #  5. Build a toolchain wrapper which executes the external toolchain
59 #  with a number of arguments (sysroot/march/mtune/..) hardcoded,
60 #  so we're sure the correct configuration is always used and the
61 #  toolchain behaves similar to an internal toolchain.
62 #  This toolchain wrapper and symlinks are installed into
63 #  $(HOST_DIR)/usr/bin like for the internal toolchains, and the rest
64 #  of Buildroot is handled identical for the 2 toolchain types.
65
66 ifeq ($(BR2_TOOLCHAIN_EXTERNAL_GLIBC)$(BR2_TOOLCHAIN_EXTERNAL_UCLIBC),y)
67 LIB_EXTERNAL_LIBS += libatomic.so.* libc.so.* libcrypt.so.* libdl.so.* libgcc_s.so.* libm.so.* libnsl.so.* libresolv.so.* librt.so.* libutil.so.*
68 ifeq ($(BR2_TOOLCHAIN_EXTERNAL_GLIBC)$(BR2_ARM_EABIHF),yy)
69 LIB_EXTERNAL_LIBS += ld-linux-armhf.so.*
70 else
71 LIB_EXTERNAL_LIBS += ld*.so.*
72 endif
73 ifeq ($(BR2_TOOLCHAIN_HAS_THREADS),y)
74 LIB_EXTERNAL_LIBS += libpthread.so.*
75 ifneq ($(BR2_PACKAGE_GDB)$(BR2_TOOLCHAIN_EXTERNAL_GDB_SERVER_COPY),)
76 LIB_EXTERNAL_LIBS += libthread_db.so.*
77 endif # gdbserver
78 endif # ! no threads
79 endif
80
81 ifeq ($(BR2_TOOLCHAIN_EXTERNAL_GLIBC),y)
82 LIB_EXTERNAL_LIBS += libnss_files.so.* libnss_dns.so.*
83 endif
84
85 ifeq ($(BR2_TOOLCHAIN_EXTERNAL_MUSL),y)
86 LIB_EXTERNAL_LIBS += libc.so libgcc_s.so.*
87 endif
88
89 ifeq ($(BR2_INSTALL_LIBSTDCPP),y)
90 USR_LIB_EXTERNAL_LIBS += libstdc++.so.*
91 endif
92
93 LIB_EXTERNAL_LIBS += $(call qstrip,$(BR2_TOOLCHAIN_EXTRA_EXTERNAL_LIBS))
94
95 # Details about sysroot directory selection.
96 #
97 # To find the sysroot directory, we use the trick of looking for the
98 # 'libc.a' file with the -print-file-name gcc option, and then
99 # mangling the path to find the base directory of the sysroot.
100 #
101 # Note that we do not use the -print-sysroot option, because it is
102 # only available since gcc 4.4.x, and we only recently dropped support
103 # for 4.2.x and 4.3.x.
104 #
105 # When doing this, we don't pass any option to gcc that could select a
106 # multilib variant (such as -march) as we want the "main" sysroot,
107 # which contains all variants of the C library in the case of multilib
108 # toolchains. We use the TARGET_CC_NO_SYSROOT variable, which is the
109 # path of the cross-compiler, without the --sysroot=$(STAGING_DIR),
110 # since what we want to find is the location of the original toolchain
111 # sysroot. This "main" sysroot directory is stored in SYSROOT_DIR.
112 #
113 # Then, multilib toolchains are a little bit more complicated, since
114 # they in fact have multiple sysroots, one for each variant supported
115 # by the toolchain. So we need to find the particular sysroot we're
116 # interested in.
117 #
118 # To do so, we ask the compiler where its sysroot is by passing all
119 # flags (including -march and al.), except the --sysroot flag since we
120 # want to the compiler to tell us where its original sysroot
121 # is. ARCH_SUBDIR will contain the subdirectory, in the main
122 # SYSROOT_DIR, that corresponds to the selected architecture
123 # variant. ARCH_SYSROOT_DIR will contain the full path to this
124 # location.
125 #
126 # One might wonder why we don't just bother with ARCH_SYSROOT_DIR. The
127 # fact is that in multilib toolchains, the header files are often only
128 # present in the main sysroot, and only the libraries are available in
129 # each variant-specific sysroot directory.
130
131
132 TOOLCHAIN_EXTERNAL_PREFIX = $(call qstrip,$(BR2_TOOLCHAIN_EXTERNAL_PREFIX))
133 ifeq ($(BR2_TOOLCHAIN_EXTERNAL_DOWNLOAD),y)
134 TOOLCHAIN_EXTERNAL_INSTALL_DIR = $(HOST_DIR)/opt/ext-toolchain
135 else
136 TOOLCHAIN_EXTERNAL_INSTALL_DIR = $(call qstrip,$(BR2_TOOLCHAIN_EXTERNAL_PATH))
137 endif
138
139 ifeq ($(TOOLCHAIN_EXTERNAL_INSTALL_DIR),)
140 ifneq ($(TOOLCHAIN_EXTERNAL_PREFIX),)
141 # if no path set, figure it out from path
142 TOOLCHAIN_EXTERNAL_BIN := $(shell dirname $(shell which $(TOOLCHAIN_EXTERNAL_PREFIX)-gcc))
143 endif
144 else
145 ifeq ($(BR2_TOOLCHAIN_EXTERNAL_BLACKFIN_UCLINUX_2014R1)$(BR2_TOOLCHAIN_EXTERNAL_BLACKFIN_UCLINUX_2013R1)$(BR2_TOOLCHAIN_EXTERNAL_BLACKFIN_UCLINUX_2012R2),y)
146 TOOLCHAIN_EXTERNAL_BIN := $(TOOLCHAIN_EXTERNAL_INSTALL_DIR)/$(TOOLCHAIN_EXTERNAL_PREFIX)/bin
147 else
148 TOOLCHAIN_EXTERNAL_BIN := $(TOOLCHAIN_EXTERNAL_INSTALL_DIR)/bin
149 endif
150 endif
151
152 TOOLCHAIN_EXTERNAL_CROSS = $(TOOLCHAIN_EXTERNAL_BIN)/$(TOOLCHAIN_EXTERNAL_PREFIX)-
153 TOOLCHAIN_EXTERNAL_CC = $(TOOLCHAIN_EXTERNAL_CROSS)gcc
154 TOOLCHAIN_EXTERNAL_CXX = $(TOOLCHAIN_EXTERNAL_CROSS)g++
155 TOOLCHAIN_EXTERNAL_READELF = $(TOOLCHAIN_EXTERNAL_CROSS)readelf
156 TOOLCHAIN_EXTERNAL_WRAPPER_ARGS = -DBR_SYSROOT='"$(STAGING_SUBDIR)"'
157
158 ifeq ($(filter $(HOST_DIR)/%,$(TOOLCHAIN_EXTERNAL_BIN)),)
159 # TOOLCHAIN_EXTERNAL_BIN points outside HOST_DIR => absolute path
160 TOOLCHAIN_EXTERNAL_WRAPPER_ARGS += \
161         -DBR_CROSS_PATH_ABS='"$(TOOLCHAIN_EXTERNAL_BIN)"'
162 else
163 # TOOLCHAIN_EXTERNAL_BIN points inside HOST_DIR => relative path
164 TOOLCHAIN_EXTERNAL_WRAPPER_ARGS += \
165         -DBR_CROSS_PATH_REL='"$(TOOLCHAIN_EXTERNAL_BIN:$(HOST_DIR)/%=%)"'
166 endif
167
168 ifeq ($(call qstrip,$(BR2_GCC_TARGET_CPU_REVISION)),)
169 CC_TARGET_CPU_ := $(call qstrip,$(BR2_GCC_TARGET_CPU))
170 else
171 CC_TARGET_CPU_ := $(call qstrip,$(BR2_GCC_TARGET_CPU)-$(BR2_GCC_TARGET_CPU_REVISION))
172 endif
173 CC_TARGET_ARCH_ := $(call qstrip,$(BR2_GCC_TARGET_ARCH))
174 CC_TARGET_ABI_ := $(call qstrip,$(BR2_GCC_TARGET_ABI))
175 CC_TARGET_FPU_ := $(call qstrip,$(BR2_GCC_TARGET_FPU))
176 CC_TARGET_FLOAT_ABI_ := $(call qstrip,$(BR2_GCC_TARGET_FLOAT_ABI))
177 CC_TARGET_MODE_ := $(call qstrip,$(BR2_GCC_TARGET_MODE))
178
179 # march/mtune/floating point mode needs to be passed to the external toolchain
180 # to select the right multilib variant
181 ifeq ($(BR2_x86_64),y)
182 TOOLCHAIN_EXTERNAL_CFLAGS += -m64
183 TOOLCHAIN_EXTERNAL_WRAPPER_ARGS += -DBR_64
184 endif
185 ifneq ($(CC_TARGET_ARCH_),)
186 TOOLCHAIN_EXTERNAL_CFLAGS += -march=$(CC_TARGET_ARCH_)
187 TOOLCHAIN_EXTERNAL_WRAPPER_ARGS += -DBR_ARCH='"$(CC_TARGET_ARCH_)"'
188 endif
189 ifneq ($(CC_TARGET_CPU_),)
190 TOOLCHAIN_EXTERNAL_CFLAGS += -mcpu=$(CC_TARGET_CPU_)
191 TOOLCHAIN_EXTERNAL_WRAPPER_ARGS += -DBR_CPU='"$(CC_TARGET_CPU_)"'
192 endif
193 ifneq ($(CC_TARGET_ABI_),)
194 TOOLCHAIN_EXTERNAL_CFLAGS += -mabi=$(CC_TARGET_ABI_)
195 TOOLCHAIN_EXTERNAL_WRAPPER_ARGS += -DBR_ABI='"$(CC_TARGET_ABI_)"'
196 endif
197 ifneq ($(CC_TARGET_FPU_),)
198 TOOLCHAIN_EXTERNAL_CFLAGS += -mfpu=$(CC_TARGET_FPU_)
199 TOOLCHAIN_EXTERNAL_WRAPPER_ARGS += -DBR_FPU='"$(CC_TARGET_FPU_)"'
200 endif
201 ifneq ($(CC_TARGET_FLOAT_ABI_),)
202 TOOLCHAIN_EXTERNAL_CFLAGS += -mfloat-abi=$(CC_TARGET_FLOAT_ABI_)
203 TOOLCHAIN_EXTERNAL_WRAPPER_ARGS += -DBR_FLOAT_ABI='"$(CC_TARGET_FLOAT_ABI_)"'
204 endif
205 ifneq ($(CC_TARGET_MODE_),)
206 TOOLCHAIN_EXTERNAL_CFLAGS += -m$(CC_TARGET_MODE_)
207 TOOLCHAIN_EXTERNAL_WRAPPER_ARGS += -DBR_MODE='"$(CC_TARGET_MODE_)"'
208 endif
209 ifeq ($(BR2_BINFMT_FLAT),y)
210 TOOLCHAIN_EXTERNAL_CFLAGS += -Wl,-elf2flt
211 TOOLCHAIN_EXTERNAL_WRAPPER_ARGS += -DBR_BINFMT_FLAT
212 endif
213 ifeq ($(BR2_mipsel)$(BR2_mips64el),y)
214 TOOLCHAIN_EXTERNAL_WRAPPER_ARGS += -DBR_MIPS_TARGET_LITTLE_ENDIAN
215 TOOLCHAIN_EXTERNAL_CFLAGS += -EL
216 endif
217 ifeq ($(BR2_mips)$(BR2_mips64),y)
218 TOOLCHAIN_EXTERNAL_WRAPPER_ARGS += -DBR_MIPS_TARGET_BIG_ENDIAN
219 TOOLCHAIN_EXTERNAL_CFLAGS += -EB
220 endif
221 ifeq ($(BR2_arceb),y)
222 TOOLCHAIN_EXTERNAL_WRAPPER_ARGS += -DBR_ARC_TARGET_BIG_ENDIAN
223 TOOLCHAIN_EXTERNAL_CFLAGS += -EB
224 endif
225 ifneq ($(BR2_TARGET_OPTIMIZATION),)
226 TOOLCHAIN_EXTERNAL_CFLAGS += $(call qstrip,$(BR2_TARGET_OPTIMIZATION))
227 # We create a list like '"-mfoo", "-mbar", "-mbarfoo"' so that each
228 # flag is a separate argument when used in execv() by the external
229 # toolchain wrapper.
230 TOOLCHAIN_EXTERNAL_WRAPPER_ARGS += -DBR_ADDITIONAL_CFLAGS='$(foreach f,$(call qstrip,$(BR2_TARGET_OPTIMIZATION)),"$(f)",)'
231 endif
232
233 ifeq ($(BR2_SOFT_FLOAT),y)
234 TOOLCHAIN_EXTERNAL_CFLAGS += -msoft-float
235 TOOLCHAIN_EXTERNAL_WRAPPER_ARGS += -DBR_SOFTFLOAT=1
236 endif
237
238 # The Linaro ARMhf toolchain expects the libraries in
239 # {/usr,}/lib/arm-linux-gnueabihf, but Buildroot copies them to
240 # {/usr,}/lib, so we need to create a symbolic link.
241 define TOOLCHAIN_EXTERNAL_LINARO_ARMHF_SYMLINK
242         ln -snf . $(TARGET_DIR)/lib/arm-linux-gnueabihf
243         ln -snf . $(TARGET_DIR)/usr/lib/arm-linux-gnueabihf
244 endef
245
246 define TOOLCHAIN_EXTERNAL_LINARO_ARMEBHF_SYMLINK
247         ln -snf . $(TARGET_DIR)/lib/armeb-linux-gnueabihf
248         ln -snf . $(TARGET_DIR)/usr/lib/armeb-linux-gnueabihf
249 endef
250
251 define TOOLCHAIN_EXTERNAL_LINARO_AARCH64_SYMLINK
252         ln -snf . $(TARGET_DIR)/lib/aarch64-linux-gnu
253         ln -snf . $(TARGET_DIR)/usr/lib/aarch64-linux-gnu
254 endef
255
256 ifeq ($(BR2_TOOLCHAIN_EXTERNAL_CODESOURCERY_ARM201305),y)
257 TOOLCHAIN_EXTERNAL_SITE = http://sourcery.mentor.com/public/gnu_toolchain/arm-none-linux-gnueabi
258 TOOLCHAIN_EXTERNAL_SOURCE = arm-2013.05-24-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2
259 else ifeq ($(BR2_TOOLCHAIN_EXTERNAL_CODESOURCERY_ARM201311),y)
260 TOOLCHAIN_EXTERNAL_SITE = http://sourcery.mentor.com/public/gnu_toolchain/arm-none-linux-gnueabi
261 TOOLCHAIN_EXTERNAL_SOURCE = arm-2013.11-33-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2
262 else ifeq ($(BR2_TOOLCHAIN_EXTERNAL_CODESOURCERY_ARM201405),y)
263 TOOLCHAIN_EXTERNAL_SITE = http://sourcery.mentor.com/public/gnu_toolchain/arm-none-linux-gnueabi
264 TOOLCHAIN_EXTERNAL_SOURCE = arm-2014.05-29-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2
265 else ifeq ($(BR2_TOOLCHAIN_EXTERNAL_ARAGO_ARMV7A_201109),y)
266 TOOLCHAIN_EXTERNAL_SITE = http://software-dl.ti.com/sdoemb/sdoemb_public_sw/arago_toolchain/2011_09/exports
267 TOOLCHAIN_EXTERNAL_SOURCE = arago-2011.09-armv7a-linux-gnueabi-sdk.tar.bz2
268 define TOOLCHAIN_EXTERNAL_FIXUP_CMDS
269         mv $(TOOLCHAIN_EXTERNAL_INSTALL_DIR)/arago-2011.09/armv7a/* $(TOOLCHAIN_EXTERNAL_INSTALL_DIR)/
270         rm -rf $(TOOLCHAIN_EXTERNAL_INSTALL_DIR)/arago-2011.09/
271 endef
272 else ifeq ($(BR2_TOOLCHAIN_EXTERNAL_ARAGO_ARMV5TE_201109),y)
273 TOOLCHAIN_EXTERNAL_SITE = http://software-dl.ti.com/sdoemb/sdoemb_public_sw/arago_toolchain/2011_09/exports
274 TOOLCHAIN_EXTERNAL_SOURCE = arago-2011.09-armv5te-linux-gnueabi-sdk.tar.bz2
275 define TOOLCHAIN_EXTERNAL_FIXUP_CMDS
276         mv $(TOOLCHAIN_EXTERNAL_INSTALL_DIR)/arago-2011.09/armv5te/* $(TOOLCHAIN_EXTERNAL_INSTALL_DIR)/
277         rm -rf $(TOOLCHAIN_EXTERNAL_INSTALL_DIR)/arago-2011.09/
278 endef
279 else ifeq ($(BR2_TOOLCHAIN_EXTERNAL_LINARO_ARM),y)
280 TOOLCHAIN_EXTERNAL_SITE = http://releases.linaro.org/14.09/components/toolchain/binaries
281 TOOLCHAIN_EXTERNAL_SOURCE = gcc-linaro-arm-linux-gnueabihf-4.9-2014.09_linux.tar.xz
282 TOOLCHAIN_EXTERNAL_POST_INSTALL_STAGING_HOOKS += TOOLCHAIN_EXTERNAL_LINARO_ARMHF_SYMLINK
283 else ifeq ($(BR2_TOOLCHAIN_EXTERNAL_LINARO_ARMEB),y)
284 TOOLCHAIN_EXTERNAL_SITE = http://releases.linaro.org/14.09/components/toolchain/binaries
285 TOOLCHAIN_EXTERNAL_SOURCE = gcc-linaro-armeb-linux-gnueabihf-4.9-2014.09_linux.tar.xz
286 TOOLCHAIN_EXTERNAL_POST_INSTALL_STAGING_HOOKS += TOOLCHAIN_EXTERNAL_LINARO_ARMEBHF_SYMLINK
287 else ifeq ($(BR2_TOOLCHAIN_EXTERNAL_CODESOURCERY_MIPS201311),y)
288 TOOLCHAIN_EXTERNAL_SITE = http://sourcery.mentor.com/public/gnu_toolchain/mips-linux-gnu
289 TOOLCHAIN_EXTERNAL_SOURCE = mips-2013.11-36-mips-linux-gnu-i686-pc-linux-gnu.tar.bz2
290 else ifeq ($(BR2_TOOLCHAIN_EXTERNAL_CODESOURCERY_MIPS201405),y)
291 TOOLCHAIN_EXTERNAL_SITE = http://sourcery.mentor.com/public/gnu_toolchain/mips-linux-gnu
292 TOOLCHAIN_EXTERNAL_SOURCE = mips-2014.05-27-mips-linux-gnu-i686-pc-linux-gnu.tar.bz2
293 else ifeq ($(BR2_TOOLCHAIN_EXTERNAL_CODESOURCERY_MIPS201411),y)
294 TOOLCHAIN_EXTERNAL_SITE = http://sourcery.mentor.com/public/gnu_toolchain/mips-linux-gnu
295 TOOLCHAIN_EXTERNAL_SOURCE = mips-2014.11-22-mips-linux-gnu-i686-pc-linux-gnu.tar.bz2
296 else ifeq ($(BR2_TOOLCHAIN_EXTERNAL_CODESOURCERY_NIOSII201305),y)
297 TOOLCHAIN_EXTERNAL_SITE = http://sourcery.mentor.com/public/gnu_toolchain/nios2-linux-gnu
298 TOOLCHAIN_EXTERNAL_SOURCE = sourceryg++-2013.05-43-nios2-linux-gnu-i686-pc-linux-gnu.tar.bz2
299 TOOLCHAIN_EXTERNAL_POST_INSTALL_STAGING_HOOKS += TOOLCHAIN_EXTERNAL_SANITIZE_KERNEL_HEADERS
300 else ifeq ($(BR2_TOOLCHAIN_EXTERNAL_CODESOURCERY_NIOSII201405),y)
301 TOOLCHAIN_EXTERNAL_SITE = http://sourcery.mentor.com/public/gnu_toolchain/nios2-linux-gnu
302 TOOLCHAIN_EXTERNAL_SOURCE = sourceryg++-2014.05-47-nios2-linux-gnu-i686-pc-linux-gnu.tar.bz2
303 else ifeq ($(BR2_TOOLCHAIN_EXTERNAL_CODESOURCERY_POWERPC201009),y)
304 TOOLCHAIN_EXTERNAL_SITE = http://sourcery.mentor.com/public/gnu_toolchain/powerpc-linux-gnu
305 TOOLCHAIN_EXTERNAL_SOURCE = freescale-2010.09-55-powerpc-linux-gnu-i686-pc-linux-gnu.tar.bz2
306 else ifeq ($(BR2_TOOLCHAIN_EXTERNAL_CODESOURCERY_POWERPC201103),y)
307 TOOLCHAIN_EXTERNAL_SITE = http://sourcery.mentor.com/public/gnu_toolchain/powerpc-linux-gnu
308 TOOLCHAIN_EXTERNAL_SOURCE = freescale-2011.03-38-powerpc-linux-gnu-i686-pc-linux-gnu.tar.bz2
309 else ifeq ($(BR2_TOOLCHAIN_EXTERNAL_CODESOURCERY_POWERPC201203),y)
310 TOOLCHAIN_EXTERNAL_SITE = http://sourcery.mentor.com/public/gnu_toolchain/powerpc-mentor-linux-gnu
311 TOOLCHAIN_EXTERNAL_SOURCE = mentor-2012.03-71-powerpc-mentor-linux-gnu-i686-pc-linux-gnu.tar.bz2
312 else ifeq ($(BR2_TOOLCHAIN_EXTERNAL_CODESOURCERY_SH201103),y)
313 TOOLCHAIN_EXTERNAL_SITE = http://sourcery.mentor.com/public/gnu_toolchain/sh-linux-gnu
314 TOOLCHAIN_EXTERNAL_SOURCE = renesas-2011.03-37-sh-linux-gnu-i686-pc-linux-gnu.tar.bz2
315 else ifeq ($(BR2_TOOLCHAIN_EXTERNAL_CODESOURCERY_SH201203),y)
316 TOOLCHAIN_EXTERNAL_SITE = http://sourcery.mentor.com/public/gnu_toolchain/sh-linux-gnu
317 TOOLCHAIN_EXTERNAL_SOURCE = renesas-2012.03-35-sh-linux-gnu-i686-pc-linux-gnu.tar.bz2
318 else ifeq ($(BR2_TOOLCHAIN_EXTERNAL_CODESOURCERY_SH201209),y)
319 TOOLCHAIN_EXTERNAL_SITE = https://sourcery.mentor.com/public/gnu_toolchain/sh-linux-gnu
320 TOOLCHAIN_EXTERNAL_SOURCE = renesas-2012.09-61-sh-linux-gnu-i686-pc-linux-gnu.tar.bz2
321 else ifeq ($(BR2_TOOLCHAIN_EXTERNAL_CODESOURCERY_SH2A_201009),y)
322 TOOLCHAIN_EXTERNAL_SITE = http://sourcery.mentor.com/public/gnu_toolchain/sh-uclinux
323 TOOLCHAIN_EXTERNAL_SOURCE = renesas-2010.09-60-sh-uclinux-i686-pc-linux-gnu.tar.bz2
324 else ifeq ($(BR2_TOOLCHAIN_EXTERNAL_CODESOURCERY_SH2A_201103),y)
325 TOOLCHAIN_EXTERNAL_SITE = http://sourcery.mentor.com/public/gnu_toolchain/sh-uclinux
326 TOOLCHAIN_EXTERNAL_SOURCE = renesas-2011.03-36-sh-uclinux-i686-pc-linux-gnu.tar.bz2
327 else ifeq ($(BR2_TOOLCHAIN_EXTERNAL_CODESOURCERY_X86_201109),y)
328 TOOLCHAIN_EXTERNAL_SITE = https://sourcery.mentor.com/public/gnu_toolchain/i686-pc-linux-gnu
329 TOOLCHAIN_EXTERNAL_SOURCE = ia32-2011.09-24-i686-pc-linux-gnu-i386-linux.tar.bz2
330 else ifeq ($(BR2_TOOLCHAIN_EXTERNAL_CODESOURCERY_X86_201203),y)
331 TOOLCHAIN_EXTERNAL_SITE = http://sourcery.mentor.com/public/gnu_toolchain/i686-pc-linux-gnu
332 TOOLCHAIN_EXTERNAL_SOURCE = ia32-2012.03-27-i686-pc-linux-gnu-i386-linux.tar.bz2
333 else ifeq ($(BR2_TOOLCHAIN_EXTERNAL_CODESOURCERY_X86_201209),y)
334 TOOLCHAIN_EXTERNAL_SITE = https://sourcery.mentor.com/public/gnu_toolchain/i686-pc-linux-gnu
335 TOOLCHAIN_EXTERNAL_SOURCE = ia32-2012.09-62-i686-pc-linux-gnu-i386-linux.tar.bz2
336 else ifeq ($(BR2_TOOLCHAIN_EXTERNAL_CODESOURCERY_AMD64_201405),y)
337 TOOLCHAIN_EXTERNAL_SITE = https://sourcery.mentor.com/public/gnu_toolchain/x86_64-amd-linux-gnu
338 TOOLCHAIN_EXTERNAL_SOURCE = amd-2014.05-25-x86_64-amd-linux-gnu-i686-pc-linux-gnu.tar.bz2
339 else ifeq ($(BR2_TOOLCHAIN_EXTERNAL_BLACKFIN_UCLINUX_2012R2),y)
340 TOOLCHAIN_EXTERNAL_SITE = http://downloads.sourceforge.net/project/adi-toolchain/2012R2/2012R2-RC2/i386
341 TOOLCHAIN_EXTERNAL_SOURCE = blackfin-toolchain-2012R2-RC2.i386.tar.bz2
342 TOOLCHAIN_EXTERNAL_EXTRA_DOWNLOADS = blackfin-toolchain-uclibc-full-2012R2-RC2.i386.tar.bz2
343 else ifeq ($(BR2_TOOLCHAIN_EXTERNAL_BLACKFIN_UCLINUX_2013R1),y)
344 TOOLCHAIN_EXTERNAL_SITE = http://downloads.sourceforge.net/project/adi-toolchain/2013R1/2013R1-RC1/i386
345 TOOLCHAIN_EXTERNAL_SOURCE = blackfin-toolchain-2013R1-RC1.i386.tar.bz2
346 TOOLCHAIN_EXTERNAL_EXTRA_DOWNLOADS = blackfin-toolchain-uclibc-full-2013R1-RC1.i386.tar.bz2
347 else ifeq ($(BR2_TOOLCHAIN_EXTERNAL_BLACKFIN_UCLINUX_2014R1),y)
348 TOOLCHAIN_EXTERNAL_SITE = http://downloads.sourceforge.net/project/adi-toolchain/2014R1/2014R1-RC2/i386
349 TOOLCHAIN_EXTERNAL_SOURCE = blackfin-toolchain-2014R1-RC2.i386.tar.bz2
350 TOOLCHAIN_EXTERNAL_EXTRA_DOWNLOADS = blackfin-toolchain-uclibc-full-2014R1-RC2.i386.tar.bz2
351 else ifeq ($(BR2_TOOLCHAIN_EXTERNAL_LINARO_AARCH64),y)
352 TOOLCHAIN_EXTERNAL_SITE = http://releases.linaro.org/14.09/components/toolchain/binaries
353 TOOLCHAIN_EXTERNAL_SOURCE = gcc-linaro-aarch64-linux-gnu-4.9-2014.09_linux.tar.xz
354 TOOLCHAIN_EXTERNAL_POST_INSTALL_STAGING_HOOKS += TOOLCHAIN_EXTERNAL_LINARO_AARCH64_SYMLINK
355 else ifeq ($(BR2_TOOLCHAIN_EXTERNAL_CODESOURCERY_AARCH64),y)
356 TOOLCHAIN_EXTERNAL_SITE = http://sourcery.mentor.com/public/gnu_toolchain/aarch64-linux-gnu
357 TOOLCHAIN_EXTERNAL_SOURCE = aarch64-2014.05-30-aarch64-linux-gnu-i686-pc-linux-gnu.tar.bz2
358 else ifeq ($(BR2_TOOLCHAIN_EXTERNAL_MUSL_CROSS),y)
359 TOOLCHAIN_EXTERNAL_VERSION = 1.1.6
360 TOOLCHAIN_EXTERNAL_SITE = https://googledrive.com/host/0BwnS5DMB0YQ6bDhPZkpOYVFhbk0/musl-$(TOOLCHAIN_EXTERNAL_VERSION)
361 ifeq ($(BR2_arm),y)
362 TOOLCHAIN_EXTERNAL_SOURCE = crossx86-arm-linux-musleabi-$(TOOLCHAIN_EXTERNAL_VERSION).tar.xz
363 else ifeq ($(BR2_armeb),y)
364 TOOLCHAIN_EXTERNAL_SOURCE = crossx86-armeb-linux-musleabi-$(TOOLCHAIN_EXTERNAL_VERSION).tar.xz
365 else ifeq ($(BR2_i386),y)
366 TOOLCHAIN_EXTERNAL_SOURCE = crossx86-i486-linux-musl-$(TOOLCHAIN_EXTERNAL_VERSION).tar.xz
367 else ifeq ($(BR2_microblazebe),y)
368 TOOLCHAIN_EXTERNAL_SOURCE = crossx86-microblaze-linux-musl-$(TOOLCHAIN_EXTERNAL_VERSION).tar.xz
369 else ifeq ($(BR2_mips),y)
370 TOOLCHAIN_EXTERNAL_SOURCE = crossx86-mips-linux-musl-$(TOOLCHAIN_EXTERNAL_VERSION).tar.xz
371 else ifeq ($(BR2_mipsel),y)
372 TOOLCHAIN_EXTERNAL_SOURCE = crossx86-mipsel-linux-musl-$(TOOLCHAIN_EXTERNAL_VERSION).tar.xz
373 else ifeq ($(BR2_powerpc),y)
374 TOOLCHAIN_EXTERNAL_SOURCE = crossx86-powerpc-linux-musl-$(TOOLCHAIN_EXTERNAL_VERSION).tar.xz
375 else ifeq ($(BR2_x86_64),y)
376 TOOLCHAIN_EXTERNAL_SOURCE = crossx86-x86_64-linux-musl-$(TOOLCHAIN_EXTERNAL_VERSION).tar.xz
377 endif
378 else ifeq ($(BR2_TOOLCHAIN_EXTERNAL_SYNOPSYS_ARC_2014_12),y)
379 TOOLCHAIN_EXTERNAL_SITE = https://github.com/foss-for-synopsys-dwc-arc-processors/toolchain/releases/download/arc-2014.12
380 ifeq ($(BR2_arc750d)$(BR2_arc770d),y)
381 TOOLCHAIN_EXTERNAL_SYNOPSYS_CORE = arc700
382 else
383 TOOLCHAIN_EXTERNAL_SYNOPSYS_CORE = archs
384 endif
385 ifeq ($(BR2_arcle),y)
386 TOOLCHAIN_EXTERNAL_SYNOPSYS_ENDIANESS = le
387 else
388 TOOLCHAIN_EXTERNAL_SYNOPSYS_ENDIANESS = be
389 endif
390 TOOLCHAIN_EXTERNAL_SOURCE = arc_gnu_2014.12_prebuilt_uclibc_$(TOOLCHAIN_EXTERNAL_SYNOPSYS_ENDIANESS)_$(TOOLCHAIN_EXTERNAL_SYNOPSYS_CORE)_linux_install.tar.gz
391 else
392 # Custom toolchain
393 TOOLCHAIN_EXTERNAL_SITE = $(dir $(call qstrip,$(BR2_TOOLCHAIN_EXTERNAL_URL)))
394 TOOLCHAIN_EXTERNAL_SOURCE = $(notdir $(call qstrip,$(BR2_TOOLCHAIN_EXTERNAL_URL)))
395 # We can't check hashes for custom downloaded toolchains
396 BR_NO_CHECK_HASH_FOR += $(TOOLCHAIN_EXTERNAL_SOURCE)
397 endif
398
399 # In fact, we don't need to download the toolchain, since it is already
400 # available on the system, so force the site and source to be empty so
401 # that nothing will be downloaded/extracted.
402 ifeq ($(BR2_TOOLCHAIN_EXTERNAL_PREINSTALLED),y)
403 TOOLCHAIN_EXTERNAL_SITE =
404 TOOLCHAIN_EXTERNAL_SOURCE =
405 endif
406
407 TOOLCHAIN_EXTERNAL_ADD_TOOLCHAIN_DEPENDENCY = NO
408
409 TOOLCHAIN_EXTERNAL_INSTALL_STAGING = YES
410
411 ifeq ($(BR2_TOOLCHAIN_EXTERNAL_BLACKFIN_UCLINUX_2012R2)$(BR2_TOOLCHAIN_EXTERNAL_BLACKFIN_UCLINUX_2013R1)$(BR2_TOOLCHAIN_EXTERNAL_BLACKFIN_UCLINUX_2014R1),y)
412 # Special handling for Blackfin toolchain, because of the split in two
413 # tarballs, and the organization of tarball contents. The tarballs
414 # contain ./opt/uClinux/{bfin-uclinux,bfin-linux-uclibc} directories,
415 # which themselves contain the toolchain. This is why we strip more
416 # components than usual.
417 define TOOLCHAIN_EXTERNAL_EXTRACT_CMDS
418         mkdir -p $(TOOLCHAIN_EXTERNAL_INSTALL_DIR)
419         $(call suitable-extractor,$(TOOLCHAIN_EXTERNAL_SOURCE)) $(DL_DIR)/$(TOOLCHAIN_EXTERNAL_SOURCE) | \
420                 $(TAR) $(TAR_STRIP_COMPONENTS)=3 --hard-dereference -C $(TOOLCHAIN_EXTERNAL_INSTALL_DIR) $(TAR_OPTIONS) -
421         $(call suitable-extractor,$(TOOLCHAIN_EXTERNAL_EXTRA_DOWNLOADS)) $(DL_DIR)/$(TOOLCHAIN_EXTERNAL_EXTRA_DOWNLOADS) | \
422                 $(TAR) $(TAR_STRIP_COMPONENTS)=3 --hard-dereference -C $(TOOLCHAIN_EXTERNAL_INSTALL_DIR) $(TAR_OPTIONS) -
423 endef
424 else ifneq ($(TOOLCHAIN_EXTERNAL_SOURCE),)
425 # Normal handling of toolchain tarball extraction.
426 define TOOLCHAIN_EXTERNAL_EXTRACT_CMDS
427         mkdir -p $(TOOLCHAIN_EXTERNAL_INSTALL_DIR)
428         $(call suitable-extractor,$(TOOLCHAIN_EXTERNAL_SOURCE)) $(DL_DIR)/$(TOOLCHAIN_EXTERNAL_SOURCE) | \
429                 $(TAR) $(TAR_STRIP_COMPONENTS)=1 --exclude='usr/lib/locale/*' -C $(TOOLCHAIN_EXTERNAL_INSTALL_DIR) $(TAR_OPTIONS) -
430         $(TOOLCHAIN_EXTERNAL_FIXUP_CMDS)
431 endef
432 endif
433
434 # Returns the location of the libc.a file for the given compiler + flags
435 define toolchain_find_libc_a
436 $$(readlink -f $$(LANG=C $(1) -print-file-name=libc.a))
437 endef
438
439 # Returns the sysroot location for the given compiler + flags
440 define toolchain_find_sysroot
441 $$(echo -n $(call toolchain_find_libc_a,$(1)) | sed -r -e 's:(usr/)?lib(32|64)?/([^/]*/)?libc\.a::')
442 endef
443
444 # Returns the lib subdirectory for the given compiler + flags (i.e
445 # typically lib32 or lib64 for some toolchains)
446 define toolchain_find_libdir
447 $$(echo -n $(call toolchain_find_libc_a,$(1)) | sed -r -e 's:.*/(usr/)?(lib(32|64)?)/([^/]*/)?libc.a:\2:')
448 endef
449
450 # Checks for an already installed toolchain: check the toolchain
451 # location, check that it supports sysroot, and then verify that it
452 # matches the configuration provided in Buildroot: ABI, C++ support,
453 # kernel headers version, type of C library and all C library features.
454 define TOOLCHAIN_EXTERNAL_CONFIGURE_CMDS
455         $(Q)$(call check_cross_compiler_exists,$(TOOLCHAIN_EXTERNAL_CC))
456         $(Q)$(call check_unusable_toolchain,$(TOOLCHAIN_EXTERNAL_CC))
457         $(Q)SYSROOT_DIR="$(call toolchain_find_sysroot,$(TOOLCHAIN_EXTERNAL_CC))" ; \
458         if test -z "$${SYSROOT_DIR}" ; then \
459                 @echo "External toolchain doesn't support --sysroot. Cannot use." ; \
460                 exit 1 ; \
461         fi ; \
462         $(call check_kernel_headers_version,\
463                 $(call toolchain_find_sysroot,$(TOOLCHAIN_EXTERNAL_CC)),\
464                 $(call qstrip,$(BR2_TOOLCHAIN_HEADERS_AT_LEAST))); \
465         if test "$(BR2_arm)" = "y" ; then \
466                 $(call check_arm_abi,\
467                         "$(TOOLCHAIN_EXTERNAL_CC) $(TOOLCHAIN_EXTERNAL_CFLAGS)",\
468                         $(TOOLCHAIN_EXTERNAL_READELF)) ; \
469         fi ; \
470         if test "$(BR2_INSTALL_LIBSTDCPP)" = "y" ; then \
471                 $(call check_cplusplus,$(TOOLCHAIN_EXTERNAL_CXX)) ; \
472         fi ; \
473         if test "$(BR2_TOOLCHAIN_EXTERNAL_UCLIBC)" = "y" ; then \
474                 $(call check_uclibc,$${SYSROOT_DIR}) ; \
475         elif test "$(BR2_TOOLCHAIN_EXTERNAL_MUSL)" = "y" ; then \
476                 $(call check_musl,$${SYSROOT_DIR}) ; \
477         else \
478                 $(call check_glibc,$${SYSROOT_DIR}) ; \
479         fi
480 endef
481
482 # With the musl C library, the libc.so library directly plays the role
483 # of the dynamic library loader. We just need to create a symbolic
484 # link to libc.so with the appropriate name.
485 ifeq ($(BR2_TOOLCHAIN_EXTERNAL_MUSL),y)
486 ifeq ($(BR2_i386),y)
487 MUSL_ARCH = i386
488 else
489 MUSL_ARCH = $(ARCH)
490 endif
491 define TOOLCHAIN_EXTERNAL_MUSL_LD_LINK
492         ln -sf libc.so $(TARGET_DIR)/lib/ld-musl-$(MUSL_ARCH).so.1
493 endef
494 TOOLCHAIN_EXTERNAL_POST_INSTALL_STAGING_HOOKS += TOOLCHAIN_EXTERNAL_MUSL_LD_LINK
495 endif
496
497 # Integration of the toolchain into Buildroot: find the main sysroot
498 # and the variant-specific sysroot, then copy the needed libraries to
499 # the $(TARGET_DIR) and copy the whole sysroot (libraries and headers)
500 # to $(STAGING_DIR).
501 #
502 # Variables are defined as follows:
503 #
504 #  LIBC_A_LOCATION:     location of the libc.a file in the default
505 #                       multilib variant (allows to find the main
506 #                       sysroot directory)
507 #                       Ex: /x-tools/mips-2011.03/mips-linux-gnu/libc/usr/lib/libc.a
508 #
509 #  SYSROOT_DIR:         the main sysroot directory, deduced from
510 #                       LIBC_A_LOCATION by removing the
511 #                       usr/lib[32|64]/libc.a part of the path.
512 #                       Ex: /x-tools/mips-2011.03/mips-linux-gnu/libc/
513 #
514 # ARCH_LIBC_A_LOCATION: location of the libc.a file in the selected
515 #                       multilib variant (taking into account the
516 #                       CFLAGS). Allows to find the sysroot of the
517 #                       selected multilib variant.
518 #                       Ex: /x-tools/mips-2011.03/mips-linux-gnu/libc/mips16/soft-float/el/usr/lib/libc.a
519 #
520 # ARCH_SYSROOT_DIR:     the sysroot of the selected multilib variant,
521 #                       deduced from ARCH_LIBC_A_LOCATION by removing
522 #                       usr/lib[32|64]/libc.a at the end of the path.
523 #                       Ex: /x-tools/mips-2011.03/mips-linux-gnu/libc/mips16/soft-float/el/
524 #
525 # ARCH_LIB_DIR:         'lib', 'lib32' or 'lib64' depending on where libraries
526 #                       are stored. Deduced from ARCH_LIBC_A_LOCATION by
527 #                       looking at usr/lib??/libc.a.
528 #                       Ex: lib
529 #
530 # ARCH_SUBDIR:          the relative location of the sysroot of the selected
531 #                       multilib variant compared to the main sysroot.
532 #                       Ex: mips16/soft-float/el
533 #
534 # SUPPORT_LIB_DIR:      some toolchains, such as recent Linaro toolchains,
535 #                       store GCC support libraries (libstdc++,
536 #                       libgcc_s, etc.) outside of the sysroot. In
537 #                       this case, SUPPORT_LIB_DIR is set to a
538 #                       non-empty value, and points to the directory
539 #                       where these support libraries are
540 #                       available. Those libraries will be copied to
541 #                       our sysroot, and the directory will also be
542 #                       considered when searching libraries for copy
543 #                       to the target filesystem.
544
545 define TOOLCHAIN_EXTERNAL_INSTALL_TARGET_LIBS
546         $(Q)SYSROOT_DIR="$(call toolchain_find_sysroot,$(TOOLCHAIN_EXTERNAL_CC))" ; \
547         if test -z "$${SYSROOT_DIR}" ; then \
548                 @echo "External toolchain doesn't support --sysroot. Cannot use." ; \
549                 exit 1 ; \
550         fi ; \
551         ARCH_SYSROOT_DIR="$(call toolchain_find_sysroot,$(TOOLCHAIN_EXTERNAL_CC) $(TOOLCHAIN_EXTERNAL_CFLAGS))" ; \
552         ARCH_LIB_DIR="$(call toolchain_find_libdir,$(TOOLCHAIN_EXTERNAL_CC) $(TOOLCHAIN_EXTERNAL_CFLAGS))" ; \
553         SUPPORT_LIB_DIR="" ; \
554         if test `find $${ARCH_SYSROOT_DIR} -name 'libstdc++.a' | wc -l` -eq 0 ; then \
555                 LIBSTDCPP_A_LOCATION=$$(LANG=C $(TOOLCHAIN_EXTERNAL_CC) $(TOOLCHAIN_EXTERNAL_CFLAGS) -print-file-name=libstdc++.a) ; \
556                 if [ -e "$${LIBSTDCPP_A_LOCATION}" ]; then \
557                         SUPPORT_LIB_DIR=`readlink -f $${LIBSTDCPP_A_LOCATION} | sed -r -e 's:libstdc\+\+\.a::'` ; \
558                 fi ; \
559         fi ; \
560         ARCH_SUBDIR=`echo $${ARCH_SYSROOT_DIR} | sed -r -e "s:^$${SYSROOT_DIR}(.*)/$$:\1:"` ; \
561         if test -z "$(BR2_STATIC_LIBS)" ; then \
562                 $(call MESSAGE,"Copying external toolchain libraries to target...") ; \
563                 for libs in $(LIB_EXTERNAL_LIBS); do \
564                         $(call copy_toolchain_lib_root,$${ARCH_SYSROOT_DIR},$${SUPPORT_LIB_DIR},$${ARCH_LIB_DIR},$$libs,/lib); \
565                 done ; \
566                 for libs in $(USR_LIB_EXTERNAL_LIBS); do \
567                         $(call copy_toolchain_lib_root,$${ARCH_SYSROOT_DIR},$${SUPPORT_LIB_DIR},$${ARCH_LIB_DIR},$$libs,/usr/lib); \
568                 done ; \
569         fi ; \
570         if test "$(BR2_TOOLCHAIN_EXTERNAL_GDB_SERVER_COPY)" = "y"; then \
571                 $(call MESSAGE,"Copying gdbserver") ; \
572                 gdbserver_found=0 ; \
573                 for d in $${ARCH_SYSROOT_DIR}/usr $${ARCH_SYSROOT_DIR}/../debug-root/usr $${ARCH_SYSROOT_DIR}/usr/$${ARCH_LIB_DIR} ; do \
574                         if test -f $${d}/bin/gdbserver ; then \
575                                 install -m 0755 -D $${d}/bin/gdbserver $(TARGET_DIR)/usr/bin/gdbserver ; \
576                                 gdbserver_found=1 ; \
577                                 break ; \
578                         fi ; \
579                 done ; \
580                 if [ $${gdbserver_found} -eq 0 ] ; then \
581                         echo "Could not find gdbserver in external toolchain" ; \
582                         exit 1 ; \
583                 fi ; \
584         fi
585 endef
586
587 define TOOLCHAIN_EXTERNAL_INSTALL_SYSROOT_LIBS
588         $(Q)SYSROOT_DIR="$(call toolchain_find_sysroot,$(TOOLCHAIN_EXTERNAL_CC))" ; \
589         if test -z "$${SYSROOT_DIR}" ; then \
590                 @echo "External toolchain doesn't support --sysroot. Cannot use." ; \
591                 exit 1 ; \
592         fi ; \
593         ARCH_SYSROOT_DIR="$(call toolchain_find_sysroot,$(TOOLCHAIN_EXTERNAL_CC) $(TOOLCHAIN_EXTERNAL_CFLAGS))" ; \
594         ARCH_LIB_DIR="$(call toolchain_find_libdir,$(TOOLCHAIN_EXTERNAL_CC) $(TOOLCHAIN_EXTERNAL_CFLAGS))" ; \
595         SUPPORT_LIB_DIR="" ; \
596         if test `find $${ARCH_SYSROOT_DIR} -name 'libstdc++.a' | wc -l` -eq 0 ; then \
597                 LIBSTDCPP_A_LOCATION=$$(LANG=C $(TOOLCHAIN_EXTERNAL_CC) $(TOOLCHAIN_EXTERNAL_CFLAGS) -print-file-name=libstdc++.a) ; \
598                 if [ -e "$${LIBSTDCPP_A_LOCATION}" ]; then \
599                         SUPPORT_LIB_DIR=`readlink -f $${LIBSTDCPP_A_LOCATION} | sed -r -e 's:libstdc\+\+\.a::'` ; \
600                 fi ; \
601         fi ; \
602         ARCH_SUBDIR=`echo $${ARCH_SYSROOT_DIR} | sed -r -e "s:^$${SYSROOT_DIR}(.*)/$$:\1:"` ; \
603         $(call MESSAGE,"Copying external toolchain sysroot to staging...") ; \
604         $(call copy_toolchain_sysroot,$${SYSROOT_DIR},$${ARCH_SYSROOT_DIR},$${ARCH_SUBDIR},$${ARCH_LIB_DIR},$${SUPPORT_LIB_DIR})
605 endef
606
607 # Special installation target used on the Blackfin architecture when
608 # FDPIC is not the primary binary format being used, but the user has
609 # nonetheless requested the installation of the FDPIC libraries to the
610 # target filesystem.
611 ifeq ($(BR2_BFIN_INSTALL_FDPIC_SHARED),y)
612 define TOOLCHAIN_EXTERNAL_INSTALL_BFIN_FDPIC
613         $(Q)$(call MESSAGE,"Install external toolchain FDPIC libraries to target...") ; \
614         FDPIC_EXTERNAL_CC=$(dir $(TOOLCHAIN_EXTERNAL_CC))/../../bfin-linux-uclibc/bin/bfin-linux-uclibc-gcc ; \
615         FDPIC_SYSROOT_DIR="$(call toolchain_find_sysroot,$${FDPIC_EXTERNAL_CC} $(TOOLCHAIN_EXTERNAL_CFLAGS))" ; \
616         FDPIC_LIB_DIR="$(call toolchain_find_libdir,$${FDPIC_EXTERNAL_CC} $(TOOLCHAIN_EXTERNAL_CFLAGS))" ; \
617         FDPIC_SUPPORT_LIB_DIR="" ; \
618         if test `find $${FDPIC_SYSROOT_DIR} -name 'libstdc++.a' | wc -l` -eq 0 ; then \
619                 FDPIC_LIBSTDCPP_A_LOCATION=$$(LANG=C $${FDPIC_EXTERNAL_CC} $(TOOLCHAIN_EXTERNAL_CFLAGS) -print-file-name=libstdc++.a) ; \
620                 if [ -e "$${FDPIC_LIBSTDCPP_A_LOCATION}" ]; then \
621                         FDPIC_SUPPORT_LIB_DIR=`readlink -f $${FDPIC_LIBSTDCPP_A_LOCATION} | sed -r -e 's:libstdc\+\+\.a::'` ; \
622                 fi ; \
623         fi ; \
624         for libs in $(LIB_EXTERNAL_LIBS); do \
625                 $(call copy_toolchain_lib_root,$${FDPIC_SYSROOT_DIR},$${FDPIC_SUPPORT_LIB_DIR},$${FDPIC_LIB_DIR},$$libs,/lib); \
626         done ; \
627         for libs in $(USR_LIB_EXTERNAL_LIBS); do \
628                 $(call copy_toolchain_lib_root,$${FDPIC_SYSROOT_DIR},$${FDPIC_SUPPORT_LIB_DIR},$${FDPIC_LIB_DIR},$$libs,/usr/lib); \
629         done
630 endef
631 endif
632
633 # Special installation target used on the Blackfin architecture when
634 # shared FLAT is not the primary format being used, but the user has
635 # nonetheless requested the installation of the shared FLAT libraries
636 # to the target filesystem. The flat libraries are found and linked
637 # according to the index in name "libN.so". Index 1 is reserved for
638 # the standard C library. Customer libraries can use 4 and above.
639 ifeq ($(BR2_BFIN_INSTALL_FLAT_SHARED),y)
640 define TOOLCHAIN_EXTERNAL_INSTALL_BFIN_FLAT
641         $(Q)$(call MESSAGE,"Install external toolchain FLAT libraries to target...") ; \
642         FLAT_EXTERNAL_CC=$(dir $(TOOLCHAIN_EXTERNAL_CC))../../bfin-uclinux/bin/bfin-uclinux-gcc ; \
643         FLAT_LIBC_A_LOCATION=`$${FLAT_EXTERNAL_CC} $(TOOLCHAIN_EXTERNAL_CFLAGS) -mid-shared-library -print-file-name=libc`; \
644         if [ -f $${FLAT_LIBC_A_LOCATION} -a ! -h $${FLAT_LIBC_A_LOCATION} ] ; then \
645                 $(INSTALL) -D $${FLAT_LIBC_A_LOCATION} $(TARGET_DIR)/lib/lib1.so; \
646         fi
647 endef
648 endif
649
650 # We use --hash-style=both to increase the compatibility of
651 # the generated binary with older platforms, except for MIPS,
652 # where the only acceptable hash style is 'sysv'
653 ifeq ($(findstring mips,$(HOSTARCH)),mips)
654 TOOLCHAIN_EXTERNAL_WRAPPER_HASH_STYLE = sysv
655 else
656 TOOLCHAIN_EXTERNAL_WRAPPER_HASH_STYLE = both
657 endif
658
659 # Build toolchain wrapper for preprocessor, C and C++ compiler and setup
660 # symlinks for everything else. Skip gdb symlink when we are building our
661 # own gdb to prevent two gdb's in output/host/usr/bin.
662 # When the link-time-optimazation flag '-flto' is used, then the compiler
663 # and binutils have to support lto. ar/ranlib need to be called with the
664 # lto plugin. The wrappers *-gcc-ar and *-gcc-ranlib provided by GCC could
665 # be used as drop-ins for ar/runlib when Makefiles are used which do not
666 # pass the lto arguments.
667 define TOOLCHAIN_EXTERNAL_INSTALL_WRAPPER
668         $(Q)$(call MESSAGE,"Building ext-toolchain wrapper")
669         mkdir -p $(HOST_DIR)/usr/bin; cd $(HOST_DIR)/usr/bin; \
670         for i in $(TOOLCHAIN_EXTERNAL_CROSS)*; do \
671                 base=$${i##*/}; \
672                 case "$$base" in \
673                 *-ar|*-ranlib|*-nm) \
674                         ln -sf $$(echo $$i | sed 's%^$(HOST_DIR)%../..%') .; \
675                         ;; \
676                 *cc|*cc-*|*++|*++-*|*cpp) \
677                         ln -sf ext-toolchain-wrapper $$base; \
678                         ;; \
679                 *gdb|*gdbtui) \
680                         if test "$(BR2_PACKAGE_HOST_GDB)" != "y"; then \
681                                 ln -sf $$(echo $$i | sed 's%^$(HOST_DIR)%../..%') .; \
682                         fi \
683                         ;; \
684                 *) \
685                         ln -sf $$(echo $$i | sed 's%^$(HOST_DIR)%../..%') .; \
686                         ;; \
687                 esac; \
688         done ;
689         $(HOSTCC) $(HOST_CFLAGS) $(TOOLCHAIN_EXTERNAL_WRAPPER_ARGS) \
690                 -s -Wl,--hash-style=$(TOOLCHAIN_EXTERNAL_WRAPPER_HASH_STYLE) \
691                 toolchain/toolchain-external/ext-toolchain-wrapper.c \
692                 -o $(HOST_DIR)/usr/bin/ext-toolchain-wrapper
693 endef
694
695 # This sed magic is taken from Linux headers_install.sh script.
696 define TOOLCHAIN_EXTERNAL_SANITIZE_KERNEL_HEADERS
697         $(Q)$(call MESSAGE,"Sanitizing kernel headers");
698         find $(STAGING_DIR)/usr/include/linux/ -name "*.h" | xargs sed -r -i \
699                 -e 's/([ \t(])(__user|__force|__iomem)[ \t]/\1/g' \
700                 -e 's/__attribute_const__([ \t]|$$)/\1/g' \
701                 -e 's@^#include <linux/compiler.h>@@' \
702                 -e 's/(^|[^a-zA-Z0-9])__packed([^a-zA-Z0-9_]|$$)/\1__attribute__((packed))\2/g' \
703                 -e 's/(^|[ \t(])(inline|asm|volatile)([ \t(]|$$)/\1__\2__\3/g' \
704                 -e 's@#(ifndef|define|endif[ \t]*/[*])[ \t]*_UAPI@#\1 @'
705 endef
706
707 define TOOLCHAIN_EXTERNAL_INSTALL_GDBINIT
708         if test -f $(TARGET_CROSS)gdb ; then \
709                 $(call gen_gdbinit_file) ; \
710         fi
711 endef
712
713 define TOOLCHAIN_EXTERNAL_INSTALL_STAGING_CMDS
714         $(TOOLCHAIN_EXTERNAL_INSTALL_SYSROOT_LIBS)
715         $(TOOLCHAIN_EXTERNAL_INSTALL_WRAPPER)
716         $(TOOLCHAIN_EXTERNAL_INSTALL_GDBINIT)
717 endef
718
719 # Even though we're installing things in both the staging, the host
720 # and the target directory, we do everything within the
721 # install-staging step, arbitrarily.
722 define TOOLCHAIN_EXTERNAL_INSTALL_TARGET_CMDS
723         $(TOOLCHAIN_EXTERNAL_INSTALL_TARGET_LIBS)
724         $(TOOLCHAIN_EXTERNAL_INSTALL_BFIN_FDPIC)
725         $(TOOLCHAIN_EXTERNAL_INSTALL_BFIN_FLAT)
726 endef
727
728 $(eval $(generic-package))