Use idiomatic way to tell Autoconf the c compiler
ClosedPublic

Authored by hvr on Dec 13 2015, 5:42 AM.

Details

Summary

The non-idiomatic --with-cc flag was added via
5c789e424c1461c1dadfd38c44fcb9e8f38bf755

However, --with-cc seems rather fragile and support for --with-cc needs
to be added explicitly to autoconf-based Cabal packages. The CC= flag, however,
is supported natively by GNU Autoconf, so let's use the standard facility for that.

Diff Detail

Repository
rGHC Glasgow Haskell Compiler
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
hvr updated this revision to Diff 5648.Dec 13 2015, 5:42 AM
hvr retitled this revision from to Use idiomatic way to tell Autoconf the c compiler.
hvr updated this object.
hvr edited the test plan for this revision. (Show Details)
hvr added reviewers: thomie, erikd.
hvr added a reviewer: kgardas.Dec 13 2015, 5:45 AM

I'm esppecially interested to hear from developers working with cross-GHCs

hvr added a reviewer: trofi.Dec 13 2015, 8:14 AM
trofi accepted this revision.Dec 13 2015, 9:55 AM
trofi edited edge metadata.

Looks good!

This revision is now accepted and ready to land.Dec 13 2015, 9:55 AM
thomie accepted this revision.Dec 13 2015, 12:21 PM
thomie edited edge metadata.

Sure.

Maybe the configure.ac file of other submodules can be simplified as well. For example libraries/directory/configure.ac currently contains:

# inherit the C compiler from Cabal but allow it to be overridden by --with-cc
# because Cabal puts its own flags at the end
AC_ARG_WITH([gcc],
            [C compiler],
            [set_with_gcc])
AC_ARG_WITH([cc],
            [C compiler],
            [CC=$withval])
hvr added a comment.Dec 13 2015, 1:22 PM

Btw, I've filed https://github.com/haskell/cabal/pull/2946 as well.

I'm waiting for @erikd to confirm this patch works as expected when crosscompiling GHC

erikd requested changes to this revision.Dec 13 2015, 3:49 PM
erikd edited edge metadata.

Sorry, not working correctly. I ran

arc patch D1608
perl boot
CC=aarch64-linux-gnu-gcc-5 ./configure --target=aarch64-linux-gnu

and fails finishes with:

GHC build  : x86_64-unknown-linux
GHC host   : x86_64-unknown-linux
GHC target : aarch64-unknown-linux
configure: Building in-tree ghc-pwd
checking for path to top of build tree... /home/erikd/Git/ghc-upstream
checking for aarch64-linux-gnu-gcc... no
checking for aarch64-linux-gnu-clang... no
configure: error: cannot find gcc nor clang in your PATH

I don't have time to look at this now, but there's a call to FIND_GCC in configure.ac which is probably screwing things up. FIND_GCC is in aclocal.m4 and it doesnt look like it does the right thing.

This revision now requires changes to proceed.Dec 13 2015, 3:49 PM
erikd added a comment.Dec 13 2015, 4:55 PM

It seems the configure command I was using was not correct. Thr correct one is:

./configure --target=aarch64-linux-gnu --with-gcc=aarch64-linux-gnu-gcc-5

however, that fails to build with:

chmod +x libraries/integer-gmp/gmp/ln
cd libraries/integer-gmp/gmp; (set -o igncr 2>/dev/null) && set -o igncr; export SHELLOPTS; \
    PATH=`pwd`:$PATH; \
    export PATH; \
    cd gmpbuild && \
    CC=aarch64-linux-gnu-gcc-5 NM=/usr/bin/aarch64-linux-gnu-nm AR=/usr/bin/aarch64-linux-gnu-ar ./configure \
          --enable-shared=no \
          --host=x86_64-unknown-linux --build=x86_64-unknown-linux
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether to enable maintainer-specific portions of Makefiles... no
checking ABI=64
checking whether aarch64-linux-gnu-gcc-5 is gcc... yes
checking compiler aarch64-linux-gnu-gcc-5 -O2 -pedantic -fPIC -m64 ... no
checking ABI=32
checking whether aarch64-linux-gnu-gcc-5 is gcc... yes
checking compiler aarch64-linux-gnu-gcc-5 -m32 -O2 -pedantic -fPIC -fomit-frame-pointer ... no
checking compiler aarch64-linux-gnu-gcc-5 -O2 -pedantic -fPIC -fomit-frame-pointer ... yes
checking compiler aarch64-linux-gnu-gcc-5 -O2 -pedantic -fPIC -fomit-frame-pointer has sizeof(long)==4... no
configure: error: could not find a working compiler, see config.log for details
libraries/integer-gmp/gmp/ghc.mk:118: recipe for target 'libraries/integer-gmp/gmp/gmp.h' failed
hvr added a comment.EditedDec 13 2015, 5:12 PM

I don't see how this patch would affect the in-tree GMP configure-phase... for one I'd be interested in the config.log file, otoh I'm wondering if you wouldn' get the same failure when building GHC HEAD w/o D1608

erikd accepted this revision.Dec 13 2015, 5:56 PM
erikd edited edge metadata.

The previous failure was because I had BuildFlavour in mk/build.mk set incorrectly. It needs to be set to quick-cross.

With that fixed, building a cross compiler suceeded. Happy to accept this revision.

This revision is now accepted and ready to land.Dec 13 2015, 5:56 PM
This revision was automatically updated to reflect the committed changes.