Make:defining macros with filenames that have '$' in them

Geoff Clare gwc at root.co.uk
Mon Mar 5 19:54:23 AEST 1990


In article <1814 at root44.co.uk> I wrote:
>DeadHead at cup.portal.com (Bruce M Ong) writes:
>|I have to include a file with '$' in its name (i.e. abc.$cf) in
>|a macro definition in Make.
>
>gwyn at brl.arpa (Doug Gwyn) writes:
>|Did you try $$ ?
>
>dce at Sony.COM (David Elliott) writes:
>| this isn't a simple question.  After all,
>|once Make tries to do anything with the filename, it uses the shell
>|('$' is in the list of characters that force the use of sh), which
>|will eat the $.
>
>Actually this IS a very simple question.  Just make sure the $ is quoted
>when it is passed to the shell: abc.'$$'cf or 'abc.$$cf' does the trick.

I received some mail from David Elliott pointing out that the intention
in the original question was for the macro to be usable as normal in
dependency lines.  My "single quotes" solution will only work where the
macro is used in commands - if the macro is used in a dependency line,
"make" will look for a file with single quotes in the name.

I apologise for overlooking that requirement, however my answer is still
basically the same: make sure the $ is quoted when passed to the shell.
A way to do this, which allows the macro to work correctly in dependency
lines, is to use a shell variable to "hide" the $ in commands, for example:

FILES = abc.$$cf abd.$$cf

all: $(FILES)
	files='$(FILES)'; cat $$files

-- 
Geoff Clare, UniSoft Limited, Saunderson House, Hayne Street, London EC1A 9HH
gwc at root.co.uk  (Dumb mailers: ...!uunet!root.co.uk!gwc)  Tel: +44-1-315-6600
                                         (from 6th May 1990): +44-71-315-6600



More information about the Comp.unix.wizards mailing list