Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trouble printing newline in makefile

How can I print a newline in a makefile?

For instance, if I have a target:

printIt:
        @echo "Compiling..."

How could I print out

Compiling...

I had read somewhere that you can define one. But I have tried what is mentioned here:

define \n

endef



printit:
        @echo "${\n}Compiling..."

But this doesn't print the newline. I have also tried a c++ style "\n". I'm using GNU Make 3.81.

like image 411
wizurd Avatar asked Oct 16 '25 02:10

wizurd


2 Answers

Use:

@echo ""; echo "Compiling..."

The first echo echoes a newline; the second echoes the message.

like image 56
Jonathan Leffler Avatar answered Oct 19 '25 10:10

Jonathan Leffler


In some implementations of echo eg. Bash, you can use echo -e to interpret escape characters. Use

printIt:
        @echo -e "\nCompiling..."
like image 42
Rob Avatar answered Oct 19 '25 11:10

Rob



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!