blob: 30880e551847428d51bdd87958371913cd7f3b78 [file] [log] [blame]
Thomas Petazzoni2e0cd952013-10-08 20:17:07 +02001# This Makefile fragment declares toolchain related helper functions.
2
3# The copy_toolchain_lib_root function copies a toolchain library and
4# its symbolic links from the sysroot directory to the target
5# directory. Note that this function is used both by the external
6# toolchain logic, and the glibc package, so care must be taken when
7# changing this function.
Yann E. MORINed181ae2010-07-28 00:08:13 +02008#
Thomas De Schampheleire2a87b642016-02-12 20:20:25 +01009# $1: library name
Yann E. MORINed181ae2010-07-28 00:08:13 +020010#
11copy_toolchain_lib_root = \
Thomas De Schampheleire2a87b642016-02-12 20:20:25 +010012 LIB="$(strip $1)"; \
Jerzy Grzegorek595bf302014-10-23 10:43:37 +020013\
Yann E. MORIN49648d42016-05-29 23:58:11 +020014 LIBPATHS=`find $(STAGING_DIR)/ -name "$${LIB}" 2>/dev/null` ; \
Thomas De Schampheleire335f3312016-02-03 22:45:28 +010015 for LIBPATH in $${LIBPATHS} ; do \
Thomas De Schampheleire2a87b642016-02-12 20:20:25 +010016 DESTDIR=`echo $${LIBPATH} | sed "s,^$(STAGING_DIR)/,," | xargs dirname` ; \
17 mkdir -p $(TARGET_DIR)/$${DESTDIR}; \
Thomas Petazzoniccc82212013-10-08 20:17:14 +020018 while true ; do \
19 LIBNAME=`basename $${LIBPATH}`; \
20 LIBDIR=`dirname $${LIBPATH}` ; \
21 LINKTARGET=`readlink $${LIBPATH}` ; \
Thomas Petazzonie1f08042012-05-07 15:02:19 +020022 rm -fr $(TARGET_DIR)/$${DESTDIR}/$${LIBNAME}; \
Thomas Petazzonie1f08042012-05-07 15:02:19 +020023 if test -h $${LIBPATH} ; then \
Thomas Petazzoniccc82212013-10-08 20:17:14 +020024 ln -sf `basename $${LINKTARGET}` $(TARGET_DIR)/$${DESTDIR}/$${LIBNAME} ; \
Thomas Petazzonie1f08042012-05-07 15:02:19 +020025 elif test -f $${LIBPATH}; then \
26 $(INSTALL) -D -m0755 $${LIBPATH} $(TARGET_DIR)/$${DESTDIR}/$${LIBNAME}; \
Yann E. MORINed181ae2010-07-28 00:08:13 +020027 else \
28 exit -1; \
29 fi; \
Thomas Petazzoniccc82212013-10-08 20:17:14 +020030 if test -z "$${LINKTARGET}" ; then \
31 break ; \
32 fi ; \
33 LIBPATH="`readlink -f $${LIBPATH}`"; \
Yann E. MORINed181ae2010-07-28 00:08:13 +020034 done; \
Maxime Hadjinlian8f59da82015-10-04 13:35:08 +020035 done
Yann E. MORINed181ae2010-07-28 00:08:13 +020036
37#
38# Copy the full external toolchain sysroot directory to the staging
39# dir. The operation of this function is rendered a little bit
40# complicated by the support for multilib toolchains.
41#
42# We start by copying etc, lib, sbin and usr from the sysroot of the
43# selected architecture variant (as pointed by ARCH_SYSROOT_DIR). This
44# allows to import into the staging directory the C library and
45# companion libraries for the correct architecture variant. We
46# explictly only copy etc, lib, sbin and usr since other directories
47# might exist for other architecture variants (on Codesourcery
48# toolchain, the sysroot for the default architecture variant contains
49# the armv4t and thumb2 subdirectories, which are the sysroot for the
50# corresponding architecture variants), and we don't want to import
51# them.
52#
Vicente Olivert Riera7b6cfca2016-05-10 15:01:37 +010053# Then, if the selected architecture variant is not the default one
54# (i.e, if SYSROOT_DIR != ARCH_SYSROOT_DIR), then we :
Yann E. MORINed181ae2010-07-28 00:08:13 +020055#
Vicente Olivert Riera7b6cfca2016-05-10 15:01:37 +010056# * Import the header files from the default architecture
Yann E. MORINed181ae2010-07-28 00:08:13 +020057# variant. Header files are typically shared between the sysroots
58# for the different architecture variants. If we use the
59# non-default one, header files were not copied by the previous
60# step, so we copy them here from the sysroot of the default
61# architecture variant.
62#
63# * Create a symbolic link that matches the name of the subdirectory
64# for the architecture variant in the original sysroot. This is
65# required as the compiler will by default look in
66# sysroot_dir/arch_variant/ for libraries and headers, when the
67# non-default architecture variant is used. Without this, the
68# compiler fails to find libraries and headers.
69#
Vicente Olivert Riera7b6cfca2016-05-10 15:01:37 +010070# Some toolchains (i.e Linaro binary toolchains) store support
71# libraries (libstdc++, libgcc_s) outside of the sysroot, so we simply
72# copy all the libraries from the "support lib directory" into our
73# sysroot.
Thomas Petazzonie1f08042012-05-07 15:02:19 +020074#
Thomas Petazzoni2c23e932011-10-02 21:20:09 +020075# Note that the 'locale' directories are not copied. They are huge
76# (400+MB) in CodeSourcery toolchains, and they are not really useful.
77#
Yann E. MORINed181ae2010-07-28 00:08:13 +020078# $1: main sysroot directory of the toolchain
79# $2: arch specific sysroot directory of the toolchain
80# $3: arch specific subdirectory in the sysroot
Samuel Martin56287762013-08-23 00:59:35 +020081# $4: directory of libraries ('lib', 'lib32' or 'lib64')
Thomas Petazzonie1f08042012-05-07 15:02:19 +020082# $5: support lib directories (for toolchains storing libgcc_s,
83# libstdc++ and other gcc support libraries outside of the
84# sysroot)
Yann E. MORINed181ae2010-07-28 00:08:13 +020085copy_toolchain_sysroot = \
86 SYSROOT_DIR="$(strip $1)"; \
87 ARCH_SYSROOT_DIR="$(strip $2)"; \
88 ARCH_SUBDIR="$(strip $3)"; \
Thomas Petazzoni0729b542011-12-31 11:57:15 +010089 ARCH_LIB_DIR="$(strip $4)" ; \
Thomas Petazzonie1f08042012-05-07 15:02:19 +020090 SUPPORT_LIB_DIR="$(strip $5)" ; \
Samuel Martin56287762013-08-23 00:59:35 +020091 for i in etc $${ARCH_LIB_DIR} sbin usr usr/$${ARCH_LIB_DIR}; do \
Thomas De Schampheleirea07e47a2017-02-07 22:56:38 +010092 if [ ! -d $${ARCH_SYSROOT_DIR}/$$i ] ; then \
93 continue ; \
Yann E. MORINed181ae2010-07-28 00:08:13 +020094 fi ; \
Thomas De Schampheleirebb924a02017-02-07 22:56:39 +010095 rsync -au --chmod=u=rwX,go=rX --exclude 'locale/' \
Thomas De Schampheleirea07e47a2017-02-07 22:56:38 +010096 --include '/libexec*/' --exclude '/lib*/' \
97 $${ARCH_SYSROOT_DIR}/$$i/ $(STAGING_DIR)/$$i/ ; \
Yann E. MORINed181ae2010-07-28 00:08:13 +020098 done ; \
Vicente Olivert Riera7b6cfca2016-05-10 15:01:37 +010099 if [ `readlink -f $${SYSROOT_DIR}` != `readlink -f $${ARCH_SYSROOT_DIR}` ] ; then \
100 if [ ! -d $${ARCH_SYSROOT_DIR}/usr/include ] ; then \
101 cp -a $${SYSROOT_DIR}/usr/include $(STAGING_DIR)/usr ; \
Vicente Olivert Riera9a1e9ef2016-01-12 17:49:38 +0000102 fi ; \
Vicente Olivert Riera7b6cfca2016-05-10 15:01:37 +0100103 mkdir -p `dirname $(STAGING_DIR)/$${ARCH_SUBDIR}` ; \
104 relpath="./" ; \
105 nbslashs=`printf $${ARCH_SUBDIR} | sed 's%[^/]%%g' | wc -c` ; \
106 for slash in `seq 1 $${nbslashs}` ; do \
107 relpath=$${relpath}"../" ; \
108 done ; \
109 ln -s $${relpath} $(STAGING_DIR)/$${ARCH_SUBDIR} ; \
110 echo "Symlinking $(STAGING_DIR)/$${ARCH_SUBDIR} -> $${relpath}" ; \
Yann E. MORINed181ae2010-07-28 00:08:13 +0200111 fi ; \
Thomas Petazzonie1f08042012-05-07 15:02:19 +0200112 if test -n "$${SUPPORT_LIB_DIR}" ; then \
113 cp -a $${SUPPORT_LIB_DIR}/* $(STAGING_DIR)/lib/ ; \
114 fi ; \
Yann E. MORINed181ae2010-07-28 00:08:13 +0200115 find $(STAGING_DIR) -type d | xargs chmod 755
116
117#
Yann E. MORINa5a30962014-03-01 15:53:01 +0100118# Check the specified kernel headers version actually matches the
119# version in the toolchain.
120#
Yann E. MORIN2a82bb82014-04-07 20:19:12 +0200121# $1: sysroot directory
Yann E. MORINa5a30962014-03-01 15:53:01 +0100122# $2: kernel version string, in the form: X.Y
123#
124check_kernel_headers_version = \
125 if ! support/scripts/check-kernel-headers.sh $(1) $(2); then \
Yann E. MORIN0aa90192014-03-30 14:59:30 +0200126 exit 1; \
Yann E. MORINa5a30962014-03-01 15:53:01 +0100127 fi
128
129#
Thomas Petazzonibd760c32015-08-04 20:00:35 +0200130# Check the specific gcc version actually matches the version in the
131# toolchain
132#
133# $1: path to gcc
134# $2: expected gcc version
135#
Thomas Petazzonibd760c32015-08-04 20:00:35 +0200136check_gcc_version = \
137 expected_version="$(strip $2)" ; \
Yann E. MORIN23fde762015-08-13 14:13:23 +0200138 if [ -z "$${expected_version}" ]; then \
Arnout Vandecappelle006ba682016-11-24 00:40:34 +0100139 exit 0 ; \
Yann E. MORIN23fde762015-08-13 14:13:23 +0200140 fi; \
Krzysztof Konopko06cd6042017-03-09 09:01:36 +0100141 real_version=`$(1) -dumpversion` ; \
Yann E. MORIN4a5f8782015-08-09 13:11:42 +0200142 if [[ ! "$${real_version}" =~ ^$${expected_version}\. ]] ; then \
143 printf "Incorrect selection of gcc version: expected %s.x, got %s\n" \
144 "$${expected_version}" "$${real_version}" ; \
Thomas Petazzonibd760c32015-08-04 20:00:35 +0200145 exit 1 ; \
146 fi
147
148#
Thomas Petazzoni9fbdf062012-11-03 18:47:50 +0100149# Check the availability of a particular glibc feature. This function
150# is used to check toolchain options that are always supported by
151# glibc, so we simply check that the corresponding option is properly
152# enabled.
Yann E. MORINed181ae2010-07-28 00:08:13 +0200153#
154# $1: Buildroot option name
155# $2: feature description
156#
157check_glibc_feature = \
Thomas Petazzoni0bbbcb92013-07-17 22:30:47 +0200158 if [ "$($(1))" != "y" ] ; then \
Yann E. MORINed181ae2010-07-28 00:08:13 +0200159 echo "$(2) available in C library, please enable $(1)" ; \
160 exit 1 ; \
161 fi
162
163#
Thomas Petazzoni9fbdf062012-11-03 18:47:50 +0100164# Check the availability of RPC support in a glibc toolchain
165#
166# $1: sysroot directory
167#
168check_glibc_rpc_feature = \
169 IS_IN_LIBC=`test -f $(1)/usr/include/rpc/rpc.h && echo y` ; \
170 if [ "$(BR2_TOOLCHAIN_HAS_NATIVE_RPC)" != "y" -a "$${IS_IN_LIBC}" = "y" ] ; then \
Yann E. MORIN808c3fb2015-05-03 17:39:16 +0200171 echo "RPC support available in C library, please enable BR2_TOOLCHAIN_EXTERNAL_INET_RPC" ; \
Thomas Petazzoni9fbdf062012-11-03 18:47:50 +0100172 exit 1 ; \
173 fi ; \
174 if [ "$(BR2_TOOLCHAIN_HAS_NATIVE_RPC)" = "y" -a "$${IS_IN_LIBC}" != "y" ] ; then \
Yann E. MORIN808c3fb2015-05-03 17:39:16 +0200175 echo "RPC support not available in C library, please disable BR2_TOOLCHAIN_EXTERNAL_INET_RPC" ; \
Thomas Petazzoni9fbdf062012-11-03 18:47:50 +0100176 exit 1 ; \
177 fi
178
179#
Yann E. MORINed181ae2010-07-28 00:08:13 +0200180# Check the correctness of a glibc external toolchain configuration.
181# 1. Check that the C library selected in Buildroot matches the one
182# of the external toolchain
183# 2. Check that all the C library-related features are enabled in the
184# config, since glibc always supports all of them
185#
186# $1: sysroot directory
187#
188check_glibc = \
189 SYSROOT_DIR="$(strip $1)"; \
Jeremy Kerrfb6dd8f2013-12-03 22:26:13 +1100190 if test `find $${SYSROOT_DIR}/ -maxdepth 2 -name 'ld-linux*.so.*' -o -name 'ld.so.*' -o -name 'ld64.so.*' | wc -l` -eq 0 ; then \
Yann E. MORINed181ae2010-07-28 00:08:13 +0200191 echo "Incorrect selection of the C library"; \
192 exit -1; \
193 fi; \
Mike Frysingere5e5f5d2011-01-10 09:28:41 -0500194 $(call check_glibc_feature,BR2_USE_MMU,MMU support) ;\
Thomas Petazzoni9fbdf062012-11-03 18:47:50 +0100195 $(call check_glibc_rpc_feature,$${SYSROOT_DIR})
Yann E. MORINed181ae2010-07-28 00:08:13 +0200196
197#
Thomas Petazzonia1d94aa2013-10-08 20:17:09 +0200198# Check that the selected C library really is musl
199#
Ilya Kuzmich3b328892017-03-20 08:56:10 +0300200# $1: cross-gcc path
201# $2: cross-readelf path
Thomas Petazzonia1d94aa2013-10-08 20:17:09 +0200202check_musl = \
Ilya Kuzmich3b328892017-03-20 08:56:10 +0300203 __CROSS_CC=$(strip $1) ; \
204 __CROSS_READELF=$(strip $2) ; \
205 echo 'void main(void) {}' | $${__CROSS_CC} -x c -o $(BUILD_DIR)/.br-toolchain-test.tmp - >/dev/null 2>&1; \
206 if ! $${__CROSS_READELF} -l $(BUILD_DIR)/.br-toolchain-test.tmp 2> /dev/null | grep 'program interpreter: /lib/ld-musl' -q; then \
207 rm -f $(BUILD_DIR)/.br-toolchain-test.tmp*; \
Thomas Petazzonia1d94aa2013-10-08 20:17:09 +0200208 echo "Incorrect selection of the C library" ; \
209 exit -1; \
Ilya Kuzmich3b328892017-03-20 08:56:10 +0300210 fi ; \
211 rm -f $(BUILD_DIR)/.br-toolchain-test.tmp*
Thomas Petazzonia1d94aa2013-10-08 20:17:09 +0200212
213#
Yann E. MORINed181ae2010-07-28 00:08:13 +0200214# Check the conformity of Buildroot configuration with regard to the
215# uClibc configuration of the external toolchain, for a particular
216# feature.
217#
Gustavo Zacarias1c51a802015-03-30 18:07:20 -0300218# If 'Buildroot option name' ($2) is empty it means the uClibc option
219# is mandatory.
220#
Yann E. MORINed181ae2010-07-28 00:08:13 +0200221# $1: uClibc macro name
222# $2: Buildroot option name
223# $3: uClibc config file
224# $4: feature description
225#
226check_uclibc_feature = \
227 IS_IN_LIBC=`grep -q "\#define $(1) 1" $(3) && echo y` ; \
Gustavo Zacarias1c51a802015-03-30 18:07:20 -0300228 if [ -z "$(2)" ] ; then \
229 if [ "$${IS_IN_LIBC}" != "y" ] ; then \
230 echo "$(4) not available in C library, toolchain unsuitable for Buildroot" ; \
231 exit 1 ; \
232 fi ; \
233 else \
234 if [ "$($(2))" != "y" -a "$${IS_IN_LIBC}" = "y" ] ; then \
235 echo "$(4) available in C library, please enable $(2)" ; \
236 exit 1 ; \
237 fi ; \
238 if [ "$($(2))" = "y" -a "$${IS_IN_LIBC}" != "y" ] ; then \
239 echo "$(4) not available in C library, please disable $(2)" ; \
240 exit 1 ; \
241 fi ; \
Yann E. MORINed181ae2010-07-28 00:08:13 +0200242 fi
243
244#
245# Check the correctness of a uclibc external toolchain configuration
246# 1. Check that the C library selected in Buildroot matches the one
247# of the external toolchain
248# 2. Check that the features enabled in the Buildroot configuration
249# match the features available in the uClibc of the external
250# toolchain
251#
252# $1: sysroot directory
253#
254check_uclibc = \
255 SYSROOT_DIR="$(strip $1)"; \
Thomas Petazzoni090d4862011-12-31 16:15:43 +0100256 if ! test -f $${SYSROOT_DIR}/usr/include/bits/uClibc_config.h ; then \
Yann E. MORINed181ae2010-07-28 00:08:13 +0200257 echo "Incorrect selection of the C library"; \
258 exit -1; \
259 fi; \
260 UCLIBC_CONFIG_FILE=$${SYSROOT_DIR}/usr/include/bits/uClibc_config.h ; \
Mike Frysingere5e5f5d2011-01-10 09:28:41 -0500261 $(call check_uclibc_feature,__ARCH_USE_MMU__,BR2_USE_MMU,$${UCLIBC_CONFIG_FILE},MMU support) ;\
Gustavo Zacarias7f96ef32015-03-30 18:07:21 -0300262 $(call check_uclibc_feature,__UCLIBC_HAS_LFS__,,$${UCLIBC_CONFIG_FILE},Large file support) ;\
Gustavo Zacarias51eaa2c2015-04-19 09:39:54 -0300263 $(call check_uclibc_feature,__UCLIBC_HAS_IPV6__,,$${UCLIBC_CONFIG_FILE},IPv6 support) ;\
Thomas Petazzoni0858e002012-11-03 18:47:49 +0100264 $(call check_uclibc_feature,__UCLIBC_HAS_RPC__,BR2_TOOLCHAIN_HAS_NATIVE_RPC,$${UCLIBC_CONFIG_FILE},RPC support) ;\
Yann E. MORINed181ae2010-07-28 00:08:13 +0200265 $(call check_uclibc_feature,__UCLIBC_HAS_LOCALE__,BR2_ENABLE_LOCALE,$${UCLIBC_CONFIG_FILE},Locale support) ;\
266 $(call check_uclibc_feature,__UCLIBC_HAS_WCHAR__,BR2_USE_WCHAR,$${UCLIBC_CONFIG_FILE},Wide char support) ;\
Peter Korsgaard5931db02011-11-24 14:26:52 +0100267 $(call check_uclibc_feature,__UCLIBC_HAS_THREADS__,BR2_TOOLCHAIN_HAS_THREADS,$${UCLIBC_CONFIG_FILE},Thread support) ;\
Thomas Petazzonic5866be2013-09-02 18:06:36 +0200268 $(call check_uclibc_feature,__PTHREADS_DEBUG_SUPPORT__,BR2_TOOLCHAIN_HAS_THREADS_DEBUG,$${UCLIBC_CONFIG_FILE},Thread debugging support) ;\
Vicente Olivert Riera79493502016-03-15 16:40:38 +0000269 $(call check_uclibc_feature,__UCLIBC_HAS_THREADS_NATIVE__,BR2_TOOLCHAIN_HAS_THREADS_NPTL,$${UCLIBC_CONFIG_FILE},NPTL thread support)
Yann E. MORINed181ae2010-07-28 00:08:13 +0200270
271#
272# Check that the Buildroot configuration of the ABI matches the
273# configuration of the external toolchain.
274#
Thomas Petazzonic59d0242011-05-08 18:52:27 +0200275# $1: cross-gcc path
Baruch Siach40ff8392014-07-03 12:35:57 +0300276# $2: cross-readelf path
Thomas Petazzonic59d0242011-05-08 18:52:27 +0200277#
Yann E. MORINed181ae2010-07-28 00:08:13 +0200278check_arm_abi = \
Thomas Petazzonic59d0242011-05-08 18:52:27 +0200279 __CROSS_CC=$(strip $1) ; \
280 EXT_TOOLCHAIN_TARGET=`LANG=C $${__CROSS_CC} -v 2>&1 | grep ^Target | cut -f2 -d ' '` ; \
Yann E. MORIN95bfc992013-07-14 00:27:32 +0200281 if ! echo $${EXT_TOOLCHAIN_TARGET} | grep -qE 'eabi(hf)?$$' ; then \
282 echo "External toolchain uses the unsuported OABI" ; \
Yann E. MORINed181ae2010-07-28 00:08:13 +0200283 exit 1 ; \
Thomas Petazzonib2e88072013-07-17 22:30:48 +0200284 fi ; \
Guido Martínez375bc182015-06-26 14:33:20 -0300285 if ! echo 'int main(void) {}' | $${__CROSS_CC} -x c -o $(BUILD_DIR)/.br-toolchain-test.tmp - ; then \
286 rm -f $(BUILD_DIR)/.br-toolchain-test.tmp*; \
Stefan Sørensen37875922014-05-09 13:44:00 +0200287 abistr_$(BR2_ARM_EABI)='EABI'; \
288 abistr_$(BR2_ARM_EABIHF)='EABIhf'; \
289 echo "Incorrect ABI setting: $${abistr_y} selected, but toolchain is incompatible"; \
Thomas Petazzonib2e88072013-07-17 22:30:48 +0200290 exit 1 ; \
Guido Martínez375bc182015-06-26 14:33:20 -0300291 fi ; \
292 rm -f $(BUILD_DIR)/.br-toolchain-test.tmp*
Yann E. MORINed181ae2010-07-28 00:08:13 +0200293
294#
295# Check that the external toolchain supports C++
296#
Thomas Petazzonic59d0242011-05-08 18:52:27 +0200297# $1: cross-g++ path
298#
Yann E. MORINed181ae2010-07-28 00:08:13 +0200299check_cplusplus = \
Thomas Petazzonic59d0242011-05-08 18:52:27 +0200300 __CROSS_CXX=$(strip $1) ; \
301 $${__CROSS_CXX} -v > /dev/null 2>&1 ; \
Yann E. MORINed181ae2010-07-28 00:08:13 +0200302 if test $$? -ne 0 ; then \
Thomas Petazzoni6b578c82010-12-13 17:27:41 +0100303 echo "C++ support is selected but is not available in external toolchain" ; \
Yann E. MORINed181ae2010-07-28 00:08:13 +0200304 exit 1 ; \
Thomas Petazzoniac38fd32010-12-13 17:27:38 +0100305 fi
Yann E. MORINed181ae2010-07-28 00:08:13 +0200306
307#
Samuel Martin26db83c2016-07-03 15:47:44 +0200308#
309# Check that the external toolchain supports Fortran
310#
311# $1: cross-gfortran path
312#
313check_fortran = \
314 __CROSS_FC=$(strip $1) ; \
315 __o=$(BUILD_DIR)/.br-toolchain-test-fortran.tmp ; \
316 printf 'program hello\n\tprint *, "Hello Fortran!\\n"\nend program hello\n' | \
317 $${__CROSS_FC} -x f95 -o $${__o} - ; \
318 if test $$? -ne 0 ; then \
319 rm -f $${__o}* ; \
320 echo "Fortran support is selected but is not available in external toolchain" ; \
321 exit 1 ; \
322 fi ; \
323 rm -f $${__o}* \
324
325#
Yann E. MORINed181ae2010-07-28 00:08:13 +0200326# Check that the cross-compiler given in the configuration exists
327#
Thomas Petazzonic59d0242011-05-08 18:52:27 +0200328# $1: cross-gcc path
329#
Yann E. MORINed181ae2010-07-28 00:08:13 +0200330check_cross_compiler_exists = \
Thomas Petazzonic59d0242011-05-08 18:52:27 +0200331 __CROSS_CC=$(strip $1) ; \
332 $${__CROSS_CC} -v > /dev/null 2>&1 ; \
Yann E. MORINed181ae2010-07-28 00:08:13 +0200333 if test $$? -ne 0 ; then \
Thomas Petazzonic59d0242011-05-08 18:52:27 +0200334 echo "Cannot execute cross-compiler '$${__CROSS_CC}'" ; \
Yann E. MORINed181ae2010-07-28 00:08:13 +0200335 exit 1 ; \
Thomas Petazzoniac38fd32010-12-13 17:27:38 +0100336 fi
Thomas Petazzoni12478502013-10-13 10:28:20 +0200337
338#
Romain Naour4b201092016-04-27 22:15:03 +0200339# Check for toolchains known not to work with Buildroot.
340# - For the Angstrom toolchains, we check by looking at the vendor part of
341# the host tuple.
342# - Exclude distro-class toolchains which are not relocatable.
343# - Exclude broken toolchains which return "libc.a" with -print-file-name.
344# - Exclude toolchains which doesn't support --sysroot option.
Thomas Petazzoni12478502013-10-13 10:28:20 +0200345#
346# $1: cross-gcc path
347#
348check_unusable_toolchain = \
349 __CROSS_CC=$(strip $1) ; \
350 vendor=`$${__CROSS_CC} -dumpmachine | cut -f2 -d'-'` ; \
351 if test "$${vendor}" = "angstrom" ; then \
352 echo "Angstrom toolchains are not pure toolchains: they contain" ; \
353 echo "many other libraries than just the C library, which makes" ; \
354 echo "them unsuitable as external toolchains for build systems" ; \
355 echo "such as Buildroot." ; \
356 exit 1 ; \
Yann E. MORINdefb9652015-03-17 16:14:55 +0100357 fi; \
358 with_sysroot=`$${__CROSS_CC} -v 2>&1 |sed -r -e '/.* --with-sysroot=([^[:space:]]+)[[:space:]].*/!d; s//\1/'`; \
359 if test "$${with_sysroot}" = "/" ; then \
360 echo "Distribution toolchains are unsuitable for use by Buildroot," ; \
361 echo "as they were configured in a way that makes them non-relocatable,"; \
362 echo "and contain a lot of pre-built libraries that would conflict with"; \
363 echo "the ones Buildroot wants to build."; \
364 exit 1; \
Romain Naourc32c3902016-04-27 22:15:01 +0200365 fi; \
366 libc_a_path=`$${__CROSS_CC} -print-file-name=libc.a` ; \
367 if test "$${libc_a_path}" = "libc.a" ; then \
368 echo "Unable to detect the toolchain sysroot, Buildroot cannot use this toolchain." ; \
369 exit 1 ; \
Romain Naour6bb03552016-04-27 22:15:02 +0200370 fi ; \
371 sysroot_dir="$(call toolchain_find_sysroot,$${__CROSS_CC})" ; \
372 if test -z "$${sysroot_dir}" ; then \
373 echo "External toolchain doesn't support --sysroot. Cannot use." ; \
374 exit 1 ; \
Thomas Petazzoni12478502013-10-13 10:28:20 +0200375 fi
Thomas Petazzoni7130ceb2014-05-05 11:25:50 +0200376
377#
Vicente Olivert Riera79493502016-03-15 16:40:38 +0000378# Check if the toolchain has SSP (stack smashing protector) support
379#
380# $1: cross-gcc path
381#
382check_toolchain_ssp = \
383 __CROSS_CC=$(strip $1) ; \
384 __HAS_SSP=`echo 'void main(){}' | $${__CROSS_CC} -fstack-protector -x c - -o $(BUILD_DIR)/.br-toolchain-test.tmp >/dev/null 2>&1 && echo y` ; \
385 if [ "$(BR2_TOOLCHAIN_HAS_SSP)" != "y" -a "$${__HAS_SSP}" = "y" ] ; then \
386 echo "SSP support available in this toolchain, please enable BR2_TOOLCHAIN_EXTERNAL_HAS_SSP" ; \
387 exit 1 ; \
388 fi ; \
389 if [ "$(BR2_TOOLCHAIN_HAS_SSP)" = "y" -a "$${__HAS_SSP}" != "y" ] ; then \
390 echo "SSP support not available in this toolchain, please disable BR2_TOOLCHAIN_EXTERNAL_HAS_SSP" ; \
391 exit 1 ; \
392 fi ; \
393 rm -f $(BUILD_DIR)/.br-toolchain-test.tmp*
394
395#
Thomas Petazzoni7130ceb2014-05-05 11:25:50 +0200396# Generate gdbinit file for use with Buildroot
397#
398gen_gdbinit_file = \
399 mkdir -p $(STAGING_DIR)/usr/share/buildroot/ ; \
400 echo "set sysroot $(STAGING_DIR)" > $(STAGING_DIR)/usr/share/buildroot/gdbinit