Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Escaping colons in filenames in a Makefile

Tags:

Is there a way to get GNU make to work correctly with filenames that contain colons?

The specific problem I'm running into happens to involve a pattern rule. Here's a simplified version that does not depend on cutting and pasting tab characters:

% make --version GNU Make 3.81 Copyright (C) 2006  Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  This program built for x86_64-redhat-linux-gnu % cat Makefile COLON := \: all: ; true %.bar: ; cp $< $@ x.bar: x.foo %.foo: ; touch $@ a$(COLON)b.bar: a$(COLON)b.foo all: x.bar a$(COLON)b.bar clean: ; rm -f *.foo *.bar % make clean rm -f *.foo *.bar % make touch x.foo cp x.foo x.bar cp  a\:b.bar cp: missing destination file operand after `a:b.bar' Try `cp --help' for more information. make: *** [a\:b.bar] Error 1 

Replacing $(COLON) with a literal : produces exactly the same result. Without the backslash, it does this:

Makefile:6: *** target pattern contains no `%'.  Stop. 
like image 875
zaphod Avatar asked Jan 12 '10 21:01

zaphod


People also ask

What does colon mean in makefile?

In the first line, the list of target names is terminated by a colon. This, in turn, is followed by the dependency list, if there is one. If several targets are listed, this indicates that each such target is to be built independently using the rule supplied.

What is $@ in makefile?

$@ is the name of the target being generated, and $< the first prerequisite (usually a source file). You can find a list of all these special variables in the GNU Make manual.

What does all in makefile do?

This means that when you do a "make all", make always thinks that it needs to build it, and so executes all the commands for that target. Those commands will typically be ones that build all the end-products that the makefile knows about, but it could do anything.


1 Answers

I doubt it's possible: see this discussion about colons in Makefiles. In summary, GNU make has never worked well with filenames that contain whitespace or colons. The maintainer, Paul D. Smith, says that adding support for escaping would tend to break existing makefiles. Furthermore, adding such support would require significant changes to the code.

You might be able to work around with some sort of nasty temporary file arrangement.

Good luck!

like image 145
martin clayton Avatar answered Oct 03 '22 16:10

martin clayton