4

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.

Ta Mu
  • 6,772
  • 5
  • 39
  • 82
Destroy666
  • 141
  • 1
  • 3

1 Answers1

1

Makefile

all: test dosomething

test:
    @echo "hello"

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

Running: make will return:

hello
world
030
  • 13,235
  • 16
  • 74
  • 173