0

I am trying to monitor coverage on a Makefile project.

CFLAGS=" -fprofile-arcs -ftest-coverage -g" make test

But the command above does not seem to work, producing the following:

gcc -DHAVE_CONFIG_H -I. -I..  -I..   -g -O2 -MT test.o -MD -MP -MF .deps/test.Tpo -c -o test.o test.c
mv -f .deps/test.Tpo .deps/test.Po
/bin/bash ../libtool  --tag=CC   --mode=compile gcc -DHAVE_CONFIG_H -I. -I..  -I..   -g -O2 -MT gaussian.lo -MD -MP -MF .deps/gaussian.Tpo -c -o gaussian.lo gaussian.c

It can be seen, from the first line, that CFLAGS are not well added when gcc is invoked. How can I include the cflags in gcc's build options while launching "make"?

I am using Bash at an Ubuntu 14, if that matters.

zell
  • 9,830
  • 10
  • 62
  • 115
  • You are dealing with a poorly written makefile that does not honor your flags. The folks who wrote the Autotools scripts should be putting their flags in `AM_CFLAGS` and `AM_CXXFLAGS` while leaving `CFLAGS` and `CXXFLAGS` for you to use. You should consider filing a bug report. Also see [7.2.3 Variables for Specifying Commands](https://www.gnu.org/prep/standards/html_node/Command-Variables.html) in the GNU Coding Standards. – jww Nov 06 '19 at 05:11

1 Answers1

1

Variables obtained from the environment, which is how you're doing it, have a lower precedence than variables set in a makefile. So if your makefile sets the CFLAGS variable directly, like:

CFLAGS = -g -O2

then setting it in the environment won't override this setting.

You can add variable assignments to the command line instead: these take precedence over almost anything set in the makefile. So use:

make test CFLAGS=" -fprofile-arcs -ftest-coverage -g"

instead.

See https://www.gnu.org/software/make/manual/html_node/Values.html

MadScientist
  • 92,819
  • 9
  • 109
  • 136