I have a makefile as follows,
all: target1
@echo "$(USER)"
target1: target2
@echo "$(HOME)"
target2:
@echo "$(SHELL)"
If I execute make all
, I will get some output as expected. But is there way to know which targets got hit when ran that command. In this case, make all
invoked target1, target2
. If I had done make target1
then only target2
would have invoked.
One very bad solution I did was adding echo statement in all my targets as follows,
all: target1
@echo "Running $@"
@echo "$(USER)"
target1: target2
@echo "Running $@"
@echo "$(HOME)"
target2:
@echo "Running $@"
@echo "$(SHELL)"
Is there any good solution without having to add such prints?
First of all, when you run
make target1
You should see first target2 then target1 executed..
If you want to see how make
orders the targets and executes them, you can run make -d
.
Alternatively, if you want to see the shell command lines that are executed without actually running them, the option --dry-run
exists but does not indicate the actual target names.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.