0

Just when I think I know how the shell works fairly, something comes along and stumps me. The following commands were executed on GNU bash, version 3.2.25.

I have several ./configure scripts that all share a group of common configure options, one of them being CFLAGS.

To that end, I have two variables

CFLAGS="-fPIC -O3"
COMMON_CONFIGURE_OPTIONS="CFLAGS=\"$CFLAGS\" --enable-static --disable-shared --prefix=$PREFIX"

When this gets passed to `./configure', it is done so like,

"$FOO/configure" $COMMON_CONFIGURE_OPTIONS

For the life of me, I cannot seem to get this to expand correctly. I have tried manually substituting the value of $CFLAGS into $COMMON_CONFIGURE_OPTIONS. I have tried every combination of single and double quotes under the sun. I have even tried quoting the entire "CFLAGS=..." argument.

The version I gave above yields the following (when set -x is enabled)

../configure 'CFLAGS="-fPIC' '-O3"' --enable-static --disable-shared --prefix=../install
configure: error: unrecognized option: `-O3"'
Try `../configure --help' for more information

What I expected, and what I desire, is for configure to be invoked like

./configure CFLAGS="-fPIC -O3" --enable-static --disable-shared --prefix="$PREFIX"

How can I achieve what I want, and additionally, are there good resources/tips on how to avoid this problem in the future?

Tyg13
  • 321
  • 2
  • 10
  • I hesitate to give this as an answer because `eval` is evil, but have you tried `eval $FOO/configure $COMMON_CONFIGURE_OPTIONS` With the quoting you're explicitly adding, it looks like you want something like that. – William Pursell Feb 05 '20 at 20:56

1 Answers1

0

To achieve what you want, I think you want to fundamentally change your approach. Assuming your configure scripts are generated by autoconf, I would suggest using a config.site file. That is, simply do something like:

mkdir -p $PREFIX/share
echo 'CFLAGS="--enable-static --disable-shared"' > $PREFIX/share/config.site

And then invoke configure as:

/path/to/configure --prefix=$PREFIX

Make sure that CONFIG_SITE is not set in the environment when you invoke configure, else the defaults will come from the file named there.

William Pursell
  • 204,365
  • 48
  • 270
  • 300
  • The configure scripts are given as part of the packages I'm building, not generated by autoconf (at least, I don't run autoconf as part of the build process). But perhaps this is still useful? In particular, I want the invocation of `configure` to look like `configure CFLAGS="-fPIC -O3" --enable-static --disable-shared` – Tyg13 Feb 05 '20 at 20:53
  • If the package was built using autoconf, you would not need to run autoconf. If you do `head configure`, it should be immediately obvious. (line 3 or so would say "Generated by GNU autoconf....") – William Pursell Feb 05 '20 at 20:55
  • They are indeed generated from `autoconf`. I'll have to see if adding the options to `$PREFIX/share/config.site` gets me what I want, but this seems like a step in the right direction. – Tyg13 Feb 05 '20 at 21:08