0

I am currently working on a simple virtual machine project and have been using Autotools to reach as many systems as possible!

Originally, I utilized AX_CHECK_COMPILE_FLAG to enable -Wall -Wextra -pedantic -g3, yet I feared that this would prevent the user from setting their own flags through $CXXFLAGS variable. Thus, I removed AX_CHECK_COMPILE_FLAG from my project and utilized a simple shell script that I could use such as the following:

#!/bin/bash
./configure CXXFLAGS="$CXXFLAGS -Wall -Wextra -pedantic -g3" && make && make check

My idea was to use this simple shell script during development, yet exclude it through my .gitattributes file and tell the user about the options available to them through my INSTALL.md file. However, am I right in doing this or should I go back to using AX_CHECK_COMPILE_FLAG?

  • 1
    What do you mean by "yet I feared that this would prevent the user from setting their own flags through $CXXFLAGS variable"? There are other [questions](https://stackoverflow.com/questions/30412576/autotools-syntax-error-with-ax-check-compile-flag) that show mixing `AX_CHECK_COMPILE_FLAG` and `CXXFLAGS`. – omajid Jun 26 '20 at 03:38
  • @omajid I thought that AX_CHECK_COMPILE_FLAG macro would somehow violate the _principle of least astonishment_ in my build system. Since people expect `-g -O2` as the standard flags. –  Jun 26 '20 at 04:18

1 Answers1

1

AX_CHECK_COMPILE_FLAGS just checks whether the selected compiler supports the specified flags. It does not, itself, cause the flags in question to be used in any particular compiler or linker invocation, nor does it make any persistent modification to any of the flag variables designated for the user, such as CXXFLAGS.

HOWEVER, it is possible for you to include your own code that modifies CXXFLAGS based on the outcome of an AX_CHECK_COMPILE_FLAGS test, and doing so is both poor form and brittle. CXXFLAGS is a user variable. If you want configure to set compiler flags, then put them in a different output variable, perhaps one designated for that particular purpose. Use these additional flags in addition to those specified via CXXFLAGS, and ensure that CXXFLAGS appears later on the command line, so that the user can thereby override configure's choices. If you're using Automake together with Autoconf then it can facilitate this.

With all that said, I'm inclined to think that your particular example of warning and debug flags is not one that I would build in to configure. I especially would never saddle a user with -Wextra by default. I have sometimes put such things in and guarded them with an --enable option, but your strategy of a wrapper script for your personal purposes seem reasonable to me, too.

John Bollinger
  • 160,171
  • 8
  • 81
  • 157
  • Thank you @John Bollinger for the clarification about how `AX_CHECK_COMPILE_FLAGS` functions! Sorry for taking a while to respond, I was looking through the GNU Autotools manual and found out about [config.site files](https://www.gnu.org/software/automake/manual/html_node/config_002esite.html). Overall, thank you for taking the time to answer my question! –  Jun 27 '20 at 21:37