All of lore.kernel.org
 help / color / mirror / Atom feed
* [Buildroot] [pull request] Pull request for branch codesourcery-toolchain-support
@ 2010-04-17  0:12 Thomas Petazzoni
  2010-04-17  0:12 ` [Buildroot] [PATCH 1/4] external toolchains: take into account architecture variant Thomas Petazzoni
                   ` (4 more replies)
  0 siblings, 5 replies; 7+ messages in thread
From: Thomas Petazzoni @ 2010-04-17  0:12 UTC (permalink / raw)
  To: buildroot

Hello,

Here is a resend of my CodeSourcery external toolchain support patch
set. I've fixed the merge conflict that Peter had, which was the only
feedback I received on this patchset.

Regards,

Thomas

The following changes since commit 65e209ca07416bc040fe98d16b60b6cb4304987f:
  Peter Korsgaard (1):
        openssl: fix build without ipv6 support

are available in the git repository at:

  git://git.busybox.net/~tpetazzoni/git/buildroot codesourcery-toolchain-support

Thomas Petazzoni (4):
      external toolchains: take into account architecture variant
      external-toolchain: support libraries outside of /lib
      external-toolchain: Support for multilib toolchains
      busybox: make sure architecture flags are used at link time

 package/Makefile.in                      |   22 +++---
 package/busybox/busybox-1.13.x.config    |    1 +
 package/busybox/busybox.mk               |    8 +-
 toolchain/external-toolchain/ext-tool.mk |  109 ++++++++++++++++++++++++-----
 4 files changed, 106 insertions(+), 34 deletions(-)

Thanks,
-- 
Thomas Petazzoni

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Buildroot] [PATCH 1/4] external toolchains: take into account architecture variant
  2010-04-17  0:12 [Buildroot] [pull request] Pull request for branch codesourcery-toolchain-support Thomas Petazzoni
@ 2010-04-17  0:12 ` Thomas Petazzoni
  2010-04-17  0:12 ` [Buildroot] [PATCH 2/4] external-toolchain: support libraries outside of /lib Thomas Petazzoni
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Thomas Petazzoni @ 2010-04-17  0:12 UTC (permalink / raw)
  To: buildroot

Until now, many TARGET_CFLAGS where missing when using an external
toolchain, due to how package/Makefile.in was written. Now, a lot more
definitions are common between the Buildroot toolchain case and the
external toolchain case.

Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
---
 package/Makefile.in |   22 +++++++++++-----------
 1 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/package/Makefile.in b/package/Makefile.in
index 983caf3..3dfc712 100644
--- a/package/Makefile.in
+++ b/package/Makefile.in
@@ -34,16 +34,7 @@ ifeq ($(BR2_DEBUG_3),y)
 TARGET_DEBUGGING=-g3
 endif
 
-
-#########################################################################
-ifeq ($(BR2_TOOLCHAIN_BUILDROOT),y)
-TARGET_CFLAGS=$(TARGET_OPTIMIZATION) $(TARGET_DEBUGGING) \
-	-I$(STAGING_DIR)/usr/include -I$(STAGING_DIR)/include
-TARGET_LDFLAGS+=-L$(STAGING_DIR)/lib -L$(STAGING_DIR)/usr/lib
-ifeq ($(BR2_TOOLCHAIN_SYSROOT),y)
-TARGET_CFLAGS+= $(BR2_SYSROOT) $(BR2_ISYSROOT)
-TARGET_LDFLAGS+= $(BR2_SYSROOT)
-endif
+TARGET_CFLAGS=$(TARGET_OPTIMIZATION) $(TARGET_DEBUGGING)
 
 CC_TARGET_TUNE_:=$(call qstrip,$(BR2_GCC_TARGET_TUNE))
 CC_TARGET_ARCH_:=$(call qstrip,$(BR2_GCC_TARGET_ARCH))
@@ -86,11 +77,20 @@ ifeq ($(BR2_LARGEFILE),y)
 TARGET_CFLAGS+=-D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
 endif
 
+
+#########################################################################
+ifeq ($(BR2_TOOLCHAIN_BUILDROOT),y)
+TARGET_CFLAGS+=-I$(STAGING_DIR)/usr/include -I$(STAGING_DIR)/include
+TARGET_LDFLAGS+=-L$(STAGING_DIR)/lib -L$(STAGING_DIR)/usr/lib
 TARGET_CXXFLAGS=$(TARGET_CFLAGS)
+ifeq ($(BR2_TOOLCHAIN_SYSROOT),y)
+TARGET_CFLAGS+= $(BR2_SYSROOT) $(BR2_ISYSROOT)
+TARGET_LDFLAGS+= $(BR2_SYSROOT)
+endif
 
 #########################################################################
 else ifeq ($(BR2_TOOLCHAIN_EXTERNAL),y)
-TARGET_CFLAGS=$(TARGET_OPTIMIZATION) $(TARGET_DEBUGGING) --sysroot $(STAGING_DIR)/
+TARGET_CFLAGS+=--sysroot $(STAGING_DIR)/
 TARGET_CXXFLAGS=$(TARGET_CFLAGS)
 TARGET_LDFLAGS=--sysroot $(STAGING_DIR)/
 endif
-- 
1.6.3.3

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [Buildroot] [PATCH 2/4] external-toolchain: support libraries outside of /lib
  2010-04-17  0:12 [Buildroot] [pull request] Pull request for branch codesourcery-toolchain-support Thomas Petazzoni
  2010-04-17  0:12 ` [Buildroot] [PATCH 1/4] external toolchains: take into account architecture variant Thomas Petazzoni
@ 2010-04-17  0:12 ` Thomas Petazzoni
  2010-04-17  0:12 ` [Buildroot] [PATCH 3/4] external-toolchain: Support for multilib toolchains Thomas Petazzoni
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Thomas Petazzoni @ 2010-04-17  0:12 UTC (permalink / raw)
  To: buildroot

The copy_toolchain_lib_root function was making the assumption that
all libraries were stored inside the /lib directory of the sysroot
directory. However, this isn't true for certain toolchains,
particularly for the libstdc++ library.

The function is therefore reworked to find the library and its related
symlink either in /lib or /usr/lib in the sysroot, and copies it at
the same location in the target directory.

Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
---
 toolchain/external-toolchain/ext-tool.mk |   23 +++++++++++++----------
 1 files changed, 13 insertions(+), 10 deletions(-)

diff --git a/toolchain/external-toolchain/ext-tool.mk b/toolchain/external-toolchain/ext-tool.mk
index 4493281..29a5cca 100644
--- a/toolchain/external-toolchain/ext-tool.mk
+++ b/toolchain/external-toolchain/ext-tool.mk
@@ -1,3 +1,4 @@
+
 #
 # This file implements the support for external toolchains, i.e
 # toolchains that have not been produced by Buildroot itself and that
@@ -45,27 +46,29 @@ copy_toolchain_lib_root = \
 	DST="$(strip $3)"; \
 	STRIP="$(strip $4)"; \
  \
-	LIB_DIR="$${SYSROOT_DIR}/lib" ; \
-	for FILE in `find $${LIB_DIR} -maxdepth 1 -name "$${LIB}.*"`; do \
+	LIBS=`(cd $${SYSROOT_DIR}; find . -path "./lib/$${LIB}.*" -o -path "./usr/lib/$${LIB}.*")` ; \
+	for FILE in $${LIBS} ; do \
 		LIB=`basename $${FILE}`; \
+		LIBDIR=`dirname $${FILE}` ; \
 		while test \! -z "$${LIB}"; do \
-			rm -fr $(TARGET_DIR)$${DST}/$${LIB}; \
-			mkdir -p $(TARGET_DIR)$${DST}; \
-			if test -h $${LIB_DIR}/$${LIB}; then \
-				cp -d $${LIB_DIR}/$${LIB} $(TARGET_DIR)$${DST}/; \
-			elif test -f $${LIB_DIR}/$${LIB}; then \
-				$(INSTALL) -D -m0755 $${LIB_DIR}/$${LIB} $(TARGET_DIR)$${DST}/$${LIB}; \
+			FULLPATH="$${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}; \
 				case "$${STRIP}" in \
 				(0 | n | no) \
 ;; \
 				(*) \
-					$(TARGET_CROSS)strip "$(TARGET_DIR)$${DST}/$${LIB}"; \
+					$(TARGET_CROSS)strip "$(TARGET_DIR)/$${LIBDIR}/$${LIB}"; \
 ;; \
 				esac; \
 			else \
 				exit -1; \
 			fi; \
-			LIB="`readlink $${LIB_DIR}/$${LIB}`"; \
+			LIB="`readlink $${FULLPATH}`"; \
 		done; \
 	done; \
  \
-- 
1.6.3.3

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [Buildroot] [PATCH 3/4] external-toolchain: Support for multilib toolchains
  2010-04-17  0:12 [Buildroot] [pull request] Pull request for branch codesourcery-toolchain-support Thomas Petazzoni
  2010-04-17  0:12 ` [Buildroot] [PATCH 1/4] external toolchains: take into account architecture variant Thomas Petazzoni
  2010-04-17  0:12 ` [Buildroot] [PATCH 2/4] external-toolchain: support libraries outside of /lib Thomas Petazzoni
@ 2010-04-17  0:12 ` Thomas Petazzoni
  2010-04-17  0:12 ` [Buildroot] [PATCH 4/4] busybox: make sure architecture flags are used at link time Thomas Petazzoni
  2010-04-21  8:40 ` [Buildroot] [pull request] Pull request for branch codesourcery-toolchain-support Peter Korsgaard
  4 siblings, 0 replies; 7+ messages in thread
From: Thomas Petazzoni @ 2010-04-17  0:12 UTC (permalink / raw)
  To: buildroot

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>
---
 toolchain/external-toolchain/ext-tool.mk |   90 ++++++++++++++++++++++++++----
 1 files changed, 79 insertions(+), 11 deletions(-)

diff --git a/toolchain/external-toolchain/ext-tool.mk b/toolchain/external-toolchain/ext-tool.mk
index 29a5cca..2c2562c 100644
--- a/toolchain/external-toolchain/ext-tool.mk
+++ b/toolchain/external-toolchain/ext-tool.mk
@@ -2,7 +2,12 @@
 #
 # This file implements the support for external toolchains, i.e
 # toolchains that have not been produced by Buildroot itself and that
-# are already available on the system on which Buildroot runs.
+# 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
 #
@@ -35,23 +40,22 @@
 # directory to the target directory. Also optionaly strips the
 # library.
 #
-# $1: sysroot directory
+# $1: arch specific sysroot directory
 # $2: library name
 # $3: destination directory
 # $4: strip (y|n), default is to strip
 #
 copy_toolchain_lib_root = \
-	SYSROOT_DIR="$(strip $1)"; \
+	ARCH_SYSROOT_DIR="$(strip $1)"; \
 	LIB="$(strip $2)"; \
-	DST="$(strip $3)"; \
 	STRIP="$(strip $4)"; \
  \
-	LIBS=`(cd $${SYSROOT_DIR}; find . -path "./lib/$${LIB}.*" -o -path "./usr/lib/$${LIB}.*")` ; \
+	LIBS=`(cd $${ARCH_SYSROOT_DIR}; find . -path "./lib/$${LIB}.*" -o -path "./usr/lib/$${LIB}.*")` ; \
 	for FILE in $${LIBS} ; do \
 		LIB=`basename $${FILE}`; \
 		LIBDIR=`dirname $${FILE}` ; \
 		while test \! -z "$${LIB}"; do \
-			FULLPATH="$${SYSROOT_DIR}/$${LIBDIR}/$${LIB}" ; \
+			FULLPATH="$${ARCH_SYSROOT_DIR}/$${LIBDIR}/$${LIB}" ; \
 			rm -fr $(TARGET_DIR)/$${LIBDIR}/$${LIB}; \
 			mkdir -p $(TARGET_DIR)/$${LIBDIR}; \
 			if test -h $${FULLPATH} ; then \
@@ -76,13 +80,54 @@ copy_toolchain_lib_root = \
 
 #
 # Copy the full external toolchain sysroot directory to the staging
-# dir
+# dir. The operation of this function is rendered a little bit
+# complicated by the support for multilib toolchains.
 #
-# $1: sysroot directory
+# 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)"; \
-	cp -a $${SYSROOT_DIR}/* $(STAGING_DIR)/ ; \
+	ARCH_SYSROOT_DIR="$(strip $2)"; \
+	ARCH_SUBDIR="$(strip $3)"; \
+	for i in etc lib sbin usr ; do \
+		cp -a $${ARCH_SYSROOT_DIR}/$$i $(STAGING_DIR)/ ; \
+	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
 
 #
@@ -208,7 +253,30 @@ ifeq ($(BR2_INSTALL_LIBSTDCPP),y)
 EXTERNAL_LIBS+=libstdc++.so
 endif
 
+# 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 the -march= option to gcc
+# as we want the "main" sysroot, which contains all variants of the C
+# library in the case of multilib toolchains.
+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::;'))
+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 the
+# appropriate -march= flags. 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.
+ifneq ($(CC_TARGET_ARCH_),)
+TARGET_CC_ARCH_CFLAGS+=-march=$(CC_TARGET_ARCH_)
+endif
+ARCH_SUBDIR=$(shell $(TARGET_CC) $(TARGET_CC_ARCH_CFLAGS) -print-multi-directory)
+ARCH_SYSROOT_DIR=$(SYSROOT_DIR)/$(ARCH_SUBDIR)
 
 $(STAMP_DIR)/ext-toolchain-installed:
 	@echo "Checking external toolchain settings"
@@ -228,8 +296,8 @@ endif
 	mkdir -p $(TARGET_DIR)/lib
 	@echo "Copy external toolchain libraries to target..."
 	$(Q)for libs in $(EXTERNAL_LIBS); do \
-		$(call copy_toolchain_lib_root,$(SYSROOT_DIR),$$libs,/lib,$(BR2_TOOLCHAIN_EXTERNAL_STRIP)); \
+		$(call copy_toolchain_lib_root,$(ARCH_SYSROOT_DIR),$$libs,$(BR2_TOOLCHAIN_EXTERNAL_STRIP)); \
 	done
 	@echo "Copy external toolchain sysroot to staging..."
-	$(Q)$(call copy_toolchain_sysroot,$(SYSROOT_DIR))
+	$(Q)$(call copy_toolchain_sysroot,$(SYSROOT_DIR),$(ARCH_SYSROOT_DIR),$(ARCH_SUBDIR))
 	@touch $@
-- 
1.6.3.3

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [Buildroot] [PATCH 4/4] busybox: make sure architecture flags are used at link time
  2010-04-17  0:12 [Buildroot] [pull request] Pull request for branch codesourcery-toolchain-support Thomas Petazzoni
                   ` (2 preceding siblings ...)
  2010-04-17  0:12 ` [Buildroot] [PATCH 3/4] external-toolchain: Support for multilib toolchains Thomas Petazzoni
@ 2010-04-17  0:12 ` Thomas Petazzoni
  2010-04-21  8:40 ` [Buildroot] [pull request] Pull request for branch codesourcery-toolchain-support Peter Korsgaard
  4 siblings, 0 replies; 7+ messages in thread
From: Thomas Petazzoni @ 2010-04-17  0:12 UTC (permalink / raw)
  To: buildroot

When compiling Busybox, according to readelf -A, all object files were
properly compiled according to the select architecture (-march=armv4t
for example), but the final busybox binary could be of a different
architecture (ARMv5t even if ARMv4t was selected).

This patch changes the way we configure/compile Busybox so that our
CFLAGS aren't anymore passed through the make EXTRA_CFLAGS variable,
but through the .config CONFIG_EXTRA_CFLAGS variable. Unfortunately,
those variables don't have exactly the same semantic for the Busybox
build system.

Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
---
 package/busybox/busybox-1.13.x.config |    1 +
 package/busybox/busybox.mk            |    8 ++++----
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/package/busybox/busybox-1.13.x.config b/package/busybox/busybox-1.13.x.config
index ee59162..059a0b3 100644
--- a/package/busybox/busybox-1.13.x.config
+++ b/package/busybox/busybox-1.13.x.config
@@ -47,6 +47,7 @@ CONFIG_FEATURE_SYSLOG=y
 # CONFIG_FEATURE_SHARED_BUSYBOX is not set
 # CONFIG_LFS is not set
 CONFIG_CROSS_COMPILER_PREFIX=""
+CONFIG_EXTRA_CFLAGS=""
 
 #
 # Debugging Options
diff --git a/package/busybox/busybox.mk b/package/busybox/busybox.mk
index c93f33a..05a6d94 100644
--- a/package/busybox/busybox.mk
+++ b/package/busybox/busybox.mk
@@ -45,6 +45,8 @@ $(BUSYBOX_DIR)/.config: $(BUSYBOX_DIR)/.unpacked $(BUSYBOX_CONFIG_FILE)
 	cp -f $(BUSYBOX_CONFIG_FILE) $(BUSYBOX_DIR)/.config
 	$(SED) s,^CONFIG_PREFIX=.*,CONFIG_PREFIX=\"$(TARGET_DIR)\", \
 		$(BUSYBOX_DIR)/.config
+	$(SED) 's,^CONFIG_EXTRA_CFLAGS=.*,CONFIG_EXTRA_CFLAGS=\"$(BUSYBOX_CFLAGS)\",' \
+		$(BUSYBOX_DIR)/.config
 # id applet breaks on >=1.13.0 with old uclibc unless the bb pwd routines are used
 ifeq ($(BR2_BUSYBOX_VERSION_1_13_X)$(BR2_BUSYBOX_VERSION_1_14_X)$(BR2_UCLIBC_VERSION_0_9_28_3)$(BR2_UCLIBC_VERSION_0_9_29),yy)
 	if grep -q 'CONFIG_ID=y' $(BUSYBOX_DIR)/.config; \
@@ -105,15 +107,13 @@ endif
 $(BUSYBOX_DIR)/busybox: $(BUSYBOX_DIR)/.config
 	$(MAKE) CC=$(TARGET_CC) CROSS_COMPILE="$(TARGET_CROSS)" \
 		CROSS="$(TARGET_CROSS)" PREFIX="$(TARGET_DIR)" \
-		ARCH=$(KERNEL_ARCH) \
-		EXTRA_CFLAGS="$(BUSYBOX_CFLAGS)" -C $(BUSYBOX_DIR)
+		ARCH=$(KERNEL_ARCH) -C $(BUSYBOX_DIR)
 
 $(TARGET_DIR)/bin/busybox: $(BUSYBOX_DIR)/busybox
 ifeq ($(BR2_PACKAGE_BUSYBOX_FULLINSTALL),y)
 	$(MAKE) CC=$(TARGET_CC) CROSS_COMPILE="$(TARGET_CROSS)" \
 		CROSS="$(TARGET_CROSS)" PREFIX="$(TARGET_DIR)" \
-		ARCH=$(KERNEL_ARCH) \
-		EXTRA_CFLAGS="$(BUSYBOX_CFLAGS)" -C $(BUSYBOX_DIR) install
+		ARCH=$(KERNEL_ARCH) -C $(BUSYBOX_DIR) install
 else
 	install -D -m 0755 $(BUSYBOX_DIR)/busybox $(TARGET_DIR)/bin/busybox
 endif
-- 
1.6.3.3

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [Buildroot] [pull request] Pull request for branch codesourcery-toolchain-support
  2010-04-17  0:12 [Buildroot] [pull request] Pull request for branch codesourcery-toolchain-support Thomas Petazzoni
                   ` (3 preceding siblings ...)
  2010-04-17  0:12 ` [Buildroot] [PATCH 4/4] busybox: make sure architecture flags are used at link time Thomas Petazzoni
@ 2010-04-21  8:40 ` Peter Korsgaard
  4 siblings, 0 replies; 7+ messages in thread
From: Peter Korsgaard @ 2010-04-21  8:40 UTC (permalink / raw)
  To: buildroot

>>>>> "Thomas" == Thomas Petazzoni <thomas.petazzoni@free-electrons.com> writes:

 Thomas> Hello,
 Thomas> Here is a resend of my CodeSourcery external toolchain support patch
 Thomas> set. I've fixed the merge conflict that Peter had, which was the only
 Thomas> feedback I received on this patchset.

Pulled and pushed, thanks!

-- 
Bye, Peter Korsgaard

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Buildroot] [PATCH 3/4] external-toolchain: Support for multilib toolchains
  2010-04-05 21:27 Thomas Petazzoni
@ 2010-04-05 21:28 ` Thomas Petazzoni
  0 siblings, 0 replies; 7+ messages in thread
From: Thomas Petazzoni @ 2010-04-05 21:28 UTC (permalink / raw)
  To: buildroot

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>
---
 toolchain/external-toolchain/ext-tool.mk |   88 ++++++++++++++++++++++++++----
 1 files changed, 78 insertions(+), 10 deletions(-)

diff --git a/toolchain/external-toolchain/ext-tool.mk b/toolchain/external-toolchain/ext-tool.mk
index 071c1e7..00da0a4 100644
--- a/toolchain/external-toolchain/ext-tool.mk
+++ b/toolchain/external-toolchain/ext-tool.mk
@@ -2,7 +2,12 @@
 #
 # This file implements the support for external toolchains, i.e
 # toolchains that have not been produced by Buildroot itself and that
-# are already available on the system on which Buildroot runs.
+# 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
 #
@@ -35,18 +40,17 @@
 # directory to the target directory. Also optionaly strips the
 # library.
 #
-# $1: sysroot directory
+# $1: arch specific sysroot directory
 # $2: library name
 # $3: destination directory
 # $4: strip (y|n), default is to strip
 #
 copy_toolchain_lib_root = \
-	SYSROOT_DIR="$(strip $1)"; \
+	ARCH_SYSROOT_DIR="$(strip $1)"; \
 	LIB="$(strip $2)"; \
-	DST="$(strip $3)"; \
 	STRIP="$(strip $4)"; \
  \
-	LIBS=`(cd $${SYSROOT_DIR}; find . -path "./lib/$${LIB}.*" -o -path "./usr/lib/$${LIB}.*")` ; \
+	LIBS=`(cd $${ARCH_SYSROOT_DIR}; find . -path "./lib/$${LIB}.*" -o -path "./usr/lib/$${LIB}.*")` ; \
 	for FILE in $${LIBS} ; do \
 		LIB=`basename $${FILE}`; \
 		LIBDIR=`dirname $${FILE}` ; \
@@ -76,13 +80,54 @@ copy_toolchain_lib_root = \
 
 #
 # Copy the full external toolchain sysroot directory to the staging
-# dir
+# dir. The operation of this function is rendered a little bit
+# complicated by the support for multilib toolchains.
 #
-# $1: sysroot directory
+# 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)"; \
-	cp -a $${SYSROOT_DIR}/* $(STAGING_DIR)/ ; \
+	ARCH_SYSROOT_DIR="$(strip $2)"; \
+	ARCH_SUBDIR="$(strip $3)"; \
+	for i in etc lib sbin usr ; do \
+		cp -a $${ARCH_SYSROOT_DIR}/$$i $(STAGING_DIR)/ ; \
+	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
 
 #
@@ -208,6 +253,14 @@ ifeq ($(BR2_INSTALL_LIBSTDCPP),y)
 EXTERNAL_LIBS+=libstdc++.so
 endif
 
+# 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 the -march= option to gcc
+# as we want the "main" sysroot, which contains all variants of the C
+# library in the case of multilib toolchains.
+SYSROOT_DIR=$(shell $(TARGET_CC) -print-sysroot 2>/dev/null)
+ifeq ($(SYSROOT_DIR),)
 # This dance is needed because the toolchain may have been relocated, so the
 # configured paths may no longer match; fortunately, the sysroot moves along
 # the toolchain, so is always at the same place relative to the toolchain's
@@ -216,6 +269,21 @@ CFG_PREFIX_DIR=$(shell LANG=C $(TARGET_CC) -v 2>&1 | grep ^Configured | tr " " "
 CFG_SYSROOT_DIR=$(shell LANG=C $(TARGET_CC) -v 2>&1 | grep ^Configured | tr " " "\n" | grep -- "--with-sysroot=" | cut -f2 -d=)
 REL_SYSROOT_DIR=$(shell echo "$(CFG_SYSROOT_DIR)" |sed -r -e 's:^$(CFG_PREFIX_DIR)::;')
 SYSROOT_DIR=$(TOOLCHAIN_EXTERNAL_PATH)/$(REL_SYSROOT_DIR)
+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 the
+# appropriate -march= flags. 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.
+ifneq ($(CC_TARGET_ARCH_),)
+TARGET_CC_ARCH_CFLAGS+=-march=$(CC_TARGET_ARCH_)
+endif
+ARCH_SUBDIR=$(shell $(TARGET_CC) $(TARGET_CC_ARCH_CFLAGS) -print-multi-directory)
+ARCH_SYSROOT_DIR=$(SYSROOT_DIR)/$(ARCH_SUBDIR)
 
 $(STAMP_DIR)/ext-toolchain-installed:
 	@echo "Checking external toolchain settings"
@@ -235,8 +303,8 @@ endif
 	mkdir -p $(TARGET_DIR)/lib
 	@echo "Copy external toolchain libraries to target..."
 	$(Q)for libs in $(EXTERNAL_LIBS); do \
-		$(call copy_toolchain_lib_root,$(SYSROOT_DIR),$$libs,/lib,$(BR2_TOOLCHAIN_EXTERNAL_STRIP)); \
+		$(call copy_toolchain_lib_root,$(ARCH_SYSROOT_DIR),$$libs,$(BR2_TOOLCHAIN_EXTERNAL_STRIP)); \
 	done
 	@echo "Copy external toolchain sysroot to staging..."
-	$(Q)$(call copy_toolchain_sysroot,$(SYSROOT_DIR))
+	$(Q)$(call copy_toolchain_sysroot,$(SYSROOT_DIR),$(ARCH_SYSROOT_DIR),$(ARCH_SUBDIR))
 	@touch $@
-- 
1.6.3.3

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2010-04-21  8:40 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-04-17  0:12 [Buildroot] [pull request] Pull request for branch codesourcery-toolchain-support Thomas Petazzoni
2010-04-17  0:12 ` [Buildroot] [PATCH 1/4] external toolchains: take into account architecture variant Thomas Petazzoni
2010-04-17  0:12 ` [Buildroot] [PATCH 2/4] external-toolchain: support libraries outside of /lib Thomas Petazzoni
2010-04-17  0:12 ` [Buildroot] [PATCH 3/4] external-toolchain: Support for multilib toolchains Thomas Petazzoni
2010-04-17  0:12 ` [Buildroot] [PATCH 4/4] busybox: make sure architecture flags are used at link time Thomas Petazzoni
2010-04-21  8:40 ` [Buildroot] [pull request] Pull request for branch codesourcery-toolchain-support Peter Korsgaard
  -- strict thread matches above, loose matches on Subject: below --
2010-04-05 21:27 Thomas Petazzoni
2010-04-05 21:28 ` [Buildroot] [PATCH 3/4] external-toolchain: Support for multilib toolchains Thomas Petazzoni

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.