简体   繁体   中英

GNU Make: no output when using `define var =`

Snippet 1:

define HELP_TEXT
This is the help text.
endef

.PHONY: help
help:
      @echo $(HELP_TEXT)

Test:

$ make help
This is the help text.
$

Snippet 2:

define HELP_TEXT =
This is the help text.
endef

.PHONY: help
help:
      @echo $(HELP_TEXT)

Test:

$ make help

$

What is going on here? According to the documentation there should be no difference in behaviour between both syntaxes.

NOTE: My GNU Make version is 3.81.

The NEWS file for version 3.82 (28 Jul 2010) mentions this:

  • The define make directive now allows a variable assignment operator after the variable name, to allow for simple, conditional, or appending multi-line variable assignment.

So it's simply a feature not present in GNU make 3.81. In fact, in earlier make versions, the variable is called HELP_TEXT = , as can be seen if you try this:

define HELP_TEXT =
This is the help text.
endef

.PHONY: help
help:
    @echo $(HELP_TEXT =)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM