Skip to contentSkip to conversation

Fix config.mak.uname to allow cross-compilation

PATCH New Mauro Condarelli 2 participants 5 messages May 22, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix config.mak.uname to allow cross-compilation

This patch is part of a patchset for BuildRoot (https://buildroot.org/)
needed to correctly cross-compile GIT.

Git compilation relies on "uname" program to determine several system charcteristics, but that does not work well in a cross-compilation environment because "uname" will run on host, while we are interested in information concerning target.

The file "config.mak.uname" unconditionally assigns variables using ":=", this prevents changing their value from the command line. This minimal patch changes the flavor of the variable and assigns it only if not already assigned, opening the road to spcify target-consistent values on the command line (which is done in the other patches for BuildRoot, but are not relevant here).

We are sending this patch upstream because we feel this might be useful in other cross-compilation contexts.

Note this patch also changes variable "flavor" thus incurring in a computational overhead; Makefile perusal doesn't seem to indicate this as a problem, but it is possible to overcome this problem, if deemed relevant, by using the construct:

  ifeq ($(origin uname_X), undefined)
    uname_X := $(shell sh -c 'uname -x 2>/dev/null || echo not')
  endif

If required I will submit another patch to this effect.

Regards
Mauro

#1 lore raw

PATCH 1/1 Fix config.mak.uname to allow cross-compilation

Current implementation imperatively sets variables from "uname" output. This breaks cross-compilation because uname is run on host while target configuration may be different.

Make current behavior a non-imperative default, so it's possible to force different values setting make variables.

To cross-compile it will be necessary to explicitly set the various uname_X variables to values compatible with target.
No change is needed with normal host compilation.
Patch is trivial.

---
 config.mak.uname | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
config.mak.uname +6 -6
index 40d6b29..d933b23 100644
@@ -1,11 +1,11 @@
 # Platform specific Makefile tweaks based on uname detection
 
-uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not')
-uname_M := $(shell sh -c 'uname -m 2>/dev/null || echo not')
-uname_O := $(shell sh -c 'uname -o 2>/dev/null || echo not')
-uname_R := $(shell sh -c 'uname -r 2>/dev/null || echo not')
-uname_P := $(shell sh -c 'uname -p 2>/dev/null || echo not')
-uname_V := $(shell sh -c 'uname -v 2>/dev/null || echo not')
+uname_S ?= $(shell sh -c 'uname -s 2>/dev/null || echo not')
+uname_M ?= $(shell sh -c 'uname -m 2>/dev/null || echo not')
+uname_O ?= $(shell sh -c 'uname -o 2>/dev/null || echo not')
+uname_R ?= $(shell sh -c 'uname -r 2>/dev/null || echo not')
+uname_P ?= $(shell sh -c 'uname -p 2>/dev/null || echo not')
+uname_V ?= $(shell sh -c 'uname -v 2>/dev/null || echo not')
 
 ifdef MSVC
 	# avoid the MingW and Cygwin configuration sections
Signature · 1 line
2.1.4
#2 lore raw

PATCH 1/1 Fix config.mak.uname to allow cross-compilation

Hello,

Thanks for your contribution.

Quoted 12 lines · Mauro Condarelli

Current implementation imperatively sets variables from "uname" output. This breaks cross-compilation because uname is run on host while target configuration may be different.

Make current behavior a non-imperative default, so it's possible to force different values setting make variables.

To cross-compile it will be necessary to explicitly set the various uname_X variables to values compatible with target.
No change is needed with normal host compilation.
Patch is trivial.

Quoted 4 lines
---
 config.mak.uname | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

This patch cannot be applied, as it is a patch against Git directly, while you should send patches against Buildroot. I.e, a patch that adds a patch.

Best regards,

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
#3 lore raw

PATCH 1/1 Fix config.mak.uname to allow cross-compilation

Thanks Thomas,
comments below.

Il 22/05/2016 22:29, Thomas Petazzoni ha scritto:

Quoted 17 lines

Hello,

Thanks for your contribution.

Quoted 12 lines · Mauro Condarelli

Current implementation imperatively sets variables from "uname" output. This breaks cross-compilation because uname is run on host while target configuration may be different.

Make current behavior a non-imperative default, so it's possible to force different values setting make variables.

To cross-compile it will be necessary to explicitly set the various uname_X variables to values compatible with target.
No change is needed with normal host compilation.
Patch is trivial.

Quoted 7 lines
Quoted 4 lines
---
  config.mak.uname | 12 ++++++------
  1 file changed, 6 insertions(+), 6 deletions(-)

This patch cannot be applied, as it is a patch against Git directly, while you should send patches against Buildroot. I.e, a patch that adds a patch.

I know.
My patchset for BuildRoot is in "[Buildroot] [PATCH v2] Fix for GIT cross-compilation." and includes this patch.
I sent this upstream and it's CC: here only FYI.

Sorry if I broke any rules.
Please advise.

Quoted 4 lines

Best regards,

Thomas

Regards
Mauro

#4 lore raw

PATCH 1/1 Fix config.mak.uname to allow cross-compilation

Hello,

Quoted 7 lines · Mauro Condarelli
Quoted 3 lines

This patch cannot be applied, as it is a patch against Git directly, while you should send patches against Buildroot. I.e, a patch that adds a patch.

I know.
My patchset for BuildRoot is in "[Buildroot] [PATCH v2] Fix for GIT cross-compilation." and includes this patch.
I sent this upstream and it's CC: here only FYI.

Ah, OK, I understand. You didn't break any rule, but I did not realize this patch was for Git upstream and not for Buildroot :/

Thomsa

Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com