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 Petazzoni | e6e60be | 2012-01-28 17:12:02 +0100 | [diff] [blame] | 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 | # |
Thomas Petazzoni | e1f0804 | 2012-05-07 15:02:19 +0200 | [diff] [blame] | 22 | # Linaro toolchains have most libraries in lib/<target-name>/, so we |
| 23 | # need to search libraries in: |
Thomas Petazzoni | e6e60be | 2012-01-28 17:12:02 +0100 | [diff] [blame] | 24 | # |
| 25 | # $${ARCH_LIB_DIR}/$(TOOLCHAIN_EXTERNAL_PREFIX) |
| 26 | # |
Thomas Petazzoni | e1f0804 | 2012-05-07 15:02:19 +0200 | [diff] [blame] | 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 | # |
Thomas Petazzoni | e6e60be | 2012-01-28 17:12:02 +0100 | [diff] [blame] | 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. |
Yann E. MORIN | ed181ae | 2010-07-28 00:08:13 +0200 | [diff] [blame] | 38 | # |
| 39 | # $1: arch specific sysroot directory |
Thomas Petazzoni | e1f0804 | 2012-05-07 15:02:19 +0200 | [diff] [blame] | 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) |
Yann E. MORIN | ed181ae | 2010-07-28 00:08:13 +0200 | [diff] [blame] | 44 | # |
| 45 | copy_toolchain_lib_root = \ |
| 46 | ARCH_SYSROOT_DIR="$(strip $1)"; \ |
Thomas Petazzoni | e1f0804 | 2012-05-07 15:02:19 +0200 | [diff] [blame] | 47 | SUPPORT_LIB_DIR="$(strip $2)" ; \ |
| 48 | ARCH_LIB_DIR="$(strip $3)" ; \ |
| 49 | LIB="$(strip $4)"; \ |
| 50 | DESTDIR="$(strip $5)" ; \ |
Jerzy Grzegorek | 595bf30 | 2014-10-23 10:43:37 +0200 | [diff] [blame] | 51 | \ |
Thomas Petazzoni | e1f0804 | 2012-05-07 15:02:19 +0200 | [diff] [blame] | 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 \ |
Thomas Petazzoni | 186a99b | 2013-10-08 20:17:06 +0200 | [diff] [blame] | 58 | LIBSPATH=`find $${dir} -maxdepth 1 -name "$${LIB}" 2>/dev/null` ; \ |
Thomas Petazzoni | e1f0804 | 2012-05-07 15:02:19 +0200 | [diff] [blame] | 59 | if test -n "$${LIBSPATH}" ; then \ |
| 60 | break ; \ |
| 61 | fi \ |
| 62 | done ; \ |
Thomas Petazzoni | ccc8221 | 2013-10-08 20:17:14 +0200 | [diff] [blame] | 63 | mkdir -p $(TARGET_DIR)/$${DESTDIR}; \ |
Thomas Petazzoni | e1f0804 | 2012-05-07 15:02:19 +0200 | [diff] [blame] | 64 | for LIBPATH in $${LIBSPATH} ; do \ |
Thomas Petazzoni | ccc8221 | 2013-10-08 20:17:14 +0200 | [diff] [blame] | 65 | while true ; do \ |
| 66 | LIBNAME=`basename $${LIBPATH}`; \ |
| 67 | LIBDIR=`dirname $${LIBPATH}` ; \ |
| 68 | LINKTARGET=`readlink $${LIBPATH}` ; \ |
Thomas Petazzoni | e1f0804 | 2012-05-07 15:02:19 +0200 | [diff] [blame] | 69 | rm -fr $(TARGET_DIR)/$${DESTDIR}/$${LIBNAME}; \ |
Thomas Petazzoni | e1f0804 | 2012-05-07 15:02:19 +0200 | [diff] [blame] | 70 | if test -h $${LIBPATH} ; then \ |
Thomas Petazzoni | ccc8221 | 2013-10-08 20:17:14 +0200 | [diff] [blame] | 71 | ln -sf `basename $${LINKTARGET}` $(TARGET_DIR)/$${DESTDIR}/$${LIBNAME} ; \ |
Thomas Petazzoni | e1f0804 | 2012-05-07 15:02:19 +0200 | [diff] [blame] | 72 | elif test -f $${LIBPATH}; then \ |
| 73 | $(INSTALL) -D -m0755 $${LIBPATH} $(TARGET_DIR)/$${DESTDIR}/$${LIBNAME}; \ |
Yann E. MORIN | ed181ae | 2010-07-28 00:08:13 +0200 | [diff] [blame] | 74 | else \ |
| 75 | exit -1; \ |
| 76 | fi; \ |
Thomas Petazzoni | ccc8221 | 2013-10-08 20:17:14 +0200 | [diff] [blame] | 77 | if test -z "$${LINKTARGET}" ; then \ |
| 78 | break ; \ |
| 79 | fi ; \ |
| 80 | LIBPATH="`readlink -f $${LIBPATH}`"; \ |
Yann E. MORIN | ed181ae | 2010-07-28 00:08:13 +0200 | [diff] [blame] | 81 | done; \ |
| 82 | done; \ |
Jerzy Grzegorek | 595bf30 | 2014-10-23 10:43:37 +0200 | [diff] [blame] | 83 | \ |
Yann E. MORIN | ed181ae | 2010-07-28 00:08:13 +0200 | [diff] [blame] | 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 | # |
Thomas Petazzoni | e1f0804 | 2012-05-07 15:02:19 +0200 | [diff] [blame] | 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 | # |
Thomas Petazzoni | 2c23e93 | 2011-10-02 21:20:09 +0200 | [diff] [blame] | 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 | # |
Yann E. MORIN | ed181ae | 2010-07-28 00:08:13 +0200 | [diff] [blame] | 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 |
Samuel Martin | 5628776 | 2013-08-23 00:59:35 +0200 | [diff] [blame] | 130 | # $4: directory of libraries ('lib', 'lib32' or 'lib64') |
Thomas Petazzoni | e1f0804 | 2012-05-07 15:02:19 +0200 | [diff] [blame] | 131 | # $5: support lib directories (for toolchains storing libgcc_s, |
| 132 | # libstdc++ and other gcc support libraries outside of the |
| 133 | # sysroot) |
Yann E. MORIN | ed181ae | 2010-07-28 00:08:13 +0200 | [diff] [blame] | 134 | copy_toolchain_sysroot = \ |
| 135 | SYSROOT_DIR="$(strip $1)"; \ |
| 136 | ARCH_SYSROOT_DIR="$(strip $2)"; \ |
| 137 | ARCH_SUBDIR="$(strip $3)"; \ |
Thomas Petazzoni | 0729b54 | 2011-12-31 11:57:15 +0100 | [diff] [blame] | 138 | ARCH_LIB_DIR="$(strip $4)" ; \ |
Thomas Petazzoni | e1f0804 | 2012-05-07 15:02:19 +0200 | [diff] [blame] | 139 | SUPPORT_LIB_DIR="$(strip $5)" ; \ |
Samuel Martin | 5628776 | 2013-08-23 00:59:35 +0200 | [diff] [blame] | 140 | for i in etc $${ARCH_LIB_DIR} sbin usr usr/$${ARCH_LIB_DIR}; do \ |
Yann E. MORIN | ed181ae | 2010-07-28 00:08:13 +0200 | [diff] [blame] | 141 | if [ -d $${ARCH_SYSROOT_DIR}/$$i ] ; then \ |
Guido Martínez | 40b2832 | 2014-11-21 13:19:02 -0300 | [diff] [blame] | 142 | rsync -au --chmod=u=rwX,go=rX --exclude 'usr/lib/locale' \ |
Samuel Martin | 5628776 | 2013-08-23 00:59:35 +0200 | [diff] [blame] | 143 | --exclude lib --exclude lib32 --exclude lib64 \ |
| 144 | $${ARCH_SYSROOT_DIR}/$$i/ $(STAGING_DIR)/$$i/ ; \ |
Yann E. MORIN | ed181ae | 2010-07-28 00:08:13 +0200 | [diff] [blame] | 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 ; \ |
Thomas Petazzoni | 50ac5f9 | 2011-12-31 12:02:52 +0100 | [diff] [blame] | 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}" ; \ |
Yann E. MORIN | ed181ae | 2010-07-28 00:08:13 +0200 | [diff] [blame] | 159 | fi ; \ |
Thomas Petazzoni | e1f0804 | 2012-05-07 15:02:19 +0200 | [diff] [blame] | 160 | if test -n "$${SUPPORT_LIB_DIR}" ; then \ |
| 161 | cp -a $${SUPPORT_LIB_DIR}/* $(STAGING_DIR)/lib/ ; \ |
| 162 | fi ; \ |
Yann E. MORIN | ed181ae | 2010-07-28 00:08:13 +0200 | [diff] [blame] | 163 | find $(STAGING_DIR) -type d | xargs chmod 755 |
| 164 | |
| 165 | # |
Yann E. MORIN | a5a3096 | 2014-03-01 15:53:01 +0100 | [diff] [blame] | 166 | # Check the specified kernel headers version actually matches the |
| 167 | # version in the toolchain. |
| 168 | # |
Yann E. MORIN | 2a82bb8 | 2014-04-07 20:19:12 +0200 | [diff] [blame] | 169 | # $1: sysroot directory |
Yann E. MORIN | a5a3096 | 2014-03-01 15:53:01 +0100 | [diff] [blame] | 170 | # $2: kernel version string, in the form: X.Y |
| 171 | # |
| 172 | check_kernel_headers_version = \ |
| 173 | if ! support/scripts/check-kernel-headers.sh $(1) $(2); then \ |
Yann E. MORIN | 0aa9019 | 2014-03-30 14:59:30 +0200 | [diff] [blame] | 174 | exit 1; \ |
Yann E. MORIN | a5a3096 | 2014-03-01 15:53:01 +0100 | [diff] [blame] | 175 | fi |
| 176 | |
| 177 | # |
Thomas Petazzoni | bd760c3 | 2015-08-04 20:00:35 +0200 | [diff] [blame] | 178 | # Check the specific gcc version actually matches the version in the |
| 179 | # toolchain |
| 180 | # |
| 181 | # $1: path to gcc |
| 182 | # $2: expected gcc version |
| 183 | # |
| 184 | # Some details about the sed expression: |
| 185 | # - 1!d |
| 186 | # - delete if not line 1 |
| 187 | # |
| 188 | # - s/^[^)]+\) ([^[:space:]]+).*/\1/ |
| 189 | # - eat all until the first ')' character followed by a space |
| 190 | # - match as many non-space chars as possible |
| 191 | # - eat all the remaining chars on the line |
| 192 | # - replace by the matched expression |
| 193 | # |
Thomas Petazzoni | bd760c3 | 2015-08-04 20:00:35 +0200 | [diff] [blame] | 194 | check_gcc_version = \ |
| 195 | expected_version="$(strip $2)" ; \ |
Yann E. MORIN | 4a5f878 | 2015-08-09 13:11:42 +0200 | [diff] [blame^] | 196 | real_version=`$(1) --version | sed -r -e '1!d; s/^[^)]+\) ([^[:space:]]+).*/\1/;'` ; \ |
| 197 | if [[ ! "$${real_version}" =~ ^$${expected_version}\. ]] ; then \ |
| 198 | printf "Incorrect selection of gcc version: expected %s.x, got %s\n" \ |
| 199 | "$${expected_version}" "$${real_version}" ; \ |
Thomas Petazzoni | bd760c3 | 2015-08-04 20:00:35 +0200 | [diff] [blame] | 200 | exit 1 ; \ |
| 201 | fi |
| 202 | |
| 203 | # |
Thomas Petazzoni | 9fbdf06 | 2012-11-03 18:47:50 +0100 | [diff] [blame] | 204 | # Check the availability of a particular glibc feature. This function |
| 205 | # is used to check toolchain options that are always supported by |
| 206 | # glibc, so we simply check that the corresponding option is properly |
| 207 | # enabled. |
Yann E. MORIN | ed181ae | 2010-07-28 00:08:13 +0200 | [diff] [blame] | 208 | # |
| 209 | # $1: Buildroot option name |
| 210 | # $2: feature description |
| 211 | # |
| 212 | check_glibc_feature = \ |
Thomas Petazzoni | 0bbbcb9 | 2013-07-17 22:30:47 +0200 | [diff] [blame] | 213 | if [ "$($(1))" != "y" ] ; then \ |
Yann E. MORIN | ed181ae | 2010-07-28 00:08:13 +0200 | [diff] [blame] | 214 | echo "$(2) available in C library, please enable $(1)" ; \ |
| 215 | exit 1 ; \ |
| 216 | fi |
| 217 | |
| 218 | # |
Thomas Petazzoni | 9fbdf06 | 2012-11-03 18:47:50 +0100 | [diff] [blame] | 219 | # Check the availability of RPC support in a glibc toolchain |
| 220 | # |
| 221 | # $1: sysroot directory |
| 222 | # |
| 223 | check_glibc_rpc_feature = \ |
| 224 | IS_IN_LIBC=`test -f $(1)/usr/include/rpc/rpc.h && echo y` ; \ |
| 225 | 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] | 226 | 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] | 227 | exit 1 ; \ |
| 228 | fi ; \ |
| 229 | 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] | 230 | 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] | 231 | exit 1 ; \ |
| 232 | fi |
| 233 | |
| 234 | # |
Yann E. MORIN | ed181ae | 2010-07-28 00:08:13 +0200 | [diff] [blame] | 235 | # Check the correctness of a glibc external toolchain configuration. |
| 236 | # 1. Check that the C library selected in Buildroot matches the one |
| 237 | # of the external toolchain |
| 238 | # 2. Check that all the C library-related features are enabled in the |
| 239 | # config, since glibc always supports all of them |
| 240 | # |
| 241 | # $1: sysroot directory |
| 242 | # |
| 243 | check_glibc = \ |
| 244 | SYSROOT_DIR="$(strip $1)"; \ |
Jeremy Kerr | fb6dd8f | 2013-12-03 22:26:13 +1100 | [diff] [blame] | 245 | 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] | 246 | echo "Incorrect selection of the C library"; \ |
| 247 | exit -1; \ |
| 248 | fi; \ |
Mike Frysinger | e5e5f5d | 2011-01-10 09:28:41 -0500 | [diff] [blame] | 249 | $(call check_glibc_feature,BR2_USE_MMU,MMU support) ;\ |
Thomas Petazzoni | 9fbdf06 | 2012-11-03 18:47:50 +0100 | [diff] [blame] | 250 | $(call check_glibc_rpc_feature,$${SYSROOT_DIR}) |
Yann E. MORIN | ed181ae | 2010-07-28 00:08:13 +0200 | [diff] [blame] | 251 | |
| 252 | # |
Thomas Petazzoni | a1d94aa | 2013-10-08 20:17:09 +0200 | [diff] [blame] | 253 | # Check that the selected C library really is musl |
| 254 | # |
| 255 | # $1: sysroot directory |
| 256 | check_musl = \ |
| 257 | SYSROOT_DIR="$(strip $1)"; \ |
| 258 | if test ! -f $${SYSROOT_DIR}/lib/libc.so -o -e $${SYSROOT_DIR}/lib/libm.so ; then \ |
| 259 | echo "Incorrect selection of the C library" ; \ |
| 260 | exit -1; \ |
| 261 | fi |
| 262 | |
| 263 | # |
Yann E. MORIN | ed181ae | 2010-07-28 00:08:13 +0200 | [diff] [blame] | 264 | # Check the conformity of Buildroot configuration with regard to the |
| 265 | # uClibc configuration of the external toolchain, for a particular |
| 266 | # feature. |
| 267 | # |
Gustavo Zacarias | 1c51a80 | 2015-03-30 18:07:20 -0300 | [diff] [blame] | 268 | # If 'Buildroot option name' ($2) is empty it means the uClibc option |
| 269 | # is mandatory. |
| 270 | # |
Yann E. MORIN | ed181ae | 2010-07-28 00:08:13 +0200 | [diff] [blame] | 271 | # $1: uClibc macro name |
| 272 | # $2: Buildroot option name |
| 273 | # $3: uClibc config file |
| 274 | # $4: feature description |
| 275 | # |
| 276 | check_uclibc_feature = \ |
| 277 | IS_IN_LIBC=`grep -q "\#define $(1) 1" $(3) && echo y` ; \ |
Gustavo Zacarias | 1c51a80 | 2015-03-30 18:07:20 -0300 | [diff] [blame] | 278 | if [ -z "$(2)" ] ; then \ |
| 279 | if [ "$${IS_IN_LIBC}" != "y" ] ; then \ |
| 280 | echo "$(4) not available in C library, toolchain unsuitable for Buildroot" ; \ |
| 281 | exit 1 ; \ |
| 282 | fi ; \ |
| 283 | else \ |
| 284 | if [ "$($(2))" != "y" -a "$${IS_IN_LIBC}" = "y" ] ; then \ |
| 285 | echo "$(4) available in C library, please enable $(2)" ; \ |
| 286 | exit 1 ; \ |
| 287 | fi ; \ |
| 288 | if [ "$($(2))" = "y" -a "$${IS_IN_LIBC}" != "y" ] ; then \ |
| 289 | echo "$(4) not available in C library, please disable $(2)" ; \ |
| 290 | exit 1 ; \ |
| 291 | fi ; \ |
Yann E. MORIN | ed181ae | 2010-07-28 00:08:13 +0200 | [diff] [blame] | 292 | fi |
| 293 | |
| 294 | # |
| 295 | # Check the correctness of a uclibc external toolchain configuration |
| 296 | # 1. Check that the C library selected in Buildroot matches the one |
| 297 | # of the external toolchain |
| 298 | # 2. Check that the features enabled in the Buildroot configuration |
| 299 | # match the features available in the uClibc of the external |
| 300 | # toolchain |
| 301 | # |
| 302 | # $1: sysroot directory |
| 303 | # |
| 304 | check_uclibc = \ |
| 305 | SYSROOT_DIR="$(strip $1)"; \ |
Thomas Petazzoni | 090d486 | 2011-12-31 16:15:43 +0100 | [diff] [blame] | 306 | 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] | 307 | echo "Incorrect selection of the C library"; \ |
| 308 | exit -1; \ |
| 309 | fi; \ |
| 310 | UCLIBC_CONFIG_FILE=$${SYSROOT_DIR}/usr/include/bits/uClibc_config.h ; \ |
Mike Frysinger | e5e5f5d | 2011-01-10 09:28:41 -0500 | [diff] [blame] | 311 | $(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] | 312 | $(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] | 313 | $(call check_uclibc_feature,__UCLIBC_HAS_IPV6__,,$${UCLIBC_CONFIG_FILE},IPv6 support) ;\ |
Thomas Petazzoni | 0858e00 | 2012-11-03 18:47:49 +0100 | [diff] [blame] | 314 | $(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] | 315 | $(call check_uclibc_feature,__UCLIBC_HAS_LOCALE__,BR2_ENABLE_LOCALE,$${UCLIBC_CONFIG_FILE},Locale support) ;\ |
| 316 | $(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] | 317 | $(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] | 318 | $(call check_uclibc_feature,__PTHREADS_DEBUG_SUPPORT__,BR2_TOOLCHAIN_HAS_THREADS_DEBUG,$${UCLIBC_CONFIG_FILE},Thread debugging support) ;\ |
Thomas Petazzoni | c64f948 | 2014-02-18 22:08:59 +0100 | [diff] [blame] | 319 | $(call check_uclibc_feature,__UCLIBC_HAS_THREADS_NATIVE__,BR2_TOOLCHAIN_HAS_THREADS_NPTL,$${UCLIBC_CONFIG_FILE},NPTL thread support) ;\ |
Thomas Petazzoni | c5866be | 2013-09-02 18:06:36 +0200 | [diff] [blame] | 320 | $(call check_uclibc_feature,__UCLIBC_HAS_SSP__,BR2_TOOLCHAIN_HAS_SSP,$${UCLIBC_CONFIG_FILE},Stack Smashing Protection support) |
Yann E. MORIN | ed181ae | 2010-07-28 00:08:13 +0200 | [diff] [blame] | 321 | |
| 322 | # |
| 323 | # Check that the Buildroot configuration of the ABI matches the |
| 324 | # configuration of the external toolchain. |
| 325 | # |
Thomas Petazzoni | c59d024 | 2011-05-08 18:52:27 +0200 | [diff] [blame] | 326 | # $1: cross-gcc path |
Baruch Siach | 40ff839 | 2014-07-03 12:35:57 +0300 | [diff] [blame] | 327 | # $2: cross-readelf path |
Thomas Petazzoni | c59d024 | 2011-05-08 18:52:27 +0200 | [diff] [blame] | 328 | # |
Yann E. MORIN | ed181ae | 2010-07-28 00:08:13 +0200 | [diff] [blame] | 329 | check_arm_abi = \ |
Thomas Petazzoni | c59d024 | 2011-05-08 18:52:27 +0200 | [diff] [blame] | 330 | __CROSS_CC=$(strip $1) ; \ |
Thomas Petazzoni | b2e8807 | 2013-07-17 22:30:48 +0200 | [diff] [blame] | 331 | __CROSS_READELF=$(strip $2) ; \ |
Thomas Petazzoni | c59d024 | 2011-05-08 18:52:27 +0200 | [diff] [blame] | 332 | 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] | 333 | if ! echo $${EXT_TOOLCHAIN_TARGET} | grep -qE 'eabi(hf)?$$' ; then \ |
| 334 | echo "External toolchain uses the unsuported OABI" ; \ |
Yann E. MORIN | ed181ae | 2010-07-28 00:08:13 +0200 | [diff] [blame] | 335 | exit 1 ; \ |
Thomas Petazzoni | b2e8807 | 2013-07-17 22:30:48 +0200 | [diff] [blame] | 336 | fi ; \ |
Guido Martínez | 375bc18 | 2015-06-26 14:33:20 -0300 | [diff] [blame] | 337 | if ! echo 'int main(void) {}' | $${__CROSS_CC} -x c -o $(BUILD_DIR)/.br-toolchain-test.tmp - ; then \ |
| 338 | rm -f $(BUILD_DIR)/.br-toolchain-test.tmp*; \ |
Stefan Sørensen | 3787592 | 2014-05-09 13:44:00 +0200 | [diff] [blame] | 339 | abistr_$(BR2_ARM_EABI)='EABI'; \ |
| 340 | abistr_$(BR2_ARM_EABIHF)='EABIhf'; \ |
| 341 | echo "Incorrect ABI setting: $${abistr_y} selected, but toolchain is incompatible"; \ |
Thomas Petazzoni | b2e8807 | 2013-07-17 22:30:48 +0200 | [diff] [blame] | 342 | exit 1 ; \ |
Guido Martínez | 375bc18 | 2015-06-26 14:33:20 -0300 | [diff] [blame] | 343 | fi ; \ |
| 344 | rm -f $(BUILD_DIR)/.br-toolchain-test.tmp* |
Yann E. MORIN | ed181ae | 2010-07-28 00:08:13 +0200 | [diff] [blame] | 345 | |
| 346 | # |
| 347 | # Check that the external toolchain supports C++ |
| 348 | # |
Thomas Petazzoni | c59d024 | 2011-05-08 18:52:27 +0200 | [diff] [blame] | 349 | # $1: cross-g++ path |
| 350 | # |
Yann E. MORIN | ed181ae | 2010-07-28 00:08:13 +0200 | [diff] [blame] | 351 | check_cplusplus = \ |
Thomas Petazzoni | c59d024 | 2011-05-08 18:52:27 +0200 | [diff] [blame] | 352 | __CROSS_CXX=$(strip $1) ; \ |
| 353 | $${__CROSS_CXX} -v > /dev/null 2>&1 ; \ |
Yann E. MORIN | ed181ae | 2010-07-28 00:08:13 +0200 | [diff] [blame] | 354 | if test $$? -ne 0 ; then \ |
Thomas Petazzoni | 6b578c8 | 2010-12-13 17:27:41 +0100 | [diff] [blame] | 355 | 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] | 356 | exit 1 ; \ |
Thomas Petazzoni | ac38fd3 | 2010-12-13 17:27:38 +0100 | [diff] [blame] | 357 | fi |
Yann E. MORIN | ed181ae | 2010-07-28 00:08:13 +0200 | [diff] [blame] | 358 | |
| 359 | # |
| 360 | # Check that the cross-compiler given in the configuration exists |
| 361 | # |
Thomas Petazzoni | c59d024 | 2011-05-08 18:52:27 +0200 | [diff] [blame] | 362 | # $1: cross-gcc path |
| 363 | # |
Yann E. MORIN | ed181ae | 2010-07-28 00:08:13 +0200 | [diff] [blame] | 364 | check_cross_compiler_exists = \ |
Thomas Petazzoni | c59d024 | 2011-05-08 18:52:27 +0200 | [diff] [blame] | 365 | __CROSS_CC=$(strip $1) ; \ |
| 366 | $${__CROSS_CC} -v > /dev/null 2>&1 ; \ |
Yann E. MORIN | ed181ae | 2010-07-28 00:08:13 +0200 | [diff] [blame] | 367 | if test $$? -ne 0 ; then \ |
Thomas Petazzoni | c59d024 | 2011-05-08 18:52:27 +0200 | [diff] [blame] | 368 | echo "Cannot execute cross-compiler '$${__CROSS_CC}'" ; \ |
Yann E. MORIN | ed181ae | 2010-07-28 00:08:13 +0200 | [diff] [blame] | 369 | exit 1 ; \ |
Thomas Petazzoni | ac38fd3 | 2010-12-13 17:27:38 +0100 | [diff] [blame] | 370 | fi |
Thomas Petazzoni | 1247850 | 2013-10-13 10:28:20 +0200 | [diff] [blame] | 371 | |
| 372 | # |
| 373 | # Check for toolchains known not to work with Buildroot. For now, we |
| 374 | # only check for Angstrom toolchains, by looking at the vendor part of |
| 375 | # the host tuple. |
| 376 | # |
| 377 | # $1: cross-gcc path |
| 378 | # |
| 379 | check_unusable_toolchain = \ |
| 380 | __CROSS_CC=$(strip $1) ; \ |
| 381 | vendor=`$${__CROSS_CC} -dumpmachine | cut -f2 -d'-'` ; \ |
| 382 | if test "$${vendor}" = "angstrom" ; then \ |
| 383 | echo "Angstrom toolchains are not pure toolchains: they contain" ; \ |
| 384 | echo "many other libraries than just the C library, which makes" ; \ |
| 385 | echo "them unsuitable as external toolchains for build systems" ; \ |
| 386 | echo "such as Buildroot." ; \ |
| 387 | exit 1 ; \ |
Yann E. MORIN | defb965 | 2015-03-17 16:14:55 +0100 | [diff] [blame] | 388 | fi; \ |
| 389 | with_sysroot=`$${__CROSS_CC} -v 2>&1 |sed -r -e '/.* --with-sysroot=([^[:space:]]+)[[:space:]].*/!d; s//\1/'`; \ |
| 390 | if test "$${with_sysroot}" = "/" ; then \ |
| 391 | echo "Distribution toolchains are unsuitable for use by Buildroot," ; \ |
| 392 | echo "as they were configured in a way that makes them non-relocatable,"; \ |
| 393 | echo "and contain a lot of pre-built libraries that would conflict with"; \ |
| 394 | echo "the ones Buildroot wants to build."; \ |
| 395 | exit 1; \ |
Thomas Petazzoni | 1247850 | 2013-10-13 10:28:20 +0200 | [diff] [blame] | 396 | fi |
Thomas Petazzoni | 7130ceb | 2014-05-05 11:25:50 +0200 | [diff] [blame] | 397 | |
| 398 | # |
| 399 | # Generate gdbinit file for use with Buildroot |
| 400 | # |
| 401 | gen_gdbinit_file = \ |
| 402 | mkdir -p $(STAGING_DIR)/usr/share/buildroot/ ; \ |
| 403 | echo "set sysroot $(STAGING_DIR)" > $(STAGING_DIR)/usr/share/buildroot/gdbinit |