2010-02-09 21:34:49 +01:00
|
|
|
|
2009-07-17 00:20:33 +02:00
|
|
|
#
|
|
|
|
# This file implements the support for external toolchains, i.e
|
|
|
|
# toolchains that have not been produced by Buildroot itself and that
|
2010-12-13 17:27:39 +01:00
|
|
|
# Buildroot can download from the Web or that are already available on
|
|
|
|
# the system on which Buildroot runs. So far, we have tested this
|
|
|
|
# with:
|
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
|
|
|
#
|
|
|
|
# * Toolchains generated by Crosstool-NG
|
|
|
|
# * Toolchains generated by Buildroot
|
2010-07-05 18:58:59 +02:00
|
|
|
# * ARM, MIPS and PowerPC toolchains made available by
|
|
|
|
# Codesourcery. For the MIPS toolchain, the -muclibc variant isn't
|
|
|
|
# supported yet, only the default glibc-based variant is.
|
2009-07-17 00:20:33 +02:00
|
|
|
#
|
|
|
|
# The basic principle is the following
|
|
|
|
#
|
2010-12-13 17:27:39 +01:00
|
|
|
# 1. a. For toolchains downloaded from the Web, Buildroot already
|
|
|
|
# knows their configuration, so it just downloads them and extract
|
|
|
|
# them in $(TOOLCHAIN_EXTERNAL_DIR).
|
|
|
|
#
|
|
|
|
# 1. b. For pre-installed toolchains, 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.
|
2009-07-17 00:20:33 +02:00
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
|
2009-07-16 19:37:47 +02:00
|
|
|
uclibc: dependencies $(STAMP_DIR)/ext-toolchain-installed
|
|
|
|
|
2010-07-05 18:59:03 +02:00
|
|
|
LIB_EXTERNAL_LIBS=ld*.so libc.so libcrypt.so libdl.so libgcc_s.so libm.so libnsl.so libresolv.so librt.so libutil.so
|
2010-07-08 22:08:46 +02:00
|
|
|
ifeq ($(BR2_TOOLCHAIN_EXTERNAL_GLIBC),y)
|
2010-07-05 18:59:03 +02:00
|
|
|
LIB_EXTERNAL_LIBS+=libnss_files.so libnss_dns.so
|
2009-07-16 23:56:10 +02:00
|
|
|
endif
|
|
|
|
|
2009-07-17 00:26:23 +02:00
|
|
|
ifeq ($(BR2_INSTALL_LIBSTDCPP),y)
|
2010-07-05 18:59:03 +02:00
|
|
|
USR_LIB_EXTERNAL_LIBS+=libstdc++.so
|
2009-07-17 00:26:23 +02:00
|
|
|
endif
|
|
|
|
|
2010-12-13 17:27:44 +01:00
|
|
|
ifeq ($(BR2_TOOLCHAIN_HAS_THREADS),y)
|
2010-07-05 18:59:03 +02:00
|
|
|
LIB_EXTERNAL_LIBS+=libpthread.so
|
2010-05-28 23:23:20 +02:00
|
|
|
ifeq ($(BR2_PACKAGE_GDB_SERVER),y)
|
2010-07-05 18:59:03 +02:00
|
|
|
LIB_EXTERNAL_LIBS+=libthread_db.so
|
2010-05-28 23:23:20 +02:00
|
|
|
endif # gdbserver
|
2010-05-28 23:23:14 +02:00
|
|
|
endif # ! no threads
|
|
|
|
|
2010-12-13 17:27:39 +01:00
|
|
|
# Details about sysroot directory selection.
|
|
|
|
#
|
|
|
|
# To find the sysroot directory:
|
|
|
|
#
|
|
|
|
# * 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.
|
|
|
|
#
|
|
|
|
# When doing those tests, we don't pass any option to gcc that could
|
|
|
|
# select a multilib variant (such as -march) as we want the "main"
|
|
|
|
# sysroot, which contains all variants of the C library in the case of
|
|
|
|
# multilib toolchains. We use the TARGET_CC_NO_SYSROOT variable, which
|
|
|
|
# is the path of the cross-compiler, without the
|
|
|
|
# --sysroot=$(STAGING_DIR), since what we want to find is the location
|
|
|
|
# of the original toolchain sysroot. This "main" sysroot directory is
|
|
|
|
# stored in SYSROOT_DIR.
|
|
|
|
#
|
|
|
|
# Then, multilib toolchains are a little bit more complicated, since
|
|
|
|
# they in fact have multiple sysroots, one for each variant supported
|
|
|
|
# by the toolchain. So we need to find the particular sysroot we're
|
|
|
|
# interested in.
|
|
|
|
#
|
|
|
|
# To do so, we ask the compiler where its sysroot is by passing all
|
|
|
|
# flags (including -march and al.), except the --sysroot flag since we
|
|
|
|
# want to the compiler to tell us where its original sysroot
|
|
|
|
# is. ARCH_SUBDIR will contain the subdirectory, in the main
|
|
|
|
# SYSROOT_DIR, that corresponds to the selected architecture
|
|
|
|
# variant. ARCH_SYSROOT_DIR will contain the full path to this
|
|
|
|
# location.
|
|
|
|
#
|
|
|
|
# One might wonder why we don't just bother with ARCH_SYSROOT_DIR. The
|
|
|
|
# fact is that in multilib toolchains, the header files are often only
|
|
|
|
# present in the main sysroot, and only the libraries are available in
|
|
|
|
# each variant-specific sysroot directory.
|
|
|
|
|
2010-12-07 21:09:56 +01:00
|
|
|
TARGET_CC_NO_SYSROOT=$(filter-out --sysroot=%,$(TARGET_CC_NOCCACHE))
|
2010-12-13 17:27:39 +01:00
|
|
|
|
|
|
|
ifeq ($(BR2_TOOLCHAIN_EXTERNAL_DOWNLOAD),y)
|
|
|
|
TOOLCHAIN_EXTERNAL_DEPENDENCIES = $(TOOLCHAIN_EXTERNAL_DIR)/.extracted
|
|
|
|
else
|
|
|
|
TOOLCHAIN_EXTERNAL_DEPENDENCIES = $(STAMP_DIR)/ext-toolchain-checked
|
|
|
|
endif
|
|
|
|
|
|
|
|
ifeq ($(BR2_TOOLCHAIN_EXTERNAL_CODESOURCERY_ARM2009Q1),y)
|
|
|
|
TOOLCHAIN_EXTERNAL_SITE=http://www.codesourcery.com/sgpp/lite/arm/portal/package5383/public/arm-none-linux-gnueabi/
|
|
|
|
TOOLCHAIN_EXTERNAL_SOURCE=arm-2009q3-67-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2
|
|
|
|
else ifeq ($(BR2_TOOLCHAIN_EXTERNAL_CODESOURCERY_ARM2010Q1),y)
|
|
|
|
TOOLCHAIN_EXTERNAL_SITE=http://www.codesourcery.com/sgpp/lite/arm/portal/package6488/public/arm-none-linux-gnueabi/
|
|
|
|
TOOLCHAIN_EXTERNAL_SOURCE=arm-2010q1-202-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2
|
|
|
|
else ifeq ($(BR2_TOOLCHAIN_EXTERNAL_CODESOURCERY_ARM201009),y)
|
|
|
|
TOOLCHAIN_EXTERNAL_SITE=http://www.codesourcery.com/sgpp/lite/arm/portal/package7851/public/arm-none-linux-gnueabi/
|
|
|
|
TOOLCHAIN_EXTERNAL_SOURCE=arm-2010.09-50-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2
|
|
|
|
else ifeq ($(BR2_TOOLCHAIN_EXTERNAL_CODESOURCERY_MIPS44),y)
|
|
|
|
TOOLCHAIN_EXTERNAL_SITE=http://www.codesourcery.com/sgpp/lite/mips/portal/package7401/public/mips-linux-gnu/
|
|
|
|
TOOLCHAIN_EXTERNAL_SOURCE=mips-4.4-303-mips-linux-gnu-i686-pc-linux-gnu.tar.bz2
|
|
|
|
else ifeq ($(BR2_TOOLCHAIN_EXTERNAL_CODESOURCERY_POWERPC201009),y)
|
|
|
|
TOOLCHAIN_EXTERNAL_SITE=http://www.codesourcery.com/sgpp/lite/power/portal/package7703/public/powerpc-linux-gnu/
|
|
|
|
TOOLCHAIN_EXTERNAL_SOURCE=freescale-2010.09-55-powerpc-linux-gnu-i686-pc-linux-gnu.tar.bz2
|
|
|
|
else ifeq ($(BR2_TOOLCHAIN_EXTERNAL_CODESOURCERY_SH201009),y)
|
|
|
|
TOOLCHAIN_EXTERNAL_SITE=http://www.codesourcery.com/sgpp/lite/superh/portal/package7783/public/sh-linux-gnu/
|
|
|
|
TOOLCHAIN_EXTERNAL_SOURCE=renesas-2010.09-45-sh-linux-gnu-i686-pc-linux-gnu.tar.bz2
|
|
|
|
else
|
|
|
|
# A value must be set (even if unused), otherwise the
|
|
|
|
# $(DL_DIR)/$(TOOLCHAIN_EXTERNAL_SOURCE) rule would override the main
|
|
|
|
# $(DL_DIR) rule
|
|
|
|
TOOLCHAIN_EXTERNAL_SOURCE=none
|
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
|
|
|
|
|
2010-12-13 17:27:39 +01:00
|
|
|
# Download and extraction of a toolchain
|
|
|
|
$(DL_DIR)/$(TOOLCHAIN_EXTERNAL_SOURCE):
|
|
|
|
$(call DOWNLOAD,$(TOOLCHAIN_EXTERNAL_SITE),$(TOOLCHAIN_EXTERNAL_SOURCE))
|
|
|
|
|
|
|
|
$(TOOLCHAIN_EXTERNAL_DIR)/.extracted: $(DL_DIR)/$(TOOLCHAIN_EXTERNAL_SOURCE)
|
|
|
|
mkdir -p $(@D)
|
|
|
|
$(INFLATE$(suffix $(TOOLCHAIN_EXTERNAL_SOURCE))) $^ | $(TAR) $(TAR_STRIP_COMPONENTS)=1 -C $(@D) $(TAR_OPTIONS) -
|
|
|
|
touch $@
|
2009-07-16 23:56:10 +02:00
|
|
|
|
2010-12-13 17:27:39 +01:00
|
|
|
# Checks for an already installed toolchain: check the toolchain
|
|
|
|
# location, check that it supports sysroot, and then verify that it
|
|
|
|
# matches the configuration provided in Buildroot: ABI, C++ support,
|
|
|
|
# type of C library and all C library features.
|
|
|
|
$(STAMP_DIR)/ext-toolchain-checked:
|
Improve external toolchain checks
This patch adds some checks on the external toolchains.
First, it checks that the C library selection is correct, by looking
if gcc is able to find the main C library file through the
-print-file-name option.
Then, it attempts to check if the Buildroot toolchain options match
the configuration of the toolchain :
* for glibc, it checks that IPv6, RPC, locales, wide-char, large file
support Buildroot options are enabled, since with glibc all these
features are always available (at least this is the assumption we
make) ;
* for uClibc, it checks the Buildroot options with the uClibc
configuration file in $SYSROOT_DIR/usr/include/bits/uClibc_config.h
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
2009-05-29 18:38:03 +02:00
|
|
|
@echo "Checking external toolchain settings"
|
2009-07-17 08:53:55 +02:00
|
|
|
$(Q)$(call check_cross_compiler_exists)
|
2010-12-13 17:27:39 +01:00
|
|
|
$(Q)SYSROOT_DIR=`$(TARGET_CC_NO_SYSROOT) -print-sysroot 2>/dev/null` ; \
|
|
|
|
if test -z "$${SYSROOT_DIR}" ; then \
|
|
|
|
SYSROOT_DIR=`readlink -f $$(LANG=C $(TARGET_CC_NO_SYSROOT) -print-file-name=libc.a) |sed -r -e 's:usr/lib/libc\.a::;'` ; \
|
|
|
|
fi ; \
|
|
|
|
if test -z "$${SYSROOT_DIR}" ; then \
|
|
|
|
@echo "External toolchain doesn't support --sysroot. Cannot use." ; \
|
|
|
|
exit 1 ; \
|
|
|
|
fi ; \
|
|
|
|
if test x$(BR2_arm) == x"y" ; then \
|
|
|
|
$(call check_arm_abi) ; \
|
|
|
|
fi ; \
|
|
|
|
if test x$(BR2_INSTALL_LIBSTDCPP) == x"y" ; then \
|
|
|
|
$(call check_cplusplus) ; \
|
|
|
|
fi ; \
|
|
|
|
if test x$(BR2_TOOLCHAIN_EXTERNAL_UCLIBC) == x"y" ; then \
|
|
|
|
$(call check_uclibc,$${SYSROOT_DIR}) ; \
|
|
|
|
else \
|
|
|
|
$(call check_glibc,$${SYSROOT_DIR}) ; \
|
2010-07-05 18:58:58 +02:00
|
|
|
fi
|
2010-12-13 17:27:39 +01:00
|
|
|
|
|
|
|
# Integration of the toolchain into Buildroot: find the main sysroot
|
|
|
|
# and the variant-specific sysroot, then copy the needed libraries to
|
|
|
|
# the $(TARGET_DIR) and copy the whole sysroot (libraries and headers)
|
|
|
|
# to $(STAGING_DIR).
|
|
|
|
$(STAMP_DIR)/ext-toolchain-installed: $(TOOLCHAIN_EXTERNAL_DEPENDENCIES)
|
|
|
|
$(Q)SYSROOT_DIR=`$(TARGET_CC_NO_SYSROOT) -print-sysroot 2>/dev/null` ; \
|
|
|
|
if test -z "$${SYSROOT_DIR}" ; then \
|
|
|
|
SYSROOT_DIR=`readlink -f $$(LANG=C $(TARGET_CC_NO_SYSROOT) -print-file-name=libc.a) |sed -r -e 's:usr/lib/libc\.a::;'` ; \
|
|
|
|
fi ; \
|
|
|
|
if test -z "$${SYSROOT_DIR}" ; then \
|
|
|
|
@echo "External toolchain doesn't support --sysroot. Cannot use." ; \
|
|
|
|
exit 1 ; \
|
|
|
|
fi ; \
|
|
|
|
ARCH_SUBDIR=`$(TARGET_CC_NO_SYSROOT) $(TARGET_CFLAGS) -print-multi-directory` ; \
|
|
|
|
ARCH_SYSROOT_DIR=$${SYSROOT_DIR}/$${ARCH_SUBDIR} ; \
|
|
|
|
mkdir -p $(TARGET_DIR)/lib ; \
|
|
|
|
echo "Copy external toolchain libraries to target..." ; \
|
|
|
|
for libs in $(LIB_EXTERNAL_LIBS); do \
|
2010-12-13 17:27:40 +01:00
|
|
|
$(call copy_toolchain_lib_root,$${ARCH_SYSROOT_DIR},$$libs,/lib); \
|
2010-12-13 17:27:39 +01:00
|
|
|
done ; \
|
|
|
|
for libs in $(USR_LIB_EXTERNAL_LIBS); do \
|
2010-12-13 17:27:40 +01:00
|
|
|
$(call copy_toolchain_lib_root,$${ARCH_SYSROOT_DIR},$$libs,/usr/lib); \
|
2010-12-13 17:27:39 +01:00
|
|
|
done ; \
|
|
|
|
echo "Copy external toolchain sysroot to staging..." ; \
|
|
|
|
$(call copy_toolchain_sysroot,$${SYSROOT_DIR},$${ARCH_SYSROOT_DIR},$${ARCH_SUBDIR}) ; \
|
|
|
|
if [ -L $${ARCH_SYSROOT_DIR}/lib64 ] ; then \
|
|
|
|
$(call create_lib64_symlinks) ; \
|
|
|
|
fi ; \
|
|
|
|
touch $@
|