Skip to contentSkip to conversation

fix mips/Makefile to support CROSS_COMPILE from environment var

PATCH In review Tim Bird 8 participants 16 messages May 4, 2006 – May 8, 2006 MIPS

lore
Share & tools
lore

Tim Bird

author
#0 lore raw

PATCH 1/1 fix mips/Makefile to support CROSS_COMPILE from environment var

The following patch allows to build using CROSS_COMPILE from the environment. I have an automated system which works like this, but it chokes on MIPS when I use it with (albeit non-standard-named) cross-compiler tools. An easy workaround I'm using is to put CROSS_COMPILE on the make command line, but it would be nice to use the definition already in the environment when I work manually in the system.

For past discussion of this see:
http://www.linux-mips.org/archives/linux-mips/2003-02/msg00196.html

I'm not sure why the change didn't make it in back in 2003, but if the complaint was about the use of "?=", that seems to be in use other places, and fairly standard now.

For example, from the top level kernel Makefile:
ARCH ?= $(SUBARCH)
CROSS_COMPILE ?=

---

arch/mips/Makefile +1 -1
@@ -49,7 +49,7 @@ UTS_MACHINE		:= mips64
 endif
 
 ifdef CONFIG_CROSSCOMPILE
-CROSS_COMPILE		= $(tool-prefix)
+CROSS_COMPILE		?= $(tool-prefix)
 endif
 
 CHECKFLAGS-y				+= -D__linux__ -D__mips__ \
#1 lore raw
Quoted 10 lines · Tim Bird

The following patch allows to build using CROSS_COMPILE from the environment. I have an automated system which works like this, but it chokes on MIPS when I use it with (albeit non-standard-named) cross-compiler tools. An easy workaround I'm using is to put CROSS_COMPILE on the make command line, but it would be nice to use the definition already in the environment when I work manually in the system.

For past discussion of this see:
http://www.linux-mips.org/archives/linux-mips/2003-02/msg00196.html

Quoted 7 lines

I'm not sure why the change didn't make it in back in 2003, but if the complaint was about the use of "?=", that seems to be in use other places, and fairly standard now.

For example, from the top level kernel Makefile:
ARCH ?= $(SUBARCH)
CROSS_COMPILE ?=

It looks like the other arch-specific Makefiles also override the environment. To work around the problem, you can disable CONFIG_CROSSCOMPILE and define CROSS_COMPILE in the environment.

Strangely enough, the help for CONFIG_CROSSCOMPILE already explains that.

Thiemo

#2 lore raw
Quoted 19 lines · Thiemo Seufer
Quoted 10 lines · Tim Bird

The following patch allows to build using CROSS_COMPILE from the environment. I have an automated system which works like this, but it chokes on MIPS when I use it with (albeit non-standard-named) cross-compiler tools. An easy workaround I'm using is to put CROSS_COMPILE on the make command line, but it would be nice to use the definition already in the environment when I work manually in the system.

For past discussion of this see:
http://www.linux-mips.org/archives/linux-mips/2003-02/msg00196.html

Quoted 7 lines

I'm not sure why the change didn't make it in back in 2003, but if the complaint was about the use of "?=", that seems to be in use other places, and fairly standard now.

For example, from the top level kernel Makefile:
ARCH ?= $(SUBARCH)
CROSS_COMPILE ?=

Quoted 6 lines

It looks like the other arch-specific Makefiles also override the environment. To work around the problem, you can disable CONFIG_CROSSCOMPILE and define CROSS_COMPILE in the environment.

Strangely enough, the help for CONFIG_CROSSCOMPILE already explains that.

Let me ask a stupid question. With all of the ways to otherwise do a cross compile, why a config option on MIPS? ARM*/SH*, which are at least as likely to not be native-compiled, don't do that. Just something I've always wondered, really.

Signature · 2 lines
Tom Rini
http://gate.crashing.org/~trini/
#3 lore raw
Quoted 4 lines

Let me ask a stupid question. With all of the ways to otherwise do a cross compile, why a config option on MIPS? ARM*/SH*, which are at least as likely to not be native-compiled, don't do that. Just something I've always wondered, really.

Probably because, unlike ARM and SH, the MIPS architecture began life as a workstation/server processor, and for a while there cross-compilation was the exception rather than the rule.

Regards,

Kevin K.

#4 lore raw
Quoted 8 lines
Quoted 4 lines

Let me ask a stupid question. With all of the ways to otherwise do a cross compile, why a config option on MIPS? ARM*/SH*, which are at least as likely to not be native-compiled, don't do that. Just something I've always wondered, really.

Probably because, unlike ARM and SH, the MIPS architecture began life as a workstation/server processor, and for a while there cross-compilation was the exception rather than the rule.

Before anyone else jumps in, yeah, ARM was sort-of a workstation processor to begin with, too, but I don't think the original Acorn RISC Machine was set up to run a "real" OS, with memory management, etc., whereas MIPS was.

Regards,

Kevin K.

#5 lore raw
In reply to Kevin D. Kissell
Quoted 8 lines · Kevin D. Kissell
Quoted 4 lines

Let me ask a stupid question. With all of the ways to otherwise do a cross compile, why a config option on MIPS? ARM*/SH*, which are at least as likely to not be native-compiled, don't do that. Just something I've always wondered, really.

Probably because, unlike ARM and SH, the MIPS architecture began life as a workstation/server processor, and for a while there cross-compilation was the exception rather than the rule.

OK, PowerPC. My kinda question/point was perhaps it's time to deprecate CONFIG_CROSSCOMPILE in favor of env or make to bring it in line with other arches (similar to how 2.4 had a few ways for arch/$(ARCH)/*config/ dirs, 2.6 is uniform).

Signature · 2 lines
Tom Rini
http://gate.crashing.org/~trini/
#6 lore raw
In reply to Tom Rini
Quoted 4 lines · Tom Rini

Let me ask a stupid question. With all of the ways to otherwise do a cross compile, why a config option on MIPS? ARM*/SH*, which are at least as likely to not be native-compiled, don't do that. Just something I've always wondered, really.

Having such information in an environment variable is imho terribly inelegant, having to pass it on the command line for each make invocation is terrible abuse for the fingertips so I went for this option which makes the makefile pick the right prefix.

Ralf

#7 lore raw
Quoted 11 lines · Ralf Baechle
Quoted 4 lines · Tom Rini

Let me ask a stupid question. With all of the ways to otherwise do a cross compile, why a config option on MIPS? ARM*/SH*, which are at least as likely to not be native-compiled, don't do that. Just something I've always wondered, really.

Having such information in an environment variable is imho terribly inelegant, having to pass it on the command line for each make invocation is terrible abuse for the fingertips so I went for this option which makes the makefile pick the right prefix.

I don't suppose you'd be willing to front pushing that to the rest of the world then, would you? Inconsistency is more of a problem for me than changing any of my scripts to use something else :)

Signature · 2 lines
Tom Rini
http://gate.crashing.org/~trini/
#8 lore raw
Quoted 8 lines · Tom Rini
Quoted 7 lines · Ralf Baechle
Quoted 4 lines · Tom Rini

Let me ask a stupid question. With all of the ways to otherwise do a cross compile, why a config option on MIPS? ARM*/SH*, which are at least as likely to not be native-compiled, don't do that. Just something I've always wondered, really.

Quoted 8 lines
Quoted 4 lines

Having such information in an environment variable is imho terribly inelegant, having to pass it on the command line for each make invocation is terrible abuse for the fingertips so I went for this option which makes the makefile pick the right prefix.

I don't suppose you'd be willing to front pushing that to the rest of the world then, would you? Inconsistency is more of a problem for me than changing any of my scripts to use something else :)

... I forgot this doesn't take a string value of what to use but hard-coded options.

Signature · 2 lines
Tom Rini
http://gate.crashing.org/~trini/
#9 lore raw
Quoted 4 lines · Tom Rini
Quoted 3 lines · Tom Rini
Quoted 2 lines · Ralf Baechle

On Thu, May 04, 2006 at 02:04:49PM -0700, Tom Rini wrote:

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 4 lines

Let me ask a stupid question. With all of the ways to otherwise do a cross compile, why a config option on MIPS? ARM*/SH*, which are at least as likely to not be native-compiled, don't do that. Just something I've always wondered, really.

Having such information in an environment variable is imho terribly inelegant, having to pass it on the command line for each make invocation is terrible abuse for the fingertips so I went for this option which makes

You can make it so that you can use both, right? This is what the suggested patch does. No CROSS_COMPILE in env or on the make command line means a native compilation.

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

the makefile pick the right prefix.

I don't suppose you'd be willing to front pushing that to the rest of the world then, would you? Inconsistency is more of a problem for me than changing any of my scripts to use something else :)

... I forgot this doesn't take a string value of what to use but hard-coded options.

So let it take a string option, and make it generic.

But on second thought: config options are part of the target configuration, while CROSS_COMPILE= is part of the host configuration, so IMHO it doesn't belong in Kconfig. I.e. do you want to have CONFIG_CROSS_COMPILE set in your defconfig? Yes or no, depending on whether you do cross-compilations or not. So you cannot simply take a defconfig, you'll have to modify it for your host setup.

So I'd prefer to keep the CROSS_COMPILE, like other arches do.

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

#10 lore raw
Quoted 7 lines · In message <[email protected]> you wrote:

But on second thought: config options are part of the target configuration, while CROSS_COMPILE= is part of the host configuration, so IMHO it doesn't belong in Kconfig. I.e. do you want to have CONFIG_CROSS_COMPILE set in your defconfig? Yes or no, depending on whether you do cross-compilations or not. So you cannot simply take a defconfig, you'll have to modify it for your host setup.

CONFIG_CROSS_COMPILE is a terrible idea. Don't do it. We may want to try different tool chains which require different CROSS_COMPILE settings with exact the same default config file. Don't break this!

Quoted 1 line

So I'd prefer to keep the CROSS_COMPILE, like other arches do.

Me too!

Best regards,

Wolfgang Denk

Signature · 4 lines
Software Engineering:  Embedded and Realtime Systems,  Embedded Linux
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: [email protected]
If A equals success, then the formula is A = X + Y + Z. X is work.  Y
is play. Z is keep your mouth shut.                 - Albert Einstein
author
#11 lore raw

Re: [PATCH] fix mips/Makefile to support CROSS_COMPILE from envir onment var

In reply to Ralf Baechle
Quoted 7 lines · Ralf Baechle
Quoted 4 lines · Tom Rini

Let me ask a stupid question. With all of the ways to otherwise do a cross compile, why a config option on MIPS? ARM*/SH*, which are at least as likely to not be native-compiled, don't do that. Just something I've always wondered, really.

Quoted 6 lines

Having such information in an environment variable is imho terribly inelegant, having to pass it on the command line for each make invocation
is terrible abuse for the fingertips so I went for this option which makes
the makefile pick the right prefix.

And a great solution it would be, if it actually picked the right prefix. :-) I understand that having the cross-compiler prefix specified outside the build system has drawbacks. When I first got into embedded Linux (many years ago), I was struck by the inelegance of this also. However, hardcoding the prefixes in the Makefile is, IMHO, not such a great idea either.

It really doesn't bother me if the "standard" prefixes are encoded in a Makefile, but it would be nice to be able to select a non-standard prefix the same way as for other Linux architectures.

I understand I can do that by turning off the "I'm cross-compiling" option, but that seems counterintuitive given the current wording of that option (not-withstanding the not-yet-mainlined help text).

My patch allows to keep the current behaviour, but also supports use of the environment variable. I don't see any downside to it, unless you are actively trying to discourage the use of the environment variable. In my own experience, use of the environment variable, while inelegant for manual use, has certain benefits for automated use.

Regards,
-- Tim

=============================
Tim Bird
Architecture Group Chair, CE Linux Forum
Senior Staff Engineer, Sony Electronics
=============================

#12 lore raw

Re: [PATCH] fix mips/Makefile to support CROSS_COMPILE from envir onment var

Quoted 4 lines · Tim Bird

..... I understand that having the cross-compiler prefix specified outside the build system has drawbacks. When I first got into embedded Linux (many years ago), I was struck by the inelegance of this also.

The only drawback is you have to type it in correctly :-) This "inelegance" of having to set an environment variable has proven extremely useful in many of my experiences with clients building real products. They have installed many different cross compilers, and often use build procedures to meet various configuration management requirements. The
need to explicitly select a complier is absolutely necessary, you can't have a Makefile guessing.

I personally like setting the environment option, and wish MIPS would just drop this whole cross compile selection from the configuration process and work like all of the other architectures.

Thanks.

	-- Dan
author
#13 lore raw
In reply to Thiemo Seufer
Quoted 2 lines · Thiemo Seufer

It looks like the other arch-specific Makefiles also override the environment.

4 other arches I work with don't.

Quoted 2 lines

To work around the problem, you can disable CONFIG_CROSSCOMPILE and define CROSS_COMPILE in the environment.

I thought that might be the case, but that's pretty broken IMHO. It's counterintuitive and undocumented.

Quoted 3 lines

Strangely enough, the help for CONFIG_CROSSCOMPILE already explains that.

Here's the help from my Kconfig.debug:

Say Y here if you are compiling the kernel on a different architecture than the one it is intended to run on.

Am I missing something?
-- Tim

=============================
Tim Bird
Architecture Group Chair, CE Linux Forum
Senior Staff Engineer, Sony Electronics
=============================

#14 lore raw
Quoted 16 lines · Tim Bird
Quoted 2 lines · Thiemo Seufer

It looks like the other arch-specific Makefiles also override the environment.

4 other arches I work with don't.

Quoted 2 lines

To work around the problem, you can disable CONFIG_CROSSCOMPILE and define CROSS_COMPILE in the environment.

I thought that might be the case, but that's pretty broken IMHO. It's counterintuitive and undocumented.

Quoted 3 lines

Strangely enough, the help for CONFIG_CROSSCOMPILE already explains that.

Quoted 6 lines

Here's the help from my Kconfig.debug:

Say Y here if you are compiling the kernel on a different architecture than the one it is intended to run on.

Am I missing something?

Update to a newer version:

config CROSSCOMPILE
bool "Are you using a crosscompiler"
help
Say Y here if you are compiling the kernel on a different architecture than the one it is intended to run on. This is just a convenience option which will select the appropriate value for the CROSS_COMPILE make variable which otherwise has to be passed on the command line from mips-linux-, mipsel-linux-, mips64-linux- and mips64el-linux- as appropriate for a particular kernel configuration. You will have to pass the value for CROSS_COMPILE manually if the name prefix for your tools is different.

Thiemo

author
#15 lore raw
Quoted 1 line · Thiemo Seufer

Update to a newer version:

Of what? I'm using a 2.6.16 kernel here.

Quoted 11 lines

config CROSSCOMPILE
bool "Are you using a crosscompiler"
help
Say Y here if you are compiling the kernel on a different architecture than the one it is intended to run on. This is just a convenience option which will select the appropriate value for the CROSS_COMPILE make variable which otherwise has to be passed on the command line from mips-linux-, mipsel-linux-, mips64-linux- and mips64el-linux- as appropriate for a particular kernel configuration. You will have to pass the value for CROSS_COMPILE manually if the name prefix for your tools is different.

Hmmm. Well, I would say that this should be pushed to mainline, but I still think it could be improved a bit.

IMHO, the config question should be something like:
"Use cross-compiler defined by Makefile", instead of "Are you using a crosscompiler".

My recommendation would be to apply my patch and drop the last sentence. Then you get the best of all worlds:
- support for command line specification, if you use it
- support for env. var specification, if you use it.
- automatic prefix selection if you use this option

=============================
Tim Bird
Architecture Group Chair, CE Linux Forum
Senior Staff Engineer, Sony Electronics
=============================