Prefixing make output with target name - for example, ant does

Assuming I have the following Makefile:

.PHONY: mytarget
mytarget:
    echo "Hello World!"

running make mytargetgives the following output:

echo "Hello World!"
Hello World!

what I would like to see looks something like this:

[mytarget] echo "Hello World!"
[mytarget] Hello World!

Is it possible?

I searched http://www.gnu.org/software/make/manual/make.html but haven't found a solution yet (provided, I haven't read the entire manual yet)

+4
source share
3 answers

I'm not sure if there is something easily accessible for what you want in GNUmake (based on your link, I assume we are talking about this taste). You can somehow imitate him, but I'm afraid that the solution will not be perfect.

use debug flags

make --debug=j mytarget make , , , . :

Live child 0x021d2360 (mytarget) PID 10747 
echo Hello World!
Hello World!
Reaping winning child 0x021d2360 PID 10747 
Removing child 0x021d2360 PID 10747 from chain.

, , , (-j options) .

SHELL

SHELL, make, . (ab), . ​​Makefile

SHELL=/bin/sh -c 'echo -n "[$@]: " && $$@'

echo "Hello World!"
[mytarget]: "Hello World!"

, make , , SHELL

, make , , :

echo_target=@echo -n '[$@]: ' && echo $(1) && echo -n '[$@]: ' && $(1)

.PHONY: all bla

mytarget:
    $(call echo_target, echo "Hello World!")

[mytarget]: echo Hello World!
[mytarget]: Hello World!

call Makefile

:

, SHELL, , , . , SHELL : , , , $@ prepended:

 SHELL=/bin/sh -c 'echo -n "[$@] " && echo "$$@" && echo -n "[$@] " && eval "$$@"'

mytarget:
    echo 'Hello World!'
    @touch foo\ bar
    @ls -l "foo bar"

echo 'Hello World!'
[mytarget] echo 'Hello World!'
[mytarget] Hello World!
[mytarget] echo foo\ bar
[mytarget] foo bar
[mytarget] touch foo\ bar
[mytarget] [mytarget] ls -l "foo bar"
[mytarget] -rw-rw-r-- 1 virgile virgile 0 juil. 23 08:44 foo bar

, - , , touch. , , , .

+3

Change SHELL @Virgile ( , . ).

, PS4.

SHELL=/bin/bash -x
export PS4=[$@]

all: mytarget blah

.PHONY: mytarget blah

mytarget:
        @echo 'Hello World!'

blah:
        @echo '$@: output'

$ make
[mytarget] echo 'Hello World!'
Hello World!
[blah] echo 'blah: output'
blah: output

, Change SHELL ( , , - ), , .

+2

, remake ( GNU make) Makefile, :

$ remake -x 
Reading makefiles...
Updating goal targets....
File 'mytarget' does not exist.
Must remake target 'mytarget'.
Makefile:3: target 'mytarget' does not exist
##>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
echo "Hello World!"
##<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Hello World!
Successfully remade target file 'mytarget'.

The number after the colon in Makefilegives the line number inside the target's Makefile. Chevrons share a command that is called from the result it outputs. If the target failed, you will get a trace of the target stack, similar to what you received in the programming language.

Although this is already a little more than you requested, in the unlikely event you need more, there is a debugger if you use -Xinstead -X.

+1
source

All Articles