[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [lmi] Specify '--build' for cross compilation?
From: |
Vadim Zeitlin |
Subject: |
Re: [lmi] Specify '--build' for cross compilation? |
Date: |
Wed, 17 Aug 2016 00:51:24 +0200 |
On Tue, 16 Aug 2016 22:06:54 +0000 Greg Chicares <address@hidden> wrote:
GC> Vadim--Although I'm on vacation, I was looking over some tentative
GC> local changes to support cross-compiling lmi binaries for msw in a
GC> GNU/Linux (debian 8.5) chroot, and it seems clear that I should use
GC> --host=i686-w64-mingw32
GC> but should '--build' be specified at all?
I always do specify it when cross-compiling but after reading this message
I realized that I've been only doing this out of habit, so I decided to
check if it's really needed.
Autoconf documentation definitely seems to imply that it is and even
explains why:
If you specify --host, but not --build, when configure performs the
first compiler test it tries to run an executable produced by the
compiler. If the execution fails, it enters cross-compilation mode.
This is fragile. Moreover, by the time the compiler test is
performed, it may be too late to modify the build-system type:
other tests may have already been performed. Therefore, whenever
you specify --host, be sure to specify --build too.
(from
https://www.gnu.org/software/autoconf/manual/autoconf-2.69/html_node/Hosts-and-Cross_002dCompilation.html)
And looking at the generated configure script sources confirms the
behaviour documented above: the "cross_compiling" variable is set to "yes"
if both host and build options are used (a piece of autoconf trivia: it
turns out that these options can be abbreviated to their first letters,
e.g. you could do --ho=i686-w64-mingw32 -bu=i686-pc-cygwin -- and now,
after sharing it with you, I'll try to forget this knowledge a.s.a.p.) and
their values are different, but only to "maybe" if the build option wasn't
used and in this case configure indeed tries to determine whether it can
execute the program compiled for the host on the build system to decide if
it's really cross-compiling.
So, to summarize, there is at least one good reason for using --build:
doing it clearly indicates to configure that we're cross-compiling and at
the very least saves time that would be wasted on running the test checking
for it and, potentially, avoids any problems if this test doesn't give the
expected result for whatever reason.
GC> I would have guessed that omitting '--build' would be better, because
GC> it would then default to `config.guess`
A simple way to have the best of both worlds would be to do
$ configure --build=`./config.guess` --host=...
However, in practice, I think the probability of using the wrong value for
the build option is
(a) Unlikely: "x86_64-unknown-linux-gnu" is not going to change.
(b) Immaterial: AFAICS, configure doesn't really use this option for
anything other than checking if it's (exactly) the same as host. I
could be wrong about this (reading shell scripts is a dark art, but
reading configure goes well beyond it), but it seems that this variable
is never used after using it as the default for "host" if it's not
specified and this would explain why using --build=i686-pc-cygwin
instead of "x86_64-unknown-linux-gnu" worked nevertheless.
So personally I'd just hard code this one under Linux, but using
config.guess as above would work too.
I hope this answers your question, but please let me know if you still
have any doubts,
VZ