'How to include flags for valgrind in a makefile?
I have a makefile with a valgrind target that looks like this:
# expects a file `test.keys` to exist; it can contain any numbers.
valgrind: $(PROG) test.keys
valgrind ./$(PROG) < test.keys
If I wanted to include valgrind flags such as --leak-check=full --show-leak-kinds=all, where would I put them? Do I put them right after valgrind:, or only on the second line before ./$(PROG) but after valgrind?
Thanks in advance!
Solution 1:[1]
The name "valgrind" appears twice in your rule because you are using it to mean two different things: it is the name of the analysis tool that you want to execute, and it is the name of your makefile rule, which is arbitrary. You could just as well have named your rule "pumpernickel":
pumpernickel: $(PROG) test.keys
valgrind ./$(PROG) < test.keys
The flags are to be passed to valgrind (the analysis tool) as if you were invoking it on the command line. That's what the second line is; that line is passed to the shell as a command. So that's where the flags belong.
P.S. Whatever name you choose for this rule, be aware that by default Make expects a rule with a given name to build a file with that name. This rule builds nothing, so you should use .PHONY to warn Make not to expect this rule to behave in the default way.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | DharmanBot |
