]>
Commit | Line | Data |
---|---|---|
2e0cd951 TP |
1 | # 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. | |
ed181aee | 8 | # |
e6e60bec TP |
9 | # Most toolchains (CodeSourcery ones) have their libraries either in |
10 | # /lib or /usr/lib relative to their ARCH_SYSROOT_DIR, so we search | |
11 | # libraries in: | |
12 | # | |
13 | # $${ARCH_LIB_DIR} | |
14 | # usr/$${ARCH_LIB_DIR} | |
15 | # | |
16 | # Buildroot toolchains, however, have basic libraries in /lib, and | |
17 | # libstdc++/libgcc_s in /usr/<target-name>/lib(64), so we also need to | |
18 | # search libraries in: | |
19 | # | |
20 | # usr/$(TOOLCHAIN_EXTERNAL_PREFIX)/$${ARCH_LIB_DIR} | |
21 | # | |
e1f0804c TP |
22 | # Linaro toolchains have most libraries in lib/<target-name>/, so we |
23 | # need to search libraries in: | |
e6e60bec TP |
24 | # |
25 | # $${ARCH_LIB_DIR}/$(TOOLCHAIN_EXTERNAL_PREFIX) | |
26 | # | |
e1f0804c TP |
27 | # And recent Linaro toolchains have the GCC support libraries |
28 | # (libstdc++, libgcc_s, etc.) into a separate directory, outside of | |
29 | # the sysroot, that we called the "SUPPORT_LIB_DIR", into which we | |
30 | # need to search as well. | |
31 | # | |
e6e60bec TP |
32 | # Thanks to ARCH_LIB_DIR we also take into account toolchains that |
33 | # have the libraries in lib64 and usr/lib64. | |
34 | # | |
35 | # Please be very careful to check the major toolchain sources: | |
36 | # Buildroot, Crosstool-NG, CodeSourcery and Linaro before doing any | |
37 | # modification on the below logic. | |
ed181aee YM |
38 | # |
39 | # $1: arch specific sysroot directory | |
e1f0804c TP |
40 | # $2: support libraries directory (can be empty) |
41 | # $3: library directory ('lib' or 'lib64') from which libraries must be copied | |
42 | # $4: library name | |
43 | # $5: destination directory of the libary, relative to $(TARGET_DIR) | |
ed181aee YM |
44 | # |
45 | copy_toolchain_lib_root = \ | |
46 | ARCH_SYSROOT_DIR="$(strip $1)"; \ | |
e1f0804c TP |
47 | SUPPORT_LIB_DIR="$(strip $2)" ; \ |
48 | ARCH_LIB_DIR="$(strip $3)" ; \ | |
49 | LIB="$(strip $4)"; \ | |
50 | DESTDIR="$(strip $5)" ; \ | |
ed181aee | 51 | \ |
e1f0804c TP |
52 | for dir in \ |
53 | $${ARCH_SYSROOT_DIR}/$${ARCH_LIB_DIR}/$(TOOLCHAIN_EXTERNAL_PREFIX) \ | |
54 | $${ARCH_SYSROOT_DIR}/usr/$(TOOLCHAIN_EXTERNAL_PREFIX)/$${ARCH_LIB_DIR} \ | |
55 | $${ARCH_SYSROOT_DIR}/$${ARCH_LIB_DIR} \ | |
56 | $${ARCH_SYSROOT_DIR}/usr/$${ARCH_LIB_DIR} \ | |
57 | $${SUPPORT_LIB_DIR} ; do \ | |
186a99b1 | 58 | LIBSPATH=`find $${dir} -maxdepth 1 -name "$${LIB}" 2>/dev/null` ; \ |
e1f0804c TP |
59 | if test -n "$${LIBSPATH}" ; then \ |
60 | break ; \ | |
61 | fi \ | |
62 | done ; \ | |
ccc82214 | 63 | mkdir -p $(TARGET_DIR)/$${DESTDIR}; \ |
e1f0804c | 64 | for LIBPATH in $${LIBSPATH} ; do \ |
ccc82214 TP |
65 | while true ; do \ |
66 | LIBNAME=`basename $${LIBPATH}`; \ | |
67 | LIBDIR=`dirname $${LIBPATH}` ; \ | |
68 | LINKTARGET=`readlink $${LIBPATH}` ; \ | |
e1f0804c | 69 | rm -fr $(TARGET_DIR)/$${DESTDIR}/$${LIBNAME}; \ |
e1f0804c | 70 | if test -h $${LIBPATH} ; then \ |
ccc82214 | 71 | ln -sf `basename $${LINKTARGET}` $(TARGET_DIR)/$${DESTDIR}/$${LIBNAME} ; \ |
e1f0804c TP |
72 | elif test -f $${LIBPATH}; then \ |
73 | $(INSTALL) -D -m0755 $${LIBPATH} $(TARGET_DIR)/$${DESTDIR}/$${LIBNAME}; \ | |
ed181aee YM |
74 | else \ |
75 | exit -1; \ | |
76 | fi; \ | |
ccc82214 TP |
77 | if test -z "$${LINKTARGET}" ; then \ |
78 | break ; \ | |
79 | fi ; \ | |
80 | LIBPATH="`readlink -f $${LIBPATH}`"; \ | |
ed181aee YM |
81 | done; \ |
82 | done; \ | |
83 | \ | |
84 | echo -n | |
85 | ||
86 | # | |
87 | # Copy the full external toolchain sysroot directory to the staging | |
88 | # dir. The operation of this function is rendered a little bit | |
89 | # complicated by the support for multilib toolchains. | |
90 | # | |
91 | # We start by copying etc, lib, sbin and usr from the sysroot of the | |
92 | # selected architecture variant (as pointed by ARCH_SYSROOT_DIR). This | |
93 | # allows to import into the staging directory the C library and | |
94 | # companion libraries for the correct architecture variant. We | |
95 | # explictly only copy etc, lib, sbin and usr since other directories | |
96 | # might exist for other architecture variants (on Codesourcery | |
97 | # toolchain, the sysroot for the default architecture variant contains | |
98 | # the armv4t and thumb2 subdirectories, which are the sysroot for the | |
99 | # corresponding architecture variants), and we don't want to import | |
100 | # them. | |
101 | # | |
102 | # Then, if the selected architecture variant is not the default one | |
103 | # (i.e, if SYSROOT_DIR != ARCH_SYSROOT_DIR), then we : | |
104 | # | |
105 | # * Import the header files from the default architecture | |
106 | # variant. Header files are typically shared between the sysroots | |
107 | # for the different architecture variants. If we use the | |
108 | # non-default one, header files were not copied by the previous | |
109 | # step, so we copy them here from the sysroot of the default | |
110 | # architecture variant. | |
111 | # | |
112 | # * Create a symbolic link that matches the name of the subdirectory | |
113 | # for the architecture variant in the original sysroot. This is | |
114 | # required as the compiler will by default look in | |
115 | # sysroot_dir/arch_variant/ for libraries and headers, when the | |
116 | # non-default architecture variant is used. Without this, the | |
117 | # compiler fails to find libraries and headers. | |
118 | # | |
e1f0804c TP |
119 | # Some toolchains (i.e Linaro binary toolchains) store support |
120 | # libraries (libstdc++, libgcc_s) outside of the sysroot, so we simply | |
121 | # copy all the libraries from the "support lib directory" into our | |
122 | # sysroot. | |
123 | # | |
2c23e937 TP |
124 | # Note that the 'locale' directories are not copied. They are huge |
125 | # (400+MB) in CodeSourcery toolchains, and they are not really useful. | |
126 | # | |
ed181aee YM |
127 | # $1: main sysroot directory of the toolchain |
128 | # $2: arch specific sysroot directory of the toolchain | |
129 | # $3: arch specific subdirectory in the sysroot | |
5628776c | 130 | # $4: directory of libraries ('lib', 'lib32' or 'lib64') |
e1f0804c TP |
131 | # $5: support lib directories (for toolchains storing libgcc_s, |
132 | # libstdc++ and other gcc support libraries outside of the | |
133 | # sysroot) | |
ed181aee YM |
134 | copy_toolchain_sysroot = \ |
135 | SYSROOT_DIR="$(strip $1)"; \ | |
136 | ARCH_SYSROOT_DIR="$(strip $2)"; \ | |
137 | ARCH_SUBDIR="$(strip $3)"; \ | |
0729b544 | 138 | ARCH_LIB_DIR="$(strip $4)" ; \ |
e1f0804c | 139 | SUPPORT_LIB_DIR="$(strip $5)" ; \ |
5628776c | 140 | for i in etc $${ARCH_LIB_DIR} sbin usr usr/$${ARCH_LIB_DIR}; do \ |
ed181aee | 141 | if [ -d $${ARCH_SYSROOT_DIR}/$$i ] ; then \ |
5628776c SM |
142 | rsync -au --chmod=Du+w --exclude 'usr/lib/locale' \ |
143 | --exclude lib --exclude lib32 --exclude lib64 \ | |
144 | $${ARCH_SYSROOT_DIR}/$$i/ $(STAGING_DIR)/$$i/ ; \ | |
ed181aee YM |
145 | fi ; \ |
146 | done ; \ | |
147 | if [ `readlink -f $${SYSROOT_DIR}` != `readlink -f $${ARCH_SYSROOT_DIR}` ] ; then \ | |
148 | if [ ! -d $${ARCH_SYSROOT_DIR}/usr/include ] ; then \ | |
149 | cp -a $${SYSROOT_DIR}/usr/include $(STAGING_DIR)/usr ; \ | |
150 | fi ; \ | |
50ac5f9a TP |
151 | mkdir -p `dirname $(STAGING_DIR)/$${ARCH_SUBDIR}` ; \ |
152 | relpath="./" ; \ | |
153 | nbslashs=`echo -n $${ARCH_SUBDIR} | sed 's%[^/]%%g' | wc -c` ; \ | |
154 | for slash in `seq 1 $${nbslashs}` ; do \ | |
155 | relpath=$${relpath}"../" ; \ | |
156 | done ; \ | |
157 | ln -s $${relpath} $(STAGING_DIR)/$${ARCH_SUBDIR} ; \ | |
158 | echo "Symlinking $(STAGING_DIR)/$${ARCH_SUBDIR} -> $${relpath}" ; \ | |
ed181aee | 159 | fi ; \ |
e1f0804c TP |
160 | if test -n "$${SUPPORT_LIB_DIR}" ; then \ |
161 | cp -a $${SUPPORT_LIB_DIR}/* $(STAGING_DIR)/lib/ ; \ | |
162 | fi ; \ | |
ed181aee YM |
163 | find $(STAGING_DIR) -type d | xargs chmod 755 |
164 | ||
ed181aee | 165 | # |
9fbdf062 TP |
166 | # Check the availability of a particular glibc feature. This function |
167 | # is used to check toolchain options that are always supported by | |
168 | # glibc, so we simply check that the corresponding option is properly | |
169 | # enabled. | |
ed181aee YM |
170 | # |
171 | # $1: Buildroot option name | |
172 | # $2: feature description | |
173 | # | |
174 | check_glibc_feature = \ | |
0bbbcb96 | 175 | if [ "$($(1))" != "y" ] ; then \ |
ed181aee YM |
176 | echo "$(2) available in C library, please enable $(1)" ; \ |
177 | exit 1 ; \ | |
178 | fi | |
179 | ||
9fbdf062 TP |
180 | # |
181 | # Check the availability of RPC support in a glibc toolchain | |
182 | # | |
183 | # $1: sysroot directory | |
184 | # | |
185 | check_glibc_rpc_feature = \ | |
186 | IS_IN_LIBC=`test -f $(1)/usr/include/rpc/rpc.h && echo y` ; \ | |
187 | if [ "$(BR2_TOOLCHAIN_HAS_NATIVE_RPC)" != "y" -a "$${IS_IN_LIBC}" = "y" ] ; then \ | |
188 | echo "RPC support available in C library, please enable BR2_TOOLCHAIN_HAS_NATIVE_RPC" ; \ | |
189 | exit 1 ; \ | |
190 | fi ; \ | |
191 | if [ "$(BR2_TOOLCHAIN_HAS_NATIVE_RPC)" = "y" -a "$${IS_IN_LIBC}" != "y" ] ; then \ | |
192 | echo "RPC support not available in C library, please disable BR2_TOOLCHAIN_HAS_NATIVE_RPC" ; \ | |
193 | exit 1 ; \ | |
194 | fi | |
195 | ||
ed181aee YM |
196 | # |
197 | # Check the correctness of a glibc external toolchain configuration. | |
198 | # 1. Check that the C library selected in Buildroot matches the one | |
199 | # of the external toolchain | |
200 | # 2. Check that all the C library-related features are enabled in the | |
201 | # config, since glibc always supports all of them | |
202 | # | |
203 | # $1: sysroot directory | |
204 | # | |
205 | check_glibc = \ | |
206 | SYSROOT_DIR="$(strip $1)"; \ | |
fb6dd8f4 | 207 | if test `find $${SYSROOT_DIR}/ -maxdepth 2 -name 'ld-linux*.so.*' -o -name 'ld.so.*' -o -name 'ld64.so.*' | wc -l` -eq 0 ; then \ |
ed181aee YM |
208 | echo "Incorrect selection of the C library"; \ |
209 | exit -1; \ | |
210 | fi; \ | |
e5e5f5d8 | 211 | $(call check_glibc_feature,BR2_USE_MMU,MMU support) ;\ |
9fbdf062 | 212 | $(call check_glibc_rpc_feature,$${SYSROOT_DIR}) |
ed181aee | 213 | |
a1d94aaa TP |
214 | # |
215 | # Check that the selected C library really is musl | |
216 | # | |
217 | # $1: sysroot directory | |
218 | check_musl = \ | |
219 | SYSROOT_DIR="$(strip $1)"; \ | |
220 | if test ! -f $${SYSROOT_DIR}/lib/libc.so -o -e $${SYSROOT_DIR}/lib/libm.so ; then \ | |
221 | echo "Incorrect selection of the C library" ; \ | |
222 | exit -1; \ | |
223 | fi | |
224 | ||
ed181aee YM |
225 | # |
226 | # Check the conformity of Buildroot configuration with regard to the | |
227 | # uClibc configuration of the external toolchain, for a particular | |
228 | # feature. | |
229 | # | |
230 | # $1: uClibc macro name | |
231 | # $2: Buildroot option name | |
232 | # $3: uClibc config file | |
233 | # $4: feature description | |
234 | # | |
235 | check_uclibc_feature = \ | |
236 | IS_IN_LIBC=`grep -q "\#define $(1) 1" $(3) && echo y` ; \ | |
0bbbcb96 | 237 | if [ "$($(2))" != "y" -a "$${IS_IN_LIBC}" = "y" ] ; then \ |
ed181aee YM |
238 | echo "$(4) available in C library, please enable $(2)" ; \ |
239 | exit 1 ; \ | |
240 | fi ; \ | |
0bbbcb96 | 241 | if [ "$($(2))" = "y" -a "$${IS_IN_LIBC}" != "y" ] ; then \ |
ed181aee YM |
242 | echo "$(4) not available in C library, please disable $(2)" ; \ |
243 | exit 1 ; \ | |
244 | fi | |
245 | ||
246 | # | |
247 | # Check the correctness of a uclibc external toolchain configuration | |
248 | # 1. Check that the C library selected in Buildroot matches the one | |
249 | # of the external toolchain | |
250 | # 2. Check that the features enabled in the Buildroot configuration | |
251 | # match the features available in the uClibc of the external | |
252 | # toolchain | |
253 | # | |
254 | # $1: sysroot directory | |
255 | # | |
256 | check_uclibc = \ | |
257 | SYSROOT_DIR="$(strip $1)"; \ | |
090d4864 | 258 | if ! test -f $${SYSROOT_DIR}/usr/include/bits/uClibc_config.h ; then \ |
ed181aee YM |
259 | echo "Incorrect selection of the C library"; \ |
260 | exit -1; \ | |
261 | fi; \ | |
262 | UCLIBC_CONFIG_FILE=$${SYSROOT_DIR}/usr/include/bits/uClibc_config.h ; \ | |
e5e5f5d8 | 263 | $(call check_uclibc_feature,__ARCH_USE_MMU__,BR2_USE_MMU,$${UCLIBC_CONFIG_FILE},MMU support) ;\ |
ed181aee YM |
264 | $(call check_uclibc_feature,__UCLIBC_HAS_LFS__,BR2_LARGEFILE,$${UCLIBC_CONFIG_FILE},Large file support) ;\ |
265 | $(call check_uclibc_feature,__UCLIBC_HAS_IPV6__,BR2_INET_IPV6,$${UCLIBC_CONFIG_FILE},IPv6 support) ;\ | |
0858e000 | 266 | $(call check_uclibc_feature,__UCLIBC_HAS_RPC__,BR2_TOOLCHAIN_HAS_NATIVE_RPC,$${UCLIBC_CONFIG_FILE},RPC support) ;\ |
ed181aee YM |
267 | $(call check_uclibc_feature,__UCLIBC_HAS_LOCALE__,BR2_ENABLE_LOCALE,$${UCLIBC_CONFIG_FILE},Locale support) ;\ |
268 | $(call check_uclibc_feature,__UCLIBC_HAS_WCHAR__,BR2_USE_WCHAR,$${UCLIBC_CONFIG_FILE},Wide char support) ;\ | |
5931db0d | 269 | $(call check_uclibc_feature,__UCLIBC_HAS_THREADS__,BR2_TOOLCHAIN_HAS_THREADS,$${UCLIBC_CONFIG_FILE},Thread support) ;\ |
c5866be0 TP |
270 | $(call check_uclibc_feature,__PTHREADS_DEBUG_SUPPORT__,BR2_TOOLCHAIN_HAS_THREADS_DEBUG,$${UCLIBC_CONFIG_FILE},Thread debugging support) ;\ |
271 | $(call check_uclibc_feature,__UCLIBC_HAS_SSP__,BR2_TOOLCHAIN_HAS_SSP,$${UCLIBC_CONFIG_FILE},Stack Smashing Protection support) | |
ed181aee YM |
272 | |
273 | # | |
274 | # Check that the Buildroot configuration of the ABI matches the | |
275 | # configuration of the external toolchain. | |
276 | # | |
c59d0247 TP |
277 | # $1: cross-gcc path |
278 | # | |
ed181aee | 279 | check_arm_abi = \ |
c59d0247 | 280 | __CROSS_CC=$(strip $1) ; \ |
b2e88073 | 281 | __CROSS_READELF=$(strip $2) ; \ |
c59d0247 | 282 | EXT_TOOLCHAIN_TARGET=`LANG=C $${__CROSS_CC} -v 2>&1 | grep ^Target | cut -f2 -d ' '` ; \ |
95bfc99f YM |
283 | if ! echo $${EXT_TOOLCHAIN_TARGET} | grep -qE 'eabi(hf)?$$' ; then \ |
284 | echo "External toolchain uses the unsuported OABI" ; \ | |
ed181aee | 285 | exit 1 ; \ |
b2e88073 TP |
286 | fi ; \ |
287 | EXT_TOOLCHAIN_CRT1=`LANG=C $${__CROSS_CC} -print-file-name=crt1.o` ; \ | |
288 | if $${__CROSS_READELF} -A $${EXT_TOOLCHAIN_CRT1} | grep -q "Tag_ABI_VFP_args:" ; then \ | |
289 | EXT_TOOLCHAIN_ABI="eabihf" ; \ | |
290 | else \ | |
291 | EXT_TOOLCHAIN_ABI="eabi" ; \ | |
292 | fi ; \ | |
293 | if [ "$(BR2_ARM_EABI)" = "y" -a "$${EXT_TOOLCHAIN_ABI}" = "eabihf" ] ; then \ | |
294 | echo "Incorrect ABI setting: EABI selected, but toolchain uses EABIhf" ; \ | |
295 | exit 1 ; \ | |
296 | fi ; \ | |
297 | if [ "$(BR2_ARM_EABIHF)" = "y" -a "$${EXT_TOOLCHAIN_ABI}" = "eabi" ] ; then \ | |
298 | echo "Incorrect ABI setting: EABIhf selected, but toolchain uses EABI" ; \ | |
299 | exit 1 ; \ | |
ac38fd3d | 300 | fi |
ed181aee YM |
301 | |
302 | # | |
303 | # Check that the external toolchain supports C++ | |
304 | # | |
c59d0247 TP |
305 | # $1: cross-g++ path |
306 | # | |
ed181aee | 307 | check_cplusplus = \ |
c59d0247 TP |
308 | __CROSS_CXX=$(strip $1) ; \ |
309 | $${__CROSS_CXX} -v > /dev/null 2>&1 ; \ | |
ed181aee | 310 | if test $$? -ne 0 ; then \ |
6b578c8d | 311 | echo "C++ support is selected but is not available in external toolchain" ; \ |
ed181aee | 312 | exit 1 ; \ |
ac38fd3d | 313 | fi |
ed181aee YM |
314 | |
315 | # | |
316 | # Check that the cross-compiler given in the configuration exists | |
317 | # | |
c59d0247 TP |
318 | # $1: cross-gcc path |
319 | # | |
ed181aee | 320 | check_cross_compiler_exists = \ |
c59d0247 TP |
321 | __CROSS_CC=$(strip $1) ; \ |
322 | $${__CROSS_CC} -v > /dev/null 2>&1 ; \ | |
ed181aee | 323 | if test $$? -ne 0 ; then \ |
c59d0247 | 324 | echo "Cannot execute cross-compiler '$${__CROSS_CC}'" ; \ |
ed181aee | 325 | exit 1 ; \ |
ac38fd3d | 326 | fi |
1247850d TP |
327 | |
328 | # | |
329 | # Check for toolchains known not to work with Buildroot. For now, we | |
330 | # only check for Angstrom toolchains, by looking at the vendor part of | |
331 | # the host tuple. | |
332 | # | |
333 | # $1: cross-gcc path | |
334 | # | |
335 | check_unusable_toolchain = \ | |
336 | __CROSS_CC=$(strip $1) ; \ | |
337 | vendor=`$${__CROSS_CC} -dumpmachine | cut -f2 -d'-'` ; \ | |
338 | if test "$${vendor}" = "angstrom" ; then \ | |
339 | echo "Angstrom toolchains are not pure toolchains: they contain" ; \ | |
340 | echo "many other libraries than just the C library, which makes" ; \ | |
341 | echo "them unsuitable as external toolchains for build systems" ; \ | |
342 | echo "such as Buildroot." ; \ | |
343 | exit 1 ; \ | |
344 | fi |