'@echo in Makefile always causes error " *** missing separator. Stop."

I put

@echo "============= $(TOOLPREFIX) ================="

in line 34 of Makefile of xv6 used by many OS courses, in hope of printing out the value of variable TOOLPREFIX. But I always got error

Makefile:37: *** missing separator.  Stop.

This line is before any target. I tried everything I could, like adding Tab at the beginning of the command, moving the command to everywhere in Makefile, or deleting the symbol @ before echo, but I always got an error no matter what. But if I comment out this command, there is no error. So, how should I correctly print out a variable in this Makefile?

As a side note, if I add Tab at the beginning of the command, the error I got is "Makefile:37: *** recipe commences before first target. Stop." But if I move the @echo command to the bottom of Makefile, "Makefile:287: *** missing separator. Stop." comes out again.

The environment is Window Subsystem for Linux with ubuntu 20.04 installed.



Solution 1:[1]

Your directive can't be outside any rule.

You have to create one:

mydebug:
        @echo "============= $(TOOLPREFIX) ================="

Solution 2:[2]

Should not use echo command there. Should use this to print out message:

$(info ============= $(TOOLPREFIX) =================)

Solution 3:[3]

In my case $(info bla bla '$(FOO)') gives an error(missing operator) but $(warning bla bla '$(FOO)') works fine.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Mathieu
Solution 2 zzzhhh
Solution 3 akor