[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Makefile and shell
From: |
Paul D. Smith |
Subject: |
Re: Makefile and shell |
Date: |
Thu, 4 Oct 2001 09:26:17 -0400 |
%% Melanie Babineau <address@hidden> writes:
mb> I would like to know how to call a shell (including some variables
mb> declarations) in a makefile?
mb> Makefile
mb> . /toto/titi/global_variables => doesn't work
mb> and
mb> $(shell . /toto/titi/global_variables) => doesn't work too
It's not clear to me exactly what you want to do.
If you want to invoke a shell script or program as a subprocess of make,
you can use the $(shell ...) function:
$(shell /toto/titi/global_variables)
The $(shell ...) function always runs its arguments in a subshell,
though, so sourcing things won't do anything useful: they're lost as
soon as the shell exits back to make again.
There is no way for make to "source" a general shell script of course:
make reads makefiles, it doesn't read shell scripts; they are very
different things.
However, it turns out that some of the syntax of a makefile and a shell
script overlap, in particular WRT variable assignment: if you very
carefully construct your shell scripts then they can be both sourced by
the shell _and_ included by the makefile:
include /toto/titi/global_variables
To do this, you must (a) only use simple assignment (can't use make
operators like :=, +=, etc.), must use {} around all variable names
(like ${FOO}; this is valid in both shell and make), etc. One big
problem is you can't really use any quoting because make doesn't strip
it, so something like:
FOO="bar biz baz"
will result in the shell variable $FOO containing `bar biz baz', but the
make variable $(FOO) containing `"bar biz baz"' (with quotes).
It can be tricky, and of course you can't do _ANY_ shell operations like
if or case statements, etc.
But, for simple things it is possible and does work well; I've used it
in the past.
--
-------------------------------------------------------------------------------
Paul D. Smith <address@hidden> Find some GNU make tips at:
http://www.gnu.org http://www.paulandlesley.org/gmake/
"Please remain calm...I may be mad, but I am a professional." --Mad Scientist