[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: problems with 'include'

From: Paul D. Smith
Subject: Re: problems with 'include'
Date: Sat, 16 Nov 2002 11:58:26 -0500

%% Justin Chen-Wells <address@hidden> writes:

  jc> In real life I've hacked it to work like this:

  jc>   include2: include1
  jc>           @echo "B := ^(A)" | tr ^ $$> $@

  jc> which winds up writing a literal $(A) to the generated file. 
  jc> This also shows my ignorance about the right way to escape $ 
  jc> in this case. I had wanted to write

  jc>           @echo "B := $$(A)" > $@

  jc> but that doesn't work, so I tricked make with the ^/tr hack.

You just need a bit of education about make and shell
quoting... particularly shell quoting, it looks like.

Remember that there are two things happening: first, make will expand
any make variables in the script.  Then it will send the script to the
shell, and the shell will _also_ expand any _shell_ variables it sees.

Both make and shell use "$" to introduce a variable, so this means you
have to be careful and sometimes double-escape things.

In make, there is only one way to escape a variable, and that is by
using double-$ ("$$").

In shell, there are two ways: first by using a backslash (\$foo) or
second by using single quotes ('$foo').  The shell does not expand
within single quotes but it _DOES_ expand within double quotes
("$foo").  So, your command:

            echo "B := $$(A)" > $@

expands like this: first, make gets into the act and expands the above
to this command line:

    echo "B := $(A)" > include2

and sends that to the shell.  The shell looks at it and sees the "$" and
wants to expand it, but "$(A)" is an illegal shell variable syntax so it
probably gives an error.  You need to quote that "$" for the shell.  You
can do it either with the single-quote solution I posted before:

    echo 'B := $$(A)' > $@

or with a backslash:

    echo "B := \$$(A)" > $@

Like I said, understanding _both_ make and shell quoting is critical to
writing anything more than basic makefiles.


 Paul D. Smith <address@hidden>          Find some GNU make tips at:            
 "Please remain calm...I may be mad, but I am a professional." --Mad Scientist

reply via email to

[Prev in Thread] Current Thread [Next in Thread]