Thomas Petazzoni | 2e0cd95 | 2013-10-08 20:17:07 +0200 | [diff] [blame] | 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. |
Yann E. MORIN | ed181ae | 2010-07-28 00:08:13 +0200 | [diff] [blame] | 8 | # |
Thomas De Schampheleire | 2a87b64 | 2016-02-12 20:20:25 +0100 | [diff] [blame] | 9 | # $1: library name |
Yann E. MORIN | ed181ae | 2010-07-28 00:08:13 +0200 | [diff] [blame] | 10 | # |
| 11 | copy_toolchain_lib_root = \ |
Thomas De Schampheleire | 2a87b64 | 2016-02-12 20:20:25 +0100 | [diff] [blame] | 12 | LIB="$(strip $1)"; \ |
Jerzy Grzegorek | 595bf30 | 2014-10-23 10:43:37 +0200 | [diff] [blame] | 13 | \ |
Yann E. MORIN | 49648d4 | 2016-05-29 23:58:11 +0200 | [diff] [blame] | 14 | LIBPATHS=`find $(STAGING_DIR)/ -name "$${LIB}" 2>/dev/null` ; \ |
Thomas De Schampheleire | 335f331 | 2016-02-03 22:45:28 +0100 | [diff] [blame] | 15 | for LIBPATH in $${LIBPATHS} ; do \ |
Thomas De Schampheleire | 2a87b64 | 2016-02-12 20:20:25 +0100 | [diff] [blame] | 16 | DESTDIR=`echo $${LIBPATH} | sed "s,^$(STAGING_DIR)/,," | xargs dirname` ; \ |
| 17 | mkdir -p $(TARGET_DIR)/$${DESTDIR}; \ |
Thomas Petazzoni | ccc8221 | 2013-10-08 20:17:14 +0200 | [diff] [blame] | 18 | while true ; do \ |
| 19 | LIBNAME=`basename $${LIBPATH}`; \ |
| 20 | LIBDIR=`dirname $${LIBPATH}` ; \ |
| 21 | LINKTARGET=`readlink $${LIBPATH}` ; \ |
Thomas Petazzoni | e1f0804 | 2012-05-07 15:02:19 +0200 | [diff] [blame] | 22 | rm -fr $(TARGET_DIR)/$${DESTDIR}/$${LIBNAME}; \ |
Thomas Petazzoni | e1f0804 | 2012-05-07 15:02:19 +0200 | [diff] [blame] | 23 | if test -h $${LIBPATH} ; then \ |
Thomas Petazzoni | ccc8221 | 2013-10-08 20:17:14 +0200 | [diff] [blame] | 24 | ln -sf `basename $${LINKTARGET}` $(TARGET_DIR)/$${DESTDIR}/$${LIBNAME} ; \ |
Thomas Petazzoni | e1f0804 | 2012-05-07 15:02:19 +0200 | [diff] [blame] | 25 | elif test -f $${LIBPATH}; then \ |
| 26 | $(INSTALL) -D -m0755 $${LIBPATH} $(TARGET_DIR)/$${DESTDIR}/$${LIBNAME}; \ |
Yann E. MORIN | ed181ae | 2010-07-28 00:08:13 +0200 | [diff] [blame] | 27 | else \ |
| 28 | exit -1; \ |
| 29 | fi; \ |
Thomas Petazzoni | ccc8221 | 2013-10-08 20:17:14 +0200 | [diff] [blame] | 30 | if test -z "$${LINKTARGET}" ; then \ |
| 31 | break ; \ |
| 32 | fi ; \ |
| 33 | LIBPATH="`readlink -f $${LIBPATH}`"; \ |
Yann E. MORIN | ed181ae | 2010-07-28 00:08:13 +0200 | [diff] [blame] | 34 | done; \ |
Maxime Hadjinlian | 8f59da8 | 2015-10-04 13:35:08 +0200 | [diff] [blame] | 35 | done |
Yann E. MORIN | ed181ae | 2010-07-28 00:08:13 +0200 | [diff] [blame] | 36 | |
| 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 | # |
Thomas De Schampheleire | 367f4ab | 2017-02-07 22:56:40 +0100 | [diff] [blame^] | 42 | # We start by copying etc, 'lib', sbin, usr and usr/'lib' from the |
| 43 | # sysroot of the selected architecture variant (as pointed to by |
| 44 | # ARCH_SYSROOT_DIR). This allows to import into the staging directory |
| 45 | # the C library and companion libraries for the correct architecture |
| 46 | # variant. 'lib' may not be literally 'lib' but could be something else, |
| 47 | # e.g. lib32-fp (as determined by ARCH_LIB_DIR) and we only want to copy |
| 48 | # that lib directory and no other. When copying usr, we therefore need |
| 49 | # to be extra careful not to include usr/lib* but we _do_ want to |
| 50 | # include usr/libexec. |
| 51 | # We are selective in the directories we copy since other directories |
Yann E. MORIN | ed181ae | 2010-07-28 00:08:13 +0200 | [diff] [blame] | 52 | # might exist for other architecture variants (on Codesourcery |
| 53 | # toolchain, the sysroot for the default architecture variant contains |
| 54 | # the armv4t and thumb2 subdirectories, which are the sysroot for the |
| 55 | # corresponding architecture variants), and we don't want to import |
| 56 | # them. |
| 57 | # |
Vicente Olivert Riera | 7b6cfca | 2016-05-10 15:01:37 +0100 | [diff] [blame] | 58 | # Then, if the selected architecture variant is not the default one |
| 59 | # (i.e, if SYSROOT_DIR != ARCH_SYSROOT_DIR), then we : |
Yann E. MORIN | ed181ae | 2010-07-28 00:08:13 +0200 | [diff] [blame] | 60 | # |
Vicente Olivert Riera | 7b6cfca | 2016-05-10 15:01:37 +0100 | [diff] [blame] | 61 | # * Import the header files from the default architecture |
Yann E. MORIN | ed181ae | 2010-07-28 00:08:13 +0200 | [diff] [blame] | 62 | # variant. Header files are typically shared between the sysroots |
| 63 | # for the different architecture variants. If we use the |
| 64 | # non-default one, header files were not copied by the previous |
| 65 | # step, so we copy them here from the sysroot of the default |
| 66 | # architecture variant. |
| 67 | # |
| 68 | # * Create a symbolic link that matches the name of the subdirectory |
| 69 | # for the architecture variant in the original sysroot. This is |
| 70 | # required as the compiler will by default look in |
| 71 | # sysroot_dir/arch_variant/ for libraries and headers, when the |
| 72 | # non-default architecture variant is used. Without this, the |
| 73 | # compiler fails to find libraries and headers. |
| 74 | # |
Vicente Olivert Riera | 7b6cfca | 2016-05-10 15:01:37 +0100 | [diff] [blame] | 75 | # Some toolchains (i.e Linaro binary toolchains) store support |
| 76 | # libraries (libstdc++, libgcc_s) outside of the sysroot, so we simply |
| 77 | # copy all the libraries from the "support lib directory" into our |
| 78 | # sysroot. |
Thomas Petazzoni | e1f0804 | 2012-05-07 15:02:19 +0200 | [diff] [blame] | 79 | # |
Thomas Petazzoni | 2c23e93 | 2011-10-02 21:20:09 +0200 | [diff] [blame] | 80 | # Note that the 'locale' directories are not copied. They are huge |
| 81 | # (400+MB) in CodeSourcery toolchains, and they are not really useful. |
| 82 | # |
Yann E. MORIN | ed181ae | 2010-07-28 00:08:13 +0200 | [diff] [blame] | 83 | # $1: main sysroot directory of the toolchain |
| 84 | # $2: arch specific sysroot directory of the toolchain |
| 85 | # $3: arch specific subdirectory in the sysroot |
Samuel Martin | 5628776 | 2013-08-23 00:59:35 +0200 | [diff] [blame] | 86 | # $4: directory of libraries ('lib', 'lib32' or 'lib64') |
Thomas Petazzoni | e1f0804 | 2012-05-07 15:02:19 +0200 | [diff] [blame] | 87 | # $5: support lib directories (for toolchains storing libgcc_s, |
| 88 | # libstdc++ and other gcc support libraries outside of the |
| 89 | # sysroot) |
Yann E. MORIN | ed181ae | 2010-07-28 00:08:13 +0200 | [diff] [blame] | 90 | copy_toolchain_sysroot = \ |
| 91 | SYSROOT_DIR="$(strip $1)"; \ |
| 92 | ARCH_SYSROOT_DIR="$(strip $2)"; \ |
| 93 | ARCH_SUBDIR="$(strip $3)"; \ |
Thomas Petazzoni | 0729b54 | 2011-12-31 11:57:15 +0100 | [diff] [blame] | 94 | ARCH_LIB_DIR="$(strip $4)" ; \ |
Thomas Petazzoni | e1f0804 | 2012-05-07 15:02:19 +0200 | [diff] [blame] | 95 | SUPPORT_LIB_DIR="$(strip $5)" ; \ |
Samuel Martin | 5628776 | 2013-08-23 00:59:35 +0200 | [diff] [blame] | 96 | for i in etc $${ARCH_LIB_DIR} sbin usr usr/$${ARCH_LIB_DIR}; do \ |
Thomas De Schampheleire | a07e47a | 2017-02-07 22:56:38 +0100 | [diff] [blame] | 97 | if [ ! -d $${ARCH_SYSROOT_DIR}/$$i ] ; then \ |
| 98 | continue ; \ |
Yann E. MORIN | ed181ae | 2010-07-28 00:08:13 +0200 | [diff] [blame] | 99 | fi ; \ |
Thomas De Schampheleire | 367f4ab | 2017-02-07 22:56:40 +0100 | [diff] [blame^] | 100 | if [ "$$i" = "usr" ]; then \ |
| 101 | rsync -au --chmod=u=rwX,go=rX --exclude 'locale/' \ |
| 102 | --include '/libexec*/' --exclude '/lib*/' \ |
| 103 | $${ARCH_SYSROOT_DIR}/$$i/ $(STAGING_DIR)/$$i/ ; \ |
| 104 | else \ |
| 105 | rsync -au --chmod=u=rwX,go=rX --exclude 'locale/' \ |
| 106 | $${ARCH_SYSROOT_DIR}/$$i/ $(STAGING_DIR)/$$i/ ; \ |
| 107 | fi ; \ |
Yann E. MORIN | ed181ae | 2010-07-28 00:08:13 +0200 | [diff] [blame] | 108 | done ; \ |
Vicente Olivert Riera | 7b6cfca | 2016-05-10 15:01:37 +0100 | [diff] [blame] | 109 | if [ `readlink -f $${SYSROOT_DIR}` != `readlink -f $${ARCH_SYSROOT_DIR}` ] ; then \ |
| 110 | if [ ! -d $${ARCH_SYSROOT_DIR}/usr/include ] ; then \ |
| 111 | cp -a $${SYSROOT_DIR}/usr/include $(STAGING_DIR)/usr ; \ |
Vicente Olivert Riera | 9a1e9ef | 2016-01-12 17:49:38 +0000 | [diff] [blame] | 112 | fi ; \ |
Vicente Olivert Riera | 7b6cfca | 2016-05-10 15:01:37 +0100 | [diff] [blame] | 113 | mkdir -p `dirname $(STAGING_DIR)/$${ARCH_SUBDIR}` ; \ |
| 114 | relpath="./" ; \ |
| 115 | nbslashs=`printf $${ARCH_SUBDIR} | sed 's%[^/]%%g' | wc -c` ; \ |
| 116 | for slash in `seq 1 $${nbslashs}` ; do \ |
| 117 | relpath=$${relpath}"../" ; \ |
| 118 | done ; \ |
| 119 | ln -s $${relpath} $(STAGING_DIR)/$${ARCH_SUBDIR} ; \ |
| 120 | echo "Symlinking $(STAGING_DIR)/$${ARCH_SUBDIR} -> $${relpath}" ; \ |
Yann E. MORIN | ed181ae | 2010-07-28 00:08:13 +0200 | [diff] [blame] | 121 | fi ; \ |
Thomas Petazzoni | e1f0804 | 2012-05-07 15:02:19 +0200 | [diff] [blame] | 122 | if test -n "$${SUPPORT_LIB_DIR}" ; then \ |
| 123 | cp -a $${SUPPORT_LIB_DIR}/* $(STAGING_DIR)/lib/ ; \ |
| 124 | fi ; \ |
Yann E. MORIN | ed181ae | 2010-07-28 00:08:13 +0200 | [diff] [blame] | 125 | find $(STAGING_DIR) -type d | xargs chmod 755 |
| 126 | |
| 127 | # |
Yann E. MORIN | a5a3096 | 2014-03-01 15:53:01 +0100 | [diff] [blame] | 128 | # Check the specified kernel headers version actually matches the |
| 129 | # version in the toolchain. |
| 130 | # |
Yann E. MORIN | 2a82bb8 | 2014-04-07 20:19:12 +0200 | [diff] [blame] | 131 | # $1: sysroot directory |
Yann E. MORIN | a5a3096 | 2014-03-01 15:53:01 +0100 | [diff] [blame] | 132 | # $2: kernel version string, in the form: X.Y |
| 133 | # |
| 134 | check_kernel_headers_version = \ |
| 135 | if ! support/scripts/check-kernel-headers.sh $(1) $(2); then \ |
Yann E. MORIN | 0aa9019 | 2014-03-30 14:59:30 +0200 | [diff] [blame] | 136 | exit 1; \ |
Yann E. MORIN | a5a3096 | 2014-03-01 15:53:01 +0100 | [diff] [blame] | 137 | fi |
| 138 | |
| 139 | # |
Thomas Petazzoni | bd760c3 | 2015-08-04 20:00:35 +0200 | [diff] [blame] | 140 | # Check the specific gcc version actually matches the version in the |
| 141 | # toolchain |
| 142 | # |
| 143 | # $1: path to gcc |
| 144 | # $2: expected gcc version |
| 145 | # |
Thomas Petazzoni | bd760c3 | 2015-08-04 20:00:35 +0200 | [diff] [blame] | 146 | check_gcc_version = \ |
| 147 | expected_version="$(strip $2)" ; \ |
Yann E. MORIN | 23fde76 | 2015-08-13 14:13:23 +0200 | [diff] [blame] | 148 | if [ -z "$${expected_version}" ]; then \ |
Arnout Vandecappelle | 006ba68 | 2016-11-24 00:40:34 +0100 | [diff] [blame] | 149 | exit 0 ; \ |
Yann E. MORIN | 23fde76 | 2015-08-13 14:13:23 +0200 | [diff] [blame] | 150 | fi; \ |
Krzysztof Konopko | 06cd604 | 2017-03-09 09:01:36 +0100 | [diff] [blame] | 151 | real_version=`$(1) -dumpversion` ; \ |
Yann E. MORIN | 4a5f878 | 2015-08-09 13:11:42 +0200 | [diff] [blame] | 152 | if [[ ! "$${real_version}" =~ ^$${expected_version}\. ]] ; then \ |
| 153 | printf "Incorrect selection of gcc version: expected %s.x, got %s\n" \ |
| 154 | "$${expected_version}" "$${real_version}" ; \ |
Thomas Petazzoni | bd760c3 | 2015-08-04 20:00:35 +0200 | [diff] [blame] | 155 | exit 1 ; \ |
| 156 | fi |
| 157 | |
| 158 | # |
Thomas Petazzoni | 9fbdf06 | 2012-11-03 18:47:50 +0100 | [diff] [blame] | 159 | # Check the availability of a particular glibc feature. This function |
| 160 | # is used to check toolchain options that are always supported by |
| 161 | # glibc, so we simply check that the corresponding option is properly |
| 162 | # enabled. |
Yann E. MORIN | ed181ae | 2010-07-28 00:08:13 +0200 | [diff] [blame] | 163 | # |
| 164 | # $1: Buildroot option name |
| 165 | # $2: feature description |
| 166 | # |
| 167 | check_glibc_feature = \ |
Thomas Petazzoni | 0bbbcb9 | 2013-07-17 22:30:47 +0200 | [diff] [blame] | 168 | if [ "$($(1))" != "y" ] ; then \ |
Yann E. MORIN | ed181ae | 2010-07-28 00:08:13 +0200 | [diff] [blame] | 169 | echo "$(2) available in C library, please enable $(1)" ; \ |
| 170 | exit 1 ; \ |
| 171 | fi |
| 172 | |
| 173 | # |
Thomas Petazzoni | 9fbdf06 | 2012-11-03 18:47:50 +0100 | [diff] [blame] | 174 | # Check the availability of RPC support in a glibc toolchain |
| 175 | # |
| 176 | # $1: sysroot directory |
| 177 | # |
| 178 | check_glibc_rpc_feature = \ |
| 179 | IS_IN_LIBC=`test -f $(1)/usr/include/rpc/rpc.h && echo y` ; \ |
| 180 | if [ "$(BR2_TOOLCHAIN_HAS_NATIVE_RPC)" != "y" -a "$${IS_IN_LIBC}" = "y" ] ; then \ |
Yann E. MORIN | 808c3fb | 2015-05-03 17:39:16 +0200 | [diff] [blame] | 181 | echo "RPC support available in C library, please enable BR2_TOOLCHAIN_EXTERNAL_INET_RPC" ; \ |
Thomas Petazzoni | 9fbdf06 | 2012-11-03 18:47:50 +0100 | [diff] [blame] | 182 | exit 1 ; \ |
| 183 | fi ; \ |
| 184 | if [ "$(BR2_TOOLCHAIN_HAS_NATIVE_RPC)" = "y" -a "$${IS_IN_LIBC}" != "y" ] ; then \ |
Yann E. MORIN | 808c3fb | 2015-05-03 17:39:16 +0200 | [diff] [blame] | 185 | echo "RPC support not available in C library, please disable BR2_TOOLCHAIN_EXTERNAL_INET_RPC" ; \ |
Thomas Petazzoni | 9fbdf06 | 2012-11-03 18:47:50 +0100 | [diff] [blame] | 186 | exit 1 ; \ |
| 187 | fi |
| 188 | |
| 189 | # |
Yann E. MORIN | ed181ae | 2010-07-28 00:08:13 +0200 | [diff] [blame] | 190 | # Check the correctness of a glibc external toolchain configuration. |
| 191 | # 1. Check that the C library selected in Buildroot matches the one |
| 192 | # of the external toolchain |
| 193 | # 2. Check that all the C library-related features are enabled in the |
| 194 | # config, since glibc always supports all of them |
| 195 | # |
| 196 | # $1: sysroot directory |
| 197 | # |
| 198 | check_glibc = \ |
| 199 | SYSROOT_DIR="$(strip $1)"; \ |
Jeremy Kerr | fb6dd8f | 2013-12-03 22:26:13 +1100 | [diff] [blame] | 200 | 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. MORIN | ed181ae | 2010-07-28 00:08:13 +0200 | [diff] [blame] | 201 | echo "Incorrect selection of the C library"; \ |
| 202 | exit -1; \ |
| 203 | fi; \ |
Mike Frysinger | e5e5f5d | 2011-01-10 09:28:41 -0500 | [diff] [blame] | 204 | $(call check_glibc_feature,BR2_USE_MMU,MMU support) ;\ |
Thomas Petazzoni | 9fbdf06 | 2012-11-03 18:47:50 +0100 | [diff] [blame] | 205 | $(call check_glibc_rpc_feature,$${SYSROOT_DIR}) |
Yann E. MORIN | ed181ae | 2010-07-28 00:08:13 +0200 | [diff] [blame] | 206 | |
| 207 | # |
Thomas Petazzoni | a1d94aa | 2013-10-08 20:17:09 +0200 | [diff] [blame] | 208 | # Check that the selected C library really is musl |
| 209 | # |
Ilya Kuzmich | 3b32889 | 2017-03-20 08:56:10 +0300 | [diff] [blame] | 210 | # $1: cross-gcc path |
| 211 | # $2: cross-readelf path |
Thomas Petazzoni | a1d94aa | 2013-10-08 20:17:09 +0200 | [diff] [blame] | 212 | check_musl = \ |
Ilya Kuzmich | 3b32889 | 2017-03-20 08:56:10 +0300 | [diff] [blame] | 213 | __CROSS_CC=$(strip $1) ; \ |
| 214 | __CROSS_READELF=$(strip $2) ; \ |
| 215 | echo 'void main(void) {}' | $${__CROSS_CC} -x c -o $(BUILD_DIR)/.br-toolchain-test.tmp - >/dev/null 2>&1; \ |
| 216 | if ! $${__CROSS_READELF} -l $(BUILD_DIR)/.br-toolchain-test.tmp 2> /dev/null | grep 'program interpreter: /lib/ld-musl' -q; then \ |
| 217 | rm -f $(BUILD_DIR)/.br-toolchain-test.tmp*; \ |
Thomas Petazzoni | a1d94aa | 2013-10-08 20:17:09 +0200 | [diff] [blame] | 218 | echo "Incorrect selection of the C library" ; \ |
| 219 | exit -1; \ |
Ilya Kuzmich | 3b32889 | 2017-03-20 08:56:10 +0300 | [diff] [blame] | 220 | fi ; \ |
| 221 | rm -f $(BUILD_DIR)/.br-toolchain-test.tmp* |
Thomas Petazzoni | a1d94aa | 2013-10-08 20:17:09 +0200 | [diff] [blame] | 222 | |
| 223 | # |
Yann E. MORIN | ed181ae | 2010-07-28 00:08:13 +0200 | [diff] [blame] | 224 | # Check the conformity of Buildroot configuration with regard to the |
| 225 | # uClibc configuration of the external toolchain, for a particular |
| 226 | # feature. |
| 227 | # |
Gustavo Zacarias | 1c51a80 | 2015-03-30 18:07:20 -0300 | [diff] [blame] | 228 | # If 'Buildroot option name' ($2) is empty it means the uClibc option |
| 229 | # is mandatory. |
| 230 | # |
Yann E. MORIN | ed181ae | 2010-07-28 00:08:13 +0200 | [diff] [blame] | 231 | # $1: uClibc macro name |
| 232 | # $2: Buildroot option name |
| 233 | # $3: uClibc config file |
| 234 | # $4: feature description |
| 235 | # |
| 236 | check_uclibc_feature = \ |
| 237 | IS_IN_LIBC=`grep -q "\#define $(1) 1" $(3) && echo y` ; \ |
Gustavo Zacarias | 1c51a80 | 2015-03-30 18:07:20 -0300 | [diff] [blame] | 238 | if [ -z "$(2)" ] ; then \ |
| 239 | if [ "$${IS_IN_LIBC}" != "y" ] ; then \ |
| 240 | echo "$(4) not available in C library, toolchain unsuitable for Buildroot" ; \ |
| 241 | exit 1 ; \ |
| 242 | fi ; \ |
| 243 | else \ |
| 244 | if [ "$($(2))" != "y" -a "$${IS_IN_LIBC}" = "y" ] ; then \ |
| 245 | echo "$(4) available in C library, please enable $(2)" ; \ |
| 246 | exit 1 ; \ |
| 247 | fi ; \ |
| 248 | if [ "$($(2))" = "y" -a "$${IS_IN_LIBC}" != "y" ] ; then \ |
| 249 | echo "$(4) not available in C library, please disable $(2)" ; \ |
| 250 | exit 1 ; \ |
| 251 | fi ; \ |
Yann E. MORIN | ed181ae | 2010-07-28 00:08:13 +0200 | [diff] [blame] | 252 | fi |
| 253 | |
| 254 | # |
| 255 | # Check the correctness of a uclibc external toolchain configuration |
| 256 | # 1. Check that the C library selected in Buildroot matches the one |
| 257 | # of the external toolchain |
| 258 | # 2. Check that the features enabled in the Buildroot configuration |
| 259 | # match the features available in the uClibc of the external |
| 260 | # toolchain |
| 261 | # |
| 262 | # $1: sysroot directory |
| 263 | # |
| 264 | check_uclibc = \ |
| 265 | SYSROOT_DIR="$(strip $1)"; \ |
Thomas Petazzoni | 090d486 | 2011-12-31 16:15:43 +0100 | [diff] [blame] | 266 | if ! test -f $${SYSROOT_DIR}/usr/include/bits/uClibc_config.h ; then \ |
Yann E. MORIN | ed181ae | 2010-07-28 00:08:13 +0200 | [diff] [blame] | 267 | echo "Incorrect selection of the C library"; \ |
| 268 | exit -1; \ |
| 269 | fi; \ |
| 270 | UCLIBC_CONFIG_FILE=$${SYSROOT_DIR}/usr/include/bits/uClibc_config.h ; \ |
Mike Frysinger | e5e5f5d | 2011-01-10 09:28:41 -0500 | [diff] [blame] | 271 | $(call check_uclibc_feature,__ARCH_USE_MMU__,BR2_USE_MMU,$${UCLIBC_CONFIG_FILE},MMU support) ;\ |
Gustavo Zacarias | 7f96ef3 | 2015-03-30 18:07:21 -0300 | [diff] [blame] | 272 | $(call check_uclibc_feature,__UCLIBC_HAS_LFS__,,$${UCLIBC_CONFIG_FILE},Large file support) ;\ |
Gustavo Zacarias | 51eaa2c | 2015-04-19 09:39:54 -0300 | [diff] [blame] | 273 | $(call check_uclibc_feature,__UCLIBC_HAS_IPV6__,,$${UCLIBC_CONFIG_FILE},IPv6 support) ;\ |
Thomas Petazzoni | 0858e00 | 2012-11-03 18:47:49 +0100 | [diff] [blame] | 274 | $(call check_uclibc_feature,__UCLIBC_HAS_RPC__,BR2_TOOLCHAIN_HAS_NATIVE_RPC,$${UCLIBC_CONFIG_FILE},RPC support) ;\ |
Yann E. MORIN | ed181ae | 2010-07-28 00:08:13 +0200 | [diff] [blame] | 275 | $(call check_uclibc_feature,__UCLIBC_HAS_LOCALE__,BR2_ENABLE_LOCALE,$${UCLIBC_CONFIG_FILE},Locale support) ;\ |
| 276 | $(call check_uclibc_feature,__UCLIBC_HAS_WCHAR__,BR2_USE_WCHAR,$${UCLIBC_CONFIG_FILE},Wide char support) ;\ |
Peter Korsgaard | 5931db0 | 2011-11-24 14:26:52 +0100 | [diff] [blame] | 277 | $(call check_uclibc_feature,__UCLIBC_HAS_THREADS__,BR2_TOOLCHAIN_HAS_THREADS,$${UCLIBC_CONFIG_FILE},Thread support) ;\ |
Thomas Petazzoni | c5866be | 2013-09-02 18:06:36 +0200 | [diff] [blame] | 278 | $(call check_uclibc_feature,__PTHREADS_DEBUG_SUPPORT__,BR2_TOOLCHAIN_HAS_THREADS_DEBUG,$${UCLIBC_CONFIG_FILE},Thread debugging support) ;\ |
Vicente Olivert Riera | 7949350 | 2016-03-15 16:40:38 +0000 | [diff] [blame] | 279 | $(call check_uclibc_feature,__UCLIBC_HAS_THREADS_NATIVE__,BR2_TOOLCHAIN_HAS_THREADS_NPTL,$${UCLIBC_CONFIG_FILE},NPTL thread support) |
Yann E. MORIN | ed181ae | 2010-07-28 00:08:13 +0200 | [diff] [blame] | 280 | |
| 281 | # |
| 282 | # Check that the Buildroot configuration of the ABI matches the |
| 283 | # configuration of the external toolchain. |
| 284 | # |
Thomas Petazzoni | c59d024 | 2011-05-08 18:52:27 +0200 | [diff] [blame] | 285 | # $1: cross-gcc path |
Baruch Siach | 40ff839 | 2014-07-03 12:35:57 +0300 | [diff] [blame] | 286 | # $2: cross-readelf path |
Thomas Petazzoni | c59d024 | 2011-05-08 18:52:27 +0200 | [diff] [blame] | 287 | # |
Yann E. MORIN | ed181ae | 2010-07-28 00:08:13 +0200 | [diff] [blame] | 288 | check_arm_abi = \ |
Thomas Petazzoni | c59d024 | 2011-05-08 18:52:27 +0200 | [diff] [blame] | 289 | __CROSS_CC=$(strip $1) ; \ |
| 290 | EXT_TOOLCHAIN_TARGET=`LANG=C $${__CROSS_CC} -v 2>&1 | grep ^Target | cut -f2 -d ' '` ; \ |
Yann E. MORIN | 95bfc99 | 2013-07-14 00:27:32 +0200 | [diff] [blame] | 291 | if ! echo $${EXT_TOOLCHAIN_TARGET} | grep -qE 'eabi(hf)?$$' ; then \ |
| 292 | echo "External toolchain uses the unsuported OABI" ; \ |
Yann E. MORIN | ed181ae | 2010-07-28 00:08:13 +0200 | [diff] [blame] | 293 | exit 1 ; \ |
Thomas Petazzoni | b2e8807 | 2013-07-17 22:30:48 +0200 | [diff] [blame] | 294 | fi ; \ |
Guido Martínez | 375bc18 | 2015-06-26 14:33:20 -0300 | [diff] [blame] | 295 | if ! echo 'int main(void) {}' | $${__CROSS_CC} -x c -o $(BUILD_DIR)/.br-toolchain-test.tmp - ; then \ |
| 296 | rm -f $(BUILD_DIR)/.br-toolchain-test.tmp*; \ |
Stefan Sørensen | 3787592 | 2014-05-09 13:44:00 +0200 | [diff] [blame] | 297 | abistr_$(BR2_ARM_EABI)='EABI'; \ |
| 298 | abistr_$(BR2_ARM_EABIHF)='EABIhf'; \ |
| 299 | echo "Incorrect ABI setting: $${abistr_y} selected, but toolchain is incompatible"; \ |
Thomas Petazzoni | b2e8807 | 2013-07-17 22:30:48 +0200 | [diff] [blame] | 300 | exit 1 ; \ |
Guido Martínez | 375bc18 | 2015-06-26 14:33:20 -0300 | [diff] [blame] | 301 | fi ; \ |
| 302 | rm -f $(BUILD_DIR)/.br-toolchain-test.tmp* |
Yann E. MORIN | ed181ae | 2010-07-28 00:08:13 +0200 | [diff] [blame] | 303 | |
| 304 | # |
| 305 | # Check that the external toolchain supports C++ |
| 306 | # |
Thomas Petazzoni | c59d024 | 2011-05-08 18:52:27 +0200 | [diff] [blame] | 307 | # $1: cross-g++ path |
| 308 | # |
Yann E. MORIN | ed181ae | 2010-07-28 00:08:13 +0200 | [diff] [blame] | 309 | check_cplusplus = \ |
Thomas Petazzoni | c59d024 | 2011-05-08 18:52:27 +0200 | [diff] [blame] | 310 | __CROSS_CXX=$(strip $1) ; \ |
| 311 | $${__CROSS_CXX} -v > /dev/null 2>&1 ; \ |
Yann E. MORIN | ed181ae | 2010-07-28 00:08:13 +0200 | [diff] [blame] | 312 | if test $$? -ne 0 ; then \ |
Thomas Petazzoni | 6b578c8 | 2010-12-13 17:27:41 +0100 | [diff] [blame] | 313 | echo "C++ support is selected but is not available in external toolchain" ; \ |
Yann E. MORIN | ed181ae | 2010-07-28 00:08:13 +0200 | [diff] [blame] | 314 | exit 1 ; \ |
Thomas Petazzoni | ac38fd3 | 2010-12-13 17:27:38 +0100 | [diff] [blame] | 315 | fi |
Yann E. MORIN | ed181ae | 2010-07-28 00:08:13 +0200 | [diff] [blame] | 316 | |
| 317 | # |
Samuel Martin | 26db83c | 2016-07-03 15:47:44 +0200 | [diff] [blame] | 318 | # |
| 319 | # Check that the external toolchain supports Fortran |
| 320 | # |
| 321 | # $1: cross-gfortran path |
| 322 | # |
| 323 | check_fortran = \ |
| 324 | __CROSS_FC=$(strip $1) ; \ |
| 325 | __o=$(BUILD_DIR)/.br-toolchain-test-fortran.tmp ; \ |
| 326 | printf 'program hello\n\tprint *, "Hello Fortran!\\n"\nend program hello\n' | \ |
| 327 | $${__CROSS_FC} -x f95 -o $${__o} - ; \ |
| 328 | if test $$? -ne 0 ; then \ |
| 329 | rm -f $${__o}* ; \ |
| 330 | echo "Fortran support is selected but is not available in external toolchain" ; \ |
| 331 | exit 1 ; \ |
| 332 | fi ; \ |
| 333 | rm -f $${__o}* \ |
| 334 | |
| 335 | # |
Yann E. MORIN | ed181ae | 2010-07-28 00:08:13 +0200 | [diff] [blame] | 336 | # Check that the cross-compiler given in the configuration exists |
| 337 | # |
Thomas Petazzoni | c59d024 | 2011-05-08 18:52:27 +0200 | [diff] [blame] | 338 | # $1: cross-gcc path |
| 339 | # |
Yann E. MORIN | ed181ae | 2010-07-28 00:08:13 +0200 | [diff] [blame] | 340 | check_cross_compiler_exists = \ |
Thomas Petazzoni | c59d024 | 2011-05-08 18:52:27 +0200 | [diff] [blame] | 341 | __CROSS_CC=$(strip $1) ; \ |
| 342 | $${__CROSS_CC} -v > /dev/null 2>&1 ; \ |
Yann E. MORIN | ed181ae | 2010-07-28 00:08:13 +0200 | [diff] [blame] | 343 | if test $$? -ne 0 ; then \ |
Thomas Petazzoni | c59d024 | 2011-05-08 18:52:27 +0200 | [diff] [blame] | 344 | echo "Cannot execute cross-compiler '$${__CROSS_CC}'" ; \ |
Yann E. MORIN | ed181ae | 2010-07-28 00:08:13 +0200 | [diff] [blame] | 345 | exit 1 ; \ |
Thomas Petazzoni | ac38fd3 | 2010-12-13 17:27:38 +0100 | [diff] [blame] | 346 | fi |
Thomas Petazzoni | 1247850 | 2013-10-13 10:28:20 +0200 | [diff] [blame] | 347 | |
| 348 | # |
Romain Naour | 4b20109 | 2016-04-27 22:15:03 +0200 | [diff] [blame] | 349 | # Check for toolchains known not to work with Buildroot. |
| 350 | # - For the Angstrom toolchains, we check by looking at the vendor part of |
| 351 | # the host tuple. |
| 352 | # - Exclude distro-class toolchains which are not relocatable. |
| 353 | # - Exclude broken toolchains which return "libc.a" with -print-file-name. |
| 354 | # - Exclude toolchains which doesn't support --sysroot option. |
Thomas Petazzoni | 1247850 | 2013-10-13 10:28:20 +0200 | [diff] [blame] | 355 | # |
| 356 | # $1: cross-gcc path |
| 357 | # |
| 358 | check_unusable_toolchain = \ |
| 359 | __CROSS_CC=$(strip $1) ; \ |
| 360 | vendor=`$${__CROSS_CC} -dumpmachine | cut -f2 -d'-'` ; \ |
| 361 | if test "$${vendor}" = "angstrom" ; then \ |
| 362 | echo "Angstrom toolchains are not pure toolchains: they contain" ; \ |
| 363 | echo "many other libraries than just the C library, which makes" ; \ |
| 364 | echo "them unsuitable as external toolchains for build systems" ; \ |
| 365 | echo "such as Buildroot." ; \ |
| 366 | exit 1 ; \ |
Yann E. MORIN | defb965 | 2015-03-17 16:14:55 +0100 | [diff] [blame] | 367 | fi; \ |
| 368 | with_sysroot=`$${__CROSS_CC} -v 2>&1 |sed -r -e '/.* --with-sysroot=([^[:space:]]+)[[:space:]].*/!d; s//\1/'`; \ |
| 369 | if test "$${with_sysroot}" = "/" ; then \ |
| 370 | echo "Distribution toolchains are unsuitable for use by Buildroot," ; \ |
| 371 | echo "as they were configured in a way that makes them non-relocatable,"; \ |
| 372 | echo "and contain a lot of pre-built libraries that would conflict with"; \ |
| 373 | echo "the ones Buildroot wants to build."; \ |
| 374 | exit 1; \ |
Romain Naour | c32c390 | 2016-04-27 22:15:01 +0200 | [diff] [blame] | 375 | fi; \ |
| 376 | libc_a_path=`$${__CROSS_CC} -print-file-name=libc.a` ; \ |
| 377 | if test "$${libc_a_path}" = "libc.a" ; then \ |
| 378 | echo "Unable to detect the toolchain sysroot, Buildroot cannot use this toolchain." ; \ |
| 379 | exit 1 ; \ |
Romain Naour | 6bb0355 | 2016-04-27 22:15:02 +0200 | [diff] [blame] | 380 | fi ; \ |
| 381 | sysroot_dir="$(call toolchain_find_sysroot,$${__CROSS_CC})" ; \ |
| 382 | if test -z "$${sysroot_dir}" ; then \ |
| 383 | echo "External toolchain doesn't support --sysroot. Cannot use." ; \ |
| 384 | exit 1 ; \ |
Thomas Petazzoni | 1247850 | 2013-10-13 10:28:20 +0200 | [diff] [blame] | 385 | fi |
Thomas Petazzoni | 7130ceb | 2014-05-05 11:25:50 +0200 | [diff] [blame] | 386 | |
| 387 | # |
Vicente Olivert Riera | 7949350 | 2016-03-15 16:40:38 +0000 | [diff] [blame] | 388 | # Check if the toolchain has SSP (stack smashing protector) support |
| 389 | # |
| 390 | # $1: cross-gcc path |
| 391 | # |
| 392 | check_toolchain_ssp = \ |
| 393 | __CROSS_CC=$(strip $1) ; \ |
| 394 | __HAS_SSP=`echo 'void main(){}' | $${__CROSS_CC} -fstack-protector -x c - -o $(BUILD_DIR)/.br-toolchain-test.tmp >/dev/null 2>&1 && echo y` ; \ |
| 395 | if [ "$(BR2_TOOLCHAIN_HAS_SSP)" != "y" -a "$${__HAS_SSP}" = "y" ] ; then \ |
| 396 | echo "SSP support available in this toolchain, please enable BR2_TOOLCHAIN_EXTERNAL_HAS_SSP" ; \ |
| 397 | exit 1 ; \ |
| 398 | fi ; \ |
| 399 | if [ "$(BR2_TOOLCHAIN_HAS_SSP)" = "y" -a "$${__HAS_SSP}" != "y" ] ; then \ |
| 400 | echo "SSP support not available in this toolchain, please disable BR2_TOOLCHAIN_EXTERNAL_HAS_SSP" ; \ |
| 401 | exit 1 ; \ |
| 402 | fi ; \ |
| 403 | rm -f $(BUILD_DIR)/.br-toolchain-test.tmp* |
| 404 | |
| 405 | # |
Thomas Petazzoni | 7130ceb | 2014-05-05 11:25:50 +0200 | [diff] [blame] | 406 | # Generate gdbinit file for use with Buildroot |
| 407 | # |
| 408 | gen_gdbinit_file = \ |
| 409 | mkdir -p $(STAGING_DIR)/usr/share/buildroot/ ; \ |
| 410 | echo "set sysroot $(STAGING_DIR)" > $(STAGING_DIR)/usr/share/buildroot/gdbinit |