How to use heredoc in makefile 

Newsgroups: comp.unix.questions,comp.unix.programmer
> I remember seeing this somewhere but can't get it going now: How can
> I use heredoc in makefile?

AFAIK, the lines in a makefile are passed to the shell one by one, so the shell never gets a multi-line input (with the "here document").

You need to tell "make" that these lines belong together, you do so by a backslash '' as the very last character on all lines (but the last one).

I would not trust that this always works correctly on all platforms, so it might be better to use separate files for the "here document".

Joerg Bruehe

shell output in make 

*Tags*:

Symptom 

FOUND_FILES=    `find ${THE_PATH}`

test:
        echo ${FOUND_FILES}

will yield:

echo `find /home/tong/.../path`
Note
  • variable assignment does not interpret `` command. It is executed when it is used. Thus it is not possible to use it in dependant like this:

    result: ${THE_PATH} ${FOUND_FILES}
  • But the result of wildcard can be used as dependant!

    H_FILES=       $(wildcard *h)

Solution 

Use the `shell' Function

Help 
Functions -> Shell Function

The `shell' function is unlike any other function except the `wildcard' function (*note The Function `wildcard': Wildcard Function.) in that it communicates with the world outside of `make'.

The `shell' function performs the same function that backquotes (``') perform in most shells: it does "command expansion". This means that it takes an argument that is a shell command and returns the output of the command. The only processing `make' does on the result, before substituting it into the surrounding text, is to convert each newline or carriage-return / newline pair to a single space. It also removes the trailing (carriage-return and) newline, if it's the last thing in the result.

Here are some examples of the use of the `shell' function:

contents := $(shell cat foo)
files := $(shell echo *.c)