Yann E. MORIN | ed181ae | 2010-07-28 00:08:13 +0200 | [diff] [blame] | 1 | # This Makefile fragment declares helper functions, usefull to handle |
| 2 | # non- buildroot-built toolchains, eg. purely external toolchains or |
| 3 | # toolchains (internally) built using crosstool-NG. |
| 4 | |
| 5 | # |
| 6 | # Copy a toolchain library and its symbolic links from the sysroot |
| 7 | # directory to the target directory. Also optionaly strips the |
| 8 | # library. |
| 9 | # |
| 10 | # Most toolchains have their libraries either in /lib or /usr/lib |
| 11 | # relative to their ARCH_SYSROOT_DIR. Buildroot toolchains, however, |
| 12 | # have basic libraries in /lib, and libstdc++/libgcc_s in |
| 13 | # /usr/<target-name>/lib(64). |
| 14 | # |
| 15 | # $1: arch specific sysroot directory |
| 16 | # $2: library name |
| 17 | # $3: destination directory of the libary, relative to $(TARGET_DIR) |
| 18 | # $4: strip (y|n), default is to strip |
| 19 | # |
| 20 | copy_toolchain_lib_root = \ |
| 21 | ARCH_SYSROOT_DIR="$(strip $1)"; \ |
| 22 | LIB="$(strip $2)"; \ |
| 23 | DESTDIR="$(strip $3)" ; \ |
| 24 | STRIP="$(strip $4)"; \ |
| 25 | \ |
| 26 | LIBS=`(cd $${ARCH_SYSROOT_DIR}; \ |
| 27 | find -L . -path "./lib/$${LIB}.*" -o \ |
| 28 | -path "./usr/lib/$${LIB}.*" -o \ |
| 29 | -path "./usr/$(TOOLCHAIN_EXTERNAL_PREFIX)/lib*/$${LIB}.*" \ |
| 30 | )` ; \ |
| 31 | for FILE in $${LIBS} ; do \ |
| 32 | LIB=`basename $${FILE}`; \ |
| 33 | LIBDIR=`dirname $${FILE}` ; \ |
| 34 | while test \! -z "$${LIB}"; do \ |
| 35 | FULLPATH="$${ARCH_SYSROOT_DIR}/$${LIBDIR}/$${LIB}" ; \ |
| 36 | rm -fr $(TARGET_DIR)/$${DESTDIR}/$${LIB}; \ |
| 37 | mkdir -p $(TARGET_DIR)/$${DESTDIR}; \ |
| 38 | if test -h $${FULLPATH} ; then \ |
| 39 | cp -d $${FULLPATH} $(TARGET_DIR)/$${DESTDIR}/; \ |
| 40 | elif test -f $${FULLPATH}; then \ |
| 41 | $(INSTALL) -D -m0755 $${FULLPATH} $(TARGET_DIR)/$${DESTDIR}/$${LIB}; \ |
| 42 | case "$${STRIP}" in \ |
| 43 | (0 | n | no) \ |
| 44 | ;; \ |
| 45 | (*) \ |
| 46 | $(TARGET_CROSS)strip "$(TARGET_DIR)/$${DESTDIR}/$${LIB}"; \ |
| 47 | ;; \ |
| 48 | esac; \ |
| 49 | else \ |
| 50 | exit -1; \ |
| 51 | fi; \ |
| 52 | LIB="`readlink $${FULLPATH}`"; \ |
| 53 | done; \ |
| 54 | done; \ |
| 55 | \ |
| 56 | echo -n |
| 57 | |
| 58 | # |
| 59 | # Copy the full external toolchain sysroot directory to the staging |
| 60 | # dir. The operation of this function is rendered a little bit |
| 61 | # complicated by the support for multilib toolchains. |
| 62 | # |
| 63 | # We start by copying etc, lib, sbin and usr from the sysroot of the |
| 64 | # selected architecture variant (as pointed by ARCH_SYSROOT_DIR). This |
| 65 | # allows to import into the staging directory the C library and |
| 66 | # companion libraries for the correct architecture variant. We |
| 67 | # explictly only copy etc, lib, sbin and usr since other directories |
| 68 | # might exist for other architecture variants (on Codesourcery |
| 69 | # toolchain, the sysroot for the default architecture variant contains |
| 70 | # the armv4t and thumb2 subdirectories, which are the sysroot for the |
| 71 | # corresponding architecture variants), and we don't want to import |
| 72 | # them. |
| 73 | # |
| 74 | # Then, if the selected architecture variant is not the default one |
| 75 | # (i.e, if SYSROOT_DIR != ARCH_SYSROOT_DIR), then we : |
| 76 | # |
| 77 | # * Import the header files from the default architecture |
| 78 | # variant. Header files are typically shared between the sysroots |
| 79 | # for the different architecture variants. If we use the |
| 80 | # non-default one, header files were not copied by the previous |
| 81 | # step, so we copy them here from the sysroot of the default |
| 82 | # architecture variant. |
| 83 | # |
| 84 | # * Create a symbolic link that matches the name of the subdirectory |
| 85 | # for the architecture variant in the original sysroot. This is |
| 86 | # required as the compiler will by default look in |
| 87 | # sysroot_dir/arch_variant/ for libraries and headers, when the |
| 88 | # non-default architecture variant is used. Without this, the |
| 89 | # compiler fails to find libraries and headers. |
| 90 | # |
| 91 | # $1: main sysroot directory of the toolchain |
| 92 | # $2: arch specific sysroot directory of the toolchain |
| 93 | # $3: arch specific subdirectory in the sysroot |
| 94 | # |
| 95 | copy_toolchain_sysroot = \ |
| 96 | SYSROOT_DIR="$(strip $1)"; \ |
| 97 | ARCH_SYSROOT_DIR="$(strip $2)"; \ |
| 98 | ARCH_SUBDIR="$(strip $3)"; \ |
| 99 | for i in etc lib sbin usr ; do \ |
| 100 | if [ -d $${ARCH_SYSROOT_DIR}/$$i ] ; then \ |
| 101 | cp -a $${ARCH_SYSROOT_DIR}/$$i $(STAGING_DIR)/ ; \ |
| 102 | fi ; \ |
| 103 | done ; \ |
| 104 | if [ `readlink -f $${SYSROOT_DIR}` != `readlink -f $${ARCH_SYSROOT_DIR}` ] ; then \ |
| 105 | if [ ! -d $${ARCH_SYSROOT_DIR}/usr/include ] ; then \ |
| 106 | cp -a $${SYSROOT_DIR}/usr/include $(STAGING_DIR)/usr ; \ |
| 107 | fi ; \ |
| 108 | ln -s . $(STAGING_DIR)/$(ARCH_SUBDIR) ; \ |
| 109 | fi ; \ |
| 110 | find $(STAGING_DIR) -type d | xargs chmod 755 |
| 111 | |
| 112 | # |
| 113 | # Create lib64 -> lib and usr/lib64 -> usr/lib symbolic links in the |
| 114 | # target and staging directories. This is needed for some 64 bits |
| 115 | # toolchains such as the Crosstool-NG toolchains, for which the path |
| 116 | # to the dynamic loader and other libraries is /lib64, but the |
| 117 | # libraries are stored in /lib. |
| 118 | # |
| 119 | create_lib64_symlinks = \ |
| 120 | (cd $(TARGET_DIR) ; ln -s lib lib64) ; \ |
| 121 | (cd $(TARGET_DIR)/usr ; ln -s lib lib64) ; \ |
| 122 | (cd $(STAGING_DIR) ; ln -s lib lib64) ; \ |
| 123 | (cd $(STAGING_DIR)/usr ; ln -s lib lib64) |
| 124 | |
| 125 | # |
| 126 | # Check the availability of a particular glibc feature. We assume that |
| 127 | # all Buildroot toolchain options are supported by glibc, so we just |
| 128 | # check that they are enabled. |
| 129 | # |
| 130 | # $1: Buildroot option name |
| 131 | # $2: feature description |
| 132 | # |
| 133 | check_glibc_feature = \ |
| 134 | if [ x$($(1)) != x"y" ] ; then \ |
| 135 | echo "$(2) available in C library, please enable $(1)" ; \ |
| 136 | exit 1 ; \ |
| 137 | fi |
| 138 | |
| 139 | # |
| 140 | # Check the correctness of a glibc external toolchain configuration. |
| 141 | # 1. Check that the C library selected in Buildroot matches the one |
| 142 | # of the external toolchain |
| 143 | # 2. Check that all the C library-related features are enabled in the |
| 144 | # config, since glibc always supports all of them |
| 145 | # |
| 146 | # $1: sysroot directory |
| 147 | # |
| 148 | check_glibc = \ |
| 149 | SYSROOT_DIR="$(strip $1)"; \ |
| 150 | if ! test -f $${SYSROOT_DIR}/lib/ld-linux*.so.* -o -f $${SYSROOT_DIR}/lib/ld.so.* ; then \ |
| 151 | echo "Incorrect selection of the C library"; \ |
| 152 | exit -1; \ |
| 153 | fi; \ |
| 154 | $(call check_glibc_feature,BR2_LARGEFILE,Large file support) ;\ |
| 155 | $(call check_glibc_feature,BR2_INET_IPV6,IPv6 support) ;\ |
| 156 | $(call check_glibc_feature,BR2_INET_RPC,RPC support) ;\ |
| 157 | $(call check_glibc_feature,BR2_ENABLE_LOCALE,Locale support) ;\ |
| 158 | $(call check_glibc_feature,BR2_USE_WCHAR,Wide char support) ;\ |
| 159 | $(call check_glibc_feature,BR2_PROGRAM_INVOCATION,Program invocation support) |
| 160 | |
| 161 | # |
| 162 | # Check the conformity of Buildroot configuration with regard to the |
| 163 | # uClibc configuration of the external toolchain, for a particular |
| 164 | # feature. |
| 165 | # |
| 166 | # $1: uClibc macro name |
| 167 | # $2: Buildroot option name |
| 168 | # $3: uClibc config file |
| 169 | # $4: feature description |
| 170 | # |
| 171 | check_uclibc_feature = \ |
| 172 | IS_IN_LIBC=`grep -q "\#define $(1) 1" $(3) && echo y` ; \ |
Yann E. MORIN | d12bc62 | 2010-09-20 23:26:06 +0200 | [diff] [blame] | 173 | if [ x$($(2)) != x"y" -a x$${IS_IN_LIBC} = x"y" ] ; then \ |
Yann E. MORIN | ed181ae | 2010-07-28 00:08:13 +0200 | [diff] [blame] | 174 | echo "$(4) available in C library, please enable $(2)" ; \ |
| 175 | exit 1 ; \ |
| 176 | fi ; \ |
Yann E. MORIN | d12bc62 | 2010-09-20 23:26:06 +0200 | [diff] [blame] | 177 | if [ x$($(2)) = x"y" -a x$${IS_IN_LIBC} != x"y" ] ; then \ |
Yann E. MORIN | ed181ae | 2010-07-28 00:08:13 +0200 | [diff] [blame] | 178 | echo "$(4) not available in C library, please disable $(2)" ; \ |
| 179 | exit 1 ; \ |
| 180 | fi |
| 181 | |
| 182 | # |
| 183 | # Check the correctness of a uclibc external toolchain configuration |
| 184 | # 1. Check that the C library selected in Buildroot matches the one |
| 185 | # of the external toolchain |
| 186 | # 2. Check that the features enabled in the Buildroot configuration |
| 187 | # match the features available in the uClibc of the external |
| 188 | # toolchain |
| 189 | # |
| 190 | # $1: sysroot directory |
| 191 | # |
| 192 | check_uclibc = \ |
| 193 | SYSROOT_DIR="$(strip $1)"; \ |
| 194 | if ! test -f $${SYSROOT_DIR}/lib/ld*-uClibc.so.* ; then \ |
| 195 | echo "Incorrect selection of the C library"; \ |
| 196 | exit -1; \ |
| 197 | fi; \ |
| 198 | UCLIBC_CONFIG_FILE=$${SYSROOT_DIR}/usr/include/bits/uClibc_config.h ; \ |
| 199 | $(call check_uclibc_feature,__UCLIBC_HAS_LFS__,BR2_LARGEFILE,$${UCLIBC_CONFIG_FILE},Large file support) ;\ |
| 200 | $(call check_uclibc_feature,__UCLIBC_HAS_IPV6__,BR2_INET_IPV6,$${UCLIBC_CONFIG_FILE},IPv6 support) ;\ |
| 201 | $(call check_uclibc_feature,__UCLIBC_HAS_RPC__,BR2_INET_RPC,$${UCLIBC_CONFIG_FILE},RPC support) ;\ |
| 202 | $(call check_uclibc_feature,__UCLIBC_HAS_LOCALE__,BR2_ENABLE_LOCALE,$${UCLIBC_CONFIG_FILE},Locale support) ;\ |
| 203 | $(call check_uclibc_feature,__UCLIBC_HAS_WCHAR__,BR2_USE_WCHAR,$${UCLIBC_CONFIG_FILE},Wide char support) ;\ |
Thomas Petazzoni | ac38fd3 | 2010-12-13 17:27:38 +0100 | [diff] [blame^] | 204 | $(call check_uclibc_feature,__UCLIBC_HAS_PROGRAM_INVOCATION_NAME__,BR2_PROGRAM_INVOCATION,$${UCLIBC_CONFIG_FILE},Program invocation support) |
Yann E. MORIN | ed181ae | 2010-07-28 00:08:13 +0200 | [diff] [blame] | 205 | |
| 206 | # |
| 207 | # Check that the Buildroot configuration of the ABI matches the |
| 208 | # configuration of the external toolchain. |
| 209 | # |
| 210 | check_arm_abi = \ |
| 211 | EXT_TOOLCHAIN_TARGET=$(shell LANG=C $(TARGET_CC) -v 2>&1 | grep ^Target | cut -f2 -d ' ') ; \ |
| 212 | if echo $${EXT_TOOLCHAIN_TARGET} | grep -q 'eabi$$' ; then \ |
| 213 | EXT_TOOLCHAIN_ABI="eabi" ; \ |
| 214 | else \ |
| 215 | EXT_TOOLCHAIN_ABI="oabi" ; \ |
| 216 | fi ; \ |
Yann E. MORIN | d12bc62 | 2010-09-20 23:26:06 +0200 | [diff] [blame] | 217 | if [ x$(BR2_ARM_OABI) = x"y" -a $${EXT_TOOLCHAIN_ABI} = "eabi" ] ; then \ |
Yann E. MORIN | ed181ae | 2010-07-28 00:08:13 +0200 | [diff] [blame] | 218 | echo "Incorrect ABI setting" ; \ |
| 219 | exit 1 ; \ |
| 220 | fi ; \ |
Yann E. MORIN | d12bc62 | 2010-09-20 23:26:06 +0200 | [diff] [blame] | 221 | if [ x$(BR2_ARM_EABI) = x"y" -a $${EXT_TOOLCHAIN_ABI} = "oabi" ] ; then \ |
Yann E. MORIN | ed181ae | 2010-07-28 00:08:13 +0200 | [diff] [blame] | 222 | echo "Incorrect ABI setting" ; \ |
| 223 | exit 1 ; \ |
Thomas Petazzoni | ac38fd3 | 2010-12-13 17:27:38 +0100 | [diff] [blame^] | 224 | fi |
Yann E. MORIN | ed181ae | 2010-07-28 00:08:13 +0200 | [diff] [blame] | 225 | |
| 226 | # |
| 227 | # Check that the external toolchain supports C++ |
| 228 | # |
| 229 | check_cplusplus = \ |
| 230 | $(TARGET_CXX) -v > /dev/null 2>&1 ; \ |
| 231 | if test $$? -ne 0 ; then \ |
| 232 | echo "BR2_INSTALL_LIBSTDCPP is selected but C++ support not available in external toolchain" ; \ |
| 233 | exit 1 ; \ |
Thomas Petazzoni | ac38fd3 | 2010-12-13 17:27:38 +0100 | [diff] [blame^] | 234 | fi |
Yann E. MORIN | ed181ae | 2010-07-28 00:08:13 +0200 | [diff] [blame] | 235 | |
| 236 | # |
| 237 | # Check that the cross-compiler given in the configuration exists |
| 238 | # |
| 239 | check_cross_compiler_exists = \ |
| 240 | $(TARGET_CC) -v > /dev/null 2>&1 ; \ |
| 241 | if test $$? -ne 0 ; then \ |
| 242 | echo "Cannot execute cross-compiler '$(TARGET_CC)'" ; \ |
| 243 | exit 1 ; \ |
Thomas Petazzoni | ac38fd3 | 2010-12-13 17:27:38 +0100 | [diff] [blame^] | 244 | fi |