[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: Shell for evaluating .SHELLFLAGS
From: |
Cook, Malcolm |
Subject: |
RE: Shell for evaluating .SHELLFLAGS |
Date: |
Tue, 26 May 2015 17:57:47 +0000 |
Erm, there is an errant "o" on the last line of `bash1in`. ~Malcolm
-----Original Message-----
From: Cook, Malcolm
Sent: Tuesday, May 26, 2015 12:17 PM
To: 'Afif Elghraoui'; address@hidden
Subject: RE: Shell for evaluating .SHELLFLAGS
Afif,
Are you trying to get the output from different SQL recipes to go into
different files.
This will be a problem when using sqlite3 as your make .SHELL.
Why? Because the contents of a make recipe is always passed to the .SHELL as a
parameter. Never on stdin. But that is what you need.
Why do you need the recipe on stdin?
Because meta-commands (aka dot commands) such as .output are limited in where
they can appear.
In particular, that are not understood when they appear in the contents of a
multi-line string as the SQL parameter to sqlite3 .
So, the workaround to this problem in general is this one line bash utility
which you use as the .SHELL instead of sqlite3:
#!/bin/env bash
### bash1in: A bash utility script which pipes its last argument to a ###
process gained by executing all but its last argument. Useful in ### Makefiles
where you want the recipes to appear on stdin of some ### command other than
the usual bash shell. For example, to write ### recipes in sqlite3 (allowing
dot-commands), include the following in your Makefile:
### SHELL=./bash1in
### .SHELLFLAGS=sqlite3 ${DB}
### .ONESHELL: # optional
cat <<< "${@:$#}" | "${@:1:$(($# - 1))}"o
Now you can write makefiles like this:
### FILE: sqlite3.test.mk - demonstration of using sqlite3 as ### interpreter
of Make recipes using utility bash script (in same ### directory) `bash1in`.
SHELL=./bash1in
.SHELLFLAGS=sqlite3 ${DB}
.ONESHELL:
${DB}:
CREATE TABLE greeting (g string );
INSERT INTO greeting values("Hello World");
INSERT INTO greeting values("Hello sqlite3");
db.out.schema:
.output $@
.schema
db.out.select.%:
.output $@
select * from $*;
Which can be run like this:
> make -f sqlite3.test.mk DB=db.t
CREATE TABLE greeting (g string );
INSERT INTO greeting values("Hello World"); INSERT INTO greeting values("Hello
sqlite3");
> make -f sqlite3.test.mk DB=db.t db.out.select.greeting
.output db.out.select.greeting
select * from greeting;
> cat db.out.select.greeting
Hello World
Hello sqlite3
> make -f sqlite3.test.mk DB=db.t db.out.schema
.output db.out.schema
.schema
> cat db.out.schema
CREATE TABLE greeting (g string );
What is nice about this approach is that it works with other interpreters.
I've used this approach for instance with the R language as the interpreter.
This should fix ya!
Malcolm Cook
-----Original Message-----
From: address@hidden [mailto:address@hidden On Behalf Of Afif Elghraoui
Sent: Monday, May 25, 2015 11:05 PM
To: address@hidden
Subject: Shell for evaluating .SHELLFLAGS
Hello,
I am trying to use sqlite3 as my Makefile shell. In order to have the query
outputs go to a file, I need to pass a file in to sqlite using its -i flag. I
rely on the process substitution feature in bash for the .SHELLFLAGS to provide
the file:
SHELL=/usr/bin/env sqlite3
.SHELLFLAGS=-init <(echo ".output $@") $(DB)
I get this error:
/bin/sh: 1: Syntax error: "(" unexpected
Makefile:13: recipe for target 'fq' failed
It looks like .SHELLFLAGS is evaluated with /bin/sh regardless of what SHELL is
set to. Is there any way I could evaluate them with bash?
Many thanks and regards
Afif
_______________________________________________
Help-make mailing list
address@hidden
https://lists.gnu.org/mailman/listinfo/help-make