Source: coinor-cgl
Version: 0.60.3+repack1-3
Tags: patch upstream
User: debian-cr...@lists.debian.org
Usertags: ftcbfs

coinor-cgl fails to cross build from source, because it doesn't build
shared libraries and then dh_install fails. Now the reasons for that are
... a little involved. Please sit down and take a cup of coffee or tea
or like that.

Looking into the cross configure output, one can spot this:
http://crossqa.debian.net/build/coinor-cgl_0.60.3+repack1-2_s390x_20200713232329.log
> checking whether the s390x-linux-gnu-gcc linker (/usr/bin/ld -m elf64_s390) 
> supports shared libraries... /usr/bin/ld: unrecognised emulation mode: 
> elf64_s390
> Supported emulations: elf_x86_64 elf32_x86_64 elf_i386 elf_iamcu elf_l1om 
> elf_k1om i386pep i386pe
> no

Bummer. It's using the wrong ld. It should be using s390x-linux-gnu-ld.
Why does it do that? It should be driving the ld name from gcc. However,
it only does when working with a GNU compiler and as we can see:

> checking whether we are using the GNU C compiler... no

For some reason, it concludes that gcc is not a GNU C compiler. That's
strange. You can also see this in native builds and it can have a range
of misdetections as a consequence. Just why?

The actual sequence of events is this:

We start following inside AC_COIN_DEBUG_COMPILE.

> checking whether we want to compile in debug mode... no

Now we're moving inside AC_COIN_PROG_CC executing AC_REQUIREd code.

> checking for s390x-linux-gnu-gcc... s390x-linux-gnu-gcc

At this point $ac_objext is not yet computed, so it is empty. What we do
next is use AC_TRY_COMPILE and that checks whether "conftest.$ac_objext"
aka "conftest." is non-empty. It isn't, as the compiler chose to output
to "conftest.o" instead, so we're not using a GNU compiler, right?

> checking whether we are using the GNU C compiler... no
> checking whether s390x-linux-gnu-gcc accepts -g... no
> checking for s390x-linux-gnu-gcc option to accept ISO C89... unsupported
> checking whether s390x-linux-gnu-gcc understands -c and -o together... yes

Now we've completed the AC_REQUIREd stuff and proceed to the AC_PROG_CC
inside AC_COIN_PROG_CC.

> checking for s390x-linux-gnu-gcc... s390x-linux-gnu-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... yes

This time we compute $ac_cv_objext, which is propagated to $ac_objext.

> checking for suffix of object files... o

But we already checked that we're not using a GNU C compiler, so we
don't check again. If we were checking again, we'd now see that it is a
GNU C compiler as AC_TRY_COMPILE would now check for "conftest.o".

> checking whether we are using the GNU C compiler... (cached) no

The order of invocations is messed up. The basic structure of
AC_COIN_PROG_CC is:

    AC_REQUIRE([AC_COIN_ENABLE_MSVC])
    ...
    AC_PROG_CC([$comps])
    ...
    AC_TRY_LINK(...)

Unfortunately, the AC_TRY_LINK AC_REQUIREs AC_PROG_CC, so that gets
executed before AC_COIN_PROG_CC gets a chance to compute $comps for
AC_PROG_CC. The issue is that we're using AC_TRY_LINK in the same defun
as we call AC_PROG_CC. That doesn't work.

Once understood, the solution is quite simple. We must put the
AC_PROG_CC and the AC_TRY_LINK in different defuns and ensure that our
intended AC_PROG_CC is AC_REQUIREd before using AC_TRY_LINK. I'm
attaching a patch to do that. Please consider applying it. I believe
that this is worth fixing even if you don't care about cross builds.

Helmut
--- coinor-cgl-0.60.3+repack1.orig/BuildTools/coin.m4
+++ coinor-cgl-0.60.3+repack1/BuildTools/coin.m4
@@ -665,9 +665,8 @@ AC_LANG_POP(C++)
 # given my the user), and find an appropriate value for CFLAGS.  It is
 # possible to provide additional -D flags in the variable CDEFS.
 
-AC_DEFUN([AC_COIN_PROG_CC],
-[AC_REQUIRE([AC_COIN_ENABLE_MSVC])
-AC_LANG_PUSH(C)
+AC_DEFUN([AC_COIN_PROG_CC_HEAD],
+[
 
 # For consistency, we set the C compiler to the same value of the C++
 # compiler, if the C++ is set, but the C compiler isn't (only for CXX=cl)
@@ -726,6 +725,13 @@ AC_PROG_CC([$comps])
 if test -z "$CC" ; then
   AC_MSG_ERROR([Failed to find a C compiler!])
 fi
+])
+AC_DEFUN([AC_COIN_PROG_CC],
+[AC_REQUIRE([AC_COIN_ENABLE_MSVC])
+dnl Separate the head of this macro to AC_COIN_PROG_CC_HEAD such that it
+dnl controls the invocation of AC_PROG_CC instead of the AC_TRY_LINK below.
+AC_REQUIRE([AC_COIN_PROG_CC_HEAD])
+AC_LANG_PUSH(C)
 # Autoconf incorrectly concludes that cl recognises -g. It doesn't.
 case "$CC" in
   clang* ) ;;

Reply via email to