1

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

user15964
  • 2,507
  • 2
  • 31
  • 57

1 Answers1

2

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.

Florian Weimer
  • 32,022
  • 3
  • 48
  • 92
  • Hi, Florian Weimer. If I indent the $(info ) line. then make complains errors that after the test rule. This makes me confused, why make doesn't stop after test rule? Does make always scan the whole makefile? – user15964 Oct 22 '17 at 08:25
  • Please edit your question to include a minimal example which shows the problem, along with the error message. – Florian Weimer Oct 22 '17 at 08:46
  • Hi, @Florian Weimer. Thank you very much. I made a edit. But I still confused. Because people say, lines begin with tab is shell. Why I should indent `$(info ---)` between ifeq – user15964 Oct 22 '17 at 08:57
  • and according to the doc https://ftp.gnu.org/old-gnu/Manuals/make-3.79.1/html_chapter/make_7.html there are several examples have no indent – user15964 Oct 22 '17 at 09:01