3

Let's say that I have 2 targets:

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.

2
  • Please let me know whether the example is what you are looking for. Could you indicate how the expected output should look like?
    – 030
    Dec 31 '19 at 21:57
  • Not quite, I edited my question to be more specific
    – Destroy666
    Dec 31 '19 at 23:00
1

Makefile

all: test dosomething

test:
    @echo "hello"

dosomething:
    @if [ "a" = "a" ]; then\
        echo "world";\
        exit 0;\
    fi

Running: make will return:

hello
world

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.