1
votes

I have a rule like below just for test

test:
ifeq (1,1)
$(info --)
endif
    echo kkk

when I run make test, it shows

makefile:41: *** commands commence before first target. Stop.

What is wrong?

edit

according to Florian Weimer, we should indent the $(info --) line. But If I write

test:
ifeq (1,1)
    $(info --)
endif
    echo kkk

test2:
ifeq (1,1)
$(info --)
endif
    echo kkk

then make test will complain that

makefile:11: *** commands commence before first target. Stop.

So doesn't make always scan the whole makefile? It seems that it doesn't stop after rule test is finished

1
@jwdonahue Yeah, I saw this link. But I still don't know why my rule is wrong - user15964
Indentation perhaps? - jwdonahue
@jwdonahue I know the difference between space and tab. so I differentiate them. But why echo kkk is not right? it is indented by a tab, and interpreted by shell - user15964

1 Answers

2
votes

You need to tab-indent the $(info --) line, so that it does not terminate the recipe, like this:

test:
ifeq (1,1)
    $(info --)
endif
    echo kkk

(Obviously, you need to use tabs here.)

EDIT The make documentation of conditional blocks consistently uses tab indentation within recipes, and spaces or no indentation outside of recipes. This is why there are both styles.

The full example works for me if I indent both $(info --) lines.