Skip to content

configure.ac: make cross-compiler detection stricter

Sergei Trofimovich requested to merge trofi/ghc:cross-detect into master
Be more precise at detecting cross-compilation case.

Before the change configuration
  $ ./configure --host=x86_64-pc-linux-gnu --target=x86_64-gentoo-linux-musl
was not considered a cross-target. Even though libcs are different (`glibc` vs. `musl`).

Without this patch build fails as:

```
"inplace/bin/ghc-cabal" check libraries/integer-gmp
"inplace/bin/ghc-cabal" configure libraries/integer-gmp dist-install \
    --with-ghc="/home/slyfox/dev/git/ghc/inplace/bin/ghc-stage1" \
    --with-ghc-pkg="/home/slyfox/dev/git/ghc/inplace/bin/ghc-pkg" \
    --disable-library-for-ghci --enable-library-vanilla --enable-library-for-ghci \
    --enable-library-profiling --enable-shared --with-hscolour="/usr/bin/HsColour" \
    --configure-option=CFLAGS="-Wall \
    -Werror=unused-but-set-variable -Wno-error=inline \
    -iquote /home/slyfox/dev/git/ghc/libraries/integer-gmp" \
    --configure-option=LDFLAGS="  " --configure-option=CPPFLAGS="   \
    " --gcc-options="-Wall     -Werror=unused-but-set-variable -Wno-error=inline -iquote /home/slyfox/dev/git/ghc/libraries/integer-gmp   \
    " --with-gcc="x86_64-gentoo-linux-musl-gcc" --with-ld="x86_64-gentoo-linux-musl-ld.gold" --with-ar="x86_64-gentoo-linux-musl-ar" \
    --with-alex="/usr/bin/alex" --with-happy="/usr/bin/happy"
Configuring integer-gmp-1.0.2.0...
configure: WARNING: unrecognized options: --with-compiler
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... x86_64-pc-linux-gnu
checking for gcc... /usr/lib/ccache/bin/x86_64-gentoo-linux-musl-gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... configure: error: in `/home/slyfox/dev/git/ghc/libraries/integer-gmp/dist-install/build':
configure: error: cannot run C compiled programs.
If you meant to cross compile, use `--host'.
See `config.log' for more details
make[1]: *** [libraries/integer-gmp/ghc.mk:5: libraries/integer-gmp/dist-install/package-data.mk] Error 1
make: *** [Makefile:126: all] Error 2
```

Note: here `ghc-stage1` is assumed to target `musl` target but is passed
`glibc` toolchain. It happens because initial ./configure phase did not
detect host/target as different.
Edited by Ben Gamari

Merge request reports