Skip to content
This repository has been archived by the owner on Apr 2, 2019. It is now read-only.

User provided compile flags overridden by configure #37

Open
evancox10 opened this issue Oct 11, 2017 · 0 comments
Open

User provided compile flags overridden by configure #37

evancox10 opened this issue Oct 11, 2017 · 0 comments

Comments

@evancox10
Copy link

evancox10 commented Oct 11, 2017

I'm trying to debug spike and riscv-fesvr with GDB. spike by default is compiled with debug symbols (-g), which is good, but riscv-fesvr is not. On both, I also want to turn down optimization (-O0)to make tracing the code simpler. So I'm trying to figure out how to add these flags, but whatever I do is getting over-written down the line by the autoconf scripts.

I'm no expert in autotools, but I believe I should be able to do this to compile with debug symbols:

cd riscv-fesvr/build
../configure CXXFLAGS="-O0 -g"
etc...

You should also be able to pass them in via environment variables, or directly to make when you do the build (make CXXFLAGS="-O0 -g" build).

However, no matter what I do the Makefile ends up with this:

CFLAGS        += -Wall -O2
CXXFLAGS      += -Wall -O2 -std=c++11 -DPREFIX=\"$(prefix)\"

So this is going to override the -O0 level, since gcc takes the last -O it finds. (-g should stick around I guess?)

My guess is that this part of the Makefile comes from this in the configure.ac file:

#-------------------------------------------------------------------------
# Default compiler flags
#-------------------------------------------------------------------------

AC_SUBST([CFLAGS],  ["-Wall -O2"])
AC_SUBST([CXXFLAGS],["-Wall -O2 -std=c++11"])

Or possibly from the Makefile.am template. I'm having a hard time figuring out which file controls the ultimate output here.

Is there another way that autoconf/automake can be used to allow the user to supply these? The automake docs has this to say:

CPPFLAGS is the user variable (see User Variables), AM_CPPFLAGS is the Automake variable
...
Automake always uses two of these variables when compiling C sources files. When compiling an object file for the mumble target, the first variable will be mumble_CPPFLAGS if it is defined, or AM_CPPFLAGS otherwise. The second variable is always CPPFLAGS.
CPPFLAGS is a user variable, i.e., a variable that users are entitled to modify in order to compile the package. This variable, like many others, is documented at the end of the output of ‘configure --help’.
...
The reason ‘$(CPPFLAGS)’ appears after ‘$(AM_CPPFLAGS)’ or ‘$(mumble_CPPFLAGS)’ in the compile command is that users should always have the last say.

(emphasis mine)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant