Re: How to get autoconf to respect CC="gcc -std=c89"?

Niels Möller <[email protected]>
Newsgroups gmane.comp.sysutils.autoconf.patches,gmane.comp.sysutils.autoconf.general
Message-ID <[email protected]>
Paul Eggert <[email protected]> writes:

> This doesn't let you say "I want either c89 or c99, but not c11".

That's right, I tried only the very simplest thing. Providing a list
makes sense, thoguh. What should the interface be?

  AC_C_STANDARD_VERSION([c99 c89])

looks reasonable to me; list in order of preference, and whitespace
separation. That's consistent with AC_PROG_CC. But that means that

  AC_C_STANDARD_VERSION([c89 c99])

is a bit meaningless; if compiler has c89, that's what will be used, and
if it doesn't have c89, it won't have c99 either. (Alternative: Let
autoconf automatically sort the list and test for the "largest" language
on the list first. That may be a bit overengineered, though).

I considered trying this out, but then there's some impedance mismatch
between the whitespace separated list to AC_C_STANDARD_VERSION, and the
comma-separated list required by m4_map. Certainly doable, but what's
the easiest way to transform

  [c99 c89]

into 
  
  [99, 89]

?

>> +  m4_ifdef([_AC_C_STANDARD_VERSION_LIST],
>> +    [m4_fatal([AC_PROG_C_STANDARD_VERSION should only be used once], 1)])
>
> Why have this check?

I figured the user should get some error message if using
AC_C_STANDARD_VERSION too late, e.g., after some AC_FOO that implicitly
uses AC_PROG_CC, which will also trigger this check. Not sure of
m4_fatal is the right way to signals error to the user, though. (And
error message could be improved).

> How about something simpler, like replacing this:
>
> m4_map([_AC_PROG_CC_STDC_EDITION_TRY], [[11], [99], [89]])])
>
> with this:
>
> m4_map([_AC_PROG_CC_STDC_EDITION_TRY],
>   [m4_default([_AC_C_STANDARD_VERSION_LIST],
>      [[11], [99], [89]])])

I looked at m4_default, and it looked to me like it checks for empty string, not
undef:ed m4 symbol. If _AC_C_STANDARD_VERSION_LIST is undefined, I
concluded that

  m4_default([_AC_C_STANDARD_VERSION_LIST], whatever)

just expands to the text _AC_C_STANDARD_VERSION_LIST.

So I think we need _AC_C_STANDARD_VERSION_LIST to always be defined. Not
sure where that definition should go, if not in _AC_PROG_CC_STDC_EDITION
itself, but whwreever it is moved, I suspect it would be simpler to jsut
make that definition assign the default value rather than the empty list
needed for m4_default to work as intended.

> and not bothering to check for allowed or duplicated version lists?

Skipping that could make implementation a bit simpler, I guess, at the
cost of less clear user error messages.

Regards,
/Niels

-- 
Niels Möller. PGP key CB4962D070D77D7FCB8BA36271D8F1FF368C6677.
Internet email is subject to wholesale government surveillance.
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.