buildrootschalter/toolchain/external-toolchain/ext-tool.mk

340 lines
13 KiB
Makefile
Raw Normal View History

#
# This file implements the support for external toolchains, i.e
# toolchains that have not been produced by Buildroot itself and that
external-toolchain: Support for multilib toolchains Multilib toolchains provide different versions of the base libraries for different architecture variants. For example, the ARM Codesourcery toolchain provides base libraries for ARMv5 (default), ARMv4t and Thumb2. Depending on the -march= argument passed to gcc, the sysroot used by the compiler is therefore different. This means that the sysroot location in CROSS-gcc -v cannot be used. Instead, we must use CROSS-gcc -print-sysroot when available and fall back to the old way if unavailable. Moreover, we cannot simply copy the full sysroot as we used to do, because the sysroot organization of multilib toolchain is more complicated. In Codesourcery toolchains, we have : / etc -- for ARMv5 lib -- for ARMv5 sbin -- for ARMv5 usr -- for ARMv5 (includes headers) armv4t etc -- for ARMv4t lib -- for ARMv4t sbin -- for ARMv4t usr -- for ARMv4t (no headers!) thumb2 etc -- for Thumb2 lib -- for Thumb2 sbin -- for Thumb2 usr -- for Thumb2 (no headers!) So we have the default ARMv5 architecture variant that is installed in the main directory, and we have subdirectories for the ARMv4t and Thumb2 architecture variants. Copying the full sysroot to the staging directory doesn't work. All our packages are based on the fact that they should install libraries in staging/usr/lib. But if ARMv4t is used, the compiler would only look in staging/armv4t/usr/lib for libraries (even when overriding the sysroot with the --sysroot option, the multilib compiler suffixes the sysroot directory with the architecture variant if it matches a recognized one). Therefore, we have to copy only the sysroot that we are interested in. This is rendered a little bit complicated by the fact that the armv4t and thumb2 sysroot do not contain the headers since they are shared with the armv5 sysroot. So, this patch : * Modifies how we compute SYSROOT_DIR in order to use -print-sysroot if it exists. SYSROOT_DIR contains the location of the main sysroot directory, i.e the sysroot for the default architecture variant. * Defines ARCH_SUBDIR as the subdirectory in the main sysroot for the currently selected architecture variant (in our case, it can be ".", "armv4t" or "thumb2"). ARCH_SYSROOT_DIR is defined as the full path to the sysroot of the currently selected architecture variant. * Modifies copy_toolchain_lib_root (which copies a library to the target/ directory) so that libraries are taken from ARCH_SYSROOT_DIR instead of SYSROOT_DIR. This ensures that libraries for the correct architecture variant are properly copied to the target. * Modifies copy_toolchain_sysroot (which copies the sysroot to the staging/ directory), so that it copies the contents of ARCH_SYSROOT_DIR, and if needed, adds the headers from the main sysroot directory and a symbolic link (armv4t -> . or thumb2 -> .) to make the compiler believe that its sysroot is really in armv4t/ or thumb2/. Tested with Codesourcery 2009q1 ARM toolchain, Crosstool-NG ARM glibc and ARM uClibc toolchains. Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
2009-08-22 01:13:22 +02:00
# are already available on the system on which Buildroot runs. So far,
# we have tested this with:
#
# * Toolchains generated by Crosstool-NG
# * Toolchains generated by Buildroot
# * ARM toolchains made available by Codesourcery
#
# The basic principle is the following
#
# 1. Perform some checks on the conformity between the toolchain
# configuration described in the Buildroot menuconfig system, and the
# real configuration of the external toolchain. This is for example
# important to make sure that the Buildroot configuration system
# knows whether the toolchain supports RPC, IPv6, locales, large
# files, etc. Unfortunately, these things cannot be detected
# automatically, since the value of these options (such as
# BR2_INET_RPC) are needed at configuration time because these
# options are used as dependencies for other options. And at
# configuration time, we are not able to retrieve the external
# toolchain configuration.
#
# 2. Copy the libraries needed at runtime to the target directory,
# $(TARGET_DIR). Obviously, things such as the C library, the dynamic
# loader and a few other utility libraries are needed if dynamic
# applications are to be executed on the target system.
#
# 3. Copy the libraries and headers to the staging directory. This
# will allow all further calls to gcc to be made using --sysroot
# $(STAGING_DIR), which greatly simplifies the compilation of the
# packages when using external toolchains. So in the end, only the
# cross-compiler binaries remains external, all libraries and headers
# are imported into the Buildroot tree.
#
# Copy a toolchain library and its symbolic links from the sysroot
# directory to the target directory. Also optionaly strips the
# library.
#
external-toolchain: Support for multilib toolchains Multilib toolchains provide different versions of the base libraries for different architecture variants. For example, the ARM Codesourcery toolchain provides base libraries for ARMv5 (default), ARMv4t and Thumb2. Depending on the -march= argument passed to gcc, the sysroot used by the compiler is therefore different. This means that the sysroot location in CROSS-gcc -v cannot be used. Instead, we must use CROSS-gcc -print-sysroot when available and fall back to the old way if unavailable. Moreover, we cannot simply copy the full sysroot as we used to do, because the sysroot organization of multilib toolchain is more complicated. In Codesourcery toolchains, we have : / etc -- for ARMv5 lib -- for ARMv5 sbin -- for ARMv5 usr -- for ARMv5 (includes headers) armv4t etc -- for ARMv4t lib -- for ARMv4t sbin -- for ARMv4t usr -- for ARMv4t (no headers!) thumb2 etc -- for Thumb2 lib -- for Thumb2 sbin -- for Thumb2 usr -- for Thumb2 (no headers!) So we have the default ARMv5 architecture variant that is installed in the main directory, and we have subdirectories for the ARMv4t and Thumb2 architecture variants. Copying the full sysroot to the staging directory doesn't work. All our packages are based on the fact that they should install libraries in staging/usr/lib. But if ARMv4t is used, the compiler would only look in staging/armv4t/usr/lib for libraries (even when overriding the sysroot with the --sysroot option, the multilib compiler suffixes the sysroot directory with the architecture variant if it matches a recognized one). Therefore, we have to copy only the sysroot that we are interested in. This is rendered a little bit complicated by the fact that the armv4t and thumb2 sysroot do not contain the headers since they are shared with the armv5 sysroot. So, this patch : * Modifies how we compute SYSROOT_DIR in order to use -print-sysroot if it exists. SYSROOT_DIR contains the location of the main sysroot directory, i.e the sysroot for the default architecture variant. * Defines ARCH_SUBDIR as the subdirectory in the main sysroot for the currently selected architecture variant (in our case, it can be ".", "armv4t" or "thumb2"). ARCH_SYSROOT_DIR is defined as the full path to the sysroot of the currently selected architecture variant. * Modifies copy_toolchain_lib_root (which copies a library to the target/ directory) so that libraries are taken from ARCH_SYSROOT_DIR instead of SYSROOT_DIR. This ensures that libraries for the correct architecture variant are properly copied to the target. * Modifies copy_toolchain_sysroot (which copies the sysroot to the staging/ directory), so that it copies the contents of ARCH_SYSROOT_DIR, and if needed, adds the headers from the main sysroot directory and a symbolic link (armv4t -> . or thumb2 -> .) to make the compiler believe that its sysroot is really in armv4t/ or thumb2/. Tested with Codesourcery 2009q1 ARM toolchain, Crosstool-NG ARM glibc and ARM uClibc toolchains. Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
2009-08-22 01:13:22 +02:00
# $1: arch specific sysroot directory
# $2: library name
# $3: destination directory
# $4: strip (y|n), default is to strip
#
2007-08-22 14:35:41 +02:00
copy_toolchain_lib_root = \
external-toolchain: Support for multilib toolchains Multilib toolchains provide different versions of the base libraries for different architecture variants. For example, the ARM Codesourcery toolchain provides base libraries for ARMv5 (default), ARMv4t and Thumb2. Depending on the -march= argument passed to gcc, the sysroot used by the compiler is therefore different. This means that the sysroot location in CROSS-gcc -v cannot be used. Instead, we must use CROSS-gcc -print-sysroot when available and fall back to the old way if unavailable. Moreover, we cannot simply copy the full sysroot as we used to do, because the sysroot organization of multilib toolchain is more complicated. In Codesourcery toolchains, we have : / etc -- for ARMv5 lib -- for ARMv5 sbin -- for ARMv5 usr -- for ARMv5 (includes headers) armv4t etc -- for ARMv4t lib -- for ARMv4t sbin -- for ARMv4t usr -- for ARMv4t (no headers!) thumb2 etc -- for Thumb2 lib -- for Thumb2 sbin -- for Thumb2 usr -- for Thumb2 (no headers!) So we have the default ARMv5 architecture variant that is installed in the main directory, and we have subdirectories for the ARMv4t and Thumb2 architecture variants. Copying the full sysroot to the staging directory doesn't work. All our packages are based on the fact that they should install libraries in staging/usr/lib. But if ARMv4t is used, the compiler would only look in staging/armv4t/usr/lib for libraries (even when overriding the sysroot with the --sysroot option, the multilib compiler suffixes the sysroot directory with the architecture variant if it matches a recognized one). Therefore, we have to copy only the sysroot that we are interested in. This is rendered a little bit complicated by the fact that the armv4t and thumb2 sysroot do not contain the headers since they are shared with the armv5 sysroot. So, this patch : * Modifies how we compute SYSROOT_DIR in order to use -print-sysroot if it exists. SYSROOT_DIR contains the location of the main sysroot directory, i.e the sysroot for the default architecture variant. * Defines ARCH_SUBDIR as the subdirectory in the main sysroot for the currently selected architecture variant (in our case, it can be ".", "armv4t" or "thumb2"). ARCH_SYSROOT_DIR is defined as the full path to the sysroot of the currently selected architecture variant. * Modifies copy_toolchain_lib_root (which copies a library to the target/ directory) so that libraries are taken from ARCH_SYSROOT_DIR instead of SYSROOT_DIR. This ensures that libraries for the correct architecture variant are properly copied to the target. * Modifies copy_toolchain_sysroot (which copies the sysroot to the staging/ directory), so that it copies the contents of ARCH_SYSROOT_DIR, and if needed, adds the headers from the main sysroot directory and a symbolic link (armv4t -> . or thumb2 -> .) to make the compiler believe that its sysroot is really in armv4t/ or thumb2/. Tested with Codesourcery 2009q1 ARM toolchain, Crosstool-NG ARM glibc and ARM uClibc toolchains. Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
2009-08-22 01:13:22 +02:00
ARCH_SYSROOT_DIR="$(strip $1)"; \
LIB="$(strip $2)"; \
STRIP="$(strip $4)"; \
2007-08-22 14:35:41 +02:00
\
external-toolchain: Support for multilib toolchains Multilib toolchains provide different versions of the base libraries for different architecture variants. For example, the ARM Codesourcery toolchain provides base libraries for ARMv5 (default), ARMv4t and Thumb2. Depending on the -march= argument passed to gcc, the sysroot used by the compiler is therefore different. This means that the sysroot location in CROSS-gcc -v cannot be used. Instead, we must use CROSS-gcc -print-sysroot when available and fall back to the old way if unavailable. Moreover, we cannot simply copy the full sysroot as we used to do, because the sysroot organization of multilib toolchain is more complicated. In Codesourcery toolchains, we have : / etc -- for ARMv5 lib -- for ARMv5 sbin -- for ARMv5 usr -- for ARMv5 (includes headers) armv4t etc -- for ARMv4t lib -- for ARMv4t sbin -- for ARMv4t usr -- for ARMv4t (no headers!) thumb2 etc -- for Thumb2 lib -- for Thumb2 sbin -- for Thumb2 usr -- for Thumb2 (no headers!) So we have the default ARMv5 architecture variant that is installed in the main directory, and we have subdirectories for the ARMv4t and Thumb2 architecture variants. Copying the full sysroot to the staging directory doesn't work. All our packages are based on the fact that they should install libraries in staging/usr/lib. But if ARMv4t is used, the compiler would only look in staging/armv4t/usr/lib for libraries (even when overriding the sysroot with the --sysroot option, the multilib compiler suffixes the sysroot directory with the architecture variant if it matches a recognized one). Therefore, we have to copy only the sysroot that we are interested in. This is rendered a little bit complicated by the fact that the armv4t and thumb2 sysroot do not contain the headers since they are shared with the armv5 sysroot. So, this patch : * Modifies how we compute SYSROOT_DIR in order to use -print-sysroot if it exists. SYSROOT_DIR contains the location of the main sysroot directory, i.e the sysroot for the default architecture variant. * Defines ARCH_SUBDIR as the subdirectory in the main sysroot for the currently selected architecture variant (in our case, it can be ".", "armv4t" or "thumb2"). ARCH_SYSROOT_DIR is defined as the full path to the sysroot of the currently selected architecture variant. * Modifies copy_toolchain_lib_root (which copies a library to the target/ directory) so that libraries are taken from ARCH_SYSROOT_DIR instead of SYSROOT_DIR. This ensures that libraries for the correct architecture variant are properly copied to the target. * Modifies copy_toolchain_sysroot (which copies the sysroot to the staging/ directory), so that it copies the contents of ARCH_SYSROOT_DIR, and if needed, adds the headers from the main sysroot directory and a symbolic link (armv4t -> . or thumb2 -> .) to make the compiler believe that its sysroot is really in armv4t/ or thumb2/. Tested with Codesourcery 2009q1 ARM toolchain, Crosstool-NG ARM glibc and ARM uClibc toolchains. Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
2009-08-22 01:13:22 +02:00
LIBS=`(cd $${ARCH_SYSROOT_DIR}; find . -path "./lib/$${LIB}.*" -o -path "./usr/lib/$${LIB}.*")` ; \
for FILE in $${LIBS} ; do \
2007-08-22 14:35:41 +02:00
LIB=`basename $${FILE}`; \
LIBDIR=`dirname $${FILE}` ; \
2007-08-22 14:35:41 +02:00
while test \! -z "$${LIB}"; do \
external-toolchain: Support for multilib toolchains Multilib toolchains provide different versions of the base libraries for different architecture variants. For example, the ARM Codesourcery toolchain provides base libraries for ARMv5 (default), ARMv4t and Thumb2. Depending on the -march= argument passed to gcc, the sysroot used by the compiler is therefore different. This means that the sysroot location in CROSS-gcc -v cannot be used. Instead, we must use CROSS-gcc -print-sysroot when available and fall back to the old way if unavailable. Moreover, we cannot simply copy the full sysroot as we used to do, because the sysroot organization of multilib toolchain is more complicated. In Codesourcery toolchains, we have : / etc -- for ARMv5 lib -- for ARMv5 sbin -- for ARMv5 usr -- for ARMv5 (includes headers) armv4t etc -- for ARMv4t lib -- for ARMv4t sbin -- for ARMv4t usr -- for ARMv4t (no headers!) thumb2 etc -- for Thumb2 lib -- for Thumb2 sbin -- for Thumb2 usr -- for Thumb2 (no headers!) So we have the default ARMv5 architecture variant that is installed in the main directory, and we have subdirectories for the ARMv4t and Thumb2 architecture variants. Copying the full sysroot to the staging directory doesn't work. All our packages are based on the fact that they should install libraries in staging/usr/lib. But if ARMv4t is used, the compiler would only look in staging/armv4t/usr/lib for libraries (even when overriding the sysroot with the --sysroot option, the multilib compiler suffixes the sysroot directory with the architecture variant if it matches a recognized one). Therefore, we have to copy only the sysroot that we are interested in. This is rendered a little bit complicated by the fact that the armv4t and thumb2 sysroot do not contain the headers since they are shared with the armv5 sysroot. So, this patch : * Modifies how we compute SYSROOT_DIR in order to use -print-sysroot if it exists. SYSROOT_DIR contains the location of the main sysroot directory, i.e the sysroot for the default architecture variant. * Defines ARCH_SUBDIR as the subdirectory in the main sysroot for the currently selected architecture variant (in our case, it can be ".", "armv4t" or "thumb2"). ARCH_SYSROOT_DIR is defined as the full path to the sysroot of the currently selected architecture variant. * Modifies copy_toolchain_lib_root (which copies a library to the target/ directory) so that libraries are taken from ARCH_SYSROOT_DIR instead of SYSROOT_DIR. This ensures that libraries for the correct architecture variant are properly copied to the target. * Modifies copy_toolchain_sysroot (which copies the sysroot to the staging/ directory), so that it copies the contents of ARCH_SYSROOT_DIR, and if needed, adds the headers from the main sysroot directory and a symbolic link (armv4t -> . or thumb2 -> .) to make the compiler believe that its sysroot is really in armv4t/ or thumb2/. Tested with Codesourcery 2009q1 ARM toolchain, Crosstool-NG ARM glibc and ARM uClibc toolchains. Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
2009-08-22 01:13:22 +02:00
FULLPATH="$${ARCH_SYSROOT_DIR}/$${LIBDIR}/$${LIB}" ; \
rm -fr $(TARGET_DIR)/$${LIBDIR}/$${LIB}; \
mkdir -p $(TARGET_DIR)/$${LIBDIR}; \
if test -h $${FULLPATH} ; then \
cp -d $${FULLPATH} $(TARGET_DIR)/$${LIBDIR}/; \
elif test -f $${FULLPATH}; then \
$(INSTALL) -D -m0755 $${FULLPATH} $(TARGET_DIR)/$${LIBDIR}/$${LIB}; \
2007-08-22 14:35:41 +02:00
case "$${STRIP}" in \
(0 | n | no) \
;; \
(*) \
$(TARGET_CROSS)strip "$(TARGET_DIR)/$${LIBDIR}/$${LIB}"; \
2007-08-22 14:35:41 +02:00
;; \
esac; \
else \
exit -1; \
fi; \
LIB="`readlink $${FULLPATH}`"; \
2007-08-22 14:35:41 +02:00
done; \
done; \
\
echo -n
#
# Copy the full external toolchain sysroot directory to the staging
external-toolchain: Support for multilib toolchains Multilib toolchains provide different versions of the base libraries for different architecture variants. For example, the ARM Codesourcery toolchain provides base libraries for ARMv5 (default), ARMv4t and Thumb2. Depending on the -march= argument passed to gcc, the sysroot used by the compiler is therefore different. This means that the sysroot location in CROSS-gcc -v cannot be used. Instead, we must use CROSS-gcc -print-sysroot when available and fall back to the old way if unavailable. Moreover, we cannot simply copy the full sysroot as we used to do, because the sysroot organization of multilib toolchain is more complicated. In Codesourcery toolchains, we have : / etc -- for ARMv5 lib -- for ARMv5 sbin -- for ARMv5 usr -- for ARMv5 (includes headers) armv4t etc -- for ARMv4t lib -- for ARMv4t sbin -- for ARMv4t usr -- for ARMv4t (no headers!) thumb2 etc -- for Thumb2 lib -- for Thumb2 sbin -- for Thumb2 usr -- for Thumb2 (no headers!) So we have the default ARMv5 architecture variant that is installed in the main directory, and we have subdirectories for the ARMv4t and Thumb2 architecture variants. Copying the full sysroot to the staging directory doesn't work. All our packages are based on the fact that they should install libraries in staging/usr/lib. But if ARMv4t is used, the compiler would only look in staging/armv4t/usr/lib for libraries (even when overriding the sysroot with the --sysroot option, the multilib compiler suffixes the sysroot directory with the architecture variant if it matches a recognized one). Therefore, we have to copy only the sysroot that we are interested in. This is rendered a little bit complicated by the fact that the armv4t and thumb2 sysroot do not contain the headers since they are shared with the armv5 sysroot. So, this patch : * Modifies how we compute SYSROOT_DIR in order to use -print-sysroot if it exists. SYSROOT_DIR contains the location of the main sysroot directory, i.e the sysroot for the default architecture variant. * Defines ARCH_SUBDIR as the subdirectory in the main sysroot for the currently selected architecture variant (in our case, it can be ".", "armv4t" or "thumb2"). ARCH_SYSROOT_DIR is defined as the full path to the sysroot of the currently selected architecture variant. * Modifies copy_toolchain_lib_root (which copies a library to the target/ directory) so that libraries are taken from ARCH_SYSROOT_DIR instead of SYSROOT_DIR. This ensures that libraries for the correct architecture variant are properly copied to the target. * Modifies copy_toolchain_sysroot (which copies the sysroot to the staging/ directory), so that it copies the contents of ARCH_SYSROOT_DIR, and if needed, adds the headers from the main sysroot directory and a symbolic link (armv4t -> . or thumb2 -> .) to make the compiler believe that its sysroot is really in armv4t/ or thumb2/. Tested with Codesourcery 2009q1 ARM toolchain, Crosstool-NG ARM glibc and ARM uClibc toolchains. Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
2009-08-22 01:13:22 +02:00
# dir. The operation of this function is rendered a little bit
# complicated by the support for multilib toolchains.
#
external-toolchain: Support for multilib toolchains Multilib toolchains provide different versions of the base libraries for different architecture variants. For example, the ARM Codesourcery toolchain provides base libraries for ARMv5 (default), ARMv4t and Thumb2. Depending on the -march= argument passed to gcc, the sysroot used by the compiler is therefore different. This means that the sysroot location in CROSS-gcc -v cannot be used. Instead, we must use CROSS-gcc -print-sysroot when available and fall back to the old way if unavailable. Moreover, we cannot simply copy the full sysroot as we used to do, because the sysroot organization of multilib toolchain is more complicated. In Codesourcery toolchains, we have : / etc -- for ARMv5 lib -- for ARMv5 sbin -- for ARMv5 usr -- for ARMv5 (includes headers) armv4t etc -- for ARMv4t lib -- for ARMv4t sbin -- for ARMv4t usr -- for ARMv4t (no headers!) thumb2 etc -- for Thumb2 lib -- for Thumb2 sbin -- for Thumb2 usr -- for Thumb2 (no headers!) So we have the default ARMv5 architecture variant that is installed in the main directory, and we have subdirectories for the ARMv4t and Thumb2 architecture variants. Copying the full sysroot to the staging directory doesn't work. All our packages are based on the fact that they should install libraries in staging/usr/lib. But if ARMv4t is used, the compiler would only look in staging/armv4t/usr/lib for libraries (even when overriding the sysroot with the --sysroot option, the multilib compiler suffixes the sysroot directory with the architecture variant if it matches a recognized one). Therefore, we have to copy only the sysroot that we are interested in. This is rendered a little bit complicated by the fact that the armv4t and thumb2 sysroot do not contain the headers since they are shared with the armv5 sysroot. So, this patch : * Modifies how we compute SYSROOT_DIR in order to use -print-sysroot if it exists. SYSROOT_DIR contains the location of the main sysroot directory, i.e the sysroot for the default architecture variant. * Defines ARCH_SUBDIR as the subdirectory in the main sysroot for the currently selected architecture variant (in our case, it can be ".", "armv4t" or "thumb2"). ARCH_SYSROOT_DIR is defined as the full path to the sysroot of the currently selected architecture variant. * Modifies copy_toolchain_lib_root (which copies a library to the target/ directory) so that libraries are taken from ARCH_SYSROOT_DIR instead of SYSROOT_DIR. This ensures that libraries for the correct architecture variant are properly copied to the target. * Modifies copy_toolchain_sysroot (which copies the sysroot to the staging/ directory), so that it copies the contents of ARCH_SYSROOT_DIR, and if needed, adds the headers from the main sysroot directory and a symbolic link (armv4t -> . or thumb2 -> .) to make the compiler believe that its sysroot is really in armv4t/ or thumb2/. Tested with Codesourcery 2009q1 ARM toolchain, Crosstool-NG ARM glibc and ARM uClibc toolchains. Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
2009-08-22 01:13:22 +02:00
# We start by copying etc, lib, sbin and usr from the sysroot of the
# selected architecture variant (as pointed by ARCH_SYSROOT_DIR). This
# allows to import into the staging directory the C library and
# companion libraries for the correct architecture variant. We
# explictly only copy etc, lib, sbin and usr since other directories
# might exist for other architecture variants (on Codesourcery
# toolchain, the sysroot for the default architecture variant contains
# the armv4t and thumb2 subdirectories, which are the sysroot for the
# corresponding architecture variants), and we don't want to import
# them.
#
# Then, if the selected architecture variant is not the default one
# (i.e, if SYSROOT_DIR != ARCH_SYSROOT_DIR), then we :
#
# * Import the header files from the default architecture
# variant. Header files are typically shared between the sysroots
# for the different architecture variants. If we use the
# non-default one, header files were not copied by the previous
# step, so we copy them here from the sysroot of the default
# architecture variant.
#
# * Create a symbolic link that matches the name of the subdirectory
# for the architecture variant in the original sysroot. This is
# required as the compiler will by default look in
# sysroot_dir/arch_variant/ for libraries and headers, when the
# non-default architecture variant is used. Without this, the
# compiler fails to find libraries and headers.
#
# $1: main sysroot directory of the toolchain
# $2: arch specific sysroot directory of the toolchain
# $3: arch specific subdirectory in the sysroot
#
copy_toolchain_sysroot = \
SYSROOT_DIR="$(strip $1)"; \
external-toolchain: Support for multilib toolchains Multilib toolchains provide different versions of the base libraries for different architecture variants. For example, the ARM Codesourcery toolchain provides base libraries for ARMv5 (default), ARMv4t and Thumb2. Depending on the -march= argument passed to gcc, the sysroot used by the compiler is therefore different. This means that the sysroot location in CROSS-gcc -v cannot be used. Instead, we must use CROSS-gcc -print-sysroot when available and fall back to the old way if unavailable. Moreover, we cannot simply copy the full sysroot as we used to do, because the sysroot organization of multilib toolchain is more complicated. In Codesourcery toolchains, we have : / etc -- for ARMv5 lib -- for ARMv5 sbin -- for ARMv5 usr -- for ARMv5 (includes headers) armv4t etc -- for ARMv4t lib -- for ARMv4t sbin -- for ARMv4t usr -- for ARMv4t (no headers!) thumb2 etc -- for Thumb2 lib -- for Thumb2 sbin -- for Thumb2 usr -- for Thumb2 (no headers!) So we have the default ARMv5 architecture variant that is installed in the main directory, and we have subdirectories for the ARMv4t and Thumb2 architecture variants. Copying the full sysroot to the staging directory doesn't work. All our packages are based on the fact that they should install libraries in staging/usr/lib. But if ARMv4t is used, the compiler would only look in staging/armv4t/usr/lib for libraries (even when overriding the sysroot with the --sysroot option, the multilib compiler suffixes the sysroot directory with the architecture variant if it matches a recognized one). Therefore, we have to copy only the sysroot that we are interested in. This is rendered a little bit complicated by the fact that the armv4t and thumb2 sysroot do not contain the headers since they are shared with the armv5 sysroot. So, this patch : * Modifies how we compute SYSROOT_DIR in order to use -print-sysroot if it exists. SYSROOT_DIR contains the location of the main sysroot directory, i.e the sysroot for the default architecture variant. * Defines ARCH_SUBDIR as the subdirectory in the main sysroot for the currently selected architecture variant (in our case, it can be ".", "armv4t" or "thumb2"). ARCH_SYSROOT_DIR is defined as the full path to the sysroot of the currently selected architecture variant. * Modifies copy_toolchain_lib_root (which copies a library to the target/ directory) so that libraries are taken from ARCH_SYSROOT_DIR instead of SYSROOT_DIR. This ensures that libraries for the correct architecture variant are properly copied to the target. * Modifies copy_toolchain_sysroot (which copies the sysroot to the staging/ directory), so that it copies the contents of ARCH_SYSROOT_DIR, and if needed, adds the headers from the main sysroot directory and a symbolic link (armv4t -> . or thumb2 -> .) to make the compiler believe that its sysroot is really in armv4t/ or thumb2/. Tested with Codesourcery 2009q1 ARM toolchain, Crosstool-NG ARM glibc and ARM uClibc toolchains. Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
2009-08-22 01:13:22 +02:00
ARCH_SYSROOT_DIR="$(strip $2)"; \
ARCH_SUBDIR="$(strip $3)"; \
for i in etc lib sbin usr ; do \
if [ -d $${ARCH_SYSROOT_DIR}/$$i ] ; then \
cp -a $${ARCH_SYSROOT_DIR}/$$i $(STAGING_DIR)/ ; \
fi ; \
external-toolchain: Support for multilib toolchains Multilib toolchains provide different versions of the base libraries for different architecture variants. For example, the ARM Codesourcery toolchain provides base libraries for ARMv5 (default), ARMv4t and Thumb2. Depending on the -march= argument passed to gcc, the sysroot used by the compiler is therefore different. This means that the sysroot location in CROSS-gcc -v cannot be used. Instead, we must use CROSS-gcc -print-sysroot when available and fall back to the old way if unavailable. Moreover, we cannot simply copy the full sysroot as we used to do, because the sysroot organization of multilib toolchain is more complicated. In Codesourcery toolchains, we have : / etc -- for ARMv5 lib -- for ARMv5 sbin -- for ARMv5 usr -- for ARMv5 (includes headers) armv4t etc -- for ARMv4t lib -- for ARMv4t sbin -- for ARMv4t usr -- for ARMv4t (no headers!) thumb2 etc -- for Thumb2 lib -- for Thumb2 sbin -- for Thumb2 usr -- for Thumb2 (no headers!) So we have the default ARMv5 architecture variant that is installed in the main directory, and we have subdirectories for the ARMv4t and Thumb2 architecture variants. Copying the full sysroot to the staging directory doesn't work. All our packages are based on the fact that they should install libraries in staging/usr/lib. But if ARMv4t is used, the compiler would only look in staging/armv4t/usr/lib for libraries (even when overriding the sysroot with the --sysroot option, the multilib compiler suffixes the sysroot directory with the architecture variant if it matches a recognized one). Therefore, we have to copy only the sysroot that we are interested in. This is rendered a little bit complicated by the fact that the armv4t and thumb2 sysroot do not contain the headers since they are shared with the armv5 sysroot. So, this patch : * Modifies how we compute SYSROOT_DIR in order to use -print-sysroot if it exists. SYSROOT_DIR contains the location of the main sysroot directory, i.e the sysroot for the default architecture variant. * Defines ARCH_SUBDIR as the subdirectory in the main sysroot for the currently selected architecture variant (in our case, it can be ".", "armv4t" or "thumb2"). ARCH_SYSROOT_DIR is defined as the full path to the sysroot of the currently selected architecture variant. * Modifies copy_toolchain_lib_root (which copies a library to the target/ directory) so that libraries are taken from ARCH_SYSROOT_DIR instead of SYSROOT_DIR. This ensures that libraries for the correct architecture variant are properly copied to the target. * Modifies copy_toolchain_sysroot (which copies the sysroot to the staging/ directory), so that it copies the contents of ARCH_SYSROOT_DIR, and if needed, adds the headers from the main sysroot directory and a symbolic link (armv4t -> . or thumb2 -> .) to make the compiler believe that its sysroot is really in armv4t/ or thumb2/. Tested with Codesourcery 2009q1 ARM toolchain, Crosstool-NG ARM glibc and ARM uClibc toolchains. Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
2009-08-22 01:13:22 +02:00
done ; \
if [ `readlink -f $${SYSROOT_DIR}` != `readlink -f $${ARCH_SYSROOT_DIR}` ] ; then \
if [ ! -d $${ARCH_SYSROOT_DIR}/usr/include ] ; then \
cp -a $${SYSROOT_DIR}/usr/include $(STAGING_DIR)/usr ; \
fi ; \
ln -s . $(STAGING_DIR)/$(ARCH_SUBDIR) ; \
fi ; \
find $(STAGING_DIR) -type d | xargs chmod 755
#
# Create lib64 -> lib and usr/lib64 -> usr/lib symbolic links in the
# target and staging directories. This is needed for some 64 bits
# toolchains such as the Crosstool-NG toolchains, for which the path
# to the dynamic loader and other libraries is /lib64, but the
# libraries are stored in /lib.
#
create_lib64_symlinks = \
(cd $(TARGET_DIR) ; ln -s lib lib64) ; \
(cd $(TARGET_DIR)/usr ; ln -s lib lib64) ; \
(cd $(STAGING_DIR) ; ln -s lib lib64) ; \
(cd $(STAGING_DIR)/usr ; ln -s lib lib64)
#
# Check the availability of a particular glibc feature. We assume that
# all Buildroot toolchain options are supported by glibc, so we just
# check that they are enabled.
#
# $1: Buildroot option name
# $2: feature description
#
check_glibc_feature = \
if [ x$($(1)) != x"y" ] ; then \
echo "$(2) available in C library, please enable $(1)" ; \
exit 1 ; \
fi
#
# Check the correctness of a glibc external toolchain configuration.
# 1. Check that the C library selected in Buildroot matches the one
# of the external toolchain
# 2. Check that all the C library-related features are enabled in the
# config, since glibc always supports all of them
#
# $1: sysroot directory
#
check_glibc = \
SYSROOT_DIR="$(strip $1)"; \
if ! test -f $${SYSROOT_DIR}/lib/ld-linux*.so.* -o -f $${SYSROOT_DIR}/lib/ld.so.* ; then \
echo "Incorrect selection of the C library"; \
exit -1; \
fi; \
$(call check_glibc_feature,BR2_LARGEFILE,Large file support) ;\
$(call check_glibc_feature,BR2_INET_IPV6,IPv6 support) ;\
$(call check_glibc_feature,BR2_INET_RPC,RPC support) ;\
$(call check_glibc_feature,BR2_ENABLE_LOCALE,Locale support) ;\
$(call check_glibc_feature,BR2_USE_WCHAR,Wide char support) ;\
$(call check_glibc_feature,BR2_PROGRAM_INVOCATION,Program invocation support)
#
# Check the conformity of Buildroot configuration with regard to the
# uClibc configuration of the external toolchain, for a particular
# feature.
#
# $1: uClibc macro name
# $2: Buildroot option name
# $3: uClibc config file
# $4: feature description
#
check_uclibc_feature = \
IS_IN_LIBC=`grep -q "\#define $(1) 1" $(3) && echo y` ; \
if [ x$($(2)) != x"y" -a x$${IS_IN_LIBC} == x"y" ] ; then \
echo "$(4) available in C library, please enable $(2)" ; \
exit 1 ; \
fi ; \
if [ x$($(2)) == x"y" -a x$${IS_IN_LIBC} != x"y" ] ; then \
echo "$(4) not available in C library, please disable $(2)" ; \
exit 1 ; \
fi
#
# Check the correctness of a uclibc external toolchain configuration
# 1. Check that the C library selected in Buildroot matches the one
# of the external toolchain
# 2. Check that the features enabled in the Buildroot configuration
# match the features available in the uClibc of the external
# toolchain
#
# $1: sysroot directory
#
check_uclibc = \
SYSROOT_DIR="$(strip $1)"; \
if ! test -f $${SYSROOT_DIR}/lib/ld-uClibc.so.* ; then \
echo "Incorrect selection of the C library"; \
exit -1; \
fi; \
UCLIBC_CONFIG_FILE=$${SYSROOT_DIR}/usr/include/bits/uClibc_config.h ; \
$(call check_uclibc_feature,__UCLIBC_HAS_LFS__,BR2_LARGEFILE,$${UCLIBC_CONFIG_FILE},Large file support) ;\
$(call check_uclibc_feature,__UCLIBC_HAS_IPV6__,BR2_INET_IPV6,$${UCLIBC_CONFIG_FILE},IPv6 support) ;\
$(call check_uclibc_feature,__UCLIBC_HAS_RPC__,BR2_INET_RPC,$${UCLIBC_CONFIG_FILE},RPC support) ;\
$(call check_uclibc_feature,__UCLIBC_HAS_LOCALE__,BR2_ENABLE_LOCALE,$${UCLIBC_CONFIG_FILE},Locale support) ;\
$(call check_uclibc_feature,__UCLIBC_HAS_WCHAR__,BR2_USE_WCHAR,$${UCLIBC_CONFIG_FILE},Wide char support) ;\
$(call check_uclibc_feature,__UCLIBC_HAS_PROGRAM_INVOCATION_NAME__,BR2_PROGRAM_INVOCATION,$${UCLIBC_CONFIG_FILE},Program invocation support) ;\
#
# Check that the Buildroot configuration of the ABI matches the
# configuration of the external toolchain.
#
check_arm_abi = \
EXT_TOOLCHAIN_TARGET=$(shell LANG=C $(TARGET_CC) -v 2>&1 | grep ^Target | cut -f2 -d ' ') ; \
if echo $${EXT_TOOLCHAIN_TARGET} | grep -q 'eabi$$' ; then \
EXT_TOOLCHAIN_ABI="eabi" ; \
else \
EXT_TOOLCHAIN_ABI="oabi" ; \
fi ; \
if [ x$(BR2_ARM_OABI) == x"y" -a $${EXT_TOOLCHAIN_ABI} == "eabi" ] ; then \
echo "Incorrect ABI setting" ; \
exit 1 ; \
fi ; \
if [ x$(BR2_ARM_EABI) == x"y" -a $${EXT_TOOLCHAIN_ABI} == "oabi" ] ; then \
echo "Incorrect ABI setting" ; \
exit 1 ; \
fi ; \
#
# Check that the external toolchain supports C++
#
check_cplusplus = \
if ! test -x $(TARGET_CXX) ; then \
echo "BR2_INSTALL_LIBSTDCPP is selected but C++ support not available in external toolchain" ; \
exit 1 ; \
fi ; \
#
# Check that the cross-compiler given in the configuration exists
#
check_cross_compiler_exists = \
if ! test -x $(TARGET_CC) ; then \
echo "Cannot find cross-compiler $(TARGET_CC)" ; \
exit 1 ; \
fi ; \
uclibc: dependencies $(STAMP_DIR)/ext-toolchain-installed
EXTERNAL_LIBS=ld*.so libc.so libcrypt.so libdl.so libgcc_s.so libm.so libnsl.so libresolv.so librt.so libutil.so
ifeq ($(BR2_TOOLCHAIN_EXTERNAL_GCLIBC),y)
EXTERNAL_LIBS+=libnss_files.so libnss_dns.so
endif
ifeq ($(BR2_INSTALL_LIBSTDCPP),y)
EXTERNAL_LIBS+=libstdc++.so
endif
ifneq ($(BR2_PTHREADS_NONE),y)
EXTERNAL_LIBS+=libpthread.so
ifeq ($(BR2_PACKAGE_GDB_SERVER),y)
EXTERNAL_LIBS+=libthread_db.so
endif # gdbserver
endif # ! no threads
external-toolchain: Support for multilib toolchains Multilib toolchains provide different versions of the base libraries for different architecture variants. For example, the ARM Codesourcery toolchain provides base libraries for ARMv5 (default), ARMv4t and Thumb2. Depending on the -march= argument passed to gcc, the sysroot used by the compiler is therefore different. This means that the sysroot location in CROSS-gcc -v cannot be used. Instead, we must use CROSS-gcc -print-sysroot when available and fall back to the old way if unavailable. Moreover, we cannot simply copy the full sysroot as we used to do, because the sysroot organization of multilib toolchain is more complicated. In Codesourcery toolchains, we have : / etc -- for ARMv5 lib -- for ARMv5 sbin -- for ARMv5 usr -- for ARMv5 (includes headers) armv4t etc -- for ARMv4t lib -- for ARMv4t sbin -- for ARMv4t usr -- for ARMv4t (no headers!) thumb2 etc -- for Thumb2 lib -- for Thumb2 sbin -- for Thumb2 usr -- for Thumb2 (no headers!) So we have the default ARMv5 architecture variant that is installed in the main directory, and we have subdirectories for the ARMv4t and Thumb2 architecture variants. Copying the full sysroot to the staging directory doesn't work. All our packages are based on the fact that they should install libraries in staging/usr/lib. But if ARMv4t is used, the compiler would only look in staging/armv4t/usr/lib for libraries (even when overriding the sysroot with the --sysroot option, the multilib compiler suffixes the sysroot directory with the architecture variant if it matches a recognized one). Therefore, we have to copy only the sysroot that we are interested in. This is rendered a little bit complicated by the fact that the armv4t and thumb2 sysroot do not contain the headers since they are shared with the armv5 sysroot. So, this patch : * Modifies how we compute SYSROOT_DIR in order to use -print-sysroot if it exists. SYSROOT_DIR contains the location of the main sysroot directory, i.e the sysroot for the default architecture variant. * Defines ARCH_SUBDIR as the subdirectory in the main sysroot for the currently selected architecture variant (in our case, it can be ".", "armv4t" or "thumb2"). ARCH_SYSROOT_DIR is defined as the full path to the sysroot of the currently selected architecture variant. * Modifies copy_toolchain_lib_root (which copies a library to the target/ directory) so that libraries are taken from ARCH_SYSROOT_DIR instead of SYSROOT_DIR. This ensures that libraries for the correct architecture variant are properly copied to the target. * Modifies copy_toolchain_sysroot (which copies the sysroot to the staging/ directory), so that it copies the contents of ARCH_SYSROOT_DIR, and if needed, adds the headers from the main sysroot directory and a symbolic link (armv4t -> . or thumb2 -> .) to make the compiler believe that its sysroot is really in armv4t/ or thumb2/. Tested with Codesourcery 2009q1 ARM toolchain, Crosstool-NG ARM glibc and ARM uClibc toolchains. Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
2009-08-22 01:13:22 +02:00
# SYSROOT_DIR selection. We first try the -print-sysroot option,
# available in gcc 4.4.x and in some Codesourcery toolchains. If this
# option is not available, we fallback to the value of --with-sysroot
# as visible in CROSS-gcc -v. We don't pass any option to gcc that
# could select a multilib variant as we want the "main" sysroot, which
# contains all variants of the C library in the case of multilib
# toolchains.
external-toolchain: Support for multilib toolchains Multilib toolchains provide different versions of the base libraries for different architecture variants. For example, the ARM Codesourcery toolchain provides base libraries for ARMv5 (default), ARMv4t and Thumb2. Depending on the -march= argument passed to gcc, the sysroot used by the compiler is therefore different. This means that the sysroot location in CROSS-gcc -v cannot be used. Instead, we must use CROSS-gcc -print-sysroot when available and fall back to the old way if unavailable. Moreover, we cannot simply copy the full sysroot as we used to do, because the sysroot organization of multilib toolchain is more complicated. In Codesourcery toolchains, we have : / etc -- for ARMv5 lib -- for ARMv5 sbin -- for ARMv5 usr -- for ARMv5 (includes headers) armv4t etc -- for ARMv4t lib -- for ARMv4t sbin -- for ARMv4t usr -- for ARMv4t (no headers!) thumb2 etc -- for Thumb2 lib -- for Thumb2 sbin -- for Thumb2 usr -- for Thumb2 (no headers!) So we have the default ARMv5 architecture variant that is installed in the main directory, and we have subdirectories for the ARMv4t and Thumb2 architecture variants. Copying the full sysroot to the staging directory doesn't work. All our packages are based on the fact that they should install libraries in staging/usr/lib. But if ARMv4t is used, the compiler would only look in staging/armv4t/usr/lib for libraries (even when overriding the sysroot with the --sysroot option, the multilib compiler suffixes the sysroot directory with the architecture variant if it matches a recognized one). Therefore, we have to copy only the sysroot that we are interested in. This is rendered a little bit complicated by the fact that the armv4t and thumb2 sysroot do not contain the headers since they are shared with the armv5 sysroot. So, this patch : * Modifies how we compute SYSROOT_DIR in order to use -print-sysroot if it exists. SYSROOT_DIR contains the location of the main sysroot directory, i.e the sysroot for the default architecture variant. * Defines ARCH_SUBDIR as the subdirectory in the main sysroot for the currently selected architecture variant (in our case, it can be ".", "armv4t" or "thumb2"). ARCH_SYSROOT_DIR is defined as the full path to the sysroot of the currently selected architecture variant. * Modifies copy_toolchain_lib_root (which copies a library to the target/ directory) so that libraries are taken from ARCH_SYSROOT_DIR instead of SYSROOT_DIR. This ensures that libraries for the correct architecture variant are properly copied to the target. * Modifies copy_toolchain_sysroot (which copies the sysroot to the staging/ directory), so that it copies the contents of ARCH_SYSROOT_DIR, and if needed, adds the headers from the main sysroot directory and a symbolic link (armv4t -> . or thumb2 -> .) to make the compiler believe that its sysroot is really in armv4t/ or thumb2/. Tested with Codesourcery 2009q1 ARM toolchain, Crosstool-NG ARM glibc and ARM uClibc toolchains. Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
2009-08-22 01:13:22 +02:00
SYSROOT_DIR=$(shell $(TARGET_CC) -print-sysroot 2>/dev/null)
ifeq ($(SYSROOT_DIR),)
SYSROOT_DIR=$(shell readlink -f $$(LANG=C $(TARGET_CC) -print-file-name=libc.a |sed -r -e 's:usr/lib/libc\.a::;'))
external-toolchain: Support for multilib toolchains Multilib toolchains provide different versions of the base libraries for different architecture variants. For example, the ARM Codesourcery toolchain provides base libraries for ARMv5 (default), ARMv4t and Thumb2. Depending on the -march= argument passed to gcc, the sysroot used by the compiler is therefore different. This means that the sysroot location in CROSS-gcc -v cannot be used. Instead, we must use CROSS-gcc -print-sysroot when available and fall back to the old way if unavailable. Moreover, we cannot simply copy the full sysroot as we used to do, because the sysroot organization of multilib toolchain is more complicated. In Codesourcery toolchains, we have : / etc -- for ARMv5 lib -- for ARMv5 sbin -- for ARMv5 usr -- for ARMv5 (includes headers) armv4t etc -- for ARMv4t lib -- for ARMv4t sbin -- for ARMv4t usr -- for ARMv4t (no headers!) thumb2 etc -- for Thumb2 lib -- for Thumb2 sbin -- for Thumb2 usr -- for Thumb2 (no headers!) So we have the default ARMv5 architecture variant that is installed in the main directory, and we have subdirectories for the ARMv4t and Thumb2 architecture variants. Copying the full sysroot to the staging directory doesn't work. All our packages are based on the fact that they should install libraries in staging/usr/lib. But if ARMv4t is used, the compiler would only look in staging/armv4t/usr/lib for libraries (even when overriding the sysroot with the --sysroot option, the multilib compiler suffixes the sysroot directory with the architecture variant if it matches a recognized one). Therefore, we have to copy only the sysroot that we are interested in. This is rendered a little bit complicated by the fact that the armv4t and thumb2 sysroot do not contain the headers since they are shared with the armv5 sysroot. So, this patch : * Modifies how we compute SYSROOT_DIR in order to use -print-sysroot if it exists. SYSROOT_DIR contains the location of the main sysroot directory, i.e the sysroot for the default architecture variant. * Defines ARCH_SUBDIR as the subdirectory in the main sysroot for the currently selected architecture variant (in our case, it can be ".", "armv4t" or "thumb2"). ARCH_SYSROOT_DIR is defined as the full path to the sysroot of the currently selected architecture variant. * Modifies copy_toolchain_lib_root (which copies a library to the target/ directory) so that libraries are taken from ARCH_SYSROOT_DIR instead of SYSROOT_DIR. This ensures that libraries for the correct architecture variant are properly copied to the target. * Modifies copy_toolchain_sysroot (which copies the sysroot to the staging/ directory), so that it copies the contents of ARCH_SYSROOT_DIR, and if needed, adds the headers from the main sysroot directory and a symbolic link (armv4t -> . or thumb2 -> .) to make the compiler believe that its sysroot is really in armv4t/ or thumb2/. Tested with Codesourcery 2009q1 ARM toolchain, Crosstool-NG ARM glibc and ARM uClibc toolchains. Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
2009-08-22 01:13:22 +02:00
endif
# Now, find if the toolchain specifies a sub-directory for the
# specific architecture variant we're interested in. This is the case
# with multilib toolchain, when the selected architecture variant is
# not the default one. To do so, we ask the compiler by passing all
# flags, except the --sysroot flag since we want to the compiler to
# tell us where its original sysroot is. ARCH_SUBDIR will contain the
external-toolchain: Support for multilib toolchains Multilib toolchains provide different versions of the base libraries for different architecture variants. For example, the ARM Codesourcery toolchain provides base libraries for ARMv5 (default), ARMv4t and Thumb2. Depending on the -march= argument passed to gcc, the sysroot used by the compiler is therefore different. This means that the sysroot location in CROSS-gcc -v cannot be used. Instead, we must use CROSS-gcc -print-sysroot when available and fall back to the old way if unavailable. Moreover, we cannot simply copy the full sysroot as we used to do, because the sysroot organization of multilib toolchain is more complicated. In Codesourcery toolchains, we have : / etc -- for ARMv5 lib -- for ARMv5 sbin -- for ARMv5 usr -- for ARMv5 (includes headers) armv4t etc -- for ARMv4t lib -- for ARMv4t sbin -- for ARMv4t usr -- for ARMv4t (no headers!) thumb2 etc -- for Thumb2 lib -- for Thumb2 sbin -- for Thumb2 usr -- for Thumb2 (no headers!) So we have the default ARMv5 architecture variant that is installed in the main directory, and we have subdirectories for the ARMv4t and Thumb2 architecture variants. Copying the full sysroot to the staging directory doesn't work. All our packages are based on the fact that they should install libraries in staging/usr/lib. But if ARMv4t is used, the compiler would only look in staging/armv4t/usr/lib for libraries (even when overriding the sysroot with the --sysroot option, the multilib compiler suffixes the sysroot directory with the architecture variant if it matches a recognized one). Therefore, we have to copy only the sysroot that we are interested in. This is rendered a little bit complicated by the fact that the armv4t and thumb2 sysroot do not contain the headers since they are shared with the armv5 sysroot. So, this patch : * Modifies how we compute SYSROOT_DIR in order to use -print-sysroot if it exists. SYSROOT_DIR contains the location of the main sysroot directory, i.e the sysroot for the default architecture variant. * Defines ARCH_SUBDIR as the subdirectory in the main sysroot for the currently selected architecture variant (in our case, it can be ".", "armv4t" or "thumb2"). ARCH_SYSROOT_DIR is defined as the full path to the sysroot of the currently selected architecture variant. * Modifies copy_toolchain_lib_root (which copies a library to the target/ directory) so that libraries are taken from ARCH_SYSROOT_DIR instead of SYSROOT_DIR. This ensures that libraries for the correct architecture variant are properly copied to the target. * Modifies copy_toolchain_sysroot (which copies the sysroot to the staging/ directory), so that it copies the contents of ARCH_SYSROOT_DIR, and if needed, adds the headers from the main sysroot directory and a symbolic link (armv4t -> . or thumb2 -> .) to make the compiler believe that its sysroot is really in armv4t/ or thumb2/. Tested with Codesourcery 2009q1 ARM toolchain, Crosstool-NG ARM glibc and ARM uClibc toolchains. Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
2009-08-22 01:13:22 +02:00
# subdirectory, in the main SYSROOT_DIR, that corresponds to the
# selected architecture variant. ARCH_SYSROOT_DIR will contain the
# full path to this location.
TARGET_CFLAGS_NO_SYSROOT=$(filter-out --sysroot=%,$(TARGET_CFLAGS))
ARCH_SUBDIR=$(shell $(TARGET_CC) $(TARGET_CFLAGS_NO_SYSROOT) -print-multi-directory)
external-toolchain: Support for multilib toolchains Multilib toolchains provide different versions of the base libraries for different architecture variants. For example, the ARM Codesourcery toolchain provides base libraries for ARMv5 (default), ARMv4t and Thumb2. Depending on the -march= argument passed to gcc, the sysroot used by the compiler is therefore different. This means that the sysroot location in CROSS-gcc -v cannot be used. Instead, we must use CROSS-gcc -print-sysroot when available and fall back to the old way if unavailable. Moreover, we cannot simply copy the full sysroot as we used to do, because the sysroot organization of multilib toolchain is more complicated. In Codesourcery toolchains, we have : / etc -- for ARMv5 lib -- for ARMv5 sbin -- for ARMv5 usr -- for ARMv5 (includes headers) armv4t etc -- for ARMv4t lib -- for ARMv4t sbin -- for ARMv4t usr -- for ARMv4t (no headers!) thumb2 etc -- for Thumb2 lib -- for Thumb2 sbin -- for Thumb2 usr -- for Thumb2 (no headers!) So we have the default ARMv5 architecture variant that is installed in the main directory, and we have subdirectories for the ARMv4t and Thumb2 architecture variants. Copying the full sysroot to the staging directory doesn't work. All our packages are based on the fact that they should install libraries in staging/usr/lib. But if ARMv4t is used, the compiler would only look in staging/armv4t/usr/lib for libraries (even when overriding the sysroot with the --sysroot option, the multilib compiler suffixes the sysroot directory with the architecture variant if it matches a recognized one). Therefore, we have to copy only the sysroot that we are interested in. This is rendered a little bit complicated by the fact that the armv4t and thumb2 sysroot do not contain the headers since they are shared with the armv5 sysroot. So, this patch : * Modifies how we compute SYSROOT_DIR in order to use -print-sysroot if it exists. SYSROOT_DIR contains the location of the main sysroot directory, i.e the sysroot for the default architecture variant. * Defines ARCH_SUBDIR as the subdirectory in the main sysroot for the currently selected architecture variant (in our case, it can be ".", "armv4t" or "thumb2"). ARCH_SYSROOT_DIR is defined as the full path to the sysroot of the currently selected architecture variant. * Modifies copy_toolchain_lib_root (which copies a library to the target/ directory) so that libraries are taken from ARCH_SYSROOT_DIR instead of SYSROOT_DIR. This ensures that libraries for the correct architecture variant are properly copied to the target. * Modifies copy_toolchain_sysroot (which copies the sysroot to the staging/ directory), so that it copies the contents of ARCH_SYSROOT_DIR, and if needed, adds the headers from the main sysroot directory and a symbolic link (armv4t -> . or thumb2 -> .) to make the compiler believe that its sysroot is really in armv4t/ or thumb2/. Tested with Codesourcery 2009q1 ARM toolchain, Crosstool-NG ARM glibc and ARM uClibc toolchains. Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
2009-08-22 01:13:22 +02:00
ARCH_SYSROOT_DIR=$(SYSROOT_DIR)/$(ARCH_SUBDIR)
$(STAMP_DIR)/ext-toolchain-installed:
@echo "Checking external toolchain settings"
$(Q)$(call check_cross_compiler_exists)
ifeq ($(strip $(SYSROOT_DIR)),)
@echo "External toolchain doesn't support --sysroot. Cannot use."
exit 1
endif
ifeq ($(BR2_arm),y)
$(Q)$(call check_arm_abi)
endif
ifeq ($(BR2_INSTALL_LIBSTDCPP),y)
$(Q)$(call check_cplusplus)
endif
ifeq ($(BR2_TOOLCHAIN_EXTERNAL_UCLIBC),y)
$(Q)$(call check_uclibc,$(SYSROOT_DIR))
else
$(Q)$(call check_glibc,$(SYSROOT_DIR))
endif
mkdir -p $(TARGET_DIR)/lib
@echo "Copy external toolchain libraries to target..."
$(Q)for libs in $(EXTERNAL_LIBS); do \
external-toolchain: Support for multilib toolchains Multilib toolchains provide different versions of the base libraries for different architecture variants. For example, the ARM Codesourcery toolchain provides base libraries for ARMv5 (default), ARMv4t and Thumb2. Depending on the -march= argument passed to gcc, the sysroot used by the compiler is therefore different. This means that the sysroot location in CROSS-gcc -v cannot be used. Instead, we must use CROSS-gcc -print-sysroot when available and fall back to the old way if unavailable. Moreover, we cannot simply copy the full sysroot as we used to do, because the sysroot organization of multilib toolchain is more complicated. In Codesourcery toolchains, we have : / etc -- for ARMv5 lib -- for ARMv5 sbin -- for ARMv5 usr -- for ARMv5 (includes headers) armv4t etc -- for ARMv4t lib -- for ARMv4t sbin -- for ARMv4t usr -- for ARMv4t (no headers!) thumb2 etc -- for Thumb2 lib -- for Thumb2 sbin -- for Thumb2 usr -- for Thumb2 (no headers!) So we have the default ARMv5 architecture variant that is installed in the main directory, and we have subdirectories for the ARMv4t and Thumb2 architecture variants. Copying the full sysroot to the staging directory doesn't work. All our packages are based on the fact that they should install libraries in staging/usr/lib. But if ARMv4t is used, the compiler would only look in staging/armv4t/usr/lib for libraries (even when overriding the sysroot with the --sysroot option, the multilib compiler suffixes the sysroot directory with the architecture variant if it matches a recognized one). Therefore, we have to copy only the sysroot that we are interested in. This is rendered a little bit complicated by the fact that the armv4t and thumb2 sysroot do not contain the headers since they are shared with the armv5 sysroot. So, this patch : * Modifies how we compute SYSROOT_DIR in order to use -print-sysroot if it exists. SYSROOT_DIR contains the location of the main sysroot directory, i.e the sysroot for the default architecture variant. * Defines ARCH_SUBDIR as the subdirectory in the main sysroot for the currently selected architecture variant (in our case, it can be ".", "armv4t" or "thumb2"). ARCH_SYSROOT_DIR is defined as the full path to the sysroot of the currently selected architecture variant. * Modifies copy_toolchain_lib_root (which copies a library to the target/ directory) so that libraries are taken from ARCH_SYSROOT_DIR instead of SYSROOT_DIR. This ensures that libraries for the correct architecture variant are properly copied to the target. * Modifies copy_toolchain_sysroot (which copies the sysroot to the staging/ directory), so that it copies the contents of ARCH_SYSROOT_DIR, and if needed, adds the headers from the main sysroot directory and a symbolic link (armv4t -> . or thumb2 -> .) to make the compiler believe that its sysroot is really in armv4t/ or thumb2/. Tested with Codesourcery 2009q1 ARM toolchain, Crosstool-NG ARM glibc and ARM uClibc toolchains. Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
2009-08-22 01:13:22 +02:00
$(call copy_toolchain_lib_root,$(ARCH_SYSROOT_DIR),$$libs,$(BR2_TOOLCHAIN_EXTERNAL_STRIP)); \
done
@echo "Copy external toolchain sysroot to staging..."
external-toolchain: Support for multilib toolchains Multilib toolchains provide different versions of the base libraries for different architecture variants. For example, the ARM Codesourcery toolchain provides base libraries for ARMv5 (default), ARMv4t and Thumb2. Depending on the -march= argument passed to gcc, the sysroot used by the compiler is therefore different. This means that the sysroot location in CROSS-gcc -v cannot be used. Instead, we must use CROSS-gcc -print-sysroot when available and fall back to the old way if unavailable. Moreover, we cannot simply copy the full sysroot as we used to do, because the sysroot organization of multilib toolchain is more complicated. In Codesourcery toolchains, we have : / etc -- for ARMv5 lib -- for ARMv5 sbin -- for ARMv5 usr -- for ARMv5 (includes headers) armv4t etc -- for ARMv4t lib -- for ARMv4t sbin -- for ARMv4t usr -- for ARMv4t (no headers!) thumb2 etc -- for Thumb2 lib -- for Thumb2 sbin -- for Thumb2 usr -- for Thumb2 (no headers!) So we have the default ARMv5 architecture variant that is installed in the main directory, and we have subdirectories for the ARMv4t and Thumb2 architecture variants. Copying the full sysroot to the staging directory doesn't work. All our packages are based on the fact that they should install libraries in staging/usr/lib. But if ARMv4t is used, the compiler would only look in staging/armv4t/usr/lib for libraries (even when overriding the sysroot with the --sysroot option, the multilib compiler suffixes the sysroot directory with the architecture variant if it matches a recognized one). Therefore, we have to copy only the sysroot that we are interested in. This is rendered a little bit complicated by the fact that the armv4t and thumb2 sysroot do not contain the headers since they are shared with the armv5 sysroot. So, this patch : * Modifies how we compute SYSROOT_DIR in order to use -print-sysroot if it exists. SYSROOT_DIR contains the location of the main sysroot directory, i.e the sysroot for the default architecture variant. * Defines ARCH_SUBDIR as the subdirectory in the main sysroot for the currently selected architecture variant (in our case, it can be ".", "armv4t" or "thumb2"). ARCH_SYSROOT_DIR is defined as the full path to the sysroot of the currently selected architecture variant. * Modifies copy_toolchain_lib_root (which copies a library to the target/ directory) so that libraries are taken from ARCH_SYSROOT_DIR instead of SYSROOT_DIR. This ensures that libraries for the correct architecture variant are properly copied to the target. * Modifies copy_toolchain_sysroot (which copies the sysroot to the staging/ directory), so that it copies the contents of ARCH_SYSROOT_DIR, and if needed, adds the headers from the main sysroot directory and a symbolic link (armv4t -> . or thumb2 -> .) to make the compiler believe that its sysroot is really in armv4t/ or thumb2/. Tested with Codesourcery 2009q1 ARM toolchain, Crosstool-NG ARM glibc and ARM uClibc toolchains. Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
2009-08-22 01:13:22 +02:00
$(Q)$(call copy_toolchain_sysroot,$(SYSROOT_DIR),$(ARCH_SYSROOT_DIR),$(ARCH_SUBDIR))
# Create lib64 symbolic links if needed
$(Q)if [ -L $(ARCH_SYSROOT_DIR)/lib64 ] ; then \
$(call create_lib64_symlinks) ; \
fi
@touch $@