autoconf
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Trying to be fancy with feature testing


From: NightStrike
Subject: Re: Trying to be fancy with feature testing
Date: Sat, 6 Mar 2010 13:14:05 -0500

On Sat, Mar 6, 2010 at 12:49 PM, Eric Blake <address@hidden> wrote:
> According to NightStrike on 3/6/2010 10:23 AM:
>> It comes up often that we want to test to see whether a feature of GCC
>> works.  For instance, we want to see if -m64 is a valid gcc option to
>> know if we should build the 64-bit libraries by default.  Other things
>> include checking for unicode support, and the -municode option.  To do
>> this, we usually do something like the following:
>>
>> _save_CFLAGS="$CFLAGS"
>
> Overkill.  Shell assignments are NOT subject to word splitting, so it
> _does not matter_ whether $CFLAGS contains spaces.  It is perfectly safe
> to use:
>
> _save_CFLAGS=$CFLAGS

Well that just blew my mind.  Well met!

>> CFLAGS="$CFLAGS option"
>
> This line does indeed need double quotes, but that is in order to include
> literal whitespace as part of the word that will later be interpreted as a
> shell assignment.  It is also possible (although less common) to write
> this as:
>
> CFLAGS=$CFLAGS\ option
>
> with no change in semantics.
>
>> AC_COMPILE_IFELSE([AC_LANG_PROGRAM.......
>> CFLAGS="$_save_CFLAGS"
>>
>> I was trying to improve upon that using AS_VAR_COPY for the
>> save/restore, but I can't figure out how to handle variables
>> containing spaces.
>
> They are handled like any other variable.
>
> AS_VAR_COPY([_save_CFLAGS], [CFLAGS])

Well, I didn't know the first part :(


So with your guidance, I now have this:

AC_DEFUN([MW64_VAR_PUSHPOP],[
  AS_VAR_PUSHDEF([savevar],[_save_$1])
  AS_VAR_COPY([savevar],[$1])
  AS_VAR_APPEND([savevar],[" $2"])
  $3
  AS_VAR_COPY([$1],[savevar])
  AS_VAR_POPDEF([savevar])])

Is this considered a clean way of doing things?




reply via email to

[Prev in Thread] Current Thread [Next in Thread]