debugbashMinor
Exit a Makefile target called by parent without throwing an error
Viewed 0 times
withoutmakefiletargetcallederrorparentexitthrowing
Problem
Let's say that I have 2 targets:
I would like
Is there any other way to skip the rest of the target without breaking further execution of
test:
# ...
@$(MAKE) dosomething
@echo test
# ...
dosomething:
# ...
@if [ -z "$(SOMETHING)" ]; then exit 0; fi
@echo dosomething
# ...I would like
echo test to execute even if $(SOMETHING) is empty and echo dosomething only if $(SOMETHING) is not empty (which doesn't work with the example, it's still executed).exit 0 of course doesn't work here since make ignores non-negative exit in subshells used to execute instructions.Is there any other way to skip the rest of the target without breaking further execution of
test target? I could make the rest a single long instruction of else but wondering if there's a different command I'm maybe missing.Solution
Makefile
Running:
all: test dosomething
test:
@echo "hello"
dosomething:
@if [ "a" = "a" ]; then\
echo "world";\
exit 0;\
fiRunning:
make will return:hello
worldCode Snippets
all: test dosomething
test:
@echo "hello"
dosomething:
@if [ "a" = "a" ]; then\
echo "world";\
exit 0;\
fihello
worldContext
StackExchange DevOps Q#10367, answer score: 1
Revisions (0)
No revisions yet.