Buildroot Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Yann E. MORIN <yann.morin.1998@free.fr>
To: buildroot@busybox.net
Subject: [Buildroot] [PATCH] external-toolchain: Detect linux/version.h via cross compiler
Date: Tue, 3 Nov 2020 21:16:40 +0100	[thread overview]
Message-ID: <20201103201640.GI2887157@scaer> (raw)
In-Reply-To: <20201023093641.619746-1-raj.khem@gmail.com>

Khem, All,

On 2020-10-23 02:36 -0700, Khem Raj spake thusly:
> Using linux/version.h is assumed to be hardcoded inside sysroot but this
> does not consider the case where toolchains might be built with
> --with-native-system-header-dir which means the header directories will
> not be under <sysroot>/usr/include but customized, archlinux, debian
> built cross toolchains use these install settings ( due to multiarch )
> they have the headers installed like /usr/aarch64-linux-gnu/include and
> not /usr/aarch64-linux-gnu/usr/include
> 
> This patch adds logic to use cross compiler to compute the path to
> linux/version.h on the fly, it means we do not really need to assume the
> install structure
> 
> Fixes built when using external toolchains provided by archlinux e.g.

So, to summarise our previous discussion on IRC the other day:

  - Buildroot does not officially support distributions' cross
    toolchains, as they may contain extra libraries that are not
    accoutned for by Buildroot,

  - those toolchains are also not always relocatable, even if some
    might be.

Also, Thomas since replied with further questionning, so we really need
a bit more details in there, and how you manage to make it work.

Regards,
Yann E. MORIN.

> Signed-off-by: Khem Raj <raj.khem@gmail.com>
> Cc: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
> ---
>  support/scripts/check-kernel-headers.sh           | 15 ++++++++++++++-
>  toolchain/helpers.mk                              |  2 +-
>  .../toolchain-external/pkg-toolchain-external.mk  |  3 ++-
>  3 files changed, 17 insertions(+), 3 deletions(-)
> 
> diff --git a/support/scripts/check-kernel-headers.sh b/support/scripts/check-kernel-headers.sh
> index 4e6dce5487..5cedb9a082 100755
> --- a/support/scripts/check-kernel-headers.sh
> +++ b/support/scripts/check-kernel-headers.sh
> @@ -21,6 +21,9 @@ SYSROOT="${2}"
>  HDR_VER="${3}.0.0"
>  CHECK="${4}"  # 'strict' or 'loose'
>  
> +# cross compiler passed in case of external toolchains
> +CROSS_CC="${5}"
> +
>  HDR_M="${HDR_VER%%.*}"
>  HDR_V="${HDR_VER#*.}"
>  HDR_m="${HDR_V%%.*}"
> @@ -36,11 +39,21 @@ trap 'rm -f "${EXEC}"' EXIT
>  
>  EXEC="$(mktemp -p "${BUILDDIR}" -t .check-headers.XXXXXX)"
>  
> +if [ -n "${CROSS_CC}" ]; then
> +  MAKE_VER_H=$(${CROSS_CC} -M -xc - <<_EOF_
> +#include <linux/version.h>
> +_EOF_
> +  )
> +  VER_H=`echo $MAKE_VER_H | awk 'END {print $NF}'`
> +else
> +  VER_H="${SYSROOT}/usr/include/linux/version.h"
> +fi
> +
>  # We do not want to account for the patch-level, since headers are
>  # not supposed to change for different patchlevels, so we mask it out.
>  # This only applies to kernels >= 3.0, but those are the only one
>  # we actually care about; we treat all 2.6.x kernels equally.
> -${HOSTCC} -imacros "${SYSROOT}/usr/include/linux/version.h" \
> +${HOSTCC} -imacros "${VER_H}" \
>            -x c -o "${EXEC}" - <<_EOF_
>  #include <stdio.h>
>  #include <stdlib.h>
> diff --git a/toolchain/helpers.mk b/toolchain/helpers.mk
> index 17bc159f3e..51d840b176 100644
> --- a/toolchain/helpers.mk
> +++ b/toolchain/helpers.mk
> @@ -166,7 +166,7 @@ copy_toolchain_sysroot = \
>  #
>  check_kernel_headers_version = \
>  	if ! support/scripts/check-kernel-headers.sh $(1) $(2) $(3) \
> -		$(if $(BR2_TOOLCHAIN_HEADERS_LATEST),$(4),strict); \
> +		$(if $(BR2_TOOLCHAIN_HEADERS_LATEST),$(4),strict) $(5); \
>  	then \
>  		exit 1; \
>  	fi
> diff --git a/toolchain/toolchain-external/pkg-toolchain-external.mk b/toolchain/toolchain-external/pkg-toolchain-external.mk
> index 6d91cb5d1e..93f725dada 100644
> --- a/toolchain/toolchain-external/pkg-toolchain-external.mk
> +++ b/toolchain/toolchain-external/pkg-toolchain-external.mk
> @@ -549,7 +549,8 @@ define $(2)_CONFIGURE_CMDS
>  		$$(BUILD_DIR),\
>  		$$(call toolchain_find_sysroot,$$(TOOLCHAIN_EXTERNAL_CC)),\
>  		$$(call qstrip,$$(BR2_TOOLCHAIN_HEADERS_AT_LEAST)),\
> -		$$(if $$(BR2_TOOLCHAIN_EXTERNAL_CUSTOM),loose,strict)); \
> +		$$(if $$(BR2_TOOLCHAIN_EXTERNAL_CUSTOM),loose,strict),\
> +		$$(TOOLCHAIN_EXTERNAL_CC)); \
>  	$$(call check_gcc_version,$$(TOOLCHAIN_EXTERNAL_CC),\
>  		$$(call qstrip,$$(BR2_TOOLCHAIN_GCC_AT_LEAST))); \
>  	if test "$$(BR2_arm)" = "y" ; then \
> -- 
> 2.29.0
> 
> _______________________________________________
> buildroot mailing list
> buildroot at busybox.net
> http://lists.busybox.net/mailman/listinfo/buildroot

-- 
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 561 099 427 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'

  parent reply	other threads:[~2020-11-03 20:16 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-23  9:36 [Buildroot] [PATCH] external-toolchain: Detect linux/version.h via cross compiler Khem Raj
2020-11-03 20:00 ` Thomas Petazzoni
2020-11-03 20:19   ` Khem Raj
2020-11-03 20:16 ` Yann E. MORIN [this message]
2020-11-03 20:25   ` Khem Raj
2020-11-03 20:43     ` Thomas Petazzoni
2020-11-04  3:24       ` Khem Raj
2022-01-08 23:03 ` Thomas Petazzoni
2022-01-13 17:02   ` Khem Raj

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201103201640.GI2887157@scaer \
    --to=yann.morin.1998@free.fr \
    --cc=buildroot@busybox.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox