Search code examples
makefilegnu-make

make command to expose the content of a Makefile job


How can I request make to expose the content of a Makefile job ?

From this Makefile

$ cat Makedile
job1:
    echo 33
    echo 22
    echo 11

job2:
    echo Hello

I'm looking for a make command that could expose the content of a job by jobname.

e.g.

$ make xzy job1
job1:
    echo 33
    echo 22
    echo 11
$

Solution

  • I don't know what you mean by "expose the content". If you're looking for a way to show just the commands that would be run, you can use the -n option:

    $ make -n job1
    echo 33
    echo 22
    echo 11
    

    Note, however, that this will (a) only print these commands if the target job1 is determined to be out of date, and (b) it will also print the commands of any prerequisites of the job1 target, which are determined to be out of date. In your example job1 will always be out of date since the recipe doesn't update it, and there are no prerequisites for that target, so this is not a problem for the example you give.

    Another alternative is to use the -p option which will print make's entire database of variables and targets, but there is no way to restrict the output to show only the information for a single target.

    Those are your only options.

    Note, the -n option is POSIX standard so it should work with any POSIX-conforming implementation of make, but -p is specific to GNU Make.