views:

178

answers:

2

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.
A: 

I am not positivie this should work, but the reason it says "missing destination file" is simple:

%.bar: ; cp $< $@

That line says to copy the target from the first dependency. your a:b.bar does not have any dependency, so the cp fails. what did you want it to copy ? a:b.foo ? in that case, you would need:

%.bar: %.foo ; cp $< $@
Bahbar
The general rule has no dependencies, but I supply a first dependency for two specific cases in subsequent rules. Yeah, I didn't realize you could do that either, but it turns out you can. You'll notice it's able to figure out how to create x.bar from x.foo just fine.
zaphod
+3  A: 

I doubt it's possible: see this discussion about colons in Makefiles.

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

Good luck!

martin clayton
good find. That's what I was afraid of when I said I was not positive it should work!
Bahbar