Skip to content

save_flags inconsistencies #565

Open

Description

@ryandesign

When save_flags was originally added (024ed0f), the comment at the top described the function's arguments as additional CFLAGS, LDFLAGS, and CPPFLAGS. However, the function actually accepted arguments for additional CPPFLAGS, LDFLAGS, and CXXFLAGS, in that order. It did not accept an argument for additional CFLAGS. At the end of the function, it saved the modified CPPFLAGS and LDFLAGS and it also saved CFLAGS which it did not modify. It did not save the modified CXXFLAGS.

unicon/aclocal.m4

Lines 2 to 56 in 024ed0f

# arsgs: additionals cflags, ldflags and cppflags.
AC_DEFUN([save_flags],
[
for part in $1
do
FOUND=
for itm in $CPPFLAGS -a -z $FOUND
do
if test $itm = $part
then
FOUND=1
fi
done
if test -z $FOUND ; then
CPPFLAGS="$CPPFLAGS $part"
fi
done
for part in $2
do
FOUND=
for itm in $LDFLAGS -a -z $FOUND
do
if test $itm = $part
then
FOUND=1
fi
done
if test -z $FOUND ; then
LDFLAGS="$LDFLAGS $part"
fi
done
for part in $3
do
FOUND=
for itm in $CXXFLAGS -a -z $FOUND
do
if test $itm = $part
then
FOUND=1
fi
done
if test -z $FOUND ; then
CXXFLAGS="$CXXFLAGS $part"
fi
done
TMP_CPPFLAGS=$CPPFLAGS
TMP_LDFLAGS=$LDFLAGS
TMP_CFLAGS=$CFLAGS
])

This commit also added restore_flags which restored CFLAGS, LDFLAGS, and CPPFLAGS from the saved values.

In the next commit (3c76a16), save_flags was fixed to save CPPFLAGS, LDFLAGS, and CFLAGS at the beginning of the function instead of at the end, and the code that handled the third argument for modifying CXXFLAGS was removed. save_flags now only accepts two arguments. The comment at the top was not modified, making it look like the function still accepts three arguments. Everywhere that calls save_flags calls it with three arguments, the third of which is always passed as empty.

In the next commit (079471b), LIBS is also saved and restored, because AC_CHECK_LIB might change LIBS.

So my questions are:

  • Why does it save and restore CFLAGS if it does not modify them? Is the concern that some other macro will modify CFLAGS?
  • If so, does the same concern exist for CXXFLAGS? Should they be saved and restored?
  • Should the comment about the function's arguments be modified to reflect what it actually accepts?
  • Should all calls to save_flags be changed to remove the third argument?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions