From patchwork Thu Nov 13 23:03:24 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Romain Naour X-Patchwork-Id: 410639 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from fraxinus.osuosl.org (fraxinus.osuosl.org [140.211.166.137]) by ozlabs.org (Postfix) with ESMTP id 520EE1400DD for ; Fri, 14 Nov 2014 10:03:42 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id 88719A35C3; Thu, 13 Nov 2014 23:03:41 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from fraxinus.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id dynmTUSwyjgA; Thu, 13 Nov 2014 23:03:39 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by fraxinus.osuosl.org (Postfix) with ESMTP id 60E27A35D1; Thu, 13 Nov 2014 23:03:38 +0000 (UTC) X-Original-To: buildroot@lists.busybox.net Delivered-To: buildroot@osuosl.org Received: from whitealder.osuosl.org (whitealder.osuosl.org [140.211.166.138]) by ash.osuosl.org (Postfix) with ESMTP id D25BA1CEDA9 for ; Thu, 13 Nov 2014 23:03:35 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id CC4BA92A19 for ; Thu, 13 Nov 2014 23:03:35 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 3NmMUlTDCIuK for ; Thu, 13 Nov 2014 23:03:34 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from smtp5-g21.free.fr (smtp5-g21.free.fr [212.27.42.5]) by whitealder.osuosl.org (Postfix) with ESMTPS id 4004892935 for ; Thu, 13 Nov 2014 23:03:34 +0000 (UTC) Received: from localhost.localdomain (unknown [81.57.22.125]) by smtp5-g21.free.fr (Postfix) with ESMTP id 70ACDD48076; Fri, 14 Nov 2014 00:03:23 +0100 (CET) From: Romain Naour To: buildroot@buildroot.org Date: Fri, 14 Nov 2014 00:03:24 +0100 Message-Id: <1415919806-13005-2-git-send-email-romain.naour@openwide.fr> X-Mailer: git-send-email 1.9.3 In-Reply-To: <1415919806-13005-1-git-send-email-romain.naour@openwide.fr> References: <1415919806-13005-1-git-send-email-romain.naour@openwide.fr> Cc: thomas.petazzoni@free-electrons.com, yann.morin.1998@free.fr Subject: [Buildroot] [PATCH v3 1/3] toolchain-external: Detect empty or invalid sysroot X-BeenThere: buildroot@busybox.net X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Discussion and development of buildroot List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: buildroot-bounces@busybox.net Sender: "buildroot" With the Sourcery Codebench standard edition, the sysroot returned point to a non existant directory if no CFLAGS are specified. Here are the results of -print-sysroot gcc option: $ ./i686-pc-linux-gnu-gcc -print-sysroot Full/path/to/i686-pc-linux-gnu/libc/system32 (doesn't exist) $ ./i686-pc-linux-gnu-gcc -m64 -print-sysroot Full/path/to/i686-pc-linux-gnu/libc/system64 (doesn't exist) $ ./i686-pc-linux-gnu-gcc -msgxx-glibc -print-sysroot Full/path/to/i686-pc-linux-gnu/libc/sgxx-glibc (exist) The problem is that in the "libc" directory there is only the sub-directory "sgxx-glibc". Therefore all hearders files and libraries are only available in arch specific sysroot. When using the -print-file-name gcc option, the result is quite buggy and it is not empty. $ ./i686-pc-linux-gnu-gcc -print-file-name=libc.a libc.a So the toolchain check fail because $PWD/libc.a is used as SYSROOT_DIR since the toolchain-external backend does not always use CFLAGS. This patch change the SYSROOT_DIR/ARCH_SYSROOT_DIR detection logic so that if SYSROOT_DIR is empty/bogus, then the same value as ARCH_SYSROOT_DIR is used. This ensures that both SYSROOT_DIR and ARCH_SYSROOT_DIR point to valid directories (which would the same in the case of this toolchain, which brings us back to the non-multilib toolchain case). If toolchain_find_sysroot() was used without flags, then flags are added to allow the fallback to arch sysroot. In normal cases the same behavior as before is expected. If toolchain_find_sysroot() was used with flags, then it's replaced by toolchain_find_arch_sysroot() with the same flags. Signed-off-by: Romain Naour --- v3: no change v2: new patch --- toolchain/toolchain-external/toolchain-external.mk | 28 +++++++++++++++------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/toolchain/toolchain-external/toolchain-external.mk b/toolchain/toolchain-external/toolchain-external.mk index da3718c..109af21 100644 --- a/toolchain/toolchain-external/toolchain-external.mk +++ b/toolchain/toolchain-external/toolchain-external.mk @@ -432,9 +432,9 @@ define toolchain_find_libc_a $$(readlink -f $$(LANG=C $(1) -print-file-name=libc.a)) endef -# Returns the sysroot location for the given compiler + flags -define toolchain_find_sysroot -$$(echo -n $(call toolchain_find_libc_a,$(1)) | sed -r -e 's:(usr/)?lib(32|64)?/([^/]*/)?libc\.a::') +# Returns the arch sysroot location for the given compiler + flags +define toolchain_find_arch_sysroot +$$(echo -n $(call toolchain_find_libc_a,$(1) $(2)) | sed -r -e 's:(usr/)?lib(32|64)?/([^/]*/)?libc\.a::') endef # Returns the lib subdirectory for the given compiler + flags (i.e @@ -443,6 +443,18 @@ define toolchain_find_libdir $$(echo -n $(call toolchain_find_libc_a,$(1)) | sed -r -e 's:.*/(usr/)?(lib(32|64)?)/([^/]*/)?libc.a:\2:') endef +# Returns the main sysroot location for the given compiler + flags +# First, try to find the sysroot without flags. +# If the sysroot path is empty/bogus then use the arch sysroot instead. +define toolchain_find_sysroot +$$(main_sysroot="$(call toolchain_find_arch_sysroot,$(1))"; \ +if ! test -d $${main_sysroot}; then \ + echo -n $(call toolchain_find_arch_sysroot,$(1), $(2)) ; \ +else \ + echo -n $${main_sysroot}; \ +fi) +endef + # 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, @@ -450,13 +462,13 @@ endef define TOOLCHAIN_EXTERNAL_CONFIGURE_CMDS $(Q)$(call check_cross_compiler_exists,$(TOOLCHAIN_EXTERNAL_CC)) $(Q)$(call check_unusable_toolchain,$(TOOLCHAIN_EXTERNAL_CC)) - $(Q)SYSROOT_DIR="$(call toolchain_find_sysroot,$(TOOLCHAIN_EXTERNAL_CC))" ; \ + $(Q)SYSROOT_DIR="$(call toolchain_find_sysroot,$(TOOLCHAIN_EXTERNAL_CC), $(TOOLCHAIN_EXTERNAL_CFLAGS))" ; \ if test -z "$${SYSROOT_DIR}" ; then \ @echo "External toolchain doesn't support --sysroot. Cannot use." ; \ exit 1 ; \ fi ; \ $(call check_kernel_headers_version,\ - $(call toolchain_find_sysroot,$(TOOLCHAIN_EXTERNAL_CC)),\ + $(call toolchain_find_sysroot,$(TOOLCHAIN_EXTERNAL_CC), $(TOOLCHAIN_EXTERNAL_CFLAGS)),\ $(call qstrip,$(BR2_TOOLCHAIN_HEADERS_AT_LEAST))); \ if test "$(BR2_arm)" = "y" ; then \ $(call check_arm_abi,\ @@ -539,12 +551,12 @@ endif # to the target filesystem. define TOOLCHAIN_EXTERNAL_INSTALL_CORE - $(Q)SYSROOT_DIR="$(call toolchain_find_sysroot,$(TOOLCHAIN_EXTERNAL_CC))" ; \ + $(Q)SYSROOT_DIR="$(call toolchain_find_sysroot,$(TOOLCHAIN_EXTERNAL_CC), $(TOOLCHAIN_EXTERNAL_CFLAGS))" ; \ if test -z "$${SYSROOT_DIR}" ; then \ @echo "External toolchain doesn't support --sysroot. Cannot use." ; \ exit 1 ; \ fi ; \ - ARCH_SYSROOT_DIR="$(call toolchain_find_sysroot,$(TOOLCHAIN_EXTERNAL_CC) $(TOOLCHAIN_EXTERNAL_CFLAGS))" ; \ + ARCH_SYSROOT_DIR="$(call toolchain_find_arch_sysroot,$(TOOLCHAIN_EXTERNAL_CC), $(TOOLCHAIN_EXTERNAL_CFLAGS))" ; \ ARCH_LIB_DIR="$(call toolchain_find_libdir,$(TOOLCHAIN_EXTERNAL_CC) $(TOOLCHAIN_EXTERNAL_CFLAGS))" ; \ SUPPORT_LIB_DIR="" ; \ if test `find $${ARCH_SYSROOT_DIR} -name 'libstdc++.a' | wc -l` -eq 0 ; then \ @@ -590,7 +602,7 @@ ifeq ($(BR2_BFIN_INSTALL_FDPIC_SHARED),y) define TOOLCHAIN_EXTERNAL_INSTALL_BFIN_FDPIC $(Q)$(call MESSAGE,"Install external toolchain FDPIC libraries to target...") ; \ FDPIC_EXTERNAL_CC=$(dir $(TOOLCHAIN_EXTERNAL_CC))/../../bfin-linux-uclibc/bin/bfin-linux-uclibc-gcc ; \ - FDPIC_SYSROOT_DIR="$(call toolchain_find_sysroot,$${FDPIC_EXTERNAL_CC} $(TOOLCHAIN_EXTERNAL_CFLAGS))" ; \ + FDPIC_SYSROOT_DIR="$(call toolchain_find_arch_sysroot,$${FDPIC_EXTERNAL_CC}, $(TOOLCHAIN_EXTERNAL_CFLAGS))" ; \ FDPIC_LIB_DIR="$(call toolchain_find_libdir,$${FDPIC_EXTERNAL_CC} $(TOOLCHAIN_EXTERNAL_CFLAGS))" ; \ FDPIC_SUPPORT_LIB_DIR="" ; \ if test `find $${FDPIC_SYSROOT_DIR} -name 'libstdc++.a' | wc -l` -eq 0 ; then \