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 | 9e4fb20 | 2017-02-07 22:56:48 +0100 | [diff] [blame] | 9 | # $1: library name pattern (can include glob wildcards) |
Yann E. MORIN | ed181ae | 2010-07-28 00:08:13 +0200 | [diff] [blame] | 10 | # |
| 11 | copy_toolchain_lib_root = \ |
Thomas De Schampheleire | 9e4fb20 | 2017-02-07 22:56:48 +0100 | [diff] [blame] | 12 | LIBPATTERN="$(strip $1)"; \ |
Thomas De Schampheleire | 9e4fb20 | 2017-02-07 22:56:48 +0100 | [diff] [blame] | 13 | LIBPATHS=`find $(STAGING_DIR)/ -name "$${LIBPATTERN}" 2>/dev/null` ; \ |
Thomas De Schampheleire | 335f331 | 2016-02-03 22:45:28 +0100 | [diff] [blame] | 14 | for LIBPATH in $${LIBPATHS} ; do \ |
Thomas Petazzoni | ccc8221 | 2013-10-08 20:17:14 +0200 | [diff] [blame] | 15 | while true ; do \ |
| 16 | LIBNAME=`basename $${LIBPATH}`; \ |
Thomas Petazzoni | b3cc7e6 | 2017-07-02 13:39:35 +0200 | [diff] [blame] | 17 | DESTDIR=`echo $${LIBPATH} | sed "s,^$(STAGING_DIR)/,," | xargs dirname` ; \ |
Arnout Vandecappelle | 9971e93 | 2017-07-05 16:54:18 +0200 | [diff] [blame] | 18 | mkdir -p $(TARGET_DIR)/$${DESTDIR}; \ |
Thomas Petazzoni | e1f0804 | 2012-05-07 15:02:19 +0200 | [diff] [blame] | 19 | rm -fr $(TARGET_DIR)/$${DESTDIR}/$${LIBNAME}; \ |
Thomas Petazzoni | e1f0804 | 2012-05-07 15:02:19 +0200 | [diff] [blame] | 20 | if test -h $${LIBPATH} ; then \ |
Thomas De Schampheleire | 38b5173 | 2017-02-07 22:56:49 +0100 | [diff] [blame] | 21 | cp -d $${LIBPATH} $(TARGET_DIR)/$${DESTDIR}/$${LIBNAME}; \ |
Thomas De Schampheleire | d34e02a | 2017-02-07 22:56:47 +0100 | [diff] [blame] | 22 | LIBPATH="`readlink -f $${LIBPATH}`"; \ |
Thomas Petazzoni | e1f0804 | 2012-05-07 15:02:19 +0200 | [diff] [blame] | 23 | elif test -f $${LIBPATH}; then \ |
| 24 | $(INSTALL) -D -m0755 $${LIBPATH} $(TARGET_DIR)/$${DESTDIR}/$${LIBNAME}; \ |
Thomas De Schampheleire | d34e02a | 2017-02-07 22:56:47 +0100 | [diff] [blame] | 25 | break ; \ |
Yann E. MORIN | ed181ae | 2010-07-28 00:08:13 +0200 | [diff] [blame] | 26 | else \ |
| 27 | exit -1; \ |
| 28 | fi; \ |
Yann E. MORIN | ed181ae | 2010-07-28 00:08:13 +0200 | [diff] [blame] | 29 | done; \ |
Maxime Hadjinlian | 8f59da8 | 2015-10-04 13:35:08 +0200 | [diff] [blame] | 30 | done |
Yann E. MORIN | ed181ae | 2010-07-28 00:08:13 +0200 | [diff] [blame] | 31 | |
| 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 Schampheleire | 367f4ab | 2017-02-07 22:56:40 +0100 | [diff] [blame] | 37 | # 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. MORIN | ed181ae | 2010-07-28 00:08:13 +0200 | [diff] [blame] | 47 | # 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 Schampheleire | a06edf2 | 2017-02-07 22:56:43 +0100 | [diff] [blame] | 53 | # 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 Schampheleire | 68bb926 | 2017-02-07 22:56:45 +0100 | [diff] [blame] | 61 | # Once the link destination is valid again, it can be simplified to |
| 62 | # remove the dependency on intermediate directory symlinks. |
Thomas De Schampheleire | a06edf2 | 2017-02-07 22:56:43 +0100 | [diff] [blame] | 63 | # |
Thomas De Schampheleire | ba6bac1 | 2017-02-07 22:56:41 +0100 | [diff] [blame] | 64 | # 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 Schampheleire | a06edf2 | 2017-02-07 22:56:43 +0100 | [diff] [blame] | 66 | # 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 Schampheleire | ba6bac1 | 2017-02-07 22:56:41 +0100 | [diff] [blame] | 68 | # |
Vicente Olivert Riera | 7b6cfca | 2016-05-10 15:01:37 +0100 | [diff] [blame] | 69 | # Then, if the selected architecture variant is not the default one |
| 70 | # (i.e, if SYSROOT_DIR != ARCH_SYSROOT_DIR), then we : |
Yann E. MORIN | ed181ae | 2010-07-28 00:08:13 +0200 | [diff] [blame] | 71 | # |
Vicente Olivert Riera | 7b6cfca | 2016-05-10 15:01:37 +0100 | [diff] [blame] | 72 | # * Import the header files from the default architecture |
Yann E. MORIN | ed181ae | 2010-07-28 00:08:13 +0200 | [diff] [blame] | 73 | # 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 Riera | 7b6cfca | 2016-05-10 15:01:37 +0100 | [diff] [blame] | 86 | # 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 Petazzoni | e1f0804 | 2012-05-07 15:02:19 +0200 | [diff] [blame] | 90 | # |
Thomas Petazzoni | 2c23e93 | 2011-10-02 21:20:09 +0200 | [diff] [blame] | 91 | # 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. MORIN | ed181ae | 2010-07-28 00:08:13 +0200 | [diff] [blame] | 94 | # $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 Martin | 5628776 | 2013-08-23 00:59:35 +0200 | [diff] [blame] | 97 | # $4: directory of libraries ('lib', 'lib32' or 'lib64') |
Thomas Petazzoni | e1f0804 | 2012-05-07 15:02:19 +0200 | [diff] [blame] | 98 | # $5: support lib directories (for toolchains storing libgcc_s, |
| 99 | # libstdc++ and other gcc support libraries outside of the |
| 100 | # sysroot) |
Yann E. MORIN | ed181ae | 2010-07-28 00:08:13 +0200 | [diff] [blame] | 101 | copy_toolchain_sysroot = \ |
| 102 | SYSROOT_DIR="$(strip $1)"; \ |
| 103 | ARCH_SYSROOT_DIR="$(strip $2)"; \ |
| 104 | ARCH_SUBDIR="$(strip $3)"; \ |
Thomas Petazzoni | 0729b54 | 2011-12-31 11:57:15 +0100 | [diff] [blame] | 105 | ARCH_LIB_DIR="$(strip $4)" ; \ |
Thomas Petazzoni | e1f0804 | 2012-05-07 15:02:19 +0200 | [diff] [blame] | 106 | SUPPORT_LIB_DIR="$(strip $5)" ; \ |
Samuel Martin | 5628776 | 2013-08-23 00:59:35 +0200 | [diff] [blame] | 107 | 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] | 108 | if [ ! -d $${ARCH_SYSROOT_DIR}/$$i ] ; then \ |
| 109 | continue ; \ |
Yann E. MORIN | ed181ae | 2010-07-28 00:08:13 +0200 | [diff] [blame] | 110 | fi ; \ |
Thomas De Schampheleire | 367f4ab | 2017-02-07 22:56:40 +0100 | [diff] [blame] | 111 | 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. MORIN | ed181ae | 2010-07-28 00:08:13 +0200 | [diff] [blame] | 119 | done ; \ |
Thomas Petazzoni | b291525 | 2017-07-05 23:08:03 +0200 | [diff] [blame] | 120 | 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 Schampheleire | a06edf2 | 2017-02-07 22:56:43 +0100 | [diff] [blame] | 129 | 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 Schampheleire | 68bb926 | 2017-02-07 22:56:45 +0100 | [diff] [blame] | 135 | $(call simplify_symlink,$$i,$(STAGING_DIR)) ; \ |
Thomas De Schampheleire | a06edf2 | 2017-02-07 22:56:43 +0100 | [diff] [blame] | 136 | done ; \ |
| 137 | fi ; \ |
Thomas Petazzoni | eb22fe8 | 2017-07-05 12:10:50 +0200 | [diff] [blame] | 138 | if [ ! -e $(STAGING_DIR)/lib/ld*.so.* ]; then \ |
Thomas De Schampheleire | a7fda62 | 2017-04-06 22:25:05 +0200 | [diff] [blame] | 139 | 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 Schampheleire | ba6bac1 | 2017-02-07 22:56:41 +0100 | [diff] [blame] | 142 | fi ; \ |
Vicente Olivert Riera | 7b6cfca | 2016-05-10 15:01:37 +0100 | [diff] [blame] | 143 | 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 Riera | 9a1e9ef | 2016-01-12 17:49:38 +0000 | [diff] [blame] | 146 | fi ; \ |
Vicente Olivert Riera | 7b6cfca | 2016-05-10 15:01:37 +0100 | [diff] [blame] | 147 | mkdir -p `dirname $(STAGING_DIR)/$${ARCH_SUBDIR}` ; \ |
Thomas De Schampheleire | a259642 | 2017-02-07 22:56:42 +0100 | [diff] [blame] | 148 | relpath="$(call relpath_prefix,$${ARCH_SUBDIR})./" ; \ |
Vicente Olivert Riera | 7b6cfca | 2016-05-10 15:01:37 +0100 | [diff] [blame] | 149 | ln -s $${relpath} $(STAGING_DIR)/$${ARCH_SUBDIR} ; \ |
| 150 | echo "Symlinking $(STAGING_DIR)/$${ARCH_SUBDIR} -> $${relpath}" ; \ |
Yann E. MORIN | ed181ae | 2010-07-28 00:08:13 +0200 | [diff] [blame] | 151 | fi ; \ |
Thomas Petazzoni | e1f0804 | 2012-05-07 15:02:19 +0200 | [diff] [blame] | 152 | if test -n "$${SUPPORT_LIB_DIR}" ; then \ |
| 153 | cp -a $${SUPPORT_LIB_DIR}/* $(STAGING_DIR)/lib/ ; \ |
| 154 | fi ; \ |
Yann E. MORIN | ed181ae | 2010-07-28 00:08:13 +0200 | [diff] [blame] | 155 | find $(STAGING_DIR) -type d | xargs chmod 755 |
| 156 | |
| 157 | # |
Yann E. MORIN | a5a3096 | 2014-03-01 15:53:01 +0100 | [diff] [blame] | 158 | # Check the specified kernel headers version actually matches the |
| 159 | # version in the toolchain. |
| 160 | # |
Yann E. MORIN | 2a82bb8 | 2014-04-07 20:19:12 +0200 | [diff] [blame] | 161 | # $1: sysroot directory |
Yann E. MORIN | a5a3096 | 2014-03-01 15:53:01 +0100 | [diff] [blame] | 162 | # $2: kernel version string, in the form: X.Y |
| 163 | # |
| 164 | check_kernel_headers_version = \ |
| 165 | if ! support/scripts/check-kernel-headers.sh $(1) $(2); then \ |
Yann E. MORIN | 0aa9019 | 2014-03-30 14:59:30 +0200 | [diff] [blame] | 166 | exit 1; \ |
Yann E. MORIN | a5a3096 | 2014-03-01 15:53:01 +0100 | [diff] [blame] | 167 | fi |
| 168 | |
| 169 | # |
Thomas Petazzoni | bd760c3 | 2015-08-04 20:00:35 +0200 | [diff] [blame] | 170 | # 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 Petazzoni | bd760c3 | 2015-08-04 20:00:35 +0200 | [diff] [blame] | 176 | check_gcc_version = \ |
| 177 | expected_version="$(strip $2)" ; \ |
Yann E. MORIN | 23fde76 | 2015-08-13 14:13:23 +0200 | [diff] [blame] | 178 | if [ -z "$${expected_version}" ]; then \ |
Arnout Vandecappelle | 006ba68 | 2016-11-24 00:40:34 +0100 | [diff] [blame] | 179 | exit 0 ; \ |
Yann E. MORIN | 23fde76 | 2015-08-13 14:13:23 +0200 | [diff] [blame] | 180 | fi; \ |
Krzysztof Konopko | 06cd604 | 2017-03-09 09:01:36 +0100 | [diff] [blame] | 181 | real_version=`$(1) -dumpversion` ; \ |
Yann E. MORIN | 4a5f878 | 2015-08-09 13:11:42 +0200 | [diff] [blame] | 182 | 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 Petazzoni | bd760c3 | 2015-08-04 20:00:35 +0200 | [diff] [blame] | 185 | exit 1 ; \ |
| 186 | fi |
| 187 | |
| 188 | # |
Thomas Petazzoni | 9fbdf06 | 2012-11-03 18:47:50 +0100 | [diff] [blame] | 189 | # 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. MORIN | ed181ae | 2010-07-28 00:08:13 +0200 | [diff] [blame] | 193 | # |
| 194 | # $1: Buildroot option name |
| 195 | # $2: feature description |
| 196 | # |
| 197 | check_glibc_feature = \ |
Thomas Petazzoni | 0bbbcb9 | 2013-07-17 22:30:47 +0200 | [diff] [blame] | 198 | if [ "$($(1))" != "y" ] ; then \ |
Yann E. MORIN | ed181ae | 2010-07-28 00:08:13 +0200 | [diff] [blame] | 199 | echo "$(2) available in C library, please enable $(1)" ; \ |
| 200 | exit 1 ; \ |
| 201 | fi |
| 202 | |
| 203 | # |
Thomas Petazzoni | 9fbdf06 | 2012-11-03 18:47:50 +0100 | [diff] [blame] | 204 | # Check the availability of RPC support in a glibc toolchain |
| 205 | # |
| 206 | # $1: sysroot directory |
| 207 | # |
| 208 | check_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. MORIN | 808c3fb | 2015-05-03 17:39:16 +0200 | [diff] [blame] | 211 | 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] | 212 | exit 1 ; \ |
| 213 | fi ; \ |
| 214 | 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] | 215 | 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] | 216 | exit 1 ; \ |
| 217 | fi |
| 218 | |
| 219 | # |
Yann E. MORIN | ed181ae | 2010-07-28 00:08:13 +0200 | [diff] [blame] | 220 | # 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 | # |
| 228 | check_glibc = \ |
| 229 | SYSROOT_DIR="$(strip $1)"; \ |
Cam Hutchison | b55ff5a | 2017-09-04 07:00:43 +1000 | [diff] [blame] | 230 | 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. MORIN | ed181ae | 2010-07-28 00:08:13 +0200 | [diff] [blame] | 231 | echo "Incorrect selection of the C library"; \ |
| 232 | exit -1; \ |
| 233 | fi; \ |
Mike Frysinger | e5e5f5d | 2011-01-10 09:28:41 -0500 | [diff] [blame] | 234 | $(call check_glibc_feature,BR2_USE_MMU,MMU support) ;\ |
Thomas Petazzoni | 9fbdf06 | 2012-11-03 18:47:50 +0100 | [diff] [blame] | 235 | $(call check_glibc_rpc_feature,$${SYSROOT_DIR}) |
Yann E. MORIN | ed181ae | 2010-07-28 00:08:13 +0200 | [diff] [blame] | 236 | |
| 237 | # |
Thomas Petazzoni | a1d94aa | 2013-10-08 20:17:09 +0200 | [diff] [blame] | 238 | # Check that the selected C library really is musl |
| 239 | # |
Ilya Kuzmich | 3b32889 | 2017-03-20 08:56:10 +0300 | [diff] [blame] | 240 | # $1: cross-gcc path |
| 241 | # $2: cross-readelf path |
Thomas Petazzoni | a1d94aa | 2013-10-08 20:17:09 +0200 | [diff] [blame] | 242 | check_musl = \ |
Ilya Kuzmich | 3b32889 | 2017-03-20 08:56:10 +0300 | [diff] [blame] | 243 | __CROSS_CC=$(strip $1) ; \ |
Thomas Petazzoni | d67cebc | 2018-07-04 23:42:57 +0200 | [diff] [blame] | 244 | libc_a_path=`$${__CROSS_CC} -print-file-name=libc.a` ; \ |
| 245 | if ! strings $${libc_a_path} | grep -q MUSL_LOCPATH ; then \ |
Thomas Petazzoni | a1d94aa | 2013-10-08 20:17:09 +0200 | [diff] [blame] | 246 | echo "Incorrect selection of the C library" ; \ |
| 247 | exit -1; \ |
Thomas Petazzoni | d67cebc | 2018-07-04 23:42:57 +0200 | [diff] [blame] | 248 | fi |
Thomas Petazzoni | a1d94aa | 2013-10-08 20:17:09 +0200 | [diff] [blame] | 249 | |
| 250 | # |
Yann E. MORIN | ed181ae | 2010-07-28 00:08:13 +0200 | [diff] [blame] | 251 | # Check the conformity of Buildroot configuration with regard to the |
| 252 | # uClibc configuration of the external toolchain, for a particular |
| 253 | # feature. |
| 254 | # |
Gustavo Zacarias | 1c51a80 | 2015-03-30 18:07:20 -0300 | [diff] [blame] | 255 | # If 'Buildroot option name' ($2) is empty it means the uClibc option |
| 256 | # is mandatory. |
| 257 | # |
Yann E. MORIN | ed181ae | 2010-07-28 00:08:13 +0200 | [diff] [blame] | 258 | # $1: uClibc macro name |
| 259 | # $2: Buildroot option name |
| 260 | # $3: uClibc config file |
| 261 | # $4: feature description |
| 262 | # |
| 263 | check_uclibc_feature = \ |
| 264 | IS_IN_LIBC=`grep -q "\#define $(1) 1" $(3) && echo y` ; \ |
Gustavo Zacarias | 1c51a80 | 2015-03-30 18:07:20 -0300 | [diff] [blame] | 265 | 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. MORIN | ed181ae | 2010-07-28 00:08:13 +0200 | [diff] [blame] | 279 | 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 | # |
| 291 | check_uclibc = \ |
| 292 | SYSROOT_DIR="$(strip $1)"; \ |
Thomas Petazzoni | 090d486 | 2011-12-31 16:15:43 +0100 | [diff] [blame] | 293 | 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] | 294 | 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 Frysinger | e5e5f5d | 2011-01-10 09:28:41 -0500 | [diff] [blame] | 298 | $(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] | 299 | $(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] | 300 | $(call check_uclibc_feature,__UCLIBC_HAS_IPV6__,,$${UCLIBC_CONFIG_FILE},IPv6 support) ;\ |
Thomas Petazzoni | 0858e00 | 2012-11-03 18:47:49 +0100 | [diff] [blame] | 301 | $(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] | 302 | $(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 Korsgaard | 5931db0 | 2011-11-24 14:26:52 +0100 | [diff] [blame] | 304 | $(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] | 305 | $(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] | 306 | $(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] | 307 | |
| 308 | # |
| 309 | # Check that the Buildroot configuration of the ABI matches the |
| 310 | # configuration of the external toolchain. |
| 311 | # |
Thomas Petazzoni | c59d024 | 2011-05-08 18:52:27 +0200 | [diff] [blame] | 312 | # $1: cross-gcc path |
Baruch Siach | 40ff839 | 2014-07-03 12:35:57 +0300 | [diff] [blame] | 313 | # $2: cross-readelf path |
Thomas Petazzoni | c59d024 | 2011-05-08 18:52:27 +0200 | [diff] [blame] | 314 | # |
Yann E. MORIN | ed181ae | 2010-07-28 00:08:13 +0200 | [diff] [blame] | 315 | check_arm_abi = \ |
Thomas Petazzoni | c59d024 | 2011-05-08 18:52:27 +0200 | [diff] [blame] | 316 | __CROSS_CC=$(strip $1) ; \ |
| 317 | 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] | 318 | if ! echo $${EXT_TOOLCHAIN_TARGET} | grep -qE 'eabi(hf)?$$' ; then \ |
| 319 | echo "External toolchain uses the unsuported OABI" ; \ |
Yann E. MORIN | ed181ae | 2010-07-28 00:08:13 +0200 | [diff] [blame] | 320 | exit 1 ; \ |
Thomas Petazzoni | b2e8807 | 2013-07-17 22:30:48 +0200 | [diff] [blame] | 321 | fi ; \ |
Guido MartÃnez | 375bc18 | 2015-06-26 14:33:20 -0300 | [diff] [blame] | 322 | 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ørensen | 3787592 | 2014-05-09 13:44:00 +0200 | [diff] [blame] | 324 | abistr_$(BR2_ARM_EABI)='EABI'; \ |
| 325 | abistr_$(BR2_ARM_EABIHF)='EABIhf'; \ |
| 326 | echo "Incorrect ABI setting: $${abistr_y} selected, but toolchain is incompatible"; \ |
Thomas Petazzoni | b2e8807 | 2013-07-17 22:30:48 +0200 | [diff] [blame] | 327 | exit 1 ; \ |
Guido MartÃnez | 375bc18 | 2015-06-26 14:33:20 -0300 | [diff] [blame] | 328 | fi ; \ |
| 329 | rm -f $(BUILD_DIR)/.br-toolchain-test.tmp* |
Yann E. MORIN | ed181ae | 2010-07-28 00:08:13 +0200 | [diff] [blame] | 330 | |
| 331 | # |
| 332 | # Check that the external toolchain supports C++ |
| 333 | # |
Thomas Petazzoni | c59d024 | 2011-05-08 18:52:27 +0200 | [diff] [blame] | 334 | # $1: cross-g++ path |
| 335 | # |
Yann E. MORIN | ed181ae | 2010-07-28 00:08:13 +0200 | [diff] [blame] | 336 | check_cplusplus = \ |
Thomas Petazzoni | c59d024 | 2011-05-08 18:52:27 +0200 | [diff] [blame] | 337 | __CROSS_CXX=$(strip $1) ; \ |
| 338 | $${__CROSS_CXX} -v > /dev/null 2>&1 ; \ |
Yann E. MORIN | ed181ae | 2010-07-28 00:08:13 +0200 | [diff] [blame] | 339 | if test $$? -ne 0 ; then \ |
Thomas Petazzoni | 6b578c8 | 2010-12-13 17:27:41 +0100 | [diff] [blame] | 340 | 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] | 341 | exit 1 ; \ |
Thomas Petazzoni | ac38fd3 | 2010-12-13 17:27:38 +0100 | [diff] [blame] | 342 | fi |
Yann E. MORIN | ed181ae | 2010-07-28 00:08:13 +0200 | [diff] [blame] | 343 | |
| 344 | # |
Samuel Martin | 26db83c | 2016-07-03 15:47:44 +0200 | [diff] [blame] | 345 | # |
| 346 | # Check that the external toolchain supports Fortran |
| 347 | # |
| 348 | # $1: cross-gfortran path |
| 349 | # |
| 350 | check_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 Blake | ef206d8 | 2019-03-28 18:48:15 +0000 | [diff] [blame] | 363 | # |
| 364 | # Check that the external toolchain supports OpenMP |
| 365 | # |
| 366 | # $1: cross-gcc path |
| 367 | # |
| 368 | check_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. MORIN | ed181ae | 2010-07-28 00:08:13 +0200 | [diff] [blame] | 381 | # Check that the cross-compiler given in the configuration exists |
| 382 | # |
Thomas Petazzoni | c59d024 | 2011-05-08 18:52:27 +0200 | [diff] [blame] | 383 | # $1: cross-gcc path |
| 384 | # |
Yann E. MORIN | ed181ae | 2010-07-28 00:08:13 +0200 | [diff] [blame] | 385 | check_cross_compiler_exists = \ |
Thomas Petazzoni | c59d024 | 2011-05-08 18:52:27 +0200 | [diff] [blame] | 386 | __CROSS_CC=$(strip $1) ; \ |
| 387 | $${__CROSS_CC} -v > /dev/null 2>&1 ; \ |
Yann E. MORIN | ed181ae | 2010-07-28 00:08:13 +0200 | [diff] [blame] | 388 | if test $$? -ne 0 ; then \ |
Thomas Petazzoni | c59d024 | 2011-05-08 18:52:27 +0200 | [diff] [blame] | 389 | echo "Cannot execute cross-compiler '$${__CROSS_CC}'" ; \ |
Yann E. MORIN | ed181ae | 2010-07-28 00:08:13 +0200 | [diff] [blame] | 390 | exit 1 ; \ |
Thomas Petazzoni | ac38fd3 | 2010-12-13 17:27:38 +0100 | [diff] [blame] | 391 | fi |
Thomas Petazzoni | 1247850 | 2013-10-13 10:28:20 +0200 | [diff] [blame] | 392 | |
| 393 | # |
Romain Naour | 4b20109 | 2016-04-27 22:15:03 +0200 | [diff] [blame] | 394 | # 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 Petazzoni | 1247850 | 2013-10-13 10:28:20 +0200 | [diff] [blame] | 400 | # |
| 401 | # $1: cross-gcc path |
| 402 | # |
| 403 | check_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. MORIN | defb965 | 2015-03-17 16:14:55 +0100 | [diff] [blame] | 412 | 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 Naour | c32c390 | 2016-04-27 22:15:01 +0200 | [diff] [blame] | 420 | 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 Naour | 6bb0355 | 2016-04-27 22:15:02 +0200 | [diff] [blame] | 425 | 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 Petazzoni | 1247850 | 2013-10-13 10:28:20 +0200 | [diff] [blame] | 430 | fi |
Thomas Petazzoni | 7130ceb | 2014-05-05 11:25:50 +0200 | [diff] [blame] | 431 | |
| 432 | # |
Vicente Olivert Riera | 7949350 | 2016-03-15 16:40:38 +0000 | [diff] [blame] | 433 | # Check if the toolchain has SSP (stack smashing protector) support |
| 434 | # |
| 435 | # $1: cross-gcc path |
| 436 | # |
| 437 | check_toolchain_ssp = \ |
| 438 | __CROSS_CC=$(strip $1) ; \ |
Carlos Santos | c868095 | 2018-03-25 00:59:52 -0300 | [diff] [blame] | 439 | __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 Riera | 7949350 | 2016-03-15 16:40:38 +0000 | [diff] [blame] | 440 | 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 Petazzoni | 7130ceb | 2014-05-05 11:25:50 +0200 | [diff] [blame] | 451 | # Generate gdbinit file for use with Buildroot |
| 452 | # |
| 453 | gen_gdbinit_file = \ |
| 454 | mkdir -p $(STAGING_DIR)/usr/share/buildroot/ ; \ |
| 455 | echo "set sysroot $(STAGING_DIR)" > $(STAGING_DIR)/usr/share/buildroot/gdbinit |
Thomas De Schampheleire | a259642 | 2017-02-07 22:56:42 +0100 | [diff] [blame] | 456 | |
| 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 |
| 465 | define 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 | ) |
| 474 | endef |
Thomas De Schampheleire | 144caf5 | 2017-02-07 22:56:44 +0100 | [diff] [blame] | 475 | |
| 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 |
| 491 | define 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 | ) |
| 501 | endef |