Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to synthesize line breaks in GNU Make warnings or errors?

When using the built-in $(error text) and $(warning text) functions of GNU Make, how can I get line breaks into the error/warning output without acrobatics?

By acrobatics I mean funny methods such as these two:

$(warning $(shell /bin/echo -e "something\nfoo\nbar\nbaz"))
$(warning $(shell /bin/bash -c 'echo  -e "something\nfoo\nbar\nbaz"'))

which, btw, didn't work for me with GNU Make 3.81 on Ubuntu 10.04.

Rationale: I want to make the error output in conditional parts (ifeq, ifneq) of my GNUmakefile more readable.


The current workaround for me is to use for each line:

$(warning ...)

and finally for the last line:

$(error ...)
like image 808
0xC0000022L Avatar asked Jun 12 '13 00:06

0xC0000022L


People also ask

How to break a line in makefile?

As in normal makefile syntax, a single logical recipe line can be split into multiple physical lines in the makefile by placing a backslash before each newline. A sequence of lines like this is considered a single recipe line, and one instance of the shell will be invoked to run it.

What is @echo in makefile?

The ' @ ' is discarded before the line is passed to the shell. Typically you would use this for a command whose only effect is to print something, such as an echo command to indicate progress through the makefile: @echo About to make distribution files.

What is backslash in makefile?

A backslash ( \ ) followed by a newline character is interpreted as a space in the command. Use a backslash at the end of a line to continue a command onto the next line. NMAKE interprets the backslash literally if any other character, including a space or tab, follows the backslash.


1 Answers

Define a line break variable using define/endef and use it as $n like this:

define n


endef

$(warning "something$nfoo$nbar$nbaz")

Note the two blank lines between define and endef

like image 197
Eric Miller Avatar answered Nov 16 '22 02:11

Eric Miller