AX_PROG_CC_FOR_BUILD should use CFLAGS, etc. in non-crossbuilds

Ryan Lortie <[email protected]>
Newsgroups gmane.comp.sysutils.autoconf.archive-maintainers
Message-ID <[email protected]>
hi,

Please excuse (and redirect) me if this is not the correct place to file
this bug.

The AX_PROG_CC_FOR_BUILD macro in autoconf-archive defines the variables
CFLAGS_FOR_BUILD, CPPFLAGS_FOR_BUILD and LDFLAGS_FOR_BUILD so that
people can build executables on the build machine with different
compiler flags when cross-compiling.

When not cross-compiling, however, this is a bit of an anti-feature
because it requires the user to explicitly set these variables in
addition to the usual CFLAGS, CPPFLAGS, LDFLAGS.

I consider that there are probably two approaches to fixing it.

First approach (code added to the top of the macro):

if test "$cross_compiling" = "no"; then
       if test -n "$CFLAGS"; then
               CFLAGS_FOR_BUILD=$CFLAGS
       fi
       if test -n "$CPPFLAGS"; then
               CPPFLAGS_FOR_BUILD=$CPPFLAGS
       fi
       if test -n "$LDFLAGS"; then
               LDFLAGS_FOR_BUILD=$LDFLAGS
       fi
fi

ie: if we see that we are not cross-compiling, initialise the values of
the _FOR_BUILD variables from their host counterparts (since host ==
build).

Second approach:

if test -z "$CFLAGS_FOR_BUILD" -a -n "$CFLAGS"; then
      CFLAGS_FOR_BUILD="$CFLAGS"
fi
if test -z "$CPPFLAGS_FOR_BUILD" -a -n "$CPPFLAGS"; then
      CPPFLAGS_FOR_BUILD="$CPPFLAGS"
fi
if test -z "$LDFLAGS_FOR_BUILD" -a -n "$LDFLAGS"; then
      LDFLAGS_FOR_BUILD="$LDFLAGS"
fi

ie: always initialise these variables from their host counterparts
except in the case that they are already explicitly set.


The second approach would allow us to "inherit" flags from the host
automatically, but still provide a mechanism to override those if the
inherited flags are wrong.  Strictly speaking, the test -z "" check is
wrong here because it won't allow to the user to remove flags entirely
by setting the variable to the empty string.  That's fixable, but I
actually think that the first approach is the better one since it is
less presumptuous.

I can do a proper patch if that is desired.

Please let me know what you think and which approach you prefer (or if
you prefer a different approach entirely).

Cheers
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.