Other Make - multiline commands

I have a Makefile of the form:

Code:
.MAKE.JOBS=1

file.sqlite : file.sql
        sqlite3 file.sqlite << EOF
        .read file.sql
        .quit
        EOF

file.sql : ...
            ...

Why .MAKE.JOBS=1?

Because I want that all lines in the first line to be processed by one sh interpreter.
Otherwise each line is passed to a separate sh, the "here document" is not recognized.

And how I came to the idea? According to man make:

-j max_jobs
Specify the maximum number of jobs that make may have running at
any one time. The value of max_jobs is saved in .MAKE.JOBS.
Turns compatibility mode off, unless the -B option is also
specified. When compatibility mode is off, all commands
associated with a target are executed in a single shell
invocation as opposed to the traditional one shell invocation per
line. This can break traditional scripts which change
directories on each command invocation and then expect to start
with a fresh environment on the next line. It is more efficient
to correct the scripts rather than turn backwards compatibility
on.

But it is really make -j 1 equivalent to set .MAKE.JOBS=1???

Or am I using an undocumented feature?

Do you have an Idea how to execute a multiline command in compatibility mode?

And no, putting \ at the end of the lines is not the solution: it deletes the \n char that is here relevant in the syntax.

And it seems this "solution is incompatible with OpenBSD make:


and also with gmake
.
 
Due to make's syntax requiring backslash/newline to continue lines, multiline here-documents cannot be used in Makefiles.
I work around this with
Makefile:
file.sqlite: file.sql
        printf '%s\n' \
        '.read $^' \
        '.quit' \
        | sqlite3 $@
You should always replace the target in the recipe with $@ and the dependencies with $^ for proper make hygiene.
 
Back
Top