0

I have a following problem. Basically I have a really long Makefile which calls many complex commands. It uses environment variables, methods included from other Makefiles, really hard to read bash magic. So for example I have a command (cannot put the real one here, sorry) like this:

foo ${bar} (sort ...) [...]

I am analysing this Makefile and I want to know what exactly gets executed when I run it. The thing I want to achieve is this command in a text representation, so all the stuff gets evaluated and I can actually see what exactly is being executed like gcc something -Isomethingmore (so the command foo ${bar} (sort ...) [...] actually means gcc something -Isomethingmore) etc. Is there a way to do that? So I can for example echo it and see what am I dealing with?

dabljues
  • 1,663
  • 3
  • 14
  • 30
  • 1
    If GNU make, `make -d` or `make --trace`. Also, `make SHELL='/bin/sh -x'`. cf. https://stackoverflow.com/questions/5820303/how-do-i-force-make-gcc-to-show-me-the-commands – jhnc Jul 13 '19 at 01:22
  • And if I would like only one command? Cuz they are plenty and my terminal would be kinda messy – dabljues Jul 13 '19 at 01:53

1 Answers1

2

By default make prints the recipes it executes. So you should see the exact command in the standard output. Use grep maybe to isolate the one you are interested in. If make does not print the recipes it may be:

  1. because the recipe is prefixed by @, which tells make to be silent for this recipe,
  2. because the Makefile contains the .SILENT special target that silences all recipes.

Remove one or the other and you should see the recipe when it is executed.

Renaud Pacalet
  • 25,260
  • 3
  • 34
  • 51
  • By recpe you mean something like, I dont know `foo: gcc bar` and I should add `@` before foo? – dabljues Jul 13 '19 at 11:44
  • 1
    @dabljues, The recipe is the part of a rule that contains the commands to execute. What you've shown is not that, it's the part that specifies the target to be built and its prerequisites. That may be all there is to some rules, in which case either (1) the rule serves only to ensure that the prerequisites are built, or (2) the recipe is presented in a different rule for building the same target, and the one without a recipe just names additional prerequisites. – John Bollinger Jul 13 '19 at 15:45
  • Okay, that clarifies everything. Thanks! – dabljues Jul 13 '19 at 16:30