blob: 03355f56dd611ce3207bfad452870716c949c23d [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 Schampheleire9e4fb202017-02-07 22:56:48 +01009# $1: library name pattern (can include glob wildcards)
Yann E. MORINed181ae2010-07-28 00:08:13 +020010#
11copy_toolchain_lib_root = \
Thomas De Schampheleire9e4fb202017-02-07 22:56:48 +010012 LIBPATTERN="$(strip $1)"; \
Thomas De Schampheleire9e4fb202017-02-07 22:56:48 +010013 LIBPATHS=`find $(STAGING_DIR)/ -name "$${LIBPATTERN}" 2>/dev/null` ; \
Thomas De Schampheleire335f3312016-02-03 22:45:28 +010014 for LIBPATH in $${LIBPATHS} ; do \
Thomas Petazzoniccc82212013-10-08 20:17:14 +020015 while true ; do \
16 LIBNAME=`basename $${LIBPATH}`; \
Thomas Petazzonib3cc7e62017-07-02 13:39:35 +020017 DESTDIR=`echo $${LIBPATH} | sed "s,^$(STAGING_DIR)/,," | xargs dirname` ; \
Arnout Vandecappelle9971e932017-07-05 16:54:18 +020018 mkdir -p $(TARGET_DIR)/$${DESTDIR}; \
Thomas Petazzonie1f08042012-05-07 15:02:19 +020019 rm -fr $(TARGET_DIR)/$${DESTDIR}/$${LIBNAME}; \
Thomas Petazzonie1f08042012-05-07 15:02:19 +020020 if test -h $${LIBPATH} ; then \
Thomas De Schampheleire38b51732017-02-07 22:56:49 +010021 cp -d $${LIBPATH} $(TARGET_DIR)/$${DESTDIR}/$${LIBNAME}; \
Thomas De Schampheleired34e02a2017-02-07 22:56:47 +010022 LIBPATH="`readlink -f $${LIBPATH}`"; \
Thomas Petazzonie1f08042012-05-07 15:02:19 +020023 elif test -f $${LIBPATH}; then \
24 $(INSTALL) -D -m0755 $${LIBPATH} $(TARGET_DIR)/$${DESTDIR}/$${LIBNAME}; \
Thomas De Schampheleired34e02a2017-02-07 22:56:47 +010025 break ; \
Yann E. MORINed181ae2010-07-28 00:08:13 +020026 else \
27 exit -1; \
28 fi; \
Yann E. MORINed181ae2010-07-28 00:08:13 +020029 done; \
Maxime Hadjinlian8f59da82015-10-04 13:35:08 +020030 done
Yann E. MORINed181ae2010-07-28 00:08:13 +020031
32#
33# Copy the full external toolchain sysroot directory to the staging
34# dir. The operation of this function is rendered a little bit
35# complicated by the support for multilib toolchains.
36#
Thomas De Schampheleire367f4ab2017-02-07 22:56:40 +010037# We start by copying etc, 'lib', sbin, usr and usr/'lib' from the
38# sysroot of the selected architecture variant (as pointed to by
39# ARCH_SYSROOT_DIR). This allows to import into the staging directory
40# the C library and companion libraries for the correct architecture
41# variant. 'lib' may not be literally 'lib' but could be something else,
42# e.g. lib32-fp (as determined by ARCH_LIB_DIR) and we only want to copy
43# that lib directory and no other. When copying usr, we therefore need
44# to be extra careful not to include usr/lib* but we _do_ want to
45# include usr/libexec.
46# We are selective in the directories we copy since other directories
Yann E. MORINed181ae2010-07-28 00:08:13 +020047# 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#
Thomas De Schampheleirea06edf22017-02-07 22:56:43 +010053# If ARCH_LIB_DIR is not a singular directory component, e.g.
54# 'lib32/octeon2', then symbolic links in ARCH_LIB_DIR and
55# usr/ARCH_LIB_DIR may be broken because Buildroot will flatten the
56# directory structure (e.g. lib32/octeon2/foo is actually stored in
57# lib/foo). This is only relevant for links that contain one or more ../
58# components, as links to the current directory are always fine.
59# We need to fix the broken links by removing the right amount of ../
60# dots from the link destination.
Thomas De Schampheleire68bb9262017-02-07 22:56:45 +010061# Once the link destination is valid again, it can be simplified to
62# remove the dependency on intermediate directory symlinks.
Thomas De Schampheleirea06edf22017-02-07 22:56:43 +010063#
Thomas De Schampheleireba6bac12017-02-07 22:56:41 +010064# It is possible that ARCH_LIB_DIR does not contain the dynamic loader
65# (ld*.so or similar) because it (or the main symlink to it) normally
Thomas De Schampheleirea06edf22017-02-07 22:56:43 +010066# resides in /lib while ARCH_LIB_DIR may be something else (e.g. lib64,
67# lib/<tuple>, ...). Therefore, copy the dynamic loader separately.
Thomas De Schampheleireba6bac12017-02-07 22:56:41 +010068#
Vicente Olivert Riera7b6cfca2016-05-10 15:01:37 +010069# Then, if the selected architecture variant is not the default one
70# (i.e, if SYSROOT_DIR != ARCH_SYSROOT_DIR), then we :
Yann E. MORINed181ae2010-07-28 00:08:13 +020071#
Vicente Olivert Riera7b6cfca2016-05-10 15:01:37 +010072# * Import the header files from the default architecture
Yann E. MORINed181ae2010-07-28 00:08:13 +020073# variant. Header files are typically shared between the sysroots
74# for the different architecture variants. If we use the
75# non-default one, header files were not copied by the previous
76# step, so we copy them here from the sysroot of the default
77# architecture variant.
78#
79# * Create a symbolic link that matches the name of the subdirectory
80# for the architecture variant in the original sysroot. This is
81# required as the compiler will by default look in
82# sysroot_dir/arch_variant/ for libraries and headers, when the
83# non-default architecture variant is used. Without this, the
84# compiler fails to find libraries and headers.
85#
Vicente Olivert Riera7b6cfca2016-05-10 15:01:37 +010086# Some toolchains (i.e Linaro binary toolchains) store support
87# libraries (libstdc++, libgcc_s) outside of the sysroot, so we simply
88# copy all the libraries from the "support lib directory" into our
89# sysroot.
Thomas Petazzonie1f08042012-05-07 15:02:19 +020090#
Thomas Petazzoni2c23e932011-10-02 21:20:09 +020091# Note that the 'locale' directories are not copied. They are huge
92# (400+MB) in CodeSourcery toolchains, and they are not really useful.
93#
Yann E. MORINed181ae2010-07-28 00:08:13 +020094# $1: main sysroot directory of the toolchain
95# $2: arch specific sysroot directory of the toolchain
96# $3: arch specific subdirectory in the sysroot
Samuel Martin56287762013-08-23 00:59:35 +020097# $4: directory of libraries ('lib', 'lib32' or 'lib64')
Thomas Petazzonie1f08042012-05-07 15:02:19 +020098# $5: support lib directories (for toolchains storing libgcc_s,
99# libstdc++ and other gcc support libraries outside of the
100# sysroot)
Yann E. MORINed181ae2010-07-28 00:08:13 +0200101copy_toolchain_sysroot = \
102 SYSROOT_DIR="$(strip $1)"; \
103 ARCH_SYSROOT_DIR="$(strip $2)"; \
104 ARCH_SUBDIR="$(strip $3)"; \
Thomas Petazzoni0729b542011-12-31 11:57:15 +0100105 ARCH_LIB_DIR="$(strip $4)" ; \
Thomas Petazzonie1f08042012-05-07 15:02:19 +0200106 SUPPORT_LIB_DIR="$(strip $5)" ; \
Samuel Martin56287762013-08-23 00:59:35 +0200107 for i in etc $${ARCH_LIB_DIR} sbin usr usr/$${ARCH_LIB_DIR}; do \
Thomas De Schampheleirea07e47a2017-02-07 22:56:38 +0100108 if [ ! -d $${ARCH_SYSROOT_DIR}/$$i ] ; then \
109 continue ; \
Yann E. MORINed181ae2010-07-28 00:08:13 +0200110 fi ; \
Thomas De Schampheleire367f4ab2017-02-07 22:56:40 +0100111 if [ "$$i" = "usr" ]; then \
112 rsync -au --chmod=u=rwX,go=rX --exclude 'locale/' \
113 --include '/libexec*/' --exclude '/lib*/' \
114 $${ARCH_SYSROOT_DIR}/$$i/ $(STAGING_DIR)/$$i/ ; \
115 else \
116 rsync -au --chmod=u=rwX,go=rX --exclude 'locale/' \
117 $${ARCH_SYSROOT_DIR}/$$i/ $(STAGING_DIR)/$$i/ ; \
118 fi ; \
Yann E. MORINed181ae2010-07-28 00:08:13 +0200119 done ; \
Thomas Petazzonib2915252017-07-05 23:08:03 +0200120 for link in $$(find $(STAGING_DIR) -type l); do \
121 target=$$(readlink $${link}) ; \
122 if [ "$${target}" == "$${target\#/}" ] ; then \
123 continue ; \
124 fi ; \
125 relpath="$(call relpath_prefix,$${target\#/})" ; \
126 echo "Fixing symlink $${link} from $${target} to $${relpath}$${target\#/}" ; \
127 ln -sf $${relpath}$${target\#/} $${link} ; \
128 done ; \
Thomas De Schampheleirea06edf22017-02-07 22:56:43 +0100129 relpath="$(call relpath_prefix,$${ARCH_LIB_DIR})" ; \
130 if [ "$${relpath}" != "" ]; then \
131 for i in $$(find -H $(STAGING_DIR)/$${ARCH_LIB_DIR} $(STAGING_DIR)/usr/$${ARCH_LIB_DIR} -type l -xtype l); do \
132 LINKTARGET=`readlink $$i` ; \
133 NEWLINKTARGET=$${LINKTARGET\#$$relpath} ; \
134 ln -sf $${NEWLINKTARGET} $$i ; \
Thomas De Schampheleire68bb9262017-02-07 22:56:45 +0100135 $(call simplify_symlink,$$i,$(STAGING_DIR)) ; \
Thomas De Schampheleirea06edf22017-02-07 22:56:43 +0100136 done ; \
137 fi ; \
Thomas Petazzonieb22fe82017-07-05 12:10:50 +0200138 if [ ! -e $(STAGING_DIR)/lib/ld*.so.* ]; then \
Thomas De Schampheleirea7fda622017-04-06 22:25:05 +0200139 if [ -e $${ARCH_SYSROOT_DIR}/lib/ld*.so.* ]; then \
140 cp -a $${ARCH_SYSROOT_DIR}/lib/ld*.so.* $(STAGING_DIR)/lib/ ; \
141 fi ; \
Thomas De Schampheleireba6bac12017-02-07 22:56:41 +0100142 fi ; \
Vicente Olivert Riera7b6cfca2016-05-10 15:01:37 +0100143 if [ `readlink -f $${SYSROOT_DIR}` != `readlink -f $${ARCH_SYSROOT_DIR}` ] ; then \
144 if [ ! -d $${ARCH_SYSROOT_DIR}/usr/include ] ; then \
145 cp -a $${SYSROOT_DIR}/usr/include $(STAGING_DIR)/usr ; \
Vicente Olivert Riera9a1e9ef2016-01-12 17:49:38 +0000146 fi ; \
Vicente Olivert Riera7b6cfca2016-05-10 15:01:37 +0100147 mkdir -p `dirname $(STAGING_DIR)/$${ARCH_SUBDIR}` ; \
Thomas De Schampheleirea2596422017-02-07 22:56:42 +0100148 relpath="$(call relpath_prefix,$${ARCH_SUBDIR})./" ; \
Vicente Olivert Riera7b6cfca2016-05-10 15:01:37 +0100149 ln -s $${relpath} $(STAGING_DIR)/$${ARCH_SUBDIR} ; \
150 echo "Symlinking $(STAGING_DIR)/$${ARCH_SUBDIR} -> $${relpath}" ; \
Yann E. MORINed181ae2010-07-28 00:08:13 +0200151 fi ; \
Thomas Petazzonie1f08042012-05-07 15:02:19 +0200152 if test -n "$${SUPPORT_LIB_DIR}" ; then \
153 cp -a $${SUPPORT_LIB_DIR}/* $(STAGING_DIR)/lib/ ; \
154 fi ; \
Yann E. MORINed181ae2010-07-28 00:08:13 +0200155 find $(STAGING_DIR) -type d | xargs chmod 755
156
157#
Yann E. MORINa5a30962014-03-01 15:53:01 +0100158# Check the specified kernel headers version actually matches the
159# version in the toolchain.
160#
Yann E. MORIN2a82bb82014-04-07 20:19:12 +0200161# $1: sysroot directory
Yann E. MORINa5a30962014-03-01 15:53:01 +0100162# $2: kernel version string, in the form: X.Y
163#
164check_kernel_headers_version = \
165 if ! support/scripts/check-kernel-headers.sh $(1) $(2); then \
Yann E. MORIN0aa90192014-03-30 14:59:30 +0200166 exit 1; \
Yann E. MORINa5a30962014-03-01 15:53:01 +0100167 fi
168
169#
Thomas Petazzonibd760c32015-08-04 20:00:35 +0200170# Check the specific gcc version actually matches the version in the
171# toolchain
172#
173# $1: path to gcc
174# $2: expected gcc version
175#
Thomas Petazzonibd760c32015-08-04 20:00:35 +0200176check_gcc_version = \
177 expected_version="$(strip $2)" ; \
Yann E. MORIN23fde762015-08-13 14:13:23 +0200178 if [ -z "$${expected_version}" ]; then \
Arnout Vandecappelle006ba682016-11-24 00:40:34 +0100179 exit 0 ; \
Yann E. MORIN23fde762015-08-13 14:13:23 +0200180 fi; \
Krzysztof Konopko06cd6042017-03-09 09:01:36 +0100181 real_version=`$(1) -dumpversion` ; \
Yann E. MORIN4a5f8782015-08-09 13:11:42 +0200182 if [[ ! "$${real_version}" =~ ^$${expected_version}\. ]] ; then \
183 printf "Incorrect selection of gcc version: expected %s.x, got %s\n" \
184 "$${expected_version}" "$${real_version}" ; \
Thomas Petazzonibd760c32015-08-04 20:00:35 +0200185 exit 1 ; \
186 fi
187
188#
Thomas Petazzoni9fbdf062012-11-03 18:47:50 +0100189# Check the availability of a particular glibc feature. This function
190# is used to check toolchain options that are always supported by
191# glibc, so we simply check that the corresponding option is properly
192# enabled.
Yann E. MORINed181ae2010-07-28 00:08:13 +0200193#
194# $1: Buildroot option name
195# $2: feature description
196#
197check_glibc_feature = \
Thomas Petazzoni0bbbcb92013-07-17 22:30:47 +0200198 if [ "$($(1))" != "y" ] ; then \
Yann E. MORINed181ae2010-07-28 00:08:13 +0200199 echo "$(2) available in C library, please enable $(1)" ; \
200 exit 1 ; \
201 fi
202
203#
Thomas Petazzoni9fbdf062012-11-03 18:47:50 +0100204# Check the availability of RPC support in a glibc toolchain
205#
206# $1: sysroot directory
207#
208check_glibc_rpc_feature = \
209 IS_IN_LIBC=`test -f $(1)/usr/include/rpc/rpc.h && echo y` ; \
210 if [ "$(BR2_TOOLCHAIN_HAS_NATIVE_RPC)" != "y" -a "$${IS_IN_LIBC}" = "y" ] ; then \
Yann E. MORIN808c3fb2015-05-03 17:39:16 +0200211 echo "RPC support available in C library, please enable BR2_TOOLCHAIN_EXTERNAL_INET_RPC" ; \
Thomas Petazzoni9fbdf062012-11-03 18:47:50 +0100212 exit 1 ; \
213 fi ; \
214 if [ "$(BR2_TOOLCHAIN_HAS_NATIVE_RPC)" = "y" -a "$${IS_IN_LIBC}" != "y" ] ; then \
Yann E. MORIN808c3fb2015-05-03 17:39:16 +0200215 echo "RPC support not available in C library, please disable BR2_TOOLCHAIN_EXTERNAL_INET_RPC" ; \
Thomas Petazzoni9fbdf062012-11-03 18:47:50 +0100216 exit 1 ; \
217 fi
218
219#
Yann E. MORINed181ae2010-07-28 00:08:13 +0200220# Check the correctness of a glibc external toolchain configuration.
221# 1. Check that the C library selected in Buildroot matches the one
222# of the external toolchain
223# 2. Check that all the C library-related features are enabled in the
224# config, since glibc always supports all of them
225#
226# $1: sysroot directory
227#
228check_glibc = \
229 SYSROOT_DIR="$(strip $1)"; \
Cam Hutchisonb55ff5a2017-09-04 07:00:43 +1000230 if test `find -L $${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 +0200231 echo "Incorrect selection of the C library"; \
232 exit -1; \
233 fi; \
Mike Frysingere5e5f5d2011-01-10 09:28:41 -0500234 $(call check_glibc_feature,BR2_USE_MMU,MMU support) ;\
Thomas Petazzoni9fbdf062012-11-03 18:47:50 +0100235 $(call check_glibc_rpc_feature,$${SYSROOT_DIR})
Yann E. MORINed181ae2010-07-28 00:08:13 +0200236
237#
Thomas Petazzonia1d94aa2013-10-08 20:17:09 +0200238# Check that the selected C library really is musl
239#
Ilya Kuzmich3b328892017-03-20 08:56:10 +0300240# $1: cross-gcc path
241# $2: cross-readelf path
Thomas Petazzonia1d94aa2013-10-08 20:17:09 +0200242check_musl = \
Ilya Kuzmich3b328892017-03-20 08:56:10 +0300243 __CROSS_CC=$(strip $1) ; \
Thomas Petazzonid67cebc2018-07-04 23:42:57 +0200244 libc_a_path=`$${__CROSS_CC} -print-file-name=libc.a` ; \
245 if ! strings $${libc_a_path} | grep -q MUSL_LOCPATH ; then \
Thomas Petazzonia1d94aa2013-10-08 20:17:09 +0200246 echo "Incorrect selection of the C library" ; \
247 exit -1; \
Thomas Petazzonid67cebc2018-07-04 23:42:57 +0200248 fi
Thomas Petazzonia1d94aa2013-10-08 20:17:09 +0200249
250#
Yann E. MORINed181ae2010-07-28 00:08:13 +0200251# Check the conformity of Buildroot configuration with regard to the
252# uClibc configuration of the external toolchain, for a particular
253# feature.
254#
Gustavo Zacarias1c51a802015-03-30 18:07:20 -0300255# If 'Buildroot option name' ($2) is empty it means the uClibc option
256# is mandatory.
257#
Yann E. MORINed181ae2010-07-28 00:08:13 +0200258# $1: uClibc macro name
259# $2: Buildroot option name
260# $3: uClibc config file
261# $4: feature description
262#
263check_uclibc_feature = \
264 IS_IN_LIBC=`grep -q "\#define $(1) 1" $(3) && echo y` ; \
Gustavo Zacarias1c51a802015-03-30 18:07:20 -0300265 if [ -z "$(2)" ] ; then \
266 if [ "$${IS_IN_LIBC}" != "y" ] ; then \
267 echo "$(4) not available in C library, toolchain unsuitable for Buildroot" ; \
268 exit 1 ; \
269 fi ; \
270 else \
271 if [ "$($(2))" != "y" -a "$${IS_IN_LIBC}" = "y" ] ; then \
272 echo "$(4) available in C library, please enable $(2)" ; \
273 exit 1 ; \
274 fi ; \
275 if [ "$($(2))" = "y" -a "$${IS_IN_LIBC}" != "y" ] ; then \
276 echo "$(4) not available in C library, please disable $(2)" ; \
277 exit 1 ; \
278 fi ; \
Yann E. MORINed181ae2010-07-28 00:08:13 +0200279 fi
280
281#
282# Check the correctness of a uclibc external toolchain configuration
283# 1. Check that the C library selected in Buildroot matches the one
284# of the external toolchain
285# 2. Check that the features enabled in the Buildroot configuration
286# match the features available in the uClibc of the external
287# toolchain
288#
289# $1: sysroot directory
290#
291check_uclibc = \
292 SYSROOT_DIR="$(strip $1)"; \
Thomas Petazzoni090d4862011-12-31 16:15:43 +0100293 if ! test -f $${SYSROOT_DIR}/usr/include/bits/uClibc_config.h ; then \
Yann E. MORINed181ae2010-07-28 00:08:13 +0200294 echo "Incorrect selection of the C library"; \
295 exit -1; \
296 fi; \
297 UCLIBC_CONFIG_FILE=$${SYSROOT_DIR}/usr/include/bits/uClibc_config.h ; \
Mike Frysingere5e5f5d2011-01-10 09:28:41 -0500298 $(call check_uclibc_feature,__ARCH_USE_MMU__,BR2_USE_MMU,$${UCLIBC_CONFIG_FILE},MMU support) ;\
Gustavo Zacarias7f96ef32015-03-30 18:07:21 -0300299 $(call check_uclibc_feature,__UCLIBC_HAS_LFS__,,$${UCLIBC_CONFIG_FILE},Large file support) ;\
Gustavo Zacarias51eaa2c2015-04-19 09:39:54 -0300300 $(call check_uclibc_feature,__UCLIBC_HAS_IPV6__,,$${UCLIBC_CONFIG_FILE},IPv6 support) ;\
Thomas Petazzoni0858e002012-11-03 18:47:49 +0100301 $(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 +0200302 $(call check_uclibc_feature,__UCLIBC_HAS_LOCALE__,BR2_ENABLE_LOCALE,$${UCLIBC_CONFIG_FILE},Locale support) ;\
303 $(call check_uclibc_feature,__UCLIBC_HAS_WCHAR__,BR2_USE_WCHAR,$${UCLIBC_CONFIG_FILE},Wide char support) ;\
Peter Korsgaard5931db02011-11-24 14:26:52 +0100304 $(call check_uclibc_feature,__UCLIBC_HAS_THREADS__,BR2_TOOLCHAIN_HAS_THREADS,$${UCLIBC_CONFIG_FILE},Thread support) ;\
Thomas Petazzonic5866be2013-09-02 18:06:36 +0200305 $(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 +0000306 $(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 +0200307
308#
309# Check that the Buildroot configuration of the ABI matches the
310# configuration of the external toolchain.
311#
Thomas Petazzonic59d0242011-05-08 18:52:27 +0200312# $1: cross-gcc path
Baruch Siach40ff8392014-07-03 12:35:57 +0300313# $2: cross-readelf path
Thomas Petazzonic59d0242011-05-08 18:52:27 +0200314#
Yann E. MORINed181ae2010-07-28 00:08:13 +0200315check_arm_abi = \
Thomas Petazzonic59d0242011-05-08 18:52:27 +0200316 __CROSS_CC=$(strip $1) ; \
317 EXT_TOOLCHAIN_TARGET=`LANG=C $${__CROSS_CC} -v 2>&1 | grep ^Target | cut -f2 -d ' '` ; \
Yann E. MORIN95bfc992013-07-14 00:27:32 +0200318 if ! echo $${EXT_TOOLCHAIN_TARGET} | grep -qE 'eabi(hf)?$$' ; then \
319 echo "External toolchain uses the unsuported OABI" ; \
Yann E. MORINed181ae2010-07-28 00:08:13 +0200320 exit 1 ; \
Thomas Petazzonib2e88072013-07-17 22:30:48 +0200321 fi ; \
Guido Martínez375bc182015-06-26 14:33:20 -0300322 if ! echo 'int main(void) {}' | $${__CROSS_CC} -x c -o $(BUILD_DIR)/.br-toolchain-test.tmp - ; then \
323 rm -f $(BUILD_DIR)/.br-toolchain-test.tmp*; \
Stefan Sørensen37875922014-05-09 13:44:00 +0200324 abistr_$(BR2_ARM_EABI)='EABI'; \
325 abistr_$(BR2_ARM_EABIHF)='EABIhf'; \
326 echo "Incorrect ABI setting: $${abistr_y} selected, but toolchain is incompatible"; \
Thomas Petazzonib2e88072013-07-17 22:30:48 +0200327 exit 1 ; \
Guido Martínez375bc182015-06-26 14:33:20 -0300328 fi ; \
329 rm -f $(BUILD_DIR)/.br-toolchain-test.tmp*
Yann E. MORINed181ae2010-07-28 00:08:13 +0200330
331#
332# Check that the external toolchain supports C++
333#
Thomas Petazzonic59d0242011-05-08 18:52:27 +0200334# $1: cross-g++ path
335#
Yann E. MORINed181ae2010-07-28 00:08:13 +0200336check_cplusplus = \
Thomas Petazzonic59d0242011-05-08 18:52:27 +0200337 __CROSS_CXX=$(strip $1) ; \
338 $${__CROSS_CXX} -v > /dev/null 2>&1 ; \
Yann E. MORINed181ae2010-07-28 00:08:13 +0200339 if test $$? -ne 0 ; then \
Thomas Petazzoni6b578c82010-12-13 17:27:41 +0100340 echo "C++ support is selected but is not available in external toolchain" ; \
Yann E. MORINed181ae2010-07-28 00:08:13 +0200341 exit 1 ; \
Thomas Petazzoniac38fd32010-12-13 17:27:38 +0100342 fi
Yann E. MORINed181ae2010-07-28 00:08:13 +0200343
344#
Samuel Martin26db83c2016-07-03 15:47:44 +0200345#
346# Check that the external toolchain supports Fortran
347#
348# $1: cross-gfortran path
349#
350check_fortran = \
351 __CROSS_FC=$(strip $1) ; \
352 __o=$(BUILD_DIR)/.br-toolchain-test-fortran.tmp ; \
353 printf 'program hello\n\tprint *, "Hello Fortran!\\n"\nend program hello\n' | \
354 $${__CROSS_FC} -x f95 -o $${__o} - ; \
355 if test $$? -ne 0 ; then \
356 rm -f $${__o}* ; \
357 echo "Fortran support is selected but is not available in external toolchain" ; \
358 exit 1 ; \
359 fi ; \
360 rm -f $${__o}* \
361
362#
Ed Blakeef206d82019-03-28 18:48:15 +0000363#
364# Check that the external toolchain supports OpenMP
365#
366# $1: cross-gcc path
367#
368check_openmp = \
369 __CROSS_CC=$(strip $1) ; \
370 __o=$(BUILD_DIR)/.br-toolchain-test-openmp.tmp ; \
371 printf '\#include <omp.h>\nint main(void) { return omp_get_thread_num(); }' | \
372 $${__CROSS_CC} -fopenmp -x c -o $${__o} - ; \
373 if test $$? -ne 0 ; then \
374 rm -f $${__o}* ; \
375 echo "OpenMP support is selected but is not available in external toolchain"; \
376 exit 1 ; \
377 fi ; \
378 rm -f $${__o}* \
379
380#
Yann E. MORINed181ae2010-07-28 00:08:13 +0200381# Check that the cross-compiler given in the configuration exists
382#
Thomas Petazzonic59d0242011-05-08 18:52:27 +0200383# $1: cross-gcc path
384#
Yann E. MORINed181ae2010-07-28 00:08:13 +0200385check_cross_compiler_exists = \
Thomas Petazzonic59d0242011-05-08 18:52:27 +0200386 __CROSS_CC=$(strip $1) ; \
387 $${__CROSS_CC} -v > /dev/null 2>&1 ; \
Yann E. MORINed181ae2010-07-28 00:08:13 +0200388 if test $$? -ne 0 ; then \
Thomas Petazzonic59d0242011-05-08 18:52:27 +0200389 echo "Cannot execute cross-compiler '$${__CROSS_CC}'" ; \
Yann E. MORINed181ae2010-07-28 00:08:13 +0200390 exit 1 ; \
Thomas Petazzoniac38fd32010-12-13 17:27:38 +0100391 fi
Thomas Petazzoni12478502013-10-13 10:28:20 +0200392
393#
Romain Naour4b201092016-04-27 22:15:03 +0200394# Check for toolchains known not to work with Buildroot.
395# - For the Angstrom toolchains, we check by looking at the vendor part of
396# the host tuple.
397# - Exclude distro-class toolchains which are not relocatable.
398# - Exclude broken toolchains which return "libc.a" with -print-file-name.
399# - Exclude toolchains which doesn't support --sysroot option.
Thomas Petazzoni12478502013-10-13 10:28:20 +0200400#
401# $1: cross-gcc path
402#
403check_unusable_toolchain = \
404 __CROSS_CC=$(strip $1) ; \
405 vendor=`$${__CROSS_CC} -dumpmachine | cut -f2 -d'-'` ; \
406 if test "$${vendor}" = "angstrom" ; then \
407 echo "Angstrom toolchains are not pure toolchains: they contain" ; \
408 echo "many other libraries than just the C library, which makes" ; \
409 echo "them unsuitable as external toolchains for build systems" ; \
410 echo "such as Buildroot." ; \
411 exit 1 ; \
Yann E. MORINdefb9652015-03-17 16:14:55 +0100412 fi; \
413 with_sysroot=`$${__CROSS_CC} -v 2>&1 |sed -r -e '/.* --with-sysroot=([^[:space:]]+)[[:space:]].*/!d; s//\1/'`; \
414 if test "$${with_sysroot}" = "/" ; then \
415 echo "Distribution toolchains are unsuitable for use by Buildroot," ; \
416 echo "as they were configured in a way that makes them non-relocatable,"; \
417 echo "and contain a lot of pre-built libraries that would conflict with"; \
418 echo "the ones Buildroot wants to build."; \
419 exit 1; \
Romain Naourc32c3902016-04-27 22:15:01 +0200420 fi; \
421 libc_a_path=`$${__CROSS_CC} -print-file-name=libc.a` ; \
422 if test "$${libc_a_path}" = "libc.a" ; then \
423 echo "Unable to detect the toolchain sysroot, Buildroot cannot use this toolchain." ; \
424 exit 1 ; \
Romain Naour6bb03552016-04-27 22:15:02 +0200425 fi ; \
426 sysroot_dir="$(call toolchain_find_sysroot,$${__CROSS_CC})" ; \
427 if test -z "$${sysroot_dir}" ; then \
428 echo "External toolchain doesn't support --sysroot. Cannot use." ; \
429 exit 1 ; \
Thomas Petazzoni12478502013-10-13 10:28:20 +0200430 fi
Thomas Petazzoni7130ceb2014-05-05 11:25:50 +0200431
432#
Vicente Olivert Riera79493502016-03-15 16:40:38 +0000433# Check if the toolchain has SSP (stack smashing protector) support
434#
435# $1: cross-gcc path
436#
437check_toolchain_ssp = \
438 __CROSS_CC=$(strip $1) ; \
Carlos Santosc8680952018-03-25 00:59:52 -0300439 __HAS_SSP=`echo 'void main(){}' | $${__CROSS_CC} -Werror -fstack-protector -x c - -o $(BUILD_DIR)/.br-toolchain-test.tmp >/dev/null 2>&1 && echo y` ; \
Vicente Olivert Riera79493502016-03-15 16:40:38 +0000440 if [ "$(BR2_TOOLCHAIN_HAS_SSP)" != "y" -a "$${__HAS_SSP}" = "y" ] ; then \
441 echo "SSP support available in this toolchain, please enable BR2_TOOLCHAIN_EXTERNAL_HAS_SSP" ; \
442 exit 1 ; \
443 fi ; \
444 if [ "$(BR2_TOOLCHAIN_HAS_SSP)" = "y" -a "$${__HAS_SSP}" != "y" ] ; then \
445 echo "SSP support not available in this toolchain, please disable BR2_TOOLCHAIN_EXTERNAL_HAS_SSP" ; \
446 exit 1 ; \
447 fi ; \
448 rm -f $(BUILD_DIR)/.br-toolchain-test.tmp*
449
450#
Thomas Petazzoni7130ceb2014-05-05 11:25:50 +0200451# Generate gdbinit file for use with Buildroot
452#
453gen_gdbinit_file = \
454 mkdir -p $(STAGING_DIR)/usr/share/buildroot/ ; \
455 echo "set sysroot $(STAGING_DIR)" > $(STAGING_DIR)/usr/share/buildroot/gdbinit
Thomas De Schampheleirea2596422017-02-07 22:56:42 +0100456
457# Given a path, determine the relative prefix (../) needed to return to the
458# root level. Note that the last component is treated as a file component; use a
459# trailing slash to force treating it as a directory. Examples:
460# relpath_prefix(lib32) = ""
461# relpath_prefix(lib32/octeon2) = "../"
462# relpath_prefix(lib32/octeon2/) = "../../"
463#
464# $1: input path
465define relpath_prefix
466$$( \
467 prefix="" ; \
468 nbslashs=`printf $1 | sed 's%[^/]%%g' | wc -c` ; \
469 for slash in `seq 1 $${nbslashs}` ; do \
470 prefix=$${prefix}"../" ; \
471 done ; \
472 printf "$$prefix" ; \
473)
474endef
Thomas De Schampheleire144caf52017-02-07 22:56:44 +0100475
476# Replace the destination of a symbolic link with a simpler version
477# For example,
478# usr/lib/libfoo.so -> ../../lib32/libfoo.so.1
479# becomes
480# usr/lib/libfoo.so -> ../../lib/libfoo.so.1
481# since 'lib32' is a symlink to 'lib'.
482#
483# Likewise,
484# usr/lib/octeon2/libbar.so -> ../../../lib32/octeon2/libbar.so.1
485# becomes
486# usr/lib/octeon2/libbar.so -> ../../lib/libbar.so.1
487# assuming lib32->lib and lib/octeon2->lib.
488#
489# $1: symlink
490# $2: base path
491define simplify_symlink
492( \
493 FULL_SRC="$$(readlink -f $$(dirname $1))/$$(basename $1)" ; \
494 FULL_DEST="$$(readlink -f $1)" ; \
495 FULL_BASE="$$(readlink -f $2)" ; \
496 REL_SRC="$${FULL_SRC#$${FULL_BASE}/}" ; \
497 REL_DEST="$${FULL_DEST#$${FULL_BASE}/}" ; \
498 DOTS="$(call relpath_prefix,$${REL_SRC})" ; \
499 ln -sf "$${DOTS}$${REL_DEST}" "$${FULL_SRC}" ; \
500)
501endef